Example #1
0
 private bool InstallGripMoveMarker(GameObject target, Action <MonoBehaviour> moveHandler, GuideObject guideObject, bool replaceMaterial, bool installToCenter)
 {
     if (target.transform.Find("_gripmovemarker") == null)
     {
         Renderer   visibleReference = null;
         GameObject gameObject;
         if (installToCenter)
         {
             gameObject       = GameObject.CreatePrimitive(0);
             gameObject.name  = "_gripmovemarker";
             gameObject.layer = LayerMask.NameToLayer("Studio/Select");
             Renderer component = gameObject.GetComponent <Renderer>();
             Material material  = new Material(MaterialHelper.GetColorZOrderShader());
             material.color = new Color(0f, 1f, 0f, 0.3f);
             material.SetFloat("_AlphaRatio", 1.5f);
             material.renderQueue = 3800;
             component.material   = material;
             Transform transform = target.transform.Find("move/XYZ");
             if (transform != null)
             {
                 visibleReference = transform.gameObject.GetComponent <Renderer>();
             }
         }
         else
         {
             gameObject = new GameObject("_gripmovemarker");
             if (replaceMaterial)
             {
                 Renderer component2 = target.GetComponent <Renderer>();
                 if (component2 != null)
                 {
                     Material material2 = new Material(MaterialHelper.GetColorZOrderShader());
                     material2.CopyPropertiesFromMaterial(component2.material);
                     material2.SetFloat("_AlphaRatio", 1.5f);
                     material2.renderQueue = 3800;
                     component2.material   = material2;
                     visibleReference      = component2;
                 }
             }
         }
         SphereCollider sphereCollider = gameObject.AddComponent <SphereCollider>();
         Transform      transform2     = gameObject.transform;
         transform2.transform.parent        = target.transform;
         transform2.transform.localPosition = Vector3.zero;
         transform2.transform.rotation      = guideObject.transformTarget.rotation;
         transform2.transform.localScale    = Vector3.one;
         sphereCollider.isTrigger           = true;
         MoveableGUIObject moveableGUIObject = gameObject.AddComponent <MoveableGUIObject>();
         moveableGUIObject.guideObject = guideObject;
         moveableGUIObject.onMoveLister.Add(moveHandler);
         moveableGUIObject.visibleReference = visibleReference;
         if (installToCenter)
         {
             moveableGUIObject.isMoveObj = true;
         }
         return(true);
     }
     return(false);
 }
Example #2
0
        private void OnScaleReleased(MonoBehaviour marker)
        {
            MoveableGUIObject component   = marker.GetComponent <MoveableGUIObject>();
            GuideObject       guideObject = component.guideObject;
            GuideScale        guideScale  = component.guideScale;

            if (guideObject.enableScale && guideScale)
            {
                marker.transform.localPosition = CalcScaleHandleDefaultPos(guideScale);
            }
        }
Example #3
0
        private bool InstallScaleMoveMarker(GuideObject guideObject)
        {
            Transform transform = guideObject.gameObject.transform.Find("scale");

            if (transform.transform.Find("X/_gripmovemarker_scale") == null)
            {
                foreach (string text in new string[]
                {
                    "XYZ",
                    "X",
                    "Y",
                    "Z"
                })
                {
                    Transform  transform2 = transform.Find(text);
                    GuideScale component  = transform2.gameObject.GetComponent <GuideScale>();
                    if (component != null)
                    {
                        GameObject gameObject = GameObject.CreatePrimitive(0);
                        gameObject.name  = "_gripmovemarker_scale";
                        gameObject.layer = LayerMask.NameToLayer("Studio/Select");
                        Renderer component2 = gameObject.GetComponent <Renderer>();
                        Material material   = new Material(MaterialHelper.GetColorZOrderShader());
                        material.color = new Color(0f, 1f, 1f, 0.3f);
                        material.SetFloat("_AlphaRatio", 1.5f);
                        material.renderQueue = 3800;
                        component2.material  = material;
                        Renderer       component3     = transform2.gameObject.GetComponent <Renderer>();
                        SphereCollider sphereCollider = gameObject.AddComponent <SphereCollider>();
                        Transform      transform3     = gameObject.transform;
                        transform3.transform.parent        = transform2;
                        transform3.transform.localPosition = CalcScaleHandleDefaultPos(component);
                        transform3.transform.rotation      = guideObject.transformTarget.rotation;
                        transform3.transform.localScale    = Vector3.one;
                        sphereCollider.isTrigger           = true;
                        MoveableGUIObject moveableGUIObject = gameObject.AddComponent <MoveableGUIObject>();
                        moveableGUIObject.guideObject = guideObject;
                        moveableGUIObject.guideScale  = component;
                        moveableGUIObject.onMoveLister.Add(new Action <MonoBehaviour>(OnScaleMove));
                        moveableGUIObject.onReleasedLister.Add(new Action <MonoBehaviour>(OnScaleReleased));
                        moveableGUIObject.visibleReference = component3;
                    }
                }
                return(true);
            }
            return(false);
        }
Example #4
0
        private void DoOnMove(MonoBehaviour marker, Transform target, bool rotation = true, bool pos = true)
        {
            MoveableGUIObject component   = marker.GetComponent <MoveableGUIObject>();
            Transform         parent      = marker.transform.parent;
            GuideObject       guideObject = component.guideObject;

            pos      &= guideObject.enablePos;
            rotation &= guideObject.enableRot;
            if (pos)
            {
                target.position += marker.transform.position - parent.transform.position;
                guideObject.transformTarget.transform.position = target.position;
                guideObject.changeAmount.pos = guideObject.transformTarget.localPosition;
            }
            marker.transform.localPosition = Vector3.zero;
            if (rotation)
            {
                guideObject.transformTarget.rotation = marker.transform.rotation;
                guideObject.changeAmount.rot         = guideObject.transformTarget.localEulerAngles;
            }
        }
Example #5
0
        private void OnScaleMove(MonoBehaviour marker)
        {
            MoveableGUIObject component   = marker.GetComponent <MoveableGUIObject>();
            Transform         parent      = marker.transform.parent;
            GuideObject       guideObject = component.guideObject;
            GuideScale        guideScale  = component.guideScale;

            if (guideObject.enableScale && component.guideScale)
            {
                float magnitude = marker.transform.localPosition.magnitude;
                if (magnitude > 0f)
                {
                    float   num    = magnitude / 0.25f;
                    Vector3 vector = component.oldScale;
                    switch (guideScale.axis)
                    {
                    case GuideScale.ScaleAxis.X:
                        vector.x *= num;
                        break;

                    case GuideScale.ScaleAxis.Y:
                        vector.y *= num;
                        break;

                    case GuideScale.ScaleAxis.Z:
                        vector.z *= num;
                        break;

                    case GuideScale.ScaleAxis.XYZ:
                        vector *= num;
                        break;
                    }
                    vector.x = Mathf.Max(vector.x, 0.01f);
                    vector.y = Mathf.Max(vector.y, 0.01f);
                    vector.z = Mathf.Max(vector.z, 0.01f);
                    guideObject.changeAmount.scale = vector;
                }
            }
        }
Example #6
0
 protected override void OnUpdate()
 {
     base.OnUpdate();
     if (controller != null)
     {
         if (controller.GetPressDown(EVRButtonId.k_EButton_Axis1))
         {
             triggerDownTime = Time.time;
         }
         if (controller.GetPressDown(EVRButtonId.k_EButton_Grip))
         {
             gripDownTime = Time.time;
         }
         if (controller.GetPressDown(EVRButtonId.k_EButton_ApplicationMenu))
         {
             menuDownTime = Time.time;
         }
         if (controller.GetPressDown(EVRButtonId.k_EButton_Axis0) || controller.GetPressDown(EVRButtonId.k_EButton_A))
         {
             touchpadDownTime = Time.time;
         }
         if (controller.GetPress(EVRButtonId.k_EButton_Axis1) && controller.GetPress(EVRButtonId.k_EButton_Grip) && controller.GetPress(EVRButtonId.k_EButton_ApplicationMenu) && Time.time - menuDownTime > 0.5f)
         {
             lockRotXZ = !lockRotXZ;
             if (lockRotXZ)
             {
                 ResetRotation();
             }
         }
         if (controller.GetPress(EVRButtonId.k_EButton_ApplicationMenu) && Time.time - menuDownTime > 1.5f)
         {
             resetGUIPosition();
             menuDownTime = Time.time;
         }
         if (controller.GetPressDown(EVRButtonId.k_EButton_Axis0) || controller.GetPressDown(EVRButtonId.k_EButton_A))
         {
             controller.GetPress(EVRButtonId.k_EButton_Grip);
         }
         bool pressDown = controller.GetPressDown(grabScreenButton);
         bool press     = controller.GetPress(grabScreenButton);
         bool pressUp   = controller.GetPressUp(grabScreenButton);
         if (grabHandle == null)
         {
             grabHandle = new GameObject("__GripMoveGrabHandle__");
             grabHandle.transform.parent   = transform;
             grabHandle.transform.position = transform.position;
             grabHandle.transform.rotation = transform.rotation;
         }
         if (pressDown && screenGrabbed && lastGrabbedObject != null && grabHandle != null)
         {
             grabbingObject = lastGrabbedObject;
             grabHandle.transform.position = lastGrabbedObject.transform.position;
             grabHandle.transform.rotation = lastGrabbedObject.transform.rotation;
             if (lastGrabbedObject.GetComponent <MoveableGUIObject>() != null)
             {
                 Transform         parent    = lastGrabbedObject.transform.parent;
                 MoveableGUIObject component = lastGrabbedObject.GetComponent <MoveableGUIObject>();
                 if (component.guideObject != null)
                 {
                     ApplyFingerFKIfNeeded(component.guideObject);
                     grabHandle.transform.rotation     = component.guideObject.transformTarget.rotation;
                     grabbingObject.transform.rotation = component.guideObject.transformTarget.rotation;
                     component.OnMoveStart();
                 }
             }
         }
         bool flag = false;
         if ((controller.GetPressDown(EVRButtonId.k_EButton_Axis0) || controller.GetPressDown(EVRButtonId.k_EButton_A)) && lastGrabbedObject != null && lastGrabbedObject.GetComponent <MoveableGUIObject>() != null)
         {
             GuideObject guideObject = lastGrabbedObject.GetComponent <MoveableGUIObject>().guideObject;
             if (guideObject != null)
             {
                 if (guideObject.guideSelect != null && guideObject.guideSelect.treeNodeObject != null)
                 {
                     guideObject.guideSelect.treeNodeObject.OnClickSelect();
                 }
                 else
                 {
                     Singleton <GuideObjectManager> .Instance.selectObject = guideObject;
                 }
                 flag = true;
             }
         }
         if (controller.GetPressDown(EVRButtonId.k_EButton_Axis0) || (controller.GetPressDown(EVRButtonId.k_EButton_A) && !flag))
         {
             VRLog.Debug("Called on Select VRToggle", new object[0]);
             if (gripMenuHandler && gripMenuHandler.LaserVisible)
             {
                 VRItemObjMoveHelper.Instance.VRToggleObjectSelectOnCursor();
             }
         }
         if (press && grabbingObject != null)
         {
             grabbingObject.transform.position = grabHandle.transform.position;
             grabbingObject.transform.rotation = grabHandle.transform.rotation;
             if (grabbingObject.GetComponent <MoveableGUIObject>() != null)
             {
                 grabbingObject.GetComponent <MoveableGUIObject>().OnMoved();
             }
         }
         if (screenGrabbed && grabbingObject != null && pressUp)
         {
             if (grabbingObject.GetComponent <MoveableGUIObject>() != null)
             {
                 grabbingObject.GetComponent <MoveableGUIObject>().OnReleased();
             }
             grabbingObject = null;
         }
         if (controller.GetPress(moveSelfButton) && grabbingObject == null)
         {
             target = VR.Camera.SteamCam.origin.gameObject;
             if (target != null)
             {
                 if (mirror1 == null)
                 {
                     mirror1 = new GameObject("__GripMoveMirror1__");
                     mirror1.transform.position = transform.position;
                     mirror1.transform.rotation = transform.rotation;
                 }
                 Vector3    vector     = marker.transform.position - transform.position;
                 Quaternion q          = marker.transform.rotation * Quaternion.Inverse(transform.rotation);
                 Quaternion quaternion = RemoveLockedAxisRot(q);
                 Transform  parent2    = target.transform.parent;
                 mirror1.transform.position = transform.position;
                 mirror1.transform.rotation = transform.rotation;
                 target.transform.parent    = mirror1.transform;
                 mirror1.transform.rotation = quaternion * mirror1.transform.rotation;
                 mirror1.transform.position = mirror1.transform.position + vector;
                 target.transform.parent    = parent2;
             }
         }
         lastGrabbedObject         = null;
         nearestGrabable           = float.MaxValue;
         marker.transform.position = transform.position;
         marker.transform.rotation = transform.rotation;
     }
 }