using System; using Common.Utility.CombatEvent; using Fort23.Core; using UnityEngine; using Utility; using Utility.CustomizeTimeLogic.FxLogic.TimeLineEvent; using UTool.CustomizeTimeLogic.FxLogic.TimeLineEventinterface; namespace GameLogic.Combat.CombatTool { public class CombatCameraControllder : IDisposable, ICameraShaking { public Transform root; public Camera Camera; public CombatController combatController; public StressReceiver StressReceiver; private bool isStartShake; public int FollowHeroId { get { return _followHeroId; } } private int _followHeroId = -1; public bool isStop; public void Init(CombatController combatController, Camera camera) { this.combatController = combatController; Camera = camera; root = Camera.transform.parent; StressReceiver = camera.transform.GetComponentInParent(); TimeLineSingletonEventManager.Instance.AddTimeLineBasic(this); EventManager.Instance.AddEventListener(CustomEventType.HeroClick, HeroClick); // EventManager.Instance.AddEventListener(CustomEventType.HeroClick, HeroClick); } protected void HeroClick(IEventData eventData) { HeroClickEventData heroClickEventData = eventData as HeroClickEventData; int heroId = heroClickEventData.heroId; if (_followHeroId == heroId) { _followHeroId = -1; } else { _followHeroId = heroId; } } private void ShakeFinish() { isStartShake = false; } public void Update(float t) { if (!isStartShake && !isStop) { CombatHeroEntity combatHeroEntities = combatController.CombatHeroController.followTarget; if (combatHeroEntities == null) { return; } if (combatHeroEntities.isDie) { CombatHeroEntity[] allHero = combatController.CombatHeroController.GetHero(false); if (allHero != null && allHero.Length > 0) { combatHeroEntities = allHero[0]; } } Vector3 p = combatHeroEntities.GameObject.transform.TransformPoint(new Vector3(0, 8, -10)); // Vector3 p = combatHeroEntities.dotPos; // bool isHero = false; // if (_followHeroId != -1) // { // for (int i = 0; i < combatHeroEntities.Length; i++) // { // if (combatHeroEntities[i].CurrCombatHeroInfo.modelID == _followHeroId) // { // p = combatHeroEntities[i].dotPos; // isHero = true; // break; // } // } // } // // if (!isHero) // { // int c = 0; // for (int i = 0; i < combatHeroEntities.Length; i++) // { // if (!combatHeroEntities[i].isDie) // { // c++; // p += combatHeroEntities[i].dotPos; // } // } // // if (c <= 0) // { // return; // } // // p /= c; // } root.rotation = Quaternion.Lerp(root.rotation, combatHeroEntities.GameObject.transform.rotation, 0.3f); // Vector3 tp = root.TransformVector(new Vector3(0, 0, -20)); root.position = Vector3.Lerp(root.position, p, 0.3f); } } public void Dispose() { EventManager.Instance.RemoveEventListener(CustomEventType.HeroClick, HeroClick); } public void Shaking(float qiangDu) { if (StressReceiver != null) { isStartShake = true; StressReceiver.InduceStress(qiangDu, ShakeFinish); } } public void Shaking(CameraShakingSerializtion cameraShakingSerializtion) { Shaking(cameraShakingSerializtion.qiangDu); } } }