public override void Run() { //左键点击npc请求交互 if (Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { if (hit.collider.tag == "Npc") { if (Mathf.Abs(Vector3.Distance(_playerInputController.transform.position, hit.collider.transform.position)) < 5) { NpcView npcView = hit.collider.GetComponent <NpcView>(); if (npcView.EntityName == "新手引导" || npcView.EntityName == "守村人" || npcView.EntityName == "上水村长" || npcView.EntityName == "工匠" || npcView.EntityName == "店小二" || npcView.EntityName == "刘公子" || npcView.EntityName == "神秘人" || npcView.EntityName == "陈丘村长" || npcView.EntityName == "姑娘" || npcView.EntityName == "钱大娘" || npcView.EntityName == "兽族族长" || npcView.EntityName == "看箱人" || npcView.EntityName == "宝马盗贼") { KBEngine.Event.fireIn("RequestDialog", new object[] { SingletonGather.WorldMediator.CurrentSpaceId, npcView.EntityName }); } if (npcView.EntityName == "商人" || npcView.EntityName == "上水商人" || npcView.EntityName == "钻石商人") { _playerInputController.DoStore(npcView); } } } } } }
/// <summary> /// /// 寻找路径 /// </summary> public void FindPath(int npcId, Vector3 position) { if (Time.unscaledTime > lastRepath + repathRate && seeker.IsDone()) { lastRepath = Time.unscaledTime; var npcMgr = ManagementCenter.GetManager <NpcManager>(); NpcView npcView = npcMgr.GetNpc(npcId) as NpcView; seeker.StartPath(npcView.gameObject.transform.position, position, OnPathComplete); } }
/// <summary> /// 进入状态 /// </summary> public override void Enter() { base.Enter(); myNpcId = npcFsm.GetVar <int>("myNpcId"); var npcMgr = ManagementCenter.GetManager <NpcManager>(); NpcView npc = npcMgr.GetNpc(myNpcId.value) as NpcView; npc.FindPath(myNpcId.value, GetEndPoint()); }
public void DoStore(NpcView npc) { var storePanel = UiManager.instance.TryGetOrCreatePanel("TheStorePanel"); if (storePanel == null) { return; } storePanel.GetComponent <StorePanel>().CurrentNpc = npc; if (!storePanel.activeInHierarchy) { storePanel.SetActive(true); } }
void OnEnable() { npcView = target as NpcView; npcId = serializedObject.FindProperty("npcId"); }
public override void Run() { if (!_characterController.isGrounded) { if (Math.Abs(_moveVector.y - (-2)) > 0) { _moveVector = new Vector3(_moveVector.x, -2, _moveVector.z); } } if (Input.GetMouseButtonDown(1)) { //取消技能预备 _playerInputController.AvatarView.SkillManager.CancelReady(); //右键点击地面移动 Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; LayerMask layerMask = 1 << LayerMask.NameToLayer("Terrian"); if (Physics.Raycast(ray, out hit, 100, layerMask)) { if (_clickPointObject == null) { _clickPointObject = Instantiate(_playerInputController._clickPointAuxiliaryPrefab, hit.point, Quaternion.identity) as GameObject; } else { if (!_clickPointObject.activeInHierarchy) { _clickPointObject.SetActive(true); } _clickPointObject.transform.position = hit.point; } instance.transform.LookAt(new Vector3(hit.point.x, instance.transform.position.y, hit.point.z)); KBEngine.Event.fireIn("RequestMove", new object[] { hit.point }); _playerInputController.AvatarView.Animation.Play("Run"); _playerInputController.AvatarView.DoMove(null); _moveVector = new Vector3(0, 0, 0); _playerInputController.transform.DOLookAt(new Vector3(hit.point.x, _playerInputController.transform.position.y, hit.point.z), 0.0f); _moveVector = _playerInputController.transform.forward * _speed; } } //左键点击npc请求交互 if (Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { if (hit.collider.tag == "Npc") { if (Mathf.Abs(Vector3.Distance(_playerInputController.transform.position, hit.collider.transform.position)) < 5) { NpcView npcView = hit.collider.GetComponent <NpcView>(); if (npcView.EntityName == "新手引导" || npcView.EntityName == "守村人" || npcView.EntityName == "上水村长" || npcView.EntityName == "工匠" || npcView.EntityName == "店小二" || npcView.EntityName == "刘公子" || npcView.EntityName == "神秘人" || npcView.EntityName == "陈丘村长" || npcView.EntityName == "姑娘" || npcView.EntityName == "钱大娘" || npcView.EntityName == "兽族族长" || npcView.EntityName == "看箱人" || npcView.EntityName == "宝马盗贼") { KBEngine.Event.fireIn("RequestDialog", new object[] { SingletonGather.WorldMediator.CurrentSpaceId, npcView.EntityName }); } if (npcView.EntityName == "商人" || npcView.EntityName == "上水商人" || npcView.EntityName == "钻石商人") { _playerInputController.DoStore(npcView); } } } } } if (Input.GetKeyDown(KeyCode.Q)) { int skill_id = 1; _playerInputController.AvatarView.SkillManager.SkillReady(skill_id); } if (Input.GetKeyDown(KeyCode.W)) { int skill_id = 2; _playerInputController.AvatarView.SkillManager.SkillReady(skill_id); } if (Input.GetKeyDown(KeyCode.E)) { int skill_id = 3; _playerInputController.AvatarView.SkillManager.SkillReady(skill_id); } }