using Axibug.Runtime; using UnityEngine; using UnityEditor; using Axibug.Resources; using System.Collections.Generic; using System.Diagnostics.SymbolStore; using System.Runtime.Remoting.Metadata.W3cXsd2001; using System.Linq; using Axibug; using UnityEditor.Graphs; namespace Game { public class BulletMgrNoMono : NoMono { public PrefabPoolForPath _BulletPool; #region 生命周期 public BulletMgrNoMono(string Name, Transform trans = null) : base(Name, trans) { _BulletPool = new PrefabPoolForPath(this.transform, E_PREFAB_TYPE.NONE, Common.GetBulletProfabPath("1")); //注册回调 AddEvent(E_LIFE_MONO_CYCLE.Update | E_LIFE_MONO_CYCLE.FixUpdate); } public override void Update() { } public override void FixedUpdate() { FixedUpdate_BullteCheck(); FixedUpdate_BullteFly(); } public override void OnApplicationPause() { } public override void OnApplicationQuit() { } #endregion #region 执行 class BulletRunState { public Vector3 CenterPos; public float RunStartTime; public BulletGroupCfg cfgs; public bool[] Task_bStart; public bool[] Task_bFinish; public float[] Task_LastDoTime; public int[] Task_Num; public float[] Task_LastAngle; } List _BulletRunList = new List(); List Temp_RemoveRun = new List(); public void AddBulletRun(Vector3 CenterPos,string BulletCfgName) { string path = Common.GetBulletCfgPath(BulletCfgName); BulletGroupCfg cfg = GamePlayEntry.Resources.LoadAsset(path) as BulletGroupCfg; AddBulletRun(CenterPos, cfg); } public void AddBulletRun(Vector3 CenterPos, BulletGroupCfg cfg) { BulletRunState run = new BulletRunState(); run.CenterPos = CenterPos; run.RunStartTime = Time.time; run.cfgs = cfg; int taskcount = cfg.TaskList.Count; run.Task_bStart = new bool[taskcount]; run.Task_bFinish = new bool[taskcount]; run.Task_LastDoTime = new float[taskcount]; run.Task_Num = new int[taskcount]; run.Task_LastAngle = new float[taskcount]; for (int i = 0; i < cfg.TaskList.Count; i++) { run.Task_bStart[i] = false; run.Task_bFinish[i] = false; run.Task_LastDoTime[i] = -1f; run.Task_LastAngle[i] = 0; run.Task_Num[i] = 0; } _BulletRunList.Add(run); } void FixedUpdate_BullteCheck() { Temp_RemoveRun.Clear(); for (int i = 0; i < _BulletRunList.Count; i++) { BulletRunState run = _BulletRunList[i]; //没有未完成 if (!run.Task_bFinish.Contains(false)) { Temp_RemoveRun.Add(run); continue; } for (int j = 0; j < run.Task_bFinish.Length; j++) { //已完成 if (run.Task_bFinish[j]) continue; BulletGroupCfg_Task onecfg = run.cfgs.TaskList[j]; bool bFrie = false; bool bFrist = false; //未开始 判断开始时间 if (!run.Task_bStart[j]) { if (Time.time - run.RunStartTime > onecfg.StartTime) { run.Task_bStart[j] = true; bFrist = true; bFrie = true; } } else//未开始 判断间隔时间 { if (Time.time - run.Task_LastDoTime[j]> onecfg.IntervalTime) { run.Task_bStart[j] = true; bFrie = true; } } //如果发射才执行 if (!bFrie) continue; float FrieAngle; if (bFrist)//如果是第一次 { FrieAngle = onecfg.StartAngle; } else//不是第一次 { FrieAngle = run.Task_LastAngle[j] + onecfg.IntervalAngle; } //修正角度(?可能求余 好一些? if (FrieAngle > 360) FrieAngle -= 360; if (FrieAngle < -360) FrieAngle += 360; run.Task_LastAngle[j] = FrieAngle; run.Task_LastDoTime[j] = Time.time; run.Task_Num[j]++; //TODO 发射 //FrieAngle + onecfg.AfterFireAngle; AddBulletFly(run.CenterPos, onecfg, FrieAngle + onecfg.AfterFireAngle); AxibugLog.Debug("发送弹幕"); //判断是否结束 if (onecfg.bCicircular > 0)//按照圈数 { if (Mathf.Abs(run.Task_Num[j] * onecfg.IntervalAngle) / 360f >= onecfg.bCicircular) run.Task_bFinish[j] = true; } else//不按照圈数,按照数量 { if (run.Task_Num[j] >= onecfg.LimitNum) run.Task_bFinish[j] = true; } } } if (Temp_RemoveRun.Count > 0) { for (int i = 0; i < Temp_RemoveRun.Count; i++) { _BulletRunList.Remove(Temp_RemoveRun[i]); } Temp_RemoveRun.Clear(); ; } } #endregion #region 管理产生的Bullte class BulletFlyState { public Vector3 StartPos; public float StartTime; public float Speed; public Vector3 Dir; public GameObject go; } const float BulletMaxTime = 5f; List _BulletFlyStateList = new List(); List Temp_RemoveFly = new List(); public void FixedUpdate_BullteFly() { Temp_RemoveFly.Clear(); for (int i = 0; i < _BulletFlyStateList.Count; i++) { BulletFlyState fly = _BulletFlyStateList[i]; if (Time.time - fly.StartTime > BulletMaxTime) { Temp_RemoveFly.Add(fly); continue; } //飞行移动 fly.go.transform.position += Time.deltaTime * fly.Speed * fly.Dir; } if (Temp_RemoveFly.Count > 0) { for (int i = 0; i < Temp_RemoveFly.Count; i++) { //回池 Temp_RemoveFly[i].go.SetActive(false); _BulletFlyStateList.Remove(Temp_RemoveFly[i]); } Temp_RemoveFly.Clear(); } } void AddBulletFly(Vector3 Center, BulletGroupCfg_Task cfg,float FrieAngle) { GameObject obj = _BulletPool.GetAnyHide(); //TODO sprite //TODO 音效 //TODO 发射位置偏移(距离中心位置偏移距离 obj.transform.position = Center; _BulletFlyStateList.Add(new BulletFlyState() { Speed = cfg.Speed, StartPos = Center, StartTime = Time.time, Dir = Common.GetVecForAngleXY(FrieAngle), go = obj }); } #endregion } }