少年修仙传客户端代码仓库
hch
2025-01-08 dbb7a55e47da81a8c7c2b4bff7e053ff36af3d5a
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
using UnityEngine;
using UnityEngine.AI;
 
public class TestPlayerController : MonoBehaviour
{
    public float speed = 5;
    private NavMeshPath m_Path;
    private Animator m_Animator;
 
    private int m_CurrentIndex;
    private bool m_IsStartFinding = false;
 
    private bool m_StartedRotateCamera;
    private bool m_MousePressed = false;
    private Vector3 m_PreMousePos;
 
    private float m_RecordDist;
    private float m_RecordRotX;
    private float m_RecordRotY;
 
    private void Awake()
    {
        if (CameraController.Instance == null)
        {
            var prefab = Instantiate(BuiltInLoader.LoadPrefab("GameCamera"));
            CameraController.Instance.SetcamerePrefab(prefab);
        }
        CameraController.Instance.SetLookTarget(transform);
 
        m_Path = new NavMeshPath();
 
        m_Animator = gameObject.AddMissingComponent<Animator>();
        SystemSetting.Instance.SetQualityLevel(GameQuality.High);
 
        var shadowPrefab = BuiltInLoader.LoadPrefab("ActorShadowCaster");
        var shadowCaster = Instantiate(shadowPrefab).GetComponent<ActorShadowCaster>();
 
        if (shadowCaster != null)
        {
            shadowCaster.Follow(this.transform.Find("A_Name"));
            shadowCaster.Cast(this.transform);
            shadowCaster.SetActive(true);
        }
    }
 
    // 9 -45 40
    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.F1))
        {
            m_StartedRotateCamera = !m_StartedRotateCamera;
 
            if (m_StartedRotateCamera)
            {
                CameraController.Instance.Distance = 11;
                CameraController.Instance.rotationX = -110;
                CameraController.Instance.rotationY = 50;
            }
            else
            {
                CameraController.Instance.Distance = 9;
                CameraController.Instance.rotationX = -45;
                CameraController.Instance.rotationY = 40;
            }
        }
 
        if (Input.GetMouseButtonDown(0))
        {
            if (CameraController.Instance == null)
            {
                return;
            }
 
            Camera _mainCamera = CameraController.Instance.CameraObject;
 
            RaycastHit _hitInfo;
            Ray _ray = _mainCamera.ScreenPointToRay(Input.mousePosition);
 
            if (Physics.Raycast(_ray, out _hitInfo, 100, LayerUtility.WalkbleMask))
            {
                NavMeshHit _hit;
 
                Vector3 _c = transform.position;
                _c.y = 0;
                Vector3 _p = _hitInfo.point;
                _p.y = 0;
 
                if (NavMesh.SamplePosition(_p, out _hit, 10, NavMesh.AllAreas))
                {
                    NavMesh.CalculatePath(_c, _hit.position, NavMesh.AllAreas, m_Path);
                    m_IsStartFinding = true;
                    m_CurrentIndex = 0;
                    m_Animator.SetInteger(GAStaticDefine.Param_Action, GAStaticDefine.Act_Run);
                }
                else
                {
                    transform.position = _hitInfo.point;
                }
            }
        }
 
        if (!m_IsStartFinding)
        {
            return;
        }
 
        if (m_Path.corners != null)
        {
            Vector3 _current;
            if (m_CurrentIndex > m_Path.corners.Length - 1 || m_CurrentIndex < 0)
            {
                m_IsStartFinding = false;
                m_Animator.SetInteger(GAStaticDefine.Param_Action, GAStaticDefine.Act_Idle);
                return;
            }
            if (m_Path.corners.Length == 1)
            {
                _current = m_Path.corners[0];
            }
            else
            {
                _current = m_Path.corners[1];
            }
 
            Vector3 _currentPosition = transform.position;
            _current.y = 0;
            _currentPosition.y = 0;
 
            float _chkDistSqrt = MathUtility.DistanceSqrtXZ(_current, transform.position);
 
            Vector3 _dir = (_current - _currentPosition).normalized;
            _dir.y = 0;
            if (_dir != Vector3.zero)
            {
                transform.forward = _dir;
            }
            Vector3 _detla = speed * Time.deltaTime * _dir;
            _detla.y = 0;
            _currentPosition += _detla;
 
            RaycastHit _hitInfo;
 
            if (Physics.Raycast(_currentPosition + new Vector3(0, 50, 0), Vector3.down, out _hitInfo, 100, 1 << LayerMask.NameToLayer("WalkbleLayer")))
            {
                transform.position = _hitInfo.point;
            }
 
            if (_chkDistSqrt < Mathf.Pow(speed * Time.deltaTime, 2))
            {
                transform.position = new Vector3(_current.x, transform.position.y, _current.z);
                m_CurrentIndex += 1;
 
                if (m_CurrentIndex > m_Path.corners.Length - 1)
                {
                    m_IsStartFinding = false;
                    m_Animator.SetInteger(GAStaticDefine.Param_Action, GAStaticDefine.Act_Idle);
                }
            }
        }
    }
}