예제 #1
0
        public override void OnInspectorGUI()
        {
            script = handle = (HandleDefinition)target;
            ItemDefinition item = handle.transform.GetComponentInParent <ItemDefinition>();

            PointToPointButton(handle.axisLength);

            base.OnInspectorGUI();

            if (GUILayout.Button("Calculate Reach") && item)
            {
                handle.CalculateReach();
            }

            if (GUILayout.Button("Update to new orientations") && item)
            {
                handle.CheckOrientations();
            }

            if (handle.allowedOrientations.Count > 0)
            {
                EditorGUILayout.HelpBox("The allowed orientations list is obsolete, Use child HandleOrientation instead.", MessageType.Warning);
            }

            if (handle.transform.localScale != Vector3.one)
            {
                EditorGUILayout.HelpBox("Handle object scale must be set to 1.", MessageType.Error);
            }

            if (handle.axisLength < 0)
            {
                EditorGUILayout.HelpBox("Handle axis length must be a positive number or zero.", MessageType.Error);
            }

            if (handle.touchRadius <= 0)
            {
                EditorGUILayout.HelpBox("Handle touch radius must be a positive number.", MessageType.Error);
            }

            if (handle.reach <= 0)
            {
                EditorGUILayout.HelpBox("Handle reach must be a positive number.", MessageType.Error);
            }

            if (handle.slideToHandleOffset <= 0)
            {
                EditorGUILayout.HelpBox("Slide to handle offset must be a positive number.", MessageType.Error);
            }
        }
예제 #2
0
        public void AlignObject()
        {
            Animator  animator      = this.GetComponentInParent <Animator>();
            Transform rightHandBone = animator.GetBoneTransform(HumanBodyBones.RightHand);
            Transform leftHandBone  = animator.GetBoneTransform(HumanBodyBones.LeftHand);

            if (this.transform.parent.parent != rightHandBone)
            {
                Debug.LogError("HandPoseDefinition is not correctly placed, should be HandRightBone/BodyHand/HandPoseDefinition");
                return;
            }

            handleReference.CheckOrientations();
            HandleOrientation handleOrientation = handleReference.orientationDefaultRight;

            if (side == Side.Left)
            {
                handleOrientation = handleReference.orientationDefaultLeft;
            }

            if (handleOrientationIndex > 0)
            {
                int i = 0;
                foreach (HandleOrientation ho in handleReference.orientations)
                {
                    if (handleReference.orientationDefaultLeft == ho)
                    {
                        continue;
                    }
                    if (handleReference.orientationDefaultRight == ho)
                    {
                        continue;
                    }
                    if (ho.side == side)
                    {
                        if ((handleOrientationIndex - 1) == i)
                        {
                            handleOrientation = ho;
                        }
                        i++;
                    }
                }
            }

            if (handleOrientation)
            {
                ItemDefinition objectDefinition = handleReference.GetComponentInParent <ItemDefinition>();

                Transform objectGrip = new GameObject("ObjectGrip").transform;
                objectGrip.SetParent(objectDefinition ? objectDefinition.transform : handleReference.transform.root);
                objectGrip.position = handleOrientation.transform.position + (handleOrientation.handleDefinition.transform.up * handleOrientation.handleDefinition.GetDefaultAxisLocalPosition());
                objectGrip.rotation = handleOrientation.transform.rotation;

                Transform alignObject = handleReference.transform.root;
                if (objectDefinition != null)
                {
                    alignObject = objectDefinition.transform;
                }

                Transform handGripRight = this.transform.parent.Find("HandGrip");
                if (!handGripRight)
                {
                    handGripRight = new GameObject("HandGrip").transform;
                    handGripRight.SetParent(this.transform.parent);
                }
                handGripRight.localPosition = gripLocalPosition;
                handGripRight.localRotation = Quaternion.Euler(gripLocalRotation);

                if (side == Side.Right)
                {
                    alignObject.MoveAlign(objectGrip, handGripRight.position, handGripRight.rotation);
                }
                else
                {
                    Transform bodyHandLeft = leftHandBone.Find("BodyHand");
                    if (!bodyHandLeft)
                    {
                        bodyHandLeft = new GameObject("BodyHand").transform;
                        bodyHandLeft.SetParent(leftHandBone);
                        bodyHandLeft.localPosition = Vector3.zero;
                        bodyHandLeft.localRotation = Quaternion.Euler(90, 0, 0);
                    }
                    Transform handGripLeft = bodyHandLeft.Find("HandGrip");
                    if (!handGripLeft)
                    {
                        handGripLeft = new GameObject("HandGrip").transform;
                        handGripLeft.SetParent(bodyHandLeft);
                    }
                    handGripLeft.localPosition = gripLocalPosition;
                    handGripLeft.localRotation = Quaternion.Euler(gripLocalRotation);
                    handGripLeft.MirrorRelativeToParent(new Vector3(-1, 1, 1));
                    handGripLeft.localScale = Vector3.one;
                    alignObject.MoveAlign(objectGrip, handGripLeft.position, handGripLeft.rotation);
                }

                DestroyImmediate(objectGrip.gameObject);
            }
            else
            {
                Debug.LogError("No orientation set on the handle!");
            }
        }