diff --git a/Assets/GameAssets/Prefabs/Bullet/1.prefab b/Assets/GameAssets/Prefabs/Bullet/1.prefab index 8d70f79..f312cc6 100644 --- a/Assets/GameAssets/Prefabs/Bullet/1.prefab +++ b/Assets/GameAssets/Prefabs/Bullet/1.prefab @@ -28,7 +28,8 @@ Transform: m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] + m_Children: + - {fileID: 6273990009438270686} m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -91,8 +92,89 @@ BoxCollider: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 3926400312630769306} m_Material: {fileID: 0} - m_IsTrigger: 0 + m_IsTrigger: 1 m_Enabled: 1 serializedVersion: 2 m_Size: {x: 0.5, y: 0.5, z: 0.5} m_Center: {x: 0, y: 0, z: 0} +--- !u!1 &6862467690558022025 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 6273990009438270686} + - component: {fileID: 1223491631508479639} + - component: {fileID: 5437983146542946664} + m_Layer: 0 + m_Name: Capsule + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &6273990009438270686 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6862467690558022025} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 0.2, y: 0.2, z: 0.2} + m_Children: [] + m_Father: {fileID: 1694234330929003566} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!33 &1223491631508479639 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6862467690558022025} + m_Mesh: {fileID: 10208, guid: 0000000000000000e000000000000000, type: 0} +--- !u!23 &5437983146542946664 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6862467690558022025} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 2 + m_RayTraceProcedural: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: 31321ba15b8f8eb4c954353edc038b1d, type: 2} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 + m_AdditionalVertexStreams: {fileID: 0} diff --git a/Assets/GameAssets/ScriptableObjectCfg/BulletCfg.meta b/Assets/GameAssets/ScriptableObjectCfg/BulletCfg.meta new file mode 100644 index 0000000..62914df --- /dev/null +++ b/Assets/GameAssets/ScriptableObjectCfg/BulletCfg.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 8a238977bf9e79e449ad714592bd3539 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/GameAssets/ScriptableObjectCfg/BulletCfg/1.asset b/Assets/GameAssets/ScriptableObjectCfg/BulletCfg/1.asset new file mode 100644 index 0000000..bb9b022 --- /dev/null +++ b/Assets/GameAssets/ScriptableObjectCfg/BulletCfg/1.asset @@ -0,0 +1,42 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 066a4514947a39a4cb32a81dc2c9166d, type: 3} + m_Name: 1 + m_EditorClassIdentifier: + TaskList: + - StartTime: 0 + StartAngle: 0 + IntervalTime: 0.1 + IntervalAngle: 20 + Speed: 5 + sprite: {fileID: 0} + AfterFireAngle: 10 + bCicircular: 0.5 + LimitNum: 10 + - StartTime: 0.6 + StartAngle: 0 + IntervalTime: 0.1 + IntervalAngle: 20 + Speed: 5 + sprite: {fileID: 0} + AfterFireAngle: 10 + bCicircular: 0.5 + LimitNum: 10 + - StartTime: 1.2 + StartAngle: 0 + IntervalTime: 0.1 + IntervalAngle: 20 + Speed: 5 + sprite: {fileID: 0} + AfterFireAngle: 10 + bCicircular: 0.5 + LimitNum: 10 diff --git a/Assets/GameAssets/ScriptableObjectCfg/BulletCfg/1.asset.meta b/Assets/GameAssets/ScriptableObjectCfg/BulletCfg/1.asset.meta new file mode 100644 index 0000000..f2e1cbc --- /dev/null +++ b/Assets/GameAssets/ScriptableObjectCfg/BulletCfg/1.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 6ec85d61b8d0edd498cc2ba2ae16556e +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/GameAssets/ScriptableObjectCfg/BulletCfg/2.asset b/Assets/GameAssets/ScriptableObjectCfg/BulletCfg/2.asset new file mode 100644 index 0000000..effa9b7 --- /dev/null +++ b/Assets/GameAssets/ScriptableObjectCfg/BulletCfg/2.asset @@ -0,0 +1,51 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 066a4514947a39a4cb32a81dc2c9166d, type: 3} + m_Name: 2 + m_EditorClassIdentifier: + TaskList: + - StartTime: 0 + StartAngle: 180 + IntervalTime: 0.1 + IntervalAngle: -20 + Speed: 5 + sprite: {fileID: 0} + AfterFireAngle: 10 + bCicircular: 0.5 + LimitNum: 10 + - StartTime: 0.1 + StartAngle: 180 + IntervalTime: 0.1 + IntervalAngle: -20 + Speed: 5 + sprite: {fileID: 0} + AfterFireAngle: 10 + bCicircular: 0.5 + LimitNum: 10 + - StartTime: 0.2 + StartAngle: 180 + IntervalTime: 0.1 + IntervalAngle: -20 + Speed: 5 + sprite: {fileID: 0} + AfterFireAngle: 10 + bCicircular: 0.5 + LimitNum: 10 + - StartTime: 0.3 + StartAngle: 180 + IntervalTime: 0.1 + IntervalAngle: -20 + Speed: 5 + sprite: {fileID: 0} + AfterFireAngle: 10 + bCicircular: 0.5 + LimitNum: 10 diff --git a/Assets/GameAssets/ScriptableObjectCfg/BulletCfg/2.asset.meta b/Assets/GameAssets/ScriptableObjectCfg/BulletCfg/2.asset.meta new file mode 100644 index 0000000..eee739d --- /dev/null +++ b/Assets/GameAssets/ScriptableObjectCfg/BulletCfg/2.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 27a7474892ef1004e80827daa83ee917 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Main/Common/Common.cs b/Assets/Scripts/Main/Common/Common.cs index 0ff69f7..83adcaf 100644 --- a/Assets/Scripts/Main/Common/Common.cs +++ b/Assets/Scripts/Main/Common/Common.cs @@ -22,13 +22,35 @@ namespace Game return false; } - #region 弹幕 static public string GetBulletProfabPath(string Name) { return $"Assets/GameAssets/Prefabs/Bullet/{Name}.prefab"; ; } + + static public string GetBulletCfgPath(string Name) + { + return "Assets/GameAssets/ScriptableObjectCfg/BulletCfg/" + Name + ".asset"; ; + } + #endregion + + /// + /// 根据角度算向量 + /// + /// + static public Vector3 GetVecForAngleXZ(float angle) + { + return new Vector3(100 * Mathf.Cos(angle * Mathf.PI / 180), 0,100 * Mathf.Sin(angle * Mathf.PI / 180)).normalized; + } + /// + /// 根据角度算向量 + /// + /// + static public Vector3 GetVecForAngleXY(float angle) + { + return new Vector3(100 * Mathf.Cos(angle * Mathf.PI / 180),100 * Mathf.Sin(angle * Mathf.PI / 180),0).normalized; + } } } \ No newline at end of file diff --git a/Assets/Scripts/Main/CustomsComponent/MainPlayerComponent.cs b/Assets/Scripts/Main/CustomsComponent/MainPlayerComponent.cs index fc05798..c5a7bde 100644 --- a/Assets/Scripts/Main/CustomsComponent/MainPlayerComponent.cs +++ b/Assets/Scripts/Main/CustomsComponent/MainPlayerComponent.cs @@ -55,6 +55,10 @@ namespace Game void Update() { Update_MoveForInput(); + + //test + if (Input.GetKeyDown(KeyCode.Z)) GamePlayEntry.BulletMgr.AddBulletRun(GamePlayEntry.MainPlayer.Player.transform.position, "1"); + if (Input.GetKeyDown(KeyCode.X)) GamePlayEntry.BulletMgr.AddBulletRun(GamePlayEntry.MainPlayer.Player.transform.position, "2"); } public void LoadPlayer() diff --git a/Assets/Scripts/Main/CustomsComponent/NoMonoBehaviour/BulletMgrNoMono.cs b/Assets/Scripts/Main/CustomsComponent/NoMonoBehaviour/BulletMgrNoMono.cs index 4c7a655..f01eed9 100644 --- a/Assets/Scripts/Main/CustomsComponent/NoMonoBehaviour/BulletMgrNoMono.cs +++ b/Assets/Scripts/Main/CustomsComponent/NoMonoBehaviour/BulletMgrNoMono.cs @@ -5,6 +5,9 @@ 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 { @@ -28,7 +31,8 @@ namespace Game public override void FixedUpdate() { - + FixedUpdate_BullteCheck(); + FixedUpdate_BullteFly(); } public override void OnApplicationPause() @@ -41,11 +45,205 @@ namespace Game } #endregion - void NewBullet() + #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(); - obj.GetHashCode(); + //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 } } diff --git a/Assets/Scripts/Main/CustomsComponent/NoMonoBehaviour/RoleMgrNoMono.cs b/Assets/Scripts/Main/CustomsComponent/NoMonoBehaviour/RoleMgrNoMono.cs index 2961998..a01ba42 100644 --- a/Assets/Scripts/Main/CustomsComponent/NoMonoBehaviour/RoleMgrNoMono.cs +++ b/Assets/Scripts/Main/CustomsComponent/NoMonoBehaviour/RoleMgrNoMono.cs @@ -24,7 +24,6 @@ namespace Game private float temp_RequestTime = 0; private int mRoleIdSeed = 0; - #region 生命周期 public RoleMgrNoMono(string Name, Transform trans = null) : base(Name, trans) { diff --git a/Assets/Scripts/Main/Definition/ScriptableObject/BulletGroupCfg.cs b/Assets/Scripts/Main/Definition/ScriptableObject/BulletGroupCfg.cs new file mode 100644 index 0000000..847597e --- /dev/null +++ b/Assets/Scripts/Main/Definition/ScriptableObject/BulletGroupCfg.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +[CreateAssetMenu(fileName = "BulletGroupCfg", menuName = "ScriptableObject/创建BulletGroupCfg", order = 0)] +public class BulletGroupCfg : ScriptableObject +{ + public List TaskList; + + public BulletGroupCfg() + { + TaskList = new List(); + } +} + +[Serializable] +public class BulletGroupCfg_Task +{ + /// + /// 开始时间(距离释放时间) + /// + public float StartTime; + + /// + /// 开始角度 + /// + public float StartAngle; + + /// + /// 每次间隔时间 + /// + public float IntervalTime; + /// + /// 每次间隔角度 + /// + public float IntervalAngle; + + /// + /// 速度 + /// + public float Speed = 5; + + public Sprite sprite; + /// + /// 发射后的相对角度 + /// + public float AfterFireAngle; + + /// + /// 是否圆周 [0]不使用圆周限制 [1] [2] [3] 限制周数 + /// + public float bCicircular; + + /// + /// 最大数量(如果不是圆) + /// + public float LimitNum; +} diff --git a/Assets/Scripts/Main/Definition/ScriptableObject/BulletGroupCfg.cs.meta b/Assets/Scripts/Main/Definition/ScriptableObject/BulletGroupCfg.cs.meta new file mode 100644 index 0000000..93d1ba7 --- /dev/null +++ b/Assets/Scripts/Main/Definition/ScriptableObject/BulletGroupCfg.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 066a4514947a39a4cb32a81dc2c9166d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Main/Definition/ScriptableObject/MapMonsterCfg.cs b/Assets/Scripts/Main/Definition/ScriptableObject/MapMonsterCfg.cs index 4461a8f..d57fa45 100644 --- a/Assets/Scripts/Main/Definition/ScriptableObject/MapMonsterCfg.cs +++ b/Assets/Scripts/Main/Definition/ScriptableObject/MapMonsterCfg.cs @@ -3,7 +3,7 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; -[CreateAssetMenu(fileName = "BulletData", menuName = "ScriptableObject/子弹数据", order = 0)] +[CreateAssetMenu(fileName = "MapMonsterCfg", menuName = "ScriptableObject/创建MapMonsterCfg", order = 0)] public class MapMonsterCfg : ScriptableObject { public int MapID; diff --git a/Assets/Scripts/Main/ObjPool/PrefabPoolForPath.cs b/Assets/Scripts/Main/ObjPool/PrefabPoolForPath.cs index 7de4920..6ec76d8 100644 --- a/Assets/Scripts/Main/ObjPool/PrefabPoolForPath.cs +++ b/Assets/Scripts/Main/ObjPool/PrefabPoolForPath.cs @@ -57,6 +57,7 @@ public class PrefabPoolForPath mb_vParentTf = tfParent; switch (mb_vPrefabType) { + case E_PREFAB_TYPE.NONE: case E_PREFAB_TYPE.EFFECT: mb_vPrefabPath = prefabPath; break;