Beispiel #1
0
        public static void UpdateOpacity()
        {
            Transform camTransform  = Camera.main.transform;
            Vector3   primaryTarget = -GlobalState.GetPrimaryControllerUp();
            float     primaryAngle  = Vector3.Angle(primaryTarget, camTransform.forward);

            SetOpacity(VRDevice.PrimaryController, primaryAngle);

            Vector3 secondaryTarget = -GlobalState.GetSecondaryControllerUp();
            float   secondaryAngle  = Vector3.Angle(secondaryTarget, camTransform.forward);

            SetOpacity(VRDevice.SecondaryController, secondaryAngle);
        }
Beispiel #2
0
        private static void SetOpacity(VRDevice device, float angle)
        {
            Transform tooltip = GlobalState.GetTooltipTransform(device, Location.Grip);

            SetOpacity(tooltip, angle);
            tooltip = GlobalState.GetTooltipTransform(device, Location.Trigger);
            SetOpacity(tooltip, angle);
            tooltip = GlobalState.GetTooltipTransform(device, Location.Primary);
            SetOpacity(tooltip, angle);
            tooltip = GlobalState.GetTooltipTransform(device, Location.Secondary);
            SetOpacity(tooltip, angle);
            tooltip = GlobalState.GetTooltipTransform(device, Location.Joystick);
            SetOpacity(tooltip, angle);
        }
Beispiel #3
0
 private void OnAuxiliarySelectedObjectChanged(GameObject previousAuxiliarySelectedObject, GameObject auxiliarySelectedObject)
 {
     if (null != auxiliarySelectedObject)
     {
         image.sprite = grabImage;
         text.text    = "1"; // we can grab only one object outside of the selection
         GlobalState.SetPrimaryControllerDisplayText("Grab 1");
     }
     else
     {
         image.sprite = selectImage;
         SetSelectionCount();
     }
 }
Beispiel #4
0
        public static void SetText(VRDevice device, Location location, Action action, string text, bool visible = true)
        {
            Transform tooltip = GlobalState.GetTooltipTransform(device, location);

            if (null == tooltip)
            {
                return;
            }

            Transform textTransform = tooltip.Find("Canvas/Panel/Text");

            if (null != textTransform)
            {
                TextMeshProUGUI tmpro = textTransform.GetComponent <TextMeshProUGUI>();
                tmpro.text = text;
            }

            string icon = "";

            switch (action)
            {
            case Action.Push: icon = "action-push"; break;

            case Action.HoldPush: icon = "action-hold-push"; break;

            case Action.Horizontal: icon = "action-joystick-horizontal"; break;

            case Action.HoldHorizontal: icon = "action-hold-joystick-horizontal"; break;

            case Action.Vertical: icon = "action-joystick-vertical"; break;

            case Action.HoldVertical: icon = "action-hold-joystick-vertical"; break;

            case Action.Joystick: icon = "action-joystick"; break;
            }
            Transform imageTransform = tooltip.Find("Canvas/Panel/Image");

            if (null != imageTransform)
            {
                Image image = imageTransform.GetComponent <Image>();
                icon         = "empty"; // don't use icon value yet, we don't have any image
                image.sprite = UIUtils.LoadIcon(icon);
            }

            tooltip.gameObject.SetActive(visible);
        }
Beispiel #5
0
        public void OnPaletteClose()
        {
            // security
            if (!GlobalState.Settings.pinnedPalette)
            {
                Debug.LogError("Palette is not pinned, we shouldnt be able to unpin it.");
            }

            // Re-parent to Hand
            paletteRoot.transform.parent = handContainer.transform;
            GlobalState.SetPaletteOnHolder(paletteRoot);
            // Switch system buttons states
            palettePinButton.Disabled   = false;
            paletteCloseButton.Disabled = true;

            GlobalState.Settings.pinnedPalette = false;
        }
Beispiel #6
0
        public static void RemoveConstraint <T>(GameObject gobject) where T : UnityEngine.Component
        {
            T           component  = gobject.GetComponent <T>();
            IConstraint constraint = component as IConstraint;

            ParametersController parametersController = gobject.GetComponent <ParametersController>();

            if (null != parametersController)
            {
                ConstraintType constraintType = ConstraintType.Unknown;
                switch (component)
                {
                case ParentConstraint _:
                    constraintType = ConstraintType.Parent;
                    break;

                case LookAtConstraint _:
                    constraintType = ConstraintType.LookAt;
                    break;
                }

                foreach (Constraint con in constraints)
                {
                    if (con.gobject == gobject && con.constraintType == constraintType)
                    {
                        GameObject.Destroy(con.lineGameObject);
                        constraints.Remove(con);
                        break;
                    }
                }
            }

            GameObject           source = constraint.GetSource(0).sourceTransform.gameObject;
            ParametersController sourceParametersController = source.GetComponent <ParametersController>();

            if (null != sourceParametersController)
            {
                sourceParametersController.RemoveConstraintHolder(gobject);
            }

            constraint.RemoveSource(0);
            GameObject.Destroy(component);
            GlobalState.FireObjectConstraint(gobject);
        }
Beispiel #7
0
        public override GameObject CreateInstance(GameObject source, Transform parent = null, bool isPrefab = false)
        {
            GameObject      newLight        = GameObject.Instantiate(source, parent);
            LightController lightController = source.GetComponentInChildren <LightController>();

            VRInput.DeepSetLayer(newLight, "CameraHidden");

            LightController newController = newLight.GetComponentInChildren <LightController>();

            newController.CopyParameters(lightController);
            GlobalState.castShadowsEvent.AddListener(newController.OnCastShadowsChanged);

            if (!GlobalState.Settings.DisplayGizmos)
            {
                GlobalState.SetGizmoVisible(newLight, false);
            }

            return(newLight);
        }
Beispiel #8
0
        private static void SetOpacity(VRDevice device, float angle)
        {
            Transform controller = GlobalState.GetControllerTransform(device);

            if (null == controller)
            {
                return;
            }

            Transform tooltip = controller.Find("GripButtonAnchor/Tooltip");

            SetOpacity(tooltip, angle);
            tooltip = controller.Find("TriggerButtonAnchor/Tooltip");
            SetOpacity(tooltip, angle);
            tooltip = controller.Find("PrimaryButtonAnchor/Tooltip");
            SetOpacity(tooltip, angle);
            tooltip = controller.Find("SecondaryButtonAnchor/Tooltip");
            SetOpacity(tooltip, angle);
            tooltip = controller.Find("JoystickBaseAnchor/Tooltip");
            SetOpacity(tooltip, angle);
        }
Beispiel #9
0
 public void SaveWindowPosition(Transform window)
 {
     if (window.name == "PaletteHandle")
     {
         if (pinnedPalette)
         {
             palettePositionOffset = window.transform.localPosition;
             paletteRotationOffset = window.transform.localRotation;
         }
         else
         {
             palettePositionOffset = GlobalState.GetPaletteHolder().InverseTransformPoint(window.position);
             paletteRotationOffset = window.rotation * Quaternion.Inverse(GlobalState.GetPaletteHolder().rotation);
         }
     }
     if (window.name == "DopesheetHandle")
     {
         dopeSheetPosition = window.localPosition;
         dopeSheetRotation = window.localRotation;
     }
     if (window.name == "ShotManagerHandle")
     {
         shotManagerPosition = window.localPosition;
         shotManagerRotation = window.localRotation;
     }
     if (window.name == "CameraPreviewHandle")
     {
         cameraPreviewPosition = window.localPosition;
         cameraPreviewRotation = window.localRotation;
     }
     if (window.name == "ConsoleHandle")
     {
         consolePosition = window.localPosition;
         consoleRotation = window.localRotation;
     }
 }
Beispiel #10
0
        public GameObject DuplicateObject(GameObject gobject)
        {
            // Instantiate with the current transfrom
            GameObject copy = InstantiateUnityPrefab(gobject);

            copy.transform.SetParent(gobject.transform.parent, false);

            // Then put it to righthanded
            copy.transform.SetParent(SceneManager.RightHanded, true);

            // Be sure to keep original mesh name
            MeshFilter[] sourceMeshFilters = gobject.GetComponentsInChildren <MeshFilter>();
            if (sourceMeshFilters.Length > 0)
            {
                MeshFilter[] copyMeshFilters = copy.GetComponentsInChildren <MeshFilter>();
                for (int i = 0; i < sourceMeshFilters.Length; ++i)
                {
                    copyMeshFilters[i].mesh.name = sourceMeshFilters[i].mesh.name;
                }
            }

            GlobalState.FireObjectAdded(copy);
            return(copy);
        }
Beispiel #11
0
 public GameObject AddObject(GameObject gobject)
 {
     gobject.transform.SetParent(SceneManager.RightHanded, false);
     GlobalState.FireObjectAdded(gobject);
     return(gobject);
 }
Beispiel #12
0
 public void RemoveObject(GameObject gobject)
 {
     gobject.transform.SetParent(SceneManager.Trash.transform, true);
     GlobalState.FireObjectRemoved(gobject);
 }
Beispiel #13
0
 public void OnRightHanded(bool value)
 {
     GlobalState.SetRightHanded(value);
 }
Beispiel #14
0
 public void OnDisplayAvatars(bool show)
 {
     GlobalState.SetDisplayAvatars(show);
 }
Beispiel #15
0
 public void OnDisplayLocators(bool show)
 {
     GlobalState.SetDisplayLocators(show);
 }
Beispiel #16
0
 public void OnDisplayGizmos(bool show)
 {
     GlobalState.SetDisplayGizmos(show);
 }
Beispiel #17
0
        private const int RT_DEPTH  = 0;//24;

        public override GameObject CreateInstance(GameObject source, Transform parent = null, bool isPrefab = false)
        {
            GameObject newCamera = GameObject.Instantiate(source, parent);

            VRInput.DeepSetLayer(newCamera, "CameraHidden");

            newCamera.GetComponentInChildren <CameraController>(true).CopyParameters(source.GetComponentInChildren <CameraController>(true));

            if (!GlobalState.Settings.DisplayGizmos)
            {
                GlobalState.SetGizmoVisible(newCamera, false);
            }

            // Add UI
            if (isPrefab)
            {
                Transform uiRoot = newCamera.transform.Find("Rotate/Name");

                if (null == uiRoot.Find("Name"))
                {
                    UILabel nameLabel = UILabel.Create(new UILabel.CreateLabelParams
                    {
                        parent       = uiRoot,
                        widgetName   = "Name",
                        caption      = "Camera",
                        width        = 1.4f,
                        height       = 0.25f,
                        labelContent = UILabel.LabelContent.TextOnly,
                    });
                    {
                        TextMeshProUGUI text = nameLabel.gameObject.GetComponentInChildren <TextMeshProUGUI>();
                        text.enableAutoSizing = true;
                        text.fontSizeMin      = 6f;
                        text.fontSizeMax      = 72f;
                        text.alignment        = TextAlignmentOptions.Center;
                    }
                    nameLabel.baseColor.useConstant = true;
                    nameLabel.baseColor.constant    = new Color(0, 0, 0, 0);
                    nameLabel.SetLightLayer(2);
                }

                uiRoot = newCamera.transform.Find("Rotate/UI");
                if (null == uiRoot.Find("Focal"))
                {
                    // Focal slider
                    UISlider focalSlider = UISlider.Create(new UISlider.CreateArgs
                    {
                        parent           = uiRoot,
                        widgetName       = "Focal",
                        caption          = "Focal",
                        currentValue     = 35f,
                        sliderBegin      = 0.15f,
                        sliderEnd        = 0.86f,
                        relativeLocation = new Vector3(-0.30f, -0.03f, -UISlider.default_thickness),
                        width            = 0.3f,
                        height           = 0.02f,
                        railMargin       = 0.002f,
                        knobRadius       = 0.007f
                    });
                    focalSlider.DataCurve = GlobalState.Settings.focalCurve;

                    focalSlider.SetLightLayer(2);
                }

                // In front button
                if (null == uiRoot.Find("InFront"))
                {
                    UIButton inFrontButton = UIButton.Create(new UIButton.CreateButtonParams
                    {
                        parent             = uiRoot,
                        widgetName         = "InFront",
                        caption            = "Always in Front",
                        buttonContent      = UIButton.ButtonContent.ImageOnly,
                        icon               = UIUtils.LoadIcon("back"),
                        width              = 0.02f,
                        height             = 0.02f,
                        iconMarginBehavior = UIButton.IconMarginBehavior.UseIconMargin,
                        iconMargin         = 0.002f,
                        relativeLocation   = new Vector3(-0.30f, -0.005f, -UIButton.default_thickness)
                    });
                    inFrontButton.isCheckable   = true;
                    inFrontButton.baseSprite    = UIUtils.LoadIcon("back");
                    inFrontButton.checkedSprite = UIUtils.LoadIcon("front");
                    inFrontButton.SetLightLayer(2);
                }

                // Touch screen
                uiRoot = newCamera.transform.Find("Rotate/CameraPreview");
                UITouchScreen touchScreen = UITouchScreen.Create(new UITouchScreen.CreateTouchScreenParams
                {
                    parent           = uiRoot,
                    width            = 1f,
                    height           = 1f,
                    thickness        = 0.01f,
                    relativeLocation = new Vector3(-0.5f, 0.5f, -0.03f)
                });
                touchScreen.SetLightLayer(2);
                touchScreen.gameObject.SetActive(false);

                // Focus button
                uiRoot = newCamera.transform.Find("Rotate/UI");
                UIButton focusButton = UIButton.Create(new UIButton.CreateButtonParams
                {
                    parent             = uiRoot,
                    widgetName         = "FocusButton",
                    caption            = "Enable Touch Screen Focus",
                    buttonContent      = UIButton.ButtonContent.ImageOnly,
                    icon               = UIUtils.LoadIcon("dof"),
                    width              = 0.02f,
                    height             = 0.02f,
                    iconMarginBehavior = UIButton.IconMarginBehavior.UseIconMargin,
                    iconMargin         = 0.002f,
                    relativeLocation   = new Vector3(-0.27f, -0.005f, -UIButton.default_thickness)
                });
                focusButton.isCheckable   = true;
                focusButton.baseSprite    = UIUtils.LoadIcon("dof");
                focusButton.checkedSprite = UIUtils.LoadIcon("dof");
                focusButton.SetLightLayer(2);

                // Video output button
                uiRoot = newCamera.transform.Find("Rotate/UI");
                UIButton videoOutputButton = UIButton.Create(new UIButton.CreateButtonParams
                {
                    parent             = uiRoot,
                    widgetName         = "VideoOutputButton",
                    caption            = "Outputs camera to video file",
                    buttonContent      = UIButton.ButtonContent.ImageOnly,
                    icon               = UIUtils.LoadIcon("record_video"),
                    width              = 0.02f,
                    height             = 0.02f,
                    iconMarginBehavior = UIButton.IconMarginBehavior.UseIconMargin,
                    iconMargin         = 0.002f,
                    relativeLocation   = new Vector3(-0.02f, -0.005f, -UIButton.default_thickness)
                });
                videoOutputButton.isCheckable   = true;
                videoOutputButton.baseSprite    = UIUtils.LoadIcon("record_video");
                videoOutputButton.checkedSprite = UIUtils.LoadIcon("record_video");
                videoOutputButton.SetLightLayer(2);

                // Snapshot button
                uiRoot = newCamera.transform.Find("Rotate/UI");
                UIButton snapshotButton = UIButton.Create(new UIButton.CreateButtonParams
                {
                    parent             = uiRoot,
                    widgetName         = "SnapshotButton",
                    caption            = "Outputs camera to image file",
                    buttonContent      = UIButton.ButtonContent.ImageOnly,
                    icon               = UIUtils.LoadIcon("snapshot"),
                    width              = 0.02f,
                    height             = 0.02f,
                    iconMarginBehavior = UIButton.IconMarginBehavior.UseIconMargin,
                    iconMargin         = 0.002f,
                    relativeLocation   = new Vector3(-0.05f, -0.005f, -UIButton.default_thickness)
                });
                snapshotButton.SetLightLayer(2);
            }

            return(newCamera);
        }
Beispiel #18
0
        public static void AddLookAtConstraint(GameObject gobject, GameObject target, int index = -1)
        {
            LookAtConstraint constraint = gobject.GetComponent <LookAtConstraint>();

            if (null == constraint)
            {
                constraint = gobject.AddComponent <LookAtConstraint>();
                ParametersController parametersController = gobject.GetComponent <ParametersController>();
                if (null == parametersController)
                {
                    gobject.AddComponent <ParametersController>();
                }
                Constraint newConstraint = new Constraint {
                    gobject = gobject, target = target.transform, constraintType = ConstraintType.LookAt
                };
                if (index == -1)
                {
                    constraints.Add(newConstraint);
                }
                else
                {
                    constraints.Insert(index, newConstraint);
                }

                ParametersController targetParametersController = target.GetComponent <ParametersController>();
                if (null == targetParametersController)
                {
                    targetParametersController = target.AddComponent <ParametersController>();
                }
                targetParametersController.AddConstraintHolder(gobject);
            }
            else
            {
                // update visual target for LineRenderer
                foreach (Constraint c in constraints)
                {
                    if (c.gobject == gobject && c.constraintType == ConstraintType.LookAt)
                    {
                        c.target = target.transform;
                        break;
                    }
                }
            }
            ConstraintSource source;

            if (constraint.sourceCount == 0)
            {
                source = new ConstraintSource();
                constraint.AddSource(source);
            }
            else
            {
                source = constraint.GetSource(0);
            }

            source.sourceTransform = target.transform;
            source.weight          = 1f;
            constraint.SetSource(0, source);
            constraint.rotationOffset = new Vector3(0, 180, 0);

            constraint.constraintActive = true;

            GlobalState.FireObjectConstraint(gobject);
        }
Beispiel #19
0
        public static void AddParentConstraint(GameObject gobject, GameObject target, int index = -1)
        {
            ParentConstraint constraint = gobject.GetComponent <ParentConstraint>();

            if (null == constraint)
            {
                constraint = gobject.AddComponent <ParentConstraint>();
                ParametersController parametersController = gobject.GetComponent <ParametersController>();
                if (null == parametersController)
                {
                    gobject.AddComponent <ParametersController>();
                }
                Constraint newConstraint = new Constraint {
                    gobject = gobject, target = target.transform, constraintType = ConstraintType.Parent
                };
                if (index == -1)
                {
                    constraints.Add(newConstraint);
                }
                else
                {
                    constraints.Insert(index, newConstraint);
                }
                ParametersController targetParametersController = target.GetComponent <ParametersController>();
                if (null == targetParametersController)
                {
                    targetParametersController = target.AddComponent <ParametersController>();
                }
                targetParametersController.AddConstraintHolder(gobject);
            }
            else
            {
                // update visual target for LineRenderer
                foreach (Constraint c in constraints)
                {
                    if (c.gobject == gobject && c.constraintType == ConstraintType.Parent)
                    {
                        c.target = target.transform;
                        break;
                    }
                }
            }

            ConstraintSource source;

            if (constraint.sourceCount == 0)
            {
                source = new ConstraintSource();
                constraint.AddSource(source);
            }
            else
            {
                source = constraint.GetSource(0);
            }
            source.sourceTransform = target.transform;
            source.weight          = 1f;
            constraint.SetSource(0, source);

            constraint.translationAtRest = gobject.transform.localPosition;
            constraint.rotationAtRest    = gobject.transform.localRotation.eulerAngles;

            Vector3 offset = Vector3.Scale(target.transform.InverseTransformPoint(gobject.transform.position), target.transform.lossyScale);

            constraint.SetTranslationOffset(0, offset);

            Quaternion quat = Quaternion.Inverse(target.transform.rotation) * gobject.transform.rotation;

            constraint.SetRotationOffset(0, quat.eulerAngles);

            constraint.constraintActive = true;

            GlobalState.FireObjectConstraint(gobject);
        }
Beispiel #20
0
 public void RestoreObject(GameObject gobject, Transform parent)
 {
     gobject.transform.SetParent(parent, true);
     GlobalState.FireObjectAdded(gobject);
 }