public void OnSceneGUI()
        {
            bool flag = GUIUtility.hotControl == this.m_HandleControlID;
            CharacterController characterController = (CharacterController)this.target;
            Color color = Handles.color;

            if (characterController.enabled)
            {
                Handles.color = Handles.s_ColliderHandleColor;
            }
            else
            {
                Handles.color = Handles.s_ColliderHandleColorDisabled;
            }
            bool enabled = GUI.enabled;

            if (!Event.current.shift && !flag)
            {
                GUI.enabled   = false;
                Handles.color = new Color(1f, 0f, 0f, 0.001f);
            }
            float num  = characterController.height * characterController.transform.lossyScale.y;
            float num2 = characterController.radius * Mathf.Max(characterController.transform.lossyScale.x, characterController.transform.lossyScale.z);

            num = Mathf.Max(num, num2 * 2f);
            Matrix4x4 matrix     = Matrix4x4.TRS(characterController.transform.TransformPoint(characterController.center), Quaternion.identity, Vector3.one);
            int       hotControl = GUIUtility.hotControl;
            Vector3   vector     = Vector3.up * num * 0.5f;
            float     num3       = CharacterControllerEditor.SizeHandle(vector, Vector3.up, matrix, true);

            if (!GUI.changed)
            {
                num3 = CharacterControllerEditor.SizeHandle(-vector, Vector3.down, matrix, true);
            }
            if (GUI.changed)
            {
                Undo.RecordObject(characterController, "Character Controller Resize");
                float num4 = num / characterController.height;
                characterController.height += num3 / num4;
            }
            num3 = CharacterControllerEditor.SizeHandle(Vector3.left * num2, Vector3.left, matrix, true);
            if (!GUI.changed)
            {
                num3 = CharacterControllerEditor.SizeHandle(-Vector3.left * num2, -Vector3.left, matrix, true);
            }
            if (!GUI.changed)
            {
                num3 = CharacterControllerEditor.SizeHandle(Vector3.forward * num2, Vector3.forward, matrix, true);
            }
            if (!GUI.changed)
            {
                num3 = CharacterControllerEditor.SizeHandle(-Vector3.forward * num2, -Vector3.forward, matrix, true);
            }
            if (GUI.changed)
            {
                Undo.RecordObject(characterController, "Character Controller Resize");
                float num5 = num2 / characterController.radius;
                characterController.radius += num3 / num5;
            }
            if (hotControl != GUIUtility.hotControl && GUIUtility.hotControl != 0)
            {
                this.m_HandleControlID = GUIUtility.hotControl;
            }
            if (GUI.changed)
            {
                characterController.radius = Mathf.Max(characterController.radius, 1E-05f);
                characterController.height = Mathf.Max(characterController.height, 1E-05f);
            }
            Handles.color = color;
            GUI.enabled   = enabled;
        }
Beispiel #2
0
        public void OnSceneGUI()
        {
            bool flag = GUIUtility.hotControl == this.m_HandleControlID;
            CharacterController target = (CharacterController)this.target;
            Color color = Handles.color;

            Handles.color = !target.enabled ? Handles.s_ColliderHandleColorDisabled : Handles.s_ColliderHandleColor;
            bool enabled = GUI.enabled;

            if (!Event.current.shift && !flag)
            {
                GUI.enabled   = false;
                Handles.color = new Color(1f, 0.0f, 0.0f, 1f / 1000f);
            }
            float     a          = target.height * target.transform.lossyScale.y;
            float     num1       = target.radius * Mathf.Max(target.transform.lossyScale.x, target.transform.lossyScale.z);
            float     num2       = Mathf.Max(a, num1 * 2f);
            Matrix4x4 matrix     = Matrix4x4.TRS(target.transform.TransformPoint(target.center), Quaternion.identity, Vector3.one);
            int       hotControl = GUIUtility.hotControl;
            Vector3   localPos   = Vector3.up * num2 * 0.5f;
            float     num3       = CharacterControllerEditor.SizeHandle(localPos, Vector3.up, matrix, true);

            if (!GUI.changed)
            {
                num3 = CharacterControllerEditor.SizeHandle(-localPos, Vector3.down, matrix, true);
            }
            if (GUI.changed)
            {
                Undo.RecordObject((Object)target, "Character Controller Resize");
                float num4 = num2 / target.height;
                target.height += num3 / num4;
            }
            float num5 = CharacterControllerEditor.SizeHandle(Vector3.left * num1, Vector3.left, matrix, true);

            if (!GUI.changed)
            {
                num5 = CharacterControllerEditor.SizeHandle(-Vector3.left * num1, -Vector3.left, matrix, true);
            }
            if (!GUI.changed)
            {
                num5 = CharacterControllerEditor.SizeHandle(Vector3.forward * num1, Vector3.forward, matrix, true);
            }
            if (!GUI.changed)
            {
                num5 = CharacterControllerEditor.SizeHandle(-Vector3.forward * num1, -Vector3.forward, matrix, true);
            }
            if (GUI.changed)
            {
                Undo.RecordObject((Object)target, "Character Controller Resize");
                float num4 = num1 / target.radius;
                target.radius += num5 / num4;
            }
            if (hotControl != GUIUtility.hotControl && GUIUtility.hotControl != 0)
            {
                this.m_HandleControlID = GUIUtility.hotControl;
            }
            if (GUI.changed)
            {
                target.radius = Mathf.Max(target.radius, 1E-05f);
                target.height = Mathf.Max(target.height, 1E-05f);
            }
            Handles.color = color;
            GUI.enabled   = enabled;
        }