diff --git a/DungeonShooting_Godot/excel/excelFile/ActivityBase.xlsx b/DungeonShooting_Godot/excel/excelFile/ActivityBase.xlsx index 140a58a..ea04d05 100644 --- a/DungeonShooting_Godot/excel/excelFile/ActivityBase.xlsx +++ b/DungeonShooting_Godot/excel/excelFile/ActivityBase.xlsx Binary files differ diff --git a/DungeonShooting_Godot/excel/excelFile/ActivityMaterial.xlsx b/DungeonShooting_Godot/excel/excelFile/ActivityMaterial.xlsx index fbedd99..40ffb48 100644 --- a/DungeonShooting_Godot/excel/excelFile/ActivityMaterial.xlsx +++ b/DungeonShooting_Godot/excel/excelFile/ActivityMaterial.xlsx Binary files differ diff --git a/DungeonShooting_Godot/excel/excelFile/AiAttackAttr.xlsx b/DungeonShooting_Godot/excel/excelFile/AiAttackAttr.xlsx index 41be8b6..d4d9de7 100644 --- a/DungeonShooting_Godot/excel/excelFile/AiAttackAttr.xlsx +++ b/DungeonShooting_Godot/excel/excelFile/AiAttackAttr.xlsx Binary files differ diff --git a/DungeonShooting_Godot/excel/excelFile/BulletBase.xlsx b/DungeonShooting_Godot/excel/excelFile/BulletBase.xlsx index 1d30cae..32d592d 100644 --- a/DungeonShooting_Godot/excel/excelFile/BulletBase.xlsx +++ b/DungeonShooting_Godot/excel/excelFile/BulletBase.xlsx Binary files differ diff --git a/DungeonShooting_Godot/excel/excelFile/Sound.xlsx b/DungeonShooting_Godot/excel/excelFile/Sound.xlsx index 4d36202..adee5e9 100644 --- a/DungeonShooting_Godot/excel/excelFile/Sound.xlsx +++ b/DungeonShooting_Godot/excel/excelFile/Sound.xlsx Binary files differ diff --git a/DungeonShooting_Godot/excel/excelFile/WeaponBase.xlsx b/DungeonShooting_Godot/excel/excelFile/WeaponBase.xlsx index 5eff21a..511c660 100644 --- a/DungeonShooting_Godot/excel/excelFile/WeaponBase.xlsx +++ b/DungeonShooting_Godot/excel/excelFile/WeaponBase.xlsx Binary files differ diff --git a/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/inlet/Start1/Preview.png b/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/inlet/Start1/Preview.png index d64d95a..e502322 100644 --- a/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/inlet/Start1/Preview.png +++ b/DungeonShooting_Godot/resource/map/tileMaps/TestGroup1/inlet/Start1/Preview.png Binary files differ diff --git a/DungeonShooting_Godot/src/config/ExcelConfig_WeaponBase.cs b/DungeonShooting_Godot/src/config/ExcelConfig_WeaponBase.cs index af7f188..e45f05e 100644 --- a/DungeonShooting_Godot/src/config/ExcelConfig_WeaponBase.cs +++ b/DungeonShooting_Godot/src/config/ExcelConfig_WeaponBase.cs @@ -263,15 +263,13 @@ public ActivityBase Shell; /// - /// 是否在换弹时才抛壳
- /// + /// 是否在换弹时才抛弹壳 ///
[JsonInclude] public bool ReloadThrowShell; /// - /// 投抛弹壳的延时时间, 在射击或者上膛后会触发抛弹壳效果
- /// 如果为0, 则不自动抛弹 + /// 投抛弹壳的延时时间 ///
[JsonInclude] public float ThrowShellDelayTime; diff --git a/DungeonShooting_Godot/src/framework/activity/ActivityObject.cs b/DungeonShooting_Godot/src/framework/activity/ActivityObject.cs index 0c5cb3e..440b448 100644 --- a/DungeonShooting_Godot/src/framework/activity/ActivityObject.cs +++ b/DungeonShooting_Godot/src/framework/activity/ActivityObject.cs @@ -265,8 +265,12 @@ // -------------------------------------------------------------------------------- + //是否正在调用组件 Update 函数 + private bool _updatingComp = false; //组件集合 private readonly List> _components = new List>(); + //修改的组件集合, value 为 true 表示添加组件, false 表示移除组件 + private readonly List> _changeComponents = new List>(); //上一帧动画名称 private string _prevAnimation; //上一帧动画 @@ -580,13 +584,6 @@ } /// - /// 每帧调用一次, ProcessOver() 会在组件的 Process() 之后调用 - /// - protected virtual void ProcessOver(float delta) - { - } - - /// /// 每物理帧调用一次, 物体的 PhysicsProcess() 会在组件的 PhysicsProcess() 之前调用 /// protected virtual void PhysicsProcess(float delta) @@ -594,13 +591,6 @@ } /// - /// 每物理帧调用一次, PhysicsProcessOver() 会在组件的 PhysicsProcess() 之后调用 - /// - protected virtual void PhysicsProcessOver(float delta) - { - } - - /// /// 如果开启 debug, 则每帧调用该函数, 可用于绘制文字线段等 /// protected virtual void DebugDraw() @@ -772,7 +762,15 @@ public T AddComponent() where T : Component, new() { var component = new T(); - _components.Add(new KeyValuePair(typeof(T), component)); + if (_updatingComp) + { + _changeComponents.Add(new KeyValuePair(component, true)); + } + else + { + _components.Add(new KeyValuePair(typeof(T), component)); + } + component.Master = this; component.Ready(); component.OnEnable(); @@ -785,7 +783,15 @@ public Component AddComponent(Type type) { var component = (Component)Activator.CreateInstance(type); - _components.Add(new KeyValuePair(type, component)); + if (_updatingComp) + { + _changeComponents.Add(new KeyValuePair(component, true)); + } + else + { + _components.Add(new KeyValuePair(type, component)); + } + component.Master = this; component.Ready(); component.OnEnable(); @@ -798,13 +804,26 @@ /// 组件对象 public void RemoveComponent(Component component) { - for (int i = 0; i < _components.Count; i++) + if (component.IsDestroyed) { - if (_components[i].Value == component) + return; + } + + if (_updatingComp) + { + _changeComponents.Add(new KeyValuePair(component, false)); + component.Destroy(); + } + else + { + for (var i = 0; i < _components.Count; i++) { - _components.RemoveAt(i); - component.Destroy(); - return; + if (_components[i].Value == component) + { + _components.RemoveAt(i); + component.Destroy(); + return; + } } } } @@ -823,6 +842,18 @@ } } + if (_updatingComp) + { + for (var i = 0; i < _changeComponents.Count; i++) + { + var temp = _components[i]; + if (temp.Value.GetType() == type) + { + return temp.Value; + } + } + } + return null; } @@ -905,14 +936,14 @@ //更新组件 if (_components.Count > 0) { + _updatingComp = true; if (EnableCustomBehavior) //启用所有组件 { - var arr = _components.ToArray(); - for (int i = 0; i < arr.Length; i++) + for (int i = 0; i < _components.Count; i++) { if (IsDestroyed) return; - var temp = arr[i].Value; - if (temp != null && temp.Master == this && temp.Enable) + var temp = _components[i].Value; + if (temp != null && temp.Enable) { temp.Process(newDelta); } @@ -925,6 +956,12 @@ MoveController.Process(newDelta); } } + _updatingComp = false; + + if (_changeComponents.Count > 0) + { + RefreshComponent(); + } } // 更新下坠处理逻辑 @@ -958,8 +995,6 @@ //协程更新 ProxyCoroutineHandler.ProxyUpdateCoroutine(ref _coroutineList, newDelta); - - ProcessOver(newDelta); //调试绘制 if (IsDebug) @@ -1125,14 +1160,14 @@ //更新组件 if (_components.Count > 0) { + _updatingComp = true; if (EnableCustomBehavior) //启用所有组件 { - var arr = _components.ToArray(); - for (int i = 0; i < arr.Length; i++) + for (int i = 0; i < _components.Count; i++) { if (IsDestroyed) return; - var temp = arr[i].Value; - if (temp != null && temp.Master == this && temp.Enable) + var temp = _components[i].Value; + if (temp != null && temp.Enable) { temp.PhysicsProcess(newDelta); } @@ -1145,9 +1180,37 @@ MoveController.PhysicsProcess(newDelta); } } - } + _updatingComp = false; - PhysicsProcessOver(newDelta); + if (_changeComponents.Count > 0) + { + RefreshComponent(); + } + } + } + + //更新新增/移除的组件 + private void RefreshComponent() + { + for (var i = 0; i < _changeComponents.Count; i++) + { + var item = _changeComponents[i]; + if (item.Value) //添加组件 + { + _components.Add(new KeyValuePair(item.Key.GetType(), item.Key)); + } + else //移除组件 + { + for (var j = 0; j < _components.Count; j++) + { + if (_components[i].Value == item.Key) + { + _components.RemoveAt(i); + break; + } + } + } + } } /// diff --git a/DungeonShooting_Godot/src/game/activity/prop/active/ActiveProp.cs b/DungeonShooting_Godot/src/game/activity/prop/active/ActiveProp.cs index ac660c5..ea3f772 100644 --- a/DungeonShooting_Godot/src/game/activity/prop/active/ActiveProp.cs +++ b/DungeonShooting_Godot/src/game/activity/prop/active/ActiveProp.cs @@ -131,7 +131,7 @@ { } - protected override void ProcessOver(float delta) + protected override void Process(float delta) { RunUpdate(delta); } diff --git a/DungeonShooting_Godot/src/game/activity/role/Role.cs b/DungeonShooting_Godot/src/game/activity/role/Role.cs index 579739c..f9a1f9f 100644 --- a/DungeonShooting_Godot/src/game/activity/role/Role.cs +++ b/DungeonShooting_Godot/src/game/activity/role/Role.cs @@ -566,12 +566,16 @@ } //主动道具调用更新 - var props = (Prop[])ActivePropsPack.ItemSlot.Clone(); - foreach (var prop in props) + var props = ActivePropsPack.ItemSlot; + if (props.Length > 0) { - if (prop != null && !prop.IsDestroyed) + props = (ActiveProp[])props.Clone(); + foreach (var prop in props) { - prop.PackProcess(delta); + if (prop != null && !prop.IsDestroyed) + { + prop.PackProcess(delta); + } } } } diff --git a/DungeonShooting_Godot/src/game/activity/weapon/Weapon.cs b/DungeonShooting_Godot/src/game/activity/weapon/Weapon.cs index a3d92ff..0cff208 100644 --- a/DungeonShooting_Godot/src/game/activity/weapon/Weapon.cs +++ b/DungeonShooting_Godot/src/game/activity/weapon/Weapon.cs @@ -1001,7 +1001,7 @@ PlayShootSound(); //抛弹 - if ((Attribute.ContinuousShoot || !Attribute.ManualBeLoaded)) + if (!Attribute.ReloadThrowShell && (Attribute.ContinuousShoot || !Attribute.ManualBeLoaded)) { ThrowShellHandler(1f); } @@ -1211,7 +1211,8 @@ // Debug.Log("开始换弹."); //抛弹 - if (!Attribute.ContinuousShoot && (_beLoadedState == 0 || _beLoadedState == -1) && Attribute.BeLoadedTime > 0) + if (!Attribute.ReloadThrowShell && !Attribute.ContinuousShoot && + (_beLoadedState == 0 || _beLoadedState == -1) && Attribute.BeLoadedTime > 0) { ThrowShellHandler(0.6f); } @@ -1389,7 +1390,13 @@ //播放换弹音效 PlayReloadSound(); - + + //抛出弹壳 + if (Attribute.ReloadThrowShell) + { + ThrowShellHandler(0.6f); + } + OnReload(); // Debug.Log("装弹."); } @@ -1412,7 +1419,7 @@ private void BeLoadedHandler() { //上膛抛弹 - if (!Attribute.ContinuousShoot && Attribute.BeLoadedTime > 0) + if (!Attribute.ReloadThrowShell && !Attribute.ContinuousShoot && Attribute.BeLoadedTime > 0) { ThrowShellHandler(0.6f); }