/// <summary> /// 更新鼠标输入 /// </summary> private void UpdateMouseInput() { if (Input.GetMouseButtonDown(0) || (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)) { #if UNITY_IPHONE || UNITY_ANDROID if (!EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId)) #else if (!EventSystem.current.IsPointerOverGameObject()) #endif { Ray ray = _camera.ScreenPointToRay(Input.mousePosition); RaycastHit hitInfo; if (Physics.Raycast(ray, out hitInfo)) { int layer = hitInfo.collider.gameObject.layer; if (layer == LayerMask.NameToLayer("Map")) { Move(hitInfo.point); //Vector pos = new Vector { x = hitInfo.point.x, y = hitInfo.point.y, z = hitInfo.point.z }; //NetworkManager.instance.Send(SceneProtocol.CharMove_CREQ, new ReqCharacterMove { pos = pos }); } else if (layer == LayerMask.NameToLayer("Role")) { // 设定锁定目标 IDAgent idAgent = hitInfo.collider.GetComponent <IDAgent>(); _lockedTarget = CharacterManager.instance.GetCharacter(idAgent.globalID); // 设置拣选标记的位置 _targetTip.parent = hitInfo.collider.transform; _targetTip.position = hitInfo.collider.transform.position; } } } } }
public Character(int globalid, RoleCfg roleCfg, Vector3 position) { _globalID = globalid; _cfg = roleCfg; // 通过配置获取原始属性 _originAttr = CharacterAttr.GetAttr(roleCfg); // 获取当前属性 _currAttr = _originAttr.Clone(); // 对象池创建对象 _transform = (PoolManager.instance.Spawn("Units/", _cfg.ModelName)).transform; _transform.position = position; _transform.localScale = Vector3.one; _navmeshAgent = _transform.gameObject.GetComponent <UnityEngine.AI.NavMeshAgent>(); if (_navmeshAgent == null) { _navmeshAgent = _transform.gameObject.AddComponent <UnityEngine.AI.NavMeshAgent>(); } _navmeshAgent.speed = _originAttr.MoveSpeed; _navmeshAgent.enabled = false; _navmeshAgent.angularSpeed = 180; _animation = _transform.gameObject.GetComponent <Animation>(); // 在角色的GameObject上添加一个碰撞器 _collider = _transform.gameObject.GetComponent <CapsuleCollider>(); if (_collider == null) { _collider = _transform.gameObject.AddComponent <CapsuleCollider>(); } _collider.center = new Vector3(0, 1, 0); _collider.height = 2; // 添加ID代理 _idAgent = _transform.gameObject.GetComponent <IDAgent>(); if (_idAgent == null) { _idAgent = _transform.gameObject.AddComponent <IDAgent>(); } _idAgent.globalID = globalid; // 创建角色拥有的技能发射器 _skillCasters = new Dictionary <int, SkillCaster>(); Dictionary <int, SkillGroupCfg> skillGroupCfgs = ConfigManager.instance.GetSkillGroupCfgs(_cfg.ID); foreach (SkillGroupCfg cfg in skillGroupCfgs.Values) { SkillCaster caster = new SkillCaster(this); caster.SkillBasicCfg = ConfigManager.instance.GetSkillBasicCfg(cfg.ID); caster.SkillBulletCfg = ConfigManager.instance.GetSkillBulletCfg(cfg.ID); caster.SkillAOECfg = ConfigManager.instance.GetSkillAOECfg(cfg.ID); caster.SkillBuffCfg = ConfigManager.instance.GetSkillBuffCfg(cfg.ID); caster.SkillTrapCfg = ConfigManager.instance.GetSkillTrapCfg(cfg.ID); if (!_skillCasters.ContainsKey(cfg.ID)) { _skillCasters.Add(cfg.ID, caster); } } }