diff --git a/Assets/DanmakU/Core/FireBuilder.cs b/Assets/DanmakU/Core/FireBuilder.cs index 16037e76..a48369a5 100644 --- a/Assets/DanmakU/Core/FireBuilder.cs +++ b/Assets/DanmakU/Core/FireBuilder.cs @@ -442,6 +442,18 @@ public FireBuilder WithoutGroup () { #endregion + #region Field Functions + + public FireBuilder InField(DanmakuField field) { + if(field == null) + throw new ArgumentNullException("Field cannot be null!"); + + Field = field; + return this; + } + + #endregion + public void Fire () { Vector2 actualPosition = Position; DynamicFloat actualRotation = Rotation; @@ -465,15 +477,13 @@ public void Fire () { Rotation = actualRotation; if(modifiers.Count <= 0) { - Debug.Log("hello"); data.Fire(); } else if(modifiers.Count == 1) { DanmakuModifier singleModifier = modifiers[0]; - if(singleModifier == null) { + if(singleModifier == null) data.Fire(); - } else { + else singleModifier.Fire(data); - } } else { DanmakuModifier[] oldSubModifiers = new DanmakuModifier[modifiers.Count]; DanmakuModifier previous = null, current, initial = null; diff --git a/Assets/DanmakU/Core/Modifiers/CircularBurstModifier.cs b/Assets/DanmakU/Core/Modifiers/CircularBurstModifier.cs index d895a8f6..3df89fbf 100644 --- a/Assets/DanmakU/Core/Modifiers/CircularBurstModifier.cs +++ b/Assets/DanmakU/Core/Modifiers/CircularBurstModifier.cs @@ -68,9 +68,6 @@ public CircularBurstModifier(DynamicFloat range, public override void OnFire (Vector2 position, DynamicFloat rotation) { - Debug.Log(rotation.Value); - Debug.Log(rotation.Type); - int burstCount = Mathf.Abs(count.Value); if (burstCount == 1) { @@ -78,15 +75,22 @@ public override void OnFire (Vector2 position, DynamicFloat rotation) { } else { float burstRange = range.Value; float start = rotation - burstRange * 0.5f; - float delta = burstRange / burstCount; + float delta = burstRange / (burstCount - 1); float deltaV = deltaSpeed.Value; float deltaAV = deltaAngularSpeed.Value; + + DynamicFloat tempSpeed = Speed; + DynamicFloat tempASpeed = AngularSpeed; + for (int i = 0; i < burstCount; i++) { Speed += deltaV; AngularSpeed += deltaAV; FireSingle(position, start + i * delta); } + + Speed = tempSpeed; + AngularSpeed = tempASpeed; } } diff --git a/Assets/DanmakU/Core/Modifiers/LinearBurstModifier.cs b/Assets/DanmakU/Core/Modifiers/LinearBurstModifier.cs index f5a01ddf..806021c3 100644 --- a/Assets/DanmakU/Core/Modifiers/LinearBurstModifier.cs +++ b/Assets/DanmakU/Core/Modifiers/LinearBurstModifier.cs @@ -55,6 +55,8 @@ public LinearBurstModifier(DynamicInt depth, #region implemented abstract members of FireModifier public override void OnFire (Vector2 position, DynamicFloat rotation) { + DynamicFloat tempSpeed = Speed; + DynamicFloat tempASpeed = AngularSpeed; DynamicFloat deltaV = DeltaSpeed; DynamicFloat deltaAV = DeltaAngularSpeed; float depth = Depth.Value; @@ -63,7 +65,8 @@ public override void OnFire (Vector2 position, DynamicFloat rotation) { AngularSpeed += deltaAV; FireSingle(position, rotation); } - + Speed = tempSpeed; + AngularSpeed = tempASpeed; } #endregion diff --git a/Assets/SourceTest.cs b/Assets/SourceTest.cs new file mode 100644 index 00000000..eb18cc67 --- /dev/null +++ b/Assets/SourceTest.cs @@ -0,0 +1,34 @@ +// Copyright (c) 2015 James Liu +// +// See the LISCENSE file for copying permission. + +using UnityEngine; +using DanmakU; +using DanmakU.Modifiers; + +public class SourceTest : MonoBehaviour { + + [SerializeField] + private FrameCounter delay; + + [SerializeField] + private DanmakuPrefab prefab; + + [SerializeField] + private CircularBurstModifier circleBurst; + + [SerializeField] + private LinearBurstModifier lineBurst; + + void Update() { + if(delay.Tick()) { + Danmaku.ConstructFire(prefab) + .WithModifier(circleBurst) + .WithModifier(lineBurst) + .From(this) + .WithRotation(this) + .Fire(); + } + } + +} diff --git a/Assets/Test/CircularBurstTest.cs b/Assets/Test/ModifierTest.cs similarity index 54% rename from Assets/Test/CircularBurstTest.cs rename to Assets/Test/ModifierTest.cs index 5f8668d1..c96b2ca2 100644 --- a/Assets/Test/CircularBurstTest.cs +++ b/Assets/Test/ModifierTest.cs @@ -6,7 +6,7 @@ using DanmakU; using DanmakU.Modifiers; -public class CircularBurstTest : MonoBehaviour { +public class ModifierTest : MonoBehaviour { [SerializeField] private FrameCounter delay; @@ -15,11 +15,17 @@ public class CircularBurstTest : MonoBehaviour { private DanmakuPrefab prefab; [SerializeField] - private CircularBurstModifier burst; + private CircularBurstModifier circleBurst; + + [SerializeField] + private LinearBurstModifier lineBurst; void Update() { if(delay.Tick()) { - Danmaku.ConstructFire(prefab).WithModifier(burst).Fire(); + Danmaku.ConstructFire(prefab) + .WithModifier(circleBurst) + .WithModifier(lineBurst) + .Fire(); } } diff --git a/Assets/Test/Test Scene.unity b/Assets/Test/Test Scene.unity index 1f9969e5..4b88579d 100644 --- a/Assets/Test/Test Scene.unity +++ b/Assets/Test/Test Scene.unity @@ -162,7 +162,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!114 &1376768895 MonoBehaviour: m_ObjectHideFlags: 0 @@ -174,8 +174,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: d05c63e729f17a6418d9c10e07027dc5, type: 3} m_Name: m_EditorClassIdentifier: - counter: - Time: 0 + delay: + Time: 1 prefab: {fileID: 11439806, guid: bab340f2a7e388241b077215f339b191, type: 2} --- !u!4 &1376768896 Transform: @@ -189,3 +189,147 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_RootOrder: 1 +--- !u!1 &1724939925 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 4 + m_Component: + - 4: {fileID: 1724939927} + - 114: {fileID: 1724939926} + m_Layer: 0 + m_Name: GameObject + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 0 +--- !u!114 &1724939926 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1724939925} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: eceb9500f4c5a2b4aa42f7c3c2373001, type: 3} + m_Name: + m_EditorClassIdentifier: + delay: + Time: 1 + prefab: {fileID: 11439806, guid: bab340f2a7e388241b077215f339b191, type: 2} + circleBurst: + range: + type: 0 + min: 120 + max: 120 + count: + type: 0 + min: 5 + max: 5 + deltaSpeed: + type: 0 + min: 0 + max: 0 + deltaAngularSpeed: + type: 0 + min: 0 + max: 0 + lineBurst: + depth: + type: 0 + min: 3 + max: 3 + deltaSpeed: + type: 0 + min: 3 + max: 3 + deltaAngularSpeed: + type: 0 + min: 0 + max: 0 +--- !u!4 &1724939927 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1724939925} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: .474208266, y: 1.20853436, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 3 +--- !u!1 &2002943911 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 4 + m_Component: + - 4: {fileID: 2002943913} + - 114: {fileID: 2002943912} + m_Layer: 0 + m_Name: Modifier Test + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 0 +--- !u!114 &2002943912 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 2002943911} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: e2075bee9e523b34b8189254a50c9631, type: 3} + m_Name: + m_EditorClassIdentifier: + delay: + Time: 1 + prefab: {fileID: 11439806, guid: bab340f2a7e388241b077215f339b191, type: 2} + circleBurst: + range: + type: 0 + min: 360 + max: 360 + count: + type: 0 + min: 20 + max: 20 + deltaSpeed: + type: 0 + min: 0 + max: 0 + deltaAngularSpeed: + type: 0 + min: 0 + max: 0 + lineBurst: + depth: + type: 0 + min: 65 + max: 65 + deltaSpeed: + type: 0 + min: 3 + max: 3 + deltaAngularSpeed: + type: 0 + min: 15 + max: 15 +--- !u!4 &2002943913 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 2002943911} + 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_Father: {fileID: 0} + m_RootOrder: 2