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; private int _followHeroId = -1; public GameObject MainLight; 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); MainLight = camera.transform.Find("MainLight").gameObject; // 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) { CombatHeroEntity[] combatHeroEntities = combatController.CombatHeroController.GetHero(false); if (combatHeroEntities == null) { return; } Vector3 p = Vector3.zero; 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; } MainLight.transform.position = new Vector3(p.x,5.6f,p.z); // Vector3 tp = root.TransformVector(new Vector3(0, 0, -20)); root.position = Vector3.Lerp(root.position, new Vector3(p.x, root.position.y, p.z + 13), 0.1f); } } 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); } } }