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.playerHeroEntity; if (combatHeroEntities == null) { return; } Vector3 p = combatHeroEntities.GameObject.transform.TransformPoint(new Vector3(0, 8, -10)); root.rotation = Quaternion.Lerp(root.rotation, combatHeroEntities.GameObject.transform.rotation, 1); root.position = Vector3.Lerp(root.position, p, 1); } } public void SetPos(Transform target) { Vector3 p = target.TransformPoint(new Vector3(0, 8, -10)); root.rotation = Quaternion.Lerp(root.rotation, target.rotation, 1); root.position = Vector3.Lerp(root.position, p, 1); } 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); } } }