using CaoCao.Event; using CaoCao.Runtime; //using Cysharp.Threading.Tasks; //using FairyGUI; using System.Collections; using System.Collections.Generic; using UnityEngine; namespace Game { public class MainPlayerComponent : GameComponent { private Transform mainCamer; public GameObject Role; private Animator _animator; private UnityEngine.AI.NavMeshAgent _agent; private bool _bStartMove = false; private Vector3 _vMoveOffset = Vector3.zero; private float _rotationSpeed = 50; //public async UniTask LoadMainRole() //{ // mainCamer = Camera.main.transform; // var handle = ResMgr.LoadAsyn("Assets/GameAssets/role/Prefab/role_Skin1"); // await handle.ToUniTask(); // var go = handle.AssetObject as GameObject; // Role = Object.Instantiate(go, transform); // Role.transform.position = new Vector3(43.16f, 0.23f, 10.24f); // mainCamer.parent.position = Role.transform.position; // _agent = Role.AddComponent(); // _agent.angularSpeed += 50; // _agent.updateRotation = false; // _animator = Role.GetComponent(); // _bStartMove = false; // _vMoveOffset = Vector3.zero; // AppEntry.Event.Subscribe(PlayerMoveEventArgs.EventId, OnMoveCallback); //} //private void OnMoveCallback(object sender, LogicEventArgs e) //{ // PlayerMoveEventArgs args = (PlayerMoveEventArgs)e; // if (args == null) // return; // if (args.mIsMove) // { // if (args.mMoveDir == Vector3.zero) // return; // if (!_animator.GetBool("Run")) // { // _animator.SetBool("Run", true); // _agent.isStopped = false; // } // } // else // { // _animator.SetBool("Run", false); // } // Log.Debug($"{args.mIsMove}, {args.mMoveDir}"); // _bStartMove = args.mIsMove; // _vMoveOffset = args.mMoveDir; //} public Vector2 GetClickScreenPos() { //移动端 if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer) { if (Input.touchCount == 0) return Vector2.zero; // 手指刚触摸到屏幕的时候 手指在屏幕上移动 if (Input.GetTouch(0).phase != TouchPhase.Began && Input.GetTouch(0).phase != TouchPhase.Moved) return Vector2.zero; return Input.GetTouch(0).position; } //其它平台 else { if (!Input.GetMouseButtonDown(0)) return Vector2.zero; return Input.mousePosition; } } Vector2 clickPos; private void FixedUpdate() { if (_bStartMove) Move(Role.transform.position + _vMoveOffset); else if(_agent != null) { if (!_agent.isStopped) { _agent.isStopped = true; Move(Role.transform.position); } } } public void Move(Vector3 pos) { // 直接设置物体的朝向 Role.transform.forward = _vMoveOffset; _agent.SetDestination(pos); } private void Update() { if (mainCamer == null) return; if (Role == null) return; mainCamer.parent.position = Role.transform.position; } } }