summaryrefslogtreecommitdiff
path: root/ActiveRagdoll/Assets/TABG/Scripts/RotateByMouseInput.cs
blob: 3e1ee14efa060f7d22b2c3f391a6199f46daa028 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using UnityEngine;

namespace Rigging
{

    public class RotateByMouseInput : MonoBehaviour
    {
        public enum XSpace
        {
            self,
            world
        }

        public enum YSpace
        {
            self,
            world
        }

        public bool useX;

        public XSpace xSpace;

        public Vector3 xVector;

        public bool useY;

        public YSpace ySpace;

        public Vector3 yVector;

        [Header("Control")]
        public bool needControl;

        public bool needAlive;

        public bool freezeUnusedAngles;

        //private HasControl hasControl;

        //private PlayerDeath death;

        private float m = 1f;

        private void Start()
        {
            //if (needControl)
            //{
            //    hasControl = base.transform.root.GetComponent<HasControl>();
            //}
            //if (needAlive)
            //{
            //    death = base.transform.root.GetComponent<PlayerDeath>();
            //}
        }

        private void LateUpdate()
        {
            //if (needControl && !hasControl.hasControl)
            //{
            //    return;
            //}
            //if (needAlive)
            //{
            //    m = Mathf.Clamp(death.muscleFunction * 2f, 0f, 1f);
            //    if (death.dead)
            //    {
            //        return;
            //    }
            //}
            if (useX)
            {
                Vector3 vector = xVector;
                if (xSpace == XSpace.self)
                {
                    vector = base.transform.TransformDirection(vector);
                }
                base.transform.Rotate(vector * Input.GetAxis("Mouse X") * m * 0.8f, Space.World);
            }
            if (useY)
            {
                Vector3 vector2 = yVector;
                if (ySpace == YSpace.self)
                {
                    vector2 = base.transform.TransformDirection(vector2);
                }
                base.transform.Rotate(vector2 * Input.GetAxis("Mouse Y") * m * 0.8f, Space.World);
            }
            if (!freezeUnusedAngles)
            {
                return;
            }
            if (useY)
            {
                if (yVector.x == 0f)
                {
                    base.transform.localRotation = Quaternion.Euler(0f, base.transform.localEulerAngles.y, base.transform.localEulerAngles.z);
                }
                if (yVector.y == 0f)
                {
                    base.transform.localRotation = Quaternion.Euler(base.transform.localEulerAngles.x, 0f, base.transform.localEulerAngles.z);
                }
                if (yVector.z == 0f)
                {
                    base.transform.localRotation = Quaternion.Euler(base.transform.localEulerAngles.x, base.transform.localEulerAngles.y, 0f);
                }
            }
            if (useX)
            {
                if (xVector.x == 0f)
                {
                    base.transform.localRotation = Quaternion.Euler(0f, base.transform.localEulerAngles.y, base.transform.localEulerAngles.z);
                }
                if (xVector.y == 0f)
                {
                    base.transform.localRotation = Quaternion.Euler(base.transform.localEulerAngles.x, 0f, base.transform.localEulerAngles.z);
                }
                if (xVector.z == 0f)
                {
                    base.transform.localRotation = Quaternion.Euler(base.transform.localEulerAngles.x, base.transform.localEulerAngles.y, 0f);
                }
            }
        }
    }

}