| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 | 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<StressReceiver>();            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);        }    }}
 |