Exemplo n.º 1
0
        /// <summary>
        /// Allows us to render joint info into the scene. This GUI is
        /// used for displaying and manipulating the joint itself.
        /// </summary>
        /// <returns></returns>
        public override bool OnSceneConstraintGUI(bool rIsSelected)
        {
            bool lIsDirty = false;

#if UNITY_EDITOR
            //Color lLineColor = new Color(0f, 1f, 1f, 0.25f);
            //Color lFillColor = new Color(0f, 1f, 1f, 0.05f);
            Color lHandleColor = Handles.color;

            // Render out the twist limit
            if (_AllowTwist && _LimitTwist)
            {
                bool lIsLimitsDirty = HandlesHelper.JointTwistLimitsHandle(mBone, ref _MinTwistAngle, ref _MaxTwistAngle);
                if (lIsLimitsDirty)
                {
                    lIsDirty = true;
                }
            }

            // Reset
            Handles.color = lHandleColor;
#endif

            return(lIsDirty);
        }
        /// <summary>
        /// Allows us to render joint info into the scene. This GUI is
        /// used for displaying and manipulating the joint itself.
        /// </summary>
        /// <returns></returns>
        public override bool OnSceneConstraintGUI(bool rIsSelected)
        {
            bool lIsDirty = false;

#if UNITY_EDITOR
            //Vector3 lBoneForward = mBone.BoneForward;

            //Color lLineColor = new Color(0f, 1f, 1f, 0.25f);
            //Color lFillColor = new Color(0f, 1f, 1f, 0.05f);
            Color lHandleColor = Handles.color;

            //Quaternion lWorldBind = mBone.WorldBindRotation;

            // Render out the swing limits
            if (_LimitSwing)
            {
                bool lIsLimitsDirty = HandlesHelper.JointSwingAxisLimitsHandle(mBone, _SwingAxis, _MinSwingAngle, _MaxSwingAngle);
                if (lIsLimitsDirty)
                {
                    lIsDirty = true;
                }
            }

            // Render out the twist limit
            if (_AllowTwist && _LimitTwist)
            {
                bool lIsLimitsDirty = HandlesHelper.JointTwistLimitsHandle(mBone, ref _MinTwistAngle, ref _MaxTwistAngle);
                if (lIsLimitsDirty)
                {
                    lIsDirty = true;
                }
            }

            // Reset
            Handles.color = lHandleColor;
#endif

            return(lIsDirty);
        }
        /// <summary>
        /// Allow for rendering in the editor
        /// </summary>
        /// <returns></returns>
        public override bool OnSceneConstraintGUI(bool rIsSelected)
        {
            bool lIsDirty = false;

#if UNITY_EDITOR
            float lPositionScale = 0.08f;
            if (Bone.Skeleton.EditorAutoScaleHandles)
            {
                lPositionScale = HandleUtility.GetHandleSize(Bone.Transform.position) * HandlesHelper.HandleScale * 0.9f;
            }

            Color lLineColor   = new Color(0.94118f, 0.39608f, 0.13333f, 1f);
            Color lFillColor   = new Color(0.94118f, 0.39608f, 0.13333f, 0.2f);
            Color lHandleColor = Handles.color;

            Quaternion lWorldBind = Bone.WorldBindRotation;

            // Render out the swing limits
            if (_LimitSwing)
            {
                Handles.color = Color.white;

                // If we have an invalid reach cone, report it
                for (int i = 0; i < mReachCones.Length; i++)
                {
                    if (!mReachCones[i].IsVisiblePointValid)
                    {
                        lFillColor = new Color(1f, 0f, 0f, 1.0f);
                        lLineColor = new Color(1f, 0f, 0f, 1.0f);
                    }
                }

                for (int i = 0; i < mReachPoints.Length; i++)
                {
                    int iPlus1 = (i + 1) % mReachPoints.Length;

                    Vector3[] lVertices = new Vector3[4];
                    lVertices[0] = Bone.Transform.position;
                    lVertices[1] = Bone.Transform.position;
                    lVertices[2] = Bone.Transform.position + (lWorldBind * mReachPoints[i] * lPositionScale);
                    lVertices[3] = Bone.Transform.position + (lWorldBind * mReachPoints[iPlus1] * lPositionScale);

                    Handles.DrawSolidRectangleWithOutline(lVertices, lFillColor, lLineColor);

                    //Log.ConsoleWrite("Color: " + lFillColor.ToString());
                }
            }

            // Render out the twist limit
            if (_LimitTwist)
            {
                bool lIsLimitsDirty = HandlesHelper.JointTwistLimitsHandle(mBone, ref _MinTwistAngle, ref _MaxTwistAngle);
                if (lIsLimitsDirty)
                {
                    lIsDirty = true;
                }
            }

            // Only show the boundary points if we're in editor mode
            if (mIsEditing)
            {
                float lHandleScale = HandleUtility.GetHandleSize(Bone.Transform.position) * HandlesHelper.HandleScale * 0.1f;

                // Render out the code that is limiting the swing
                for (int i = 0; i < BoundaryPoints.Count; i++)
                {
                    GUI.color = new Color(0.72549f, 0.30588f, 0.10588f, 1f);
                    Handles.Label(Bone.Transform.position + (lWorldBind * (BoundaryPoints[i] * (lPositionScale + 0.01f))), (i + 1).ToString());

                    Vector3 lWorldPosition = Bone.Transform.position + (lWorldBind * (BoundaryPoints[i] * lPositionScale));

                    Handles.color = (i == mSelectedPoint ? Color.yellow : new Color(0.94118f, 0.39608f, 0.13333f, 1f));
#if UNITY_4 || UNITY_5_0 || UNITY_5_1 || UNITY_5_2 || UNITY_5_3 || UNITY_5_4 || UNITY_5_5
                    if (Handles.Button(lWorldPosition, Quaternion.identity, lHandleScale, lHandleScale, Handles.SphereCap))
#else
                    if (Handles.Button(lWorldPosition, Quaternion.identity, lHandleScale, lHandleScale, Handles.SphereHandleCap))
#endif
                    {
                        lIsDirty       = true;
                        mSelectedPoint = i;
                    }

                    if (i == mSelectedPoint)
                    {
                        Vector3 lNewPosition = Handles.PositionHandle(lWorldPosition, Quaternion.identity);
                        if (lNewPosition != lWorldPosition)
                        {
                            lIsDirty = true;

                            lNewPosition      = (lWorldBind.Conjugate() * (lNewPosition - Bone.Transform.position)) / lPositionScale;
                            BoundaryPoints[i] = lNewPosition.normalized;

                            BuildReachCones();
                        }
                    }
                }
            }

            // Reset
            Handles.color = lHandleColor;
#endif

            return(lIsDirty);
        }