An open source Danmaku development kit for Unity3D.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Rewrote DanmakuGroup to work as a wrapper

This way the developer can use their own collections and manipulate the
collection as they wish.

james713 66f4c438 4580ac90

+242 -474
+3 -3
Assets/Dependencies/DanmakU/_Core_/DanmakuField.cs
··· 26 26 private static readonly Vector2 InfiniteSize = float.PositiveInfinity* 27 27 Vector2.one; 28 28 29 - private DanmakuList activeDanmaku; 29 + private DanmakuGroup activeDanmaku; 30 30 31 31 internal Bounds2D bounds; 32 32 ··· 150 150 public virtual void Awake() { 151 151 if (_fields == null) 152 152 _fields = new List<DanmakuField>(); 153 - _fields.Add(this); 154 - activeDanmaku = new DanmakuList(); 153 + _fields.Add(this); 154 + activeDanmaku = DanmakuGroup.List(); 155 155 TargetField = this; 156 156 } 157 157
+85 -346
Assets/Dependencies/DanmakU/_Core_/DanmakuGroup.cs
··· 10 10 11 11 namespace Hourai.DanmakU { 12 12 13 - public abstract class DanmakuGroup : ICollection<Danmaku>, IFireBindable { 13 + public sealed class DanmakuGroup : ICollection<Danmaku>, IFireBindable, IComparable<ICollection<Danmaku>>{ 14 14 15 - protected ICollection<Danmaku> Group; 15 + private ICollection<Danmaku> _group; 16 16 17 - #region IEnumerable implementation 18 - 19 - public IEnumerator<Danmaku> GetEnumerator() { 20 - return Group.GetEnumerator(); 17 + public ICollection<Danmaku> Group 18 + { 19 + get { return _group; } 21 20 } 22 21 23 - #endregion 24 - 25 - #region IEnumerable implementation 26 - 27 - IEnumerator IEnumerable.GetEnumerator() { 28 - return Group.GetEnumerator(); 29 - } 30 - 31 - #endregion 32 - 33 22 public event Action<Danmaku> OnAdd; 34 23 public event Action<Danmaku> OnRemove; 35 24 36 - protected virtual void OnDanmakuDeactivate(Danmaku danmaku) { 37 - Remove(danmaku); 38 - } 39 - 40 - protected void RaiseAddEvent(Danmaku target) { 41 - if (target == null) 42 - return; 43 - target.OnDeactivate += OnDanmakuDeactivate; 44 - 45 - if (OnAdd != null) 46 - OnAdd(target); 25 + public static DanmakuGroup Set(IEnumerable<Danmaku> source = null) { 26 + HashSet<Danmaku> set; 27 + if (source == null) 28 + set = new HashSet<Danmaku>(); 29 + else 30 + set = new HashSet<Danmaku>(source); 31 + return new DanmakuGroup(set); 47 32 } 48 33 49 - protected void RaiseAddEvent(IEnumerable<Danmaku> targets) { 50 - if (targets == null) 51 - throw new ArgumentNullException(); 52 - 53 - foreach (Danmaku target in targets.Where(t => t)) { 54 - target.OnDeactivate += OnDanmakuDeactivate; 55 - OnAdd.SafeInvoke(target); 56 - } 34 + public static DanmakuGroup List(IEnumerable<Danmaku> source = null) { 35 + List<Danmaku> list; 36 + if (source == null) 37 + list = new List<Danmaku>(); 38 + else 39 + list = new List<Danmaku>(source); 40 + return new DanmakuGroup(list); 57 41 } 58 42 59 - protected void RaiseRemoveEvent(Danmaku target) { 60 - if (target == null) 43 + public DanmakuGroup(ICollection<Danmaku> collection) 44 + { 45 + if (collection == null) 46 + throw new ArgumentNullException("collection"); 47 + _group = collection; 48 + if (_group.Count <= 0) 61 49 return; 62 - OnRemove.SafeInvoke(target); 63 - } 64 - 65 - protected void RaiseRemoveEvent(IEnumerable<Danmaku> targets) { 66 - if (targets == null) 67 - throw new ArgumentNullException("targets"); 68 - 69 - foreach (Danmaku target in targets.Where(t => t)) 70 - OnRemove.SafeInvoke(target); 71 - } 72 - 73 - public bool TrueForAll(Predicate<Danmaku> match) { 74 - if (match == null) 75 - throw new ArgumentNullException("match"); 76 - 77 - var colList = Group as IList<Danmaku>; 78 - if (colList != null) { 79 - for (int i = 0; i < colList.Count; i++) { 80 - if (!match(colList[i])) 81 - return false; 82 - } 83 - } else { 84 - foreach (var danmaku in Group) { 85 - if (!match(danmaku)) 86 - return false; 87 - } 88 - } 89 - return true; 50 + foreach (Danmaku danmaku in _group) 51 + if (danmaku != null) 52 + danmaku.OnDeactivate += RemoveEvent; 90 53 } 91 54 92 55 public void AddRange(IEnumerable<Danmaku> collection) { 93 56 if (collection == null) 94 57 throw new ArgumentNullException(); 95 58 96 - if (Group is List<Danmaku>) 97 - (Group as List<Danmaku>).AddRange(collection); 98 - else if (Group is HashSet<Danmaku>) 99 - (Group as HashSet<Danmaku>).UnionWith(collection); 100 - else if (collection is IList<Danmaku>) { 101 - var colList = (IList<Danmaku>) collection; 102 - for (int i = 0; i < colList.Count; i++) 103 - Group.Add(colList[i]); 104 - } else { 105 - foreach (var danmaku in collection) 106 - Group.Add(danmaku); 107 - } 108 - RaiseAddEvent(collection); 109 - } 110 - 111 - public int RemoveRange(IEnumerable<Danmaku> collection) { 112 - if (collection == null) 113 - throw new ArgumentNullException(); 114 - 115 - int oldCount = Group.Count; 116 - if (Group is HashSet<Danmaku>) 117 - (Group as HashSet<Danmaku>).ExceptWith(collection); 118 - else if (collection is IList<Danmaku>) { 119 - var colList = (IList<Danmaku>) collection; 120 - for (int i = 0; i < colList.Count; i++) 121 - Group.Remove(colList[i]); 122 - } else { 123 - foreach (var danmaku in collection) 124 - Group.Remove(danmaku); 125 - } 126 - RaiseRemoveEvent(collection); 127 - return oldCount - Group.Count; 128 - } 129 - 130 - public bool ContainsAll(IEnumerable<Danmaku> collection) { 131 - if (collection == null) 132 - throw new ArgumentNullException(); 133 - 134 - var colList = collection as IList<Danmaku>; 135 - if (colList != null) { 136 - for (int i = 0; i < colList.Count; i++) { 137 - if (!Group.Contains(colList[i])) 138 - return false; 59 + if(OnAdd == null) 60 + foreach (var danmaku in collection) { 61 + if (danmaku != null) 62 + danmaku.OnDeactivate += RemoveEvent; 63 + _group.Add(danmaku); 139 64 } 140 - } else { 141 - foreach (var danmaku in collection) { 142 - if (!Group.Contains(danmaku)) 143 - return false; 65 + else 66 + foreach (Danmaku danmaku in collection) { 67 + if (danmaku != null) { 68 + danmaku.OnDeactivate += RemoveEvent; 69 + OnAdd(danmaku); 70 + } 71 + _group.Add(danmaku); 144 72 } 145 - } 146 - return true; 147 73 } 148 74 149 - public bool ContainsAny(IEnumerable<Danmaku> collection) { 75 + public int RemoveRange(IEnumerable<Danmaku> collection) { 150 76 if (collection == null) 151 - throw new ArgumentNullException(); 152 - 153 - foreach (var danmaku in collection) { 154 - if (Contains(danmaku)) 155 - return true; 156 - } 157 - return true; 158 - } 77 + throw new ArgumentNullException("collection"); 159 78 160 - public bool Exists(Func<Danmaku, bool> match) { 161 - return (Find(match) != null); 79 + int oldCount = _group.Count; 80 + if (OnRemove == null) 81 + RemoveAll(collection); 82 + else 83 + foreach (Danmaku danmaku in collection) 84 + if (_group.Remove(danmaku) && danmaku != null) 85 + OnRemove(danmaku); 86 + return oldCount - _group.Count; 162 87 } 163 88 164 - public Danmaku Find(Func<Danmaku, bool> match) { 165 - return Group.FirstOrDefault(match); 166 - } 167 - 168 - public List<Danmaku> FindAll(Func<Danmaku, bool> match) { 169 - return Group.Where(match).ToList(); 89 + void RemoveAll(IEnumerable<Danmaku> collection) { 90 + var set = _group as HashSet<Danmaku>; 91 + if (set != null) 92 + set.ExceptWith(collection); 93 + else 94 + foreach (Danmaku danmaku in collection) 95 + _group.Remove(danmaku); 170 96 } 171 97 172 98 public void RemoveAll(Func<Danmaku, bool> match) { 173 - RemoveRange(FindAll(match)); 99 + RemoveRange(_group.Where(match)); 174 100 } 175 101 176 102 public Danmaku[] ToArray() { ··· 180 106 } 181 107 182 108 public override int GetHashCode() { 183 - return Group.GetHashCode(); 109 + return _group.GetHashCode(); 184 110 } 185 111 186 112 public override bool Equals(object obj) { 187 - return Group.Equals(obj); 113 + return _group.Equals(obj); 188 114 } 189 115 190 116 #region ICollection implementation 191 117 192 118 public void Add(Danmaku item) { 193 - Group.Add(item); 194 - RaiseAddEvent(item); 119 + _group.Add(item); 120 + if (item != null) 121 + item.OnDeactivate += RemoveEvent; 122 + 195 123 } 196 124 197 125 public void Clear() { 198 - var groupList = Group as IList<Danmaku>; 199 - Group.Clear(); 200 - if (groupList != null) { 201 - for (int i = 0; i < groupList.Count; i++) 202 - RaiseRemoveEvent(groupList[i]); 203 - } else { 204 - foreach (var danmaku in Group) 205 - RaiseRemoveEvent(danmaku); 206 - } 126 + if (OnRemove != null) 127 + foreach (Danmaku danmaku in _group) 128 + OnRemove(danmaku); 129 + _group.Clear(); 207 130 } 208 131 209 132 public bool Contains(Danmaku item) { 210 - return Group.Contains(item); 133 + return _group.Contains(item); 211 134 } 212 135 213 136 public void CopyTo(Danmaku[] array, int arrayIndex) { 214 - Group.CopyTo(array, arrayIndex); 137 + _group.CopyTo(array, arrayIndex); 215 138 } 216 139 217 140 public bool Remove(Danmaku item) { 218 - bool success = Group.Remove(item); 141 + bool success = _group.Remove(item); 219 142 if (success) 220 - RaiseRemoveEvent(item); 143 + OnRemove.SafeInvoke(item); 221 144 return success; 222 145 } 223 146 147 + void RemoveEvent(Danmaku item) { 148 + if (_group.Remove(item) && OnRemove != null) 149 + OnRemove(item); 150 + } 151 + 224 152 public int Count { 225 - get { return Group.Count; } 153 + get { return _group.Count; } 226 154 } 227 155 228 156 public bool IsReadOnly { 229 - get { return Group.IsReadOnly; } 157 + get { return _group.IsReadOnly; } 230 158 } 231 159 232 160 #endregion ··· 243 171 if (fireData == null) 244 172 throw new ArgumentNullException("fireData"); 245 173 fireData.OnActivate -= Add; 246 - } 247 - } 248 - 249 - public class DanmakuGroup<T> : DanmakuGroup 250 - where T : ICollection<Danmaku>, new() { 251 - 252 - public DanmakuGroup() { 253 - Group = new T(); 254 - } 255 - 256 - public DanmakuGroup(IEnumerable<Danmaku> danmakus) { 257 - Group = new T(); 258 - AddRange(danmakus); 259 174 } 260 175 261 - } 262 - 263 - public class DanmakuList : DanmakuGroup<List<Danmaku>>, IList<Danmaku> { 264 - 265 - //TODO Document 266 - 267 - private List<Danmaku> danmakuList; 268 - 269 - public DanmakuList() { 270 - danmakuList = Group as List<Danmaku>; 271 - } 272 - 273 - public DanmakuList(IEnumerable<Danmaku> danmakus) : base(danmakus) { 274 - danmakuList = Group as List<Danmaku>; 275 - } 276 - 277 - public int Capacity { 278 - get { return danmakuList.Capacity; } 279 - } 280 - 281 - public int FindIndex(Predicate<Danmaku> match) { 282 - return danmakuList.FindIndex(match); 283 - } 284 - 285 - public int FindIndex(int startIndex, Predicate<Danmaku> match) { 286 - return danmakuList.FindIndex(startIndex, match); 287 - } 288 - 289 - public int FindIndex(int startIndex, int count, Predicate<Danmaku> match) { 290 - return danmakuList.FindIndex(startIndex, count, match); 291 - } 292 - 293 - public int IndexOf(Danmaku item, int start) { 294 - return danmakuList.IndexOf(item, start); 295 - } 296 - 297 - public int IndexOf(Danmaku item, int start, int end) { 298 - return danmakuList.IndexOf(item, start, end); 299 - } 300 - 301 - public int LastIndexOf(Danmaku item) { 302 - return danmakuList.LastIndexOf(item); 303 - } 304 - 305 - public int LastIndexOf(Danmaku item, int start) { 306 - return danmakuList.LastIndexOf(item, start); 307 - } 308 - 309 - public int LastIndexOf(Danmaku item, int start, int end) { 310 - return danmakuList.LastIndexOf(item, start, end); 311 - } 312 - 313 - public Danmaku FindLast(Predicate<Danmaku> match) { 314 - return danmakuList.FindLast(match); 176 + public int CompareTo(ICollection<Danmaku> other) { 177 + return _group.Count.CompareTo(other.Count); 315 178 } 316 179 317 - public int FindLastIndex(Predicate<Danmaku> match) { 318 - return FindLastIndex(0, Count, match); 180 + public IEnumerator<Danmaku> GetEnumerator() { 181 + return _group.GetEnumerator(); 319 182 } 320 183 321 - public int FindLastIndex(int startIndex, Predicate<Danmaku> match) { 322 - return danmakuList.FindLastIndex(startIndex, match); 184 + IEnumerator IEnumerable.GetEnumerator() { 185 + return _group.GetEnumerator(); 323 186 } 324 - 325 - public int FindLastIndex(int startIndex, 326 - int count, 327 - Predicate<Danmaku> match) { 328 - return danmakuList.FindLastIndex(startIndex, count, match); 329 - } 330 - 331 - public void InsertRange(int index, IEnumerable<Danmaku> collection) { 332 - danmakuList.InsertRange(index, collection); 333 - var colList = collection as IList<Danmaku>; 334 - if (colList != null) { 335 - int count = colList.Count; 336 - for (int i = 0; i < count; i++) 337 - RaiseAddEvent(colList[i]); 338 - } else { 339 - foreach (var danmaku in collection) 340 - RaiseAddEvent(danmaku); 341 - } 342 - } 343 - 344 - public void Reverse() { 345 - danmakuList.Reverse(); 346 - } 347 - 348 - public void Reverse(int start, int end) { 349 - danmakuList.Reverse(start, end); 350 - } 351 - 352 - public void TrimExcess() { 353 - danmakuList.TrimExcess(); 354 - } 355 - 356 - #region IList implementation 357 - 358 - public int IndexOf(Danmaku item) { 359 - return danmakuList.IndexOf(item); 360 - } 361 - 362 - public void Insert(int index, Danmaku item) { 363 - danmakuList.Insert(index, item); 364 - RaiseAddEvent(item); 365 - } 366 - 367 - public void RemoveAt(int index) { 368 - Danmaku target = danmakuList[index]; 369 - danmakuList.RemoveAt(index); 370 - RaiseRemoveEvent(target); 371 - } 372 - 373 - public Danmaku this[int index] { 374 - get { return danmakuList[index]; } 375 - set { 376 - Danmaku current = danmakuList[index]; 377 - if (current == value) 378 - return; 379 - RaiseRemoveEvent(current); 380 - RaiseAddEvent(value); 381 - danmakuList[index] = value; 382 - } 383 - } 384 - 385 - #endregion 386 187 } 387 - 388 - public class DanmakuSet : DanmakuGroup<HashSet<Danmaku>> { 389 - 390 - //TODO Document 391 - 392 - private HashSet<Danmaku> danmakuSet; 393 - 394 - public DanmakuSet() { 395 - danmakuSet = Group as HashSet<Danmaku>; 396 - } 397 - 398 - public DanmakuSet(IEnumerable<Danmaku> danmakus) : base(danmakus) { 399 - danmakuSet = Group as HashSet<Danmaku>; 400 - } 401 - 402 - public void UnionWith(IEnumerable<Danmaku> collection) { 403 - if (collection == null) 404 - throw new ArgumentNullException(); 405 - 406 - var otherAsCollection = collection as ICollection<Danmaku>; 407 - if (otherAsCollection != null && otherAsCollection.Count <= 0) 408 - return; 409 - 410 - AddRange(collection); 411 - } 412 - 413 - public void ExceptWith(IEnumerable<Danmaku> collection) { 414 - if (collection == null) 415 - throw new ArgumentNullException(); 416 - 417 - if (danmakuSet.Count == 0) 418 - return; 419 - 420 - var otherAsCollection = collection as ICollection<Danmaku>; 421 - if (otherAsCollection != null && otherAsCollection.Count <= 0) 422 - return; 423 - 424 - RemoveRange(collection); 425 - } 426 - 427 - public void IntersectWith(IEnumerable<Danmaku> collection) { 428 - if (collection == null) 429 - throw new ArgumentNullException(); 430 - 431 - if (danmakuSet.Count <= 0) 432 - return; 433 - 434 - var otherAsCollection = collection as ICollection<Danmaku>; 435 - if (otherAsCollection != null && otherAsCollection.Count <= 0) { 436 - Clear(); 437 - return; 438 - } 439 - 440 - foreach (var danmaku in danmakuSet) { 441 - if (!collection.Contains(danmaku)) 442 - RaiseRemoveEvent(danmaku); 443 - } 444 - danmakuSet.IntersectWith(collection); 445 - } 446 - 447 - } 448 - 449 188 }
+4 -2
Assets/Dependencies/DanmakU/_Core_/DanmakuPrefab.cs
··· 212 212 runtimeSystem.startSpeed = 0f; 213 213 runtimeSystem.enableEmission = false; 214 214 215 - currentDanmaku = new DanmakuList(); 215 + currentDanmaku = new List<Danmaku>(); 216 + currentGroup = new DanmakuGroup(currentDanmaku); 216 217 particles = new ParticleSystem.Particle[runtimeSystem.particleCount]; 217 218 218 219 runtimeRenderer.mesh = renderMesh; ··· 358 359 private ParticleSystem runtimeSystem; 359 360 private ParticleSystemRenderer runtimeRenderer; 360 361 private ParticleSystem.Particle[] particles; 361 - internal DanmakuList currentDanmaku; 362 + internal List<Danmaku> currentDanmaku; 363 + internal DanmakuGroup currentGroup; 362 364 private int danmakuCount; 363 365 private RenderingType renderingType; 364 366
+1 -3
Assets/Dependencies/DanmakU/_Core_/FireData.cs
··· 50 50 return data; 51 51 } 52 52 53 - public Danmaku Fire(Vector2? position = null, float? rotation = null) { 53 + public Danmaku Fire() { 54 54 Danmaku danmaku = Danmaku.GetInactive(this); 55 - danmaku.Position = position ?? Position; 56 - danmaku.Rotation = rotation ?? Rotation; 57 55 danmaku.Activate(); 58 56 return danmaku; 59 57 }
+56 -56
Assets/Dependencies/HouraiLib/Game.cs
··· 5 5 using Vexe.Runtime.Extensions; 6 6 using Vexe.Runtime.Types; 7 7 8 - namespace Hourai { 8 + namespace Hourai { 9 9 10 - public abstract class Game : Singleton<Game> { 10 + public class Game : Singleton<Game> { 11 11 12 12 private bool _paused; 13 13 private float _oldTimeScale; ··· 25 25 } 26 26 _paused = value; 27 27 } 28 - } 29 - 28 + } 29 + 30 30 // All the things that require an actual instance 31 - #region Global Callbacks 32 - 33 - public static event Action OnUpdate; 34 - public static event Action OnLateUpdate; 35 - public static event Action OnFixedUpdate; 36 - public static event Action<int> OnLoad; 37 - public static event Action OnApplicationFocused; 38 - public static event Action OnApplicationUnfocused; 39 - public static event Action OnApplicationExit; 40 - 41 - private void Update() { 42 - OnUpdate.SafeInvoke(); 43 - } 44 - 45 - private void LateUpdate() { 46 - OnLateUpdate.SafeInvoke(); 47 - } 48 - 49 - private void FixedUpdate() { 50 - OnFixedUpdate.SafeInvoke(); 51 - } 52 - 53 - private void OnApplicationFocus(bool focus) { 54 - if (focus) 55 - OnApplicationFocused.SafeInvoke(); 56 - else 57 - OnApplicationUnfocused.SafeInvoke(); 58 - } 59 - 60 - private void OnApplicationQuit() { 61 - OnApplicationExit.SafeInvoke(); 62 - } 63 - 64 - private void OnLevelWasLoaded(int level) { 65 - OnLoad.SafeInvoke(level); 66 - } 67 - 68 - #endregion 31 + #region Global Callbacks 32 + 33 + public static event Action OnUpdate; 34 + public static event Action OnLateUpdate; 35 + public static event Action OnFixedUpdate; 36 + public static event Action<int> OnLoad; 37 + public static event Action OnApplicationFocused; 38 + public static event Action OnApplicationUnfocused; 39 + public static event Action OnApplicationExit; 40 + 41 + private void Update() { 42 + OnUpdate.SafeInvoke(); 43 + } 44 + 45 + private void LateUpdate() { 46 + OnLateUpdate.SafeInvoke(); 47 + } 48 + 49 + private void FixedUpdate() { 50 + OnFixedUpdate.SafeInvoke(); 51 + } 52 + 53 + private void OnApplicationFocus(bool focus) { 54 + if (focus) 55 + OnApplicationFocused.SafeInvoke(); 56 + else 57 + OnApplicationUnfocused.SafeInvoke(); 58 + } 59 + 60 + private void OnApplicationQuit() { 61 + OnApplicationExit.SafeInvoke(); 62 + } 63 + 64 + private void OnLevelWasLoaded(int level) { 65 + OnLoad.SafeInvoke(level); 66 + } 67 + 68 + #endregion 69 69 70 70 #region Global Coroutines 71 71 ··· 77 77 return Instance.StartCoroutine(coroutine); 78 78 } 79 79 80 - public static Coroutine StaticCoroutine(IEnumerable coroutine) { 80 + public static Coroutine StaticCoroutine(IEnumerable coroutine) { 81 81 if(Instance == null) 82 - throw new InvalidOperationException("Cannot start a static coroutine without a Game instance."); 82 + throw new InvalidOperationException("Cannot start a static coroutine without a Game instance."); 83 83 if (coroutine == null) 84 84 throw new ArgumentNullException("coroutine"); 85 85 return StaticCoroutine(coroutine.GetEnumerator()); 86 - } 87 - 86 + } 87 + 88 88 #endregion 89 - } 90 - 89 + } 90 + 91 91 public abstract class ConfigurableGame<T> : Game where T : GameConfig { 92 92 93 93 [Serialize, Show, Inline] ··· 95 95 96 96 public static T Config { 97 97 get { return Instance == null ? null : ((ConfigurableGame<T>)Instance)._config; } 98 - } 99 - 98 + } 99 + 100 100 protected override void Awake() { 101 101 base.Awake(); 102 102 if (_config != null) ··· 108 108 Debug.LogError( 109 109 "Game singledton does not have an assigned Config and no configs are found in resources"); 110 110 } 111 - } 112 - 111 + } 112 + 113 113 public static bool IsPlayer(Component obj) { 114 114 return obj.CompareTag(Config.PlayerTag); 115 - } 116 - 115 + } 116 + 117 117 public static Transform[] GetRespawnPoints() { 118 118 return GameObject.FindGameObjectsWithTag(Config.RespawnTag).Select(go => go.transform).ToArray(); 119 - } 120 - 119 + } 120 + 121 121 public static GameObject FindPlayer() { 122 122 return GameObject.FindGameObjectWithTag(Config.PlayerTag); 123 123 }
+35 -34
Assets/Dependencies/HouraiLib/General/Singleton.cs
··· 1 1 using UnityEngine; 2 2 using Vexe.Runtime.Types; 3 3 4 - namespace Hourai { 5 - 6 - public abstract class Singleton<T> : BetterBehaviour where T : Singleton<T> { 7 - 8 - private static T _instance; 9 - 10 - [Serialize, Show, Default(false)] 11 - private bool _dontDestroyOnLoad; 12 - 13 - public static T Instance { 14 - get { 15 - if (_instance == null) { 16 - _instance = FindObjectOfType<T>(); 17 - if (_instance == null) { 18 - Debug.LogError("Something is trying to access the " + typeof(T) + 19 - " Singleton instance, but none exists."); 20 - } 21 - } 22 - return _instance; 23 - } 24 - } 25 - 26 - protected virtual void Awake() { 27 - if (_instance == null) { 28 - _instance = this as T; 29 - if (_dontDestroyOnLoad) 30 - DontDestroyOnLoad(this); 31 - } else { 32 - if (_instance == this) 33 - return; 34 - Debug.Log("Destroying " + gameObject + " because " + _instance + " already exists."); 35 - Destroy(gameObject); 36 - } 37 - } 4 + namespace Hourai { 5 + 6 + public abstract class Singleton<T> : BetterBehaviour where T : Singleton<T> { 7 + 8 + private static T _instance; 9 + 10 + [Serialize, Show, Default(false)] 11 + private bool _dontDestroyOnLoad; 12 + 13 + public static T Instance { 14 + get { 15 + if (_instance == null) { 16 + _instance = FindObjectOfType<T>(); 17 + if (_instance == null) { 18 + Debug.LogError("Something is trying to access the " + typeof(T) + 19 + " Singleton instance, but none exists."); 20 + _instance = new GameObject(typeof(T).Name).AddComponent<T>(); 21 + } 22 + } 23 + return _instance; 24 + } 25 + } 26 + 27 + protected virtual void Awake() { 28 + if (_instance == null) { 29 + _instance = this as T; 30 + if (_dontDestroyOnLoad) 31 + DontDestroyOnLoad(this); 32 + } else { 33 + if (_instance == this) 34 + return; 35 + Debug.Log("Destroying " + gameObject + " because " + _instance + " already exists."); 36 + Destroy(gameObject); 37 + } 38 + } 38 39 } 39 40 }
+14 -5
Assets/Test/BasicFireTest.cs
··· 15 15 [SerializeField] 16 16 private DanmakuPrefab prefab; 17 17 18 + [SerializeField] 19 + private Gradient grad; 20 + 18 21 private Task test; 22 + private DanmakuGroup group; 19 23 20 24 private void Start() { 21 - 22 - test = prefab.Infinite() 23 - .From(gameObject.Descendants()) 24 - .WithSpeed(2) 25 + group = DanmakuGroup.List(); 26 + FireData data = prefab; 27 + group.Bind(data); 28 + test = data.Infinite() 29 + //.From(gameObject.Descendants()) 30 + //.WithSpeed(2) 31 + //.Towards(Vector2.zero) 25 32 .Delay(delay) 26 - .RadialBurst(360, 10) 33 + .Circle(5,1) 27 34 .Execute(); 28 35 Invoke("Test", 10); 29 36 } 30 37 31 38 void Test() { 39 + Debug.Log(group.Count); 40 + group.Color(grad); 32 41 test.Stop(); 33 42 } 34 43
+44 -25
Assets/Test/Test Scene.unity
··· 179 179 m_Component: 180 180 - 4: {fileID: 513550417} 181 181 - 20: {fileID: 513550416} 182 - - 114: {fileID: 513550413} 183 - - 114: {fileID: 513550414} 184 182 m_Layer: 0 185 183 m_Name: Main Camera 186 184 m_TagString: MainCamera ··· 188 186 m_NavMeshLayer: 0 189 187 m_StaticEditorFlags: 0 190 188 m_IsActive: 1 191 - --- !u!114 &513550413 192 - MonoBehaviour: 193 - m_ObjectHideFlags: 0 194 - m_PrefabParentObject: {fileID: 0} 195 - m_PrefabInternal: {fileID: 0} 196 - m_GameObject: {fileID: 513550412} 197 - m_Enabled: 1 198 - m_EditorHideFlags: 0 199 - m_Script: {fileID: 11500000, guid: 962dd0a4b09ff7848a4053b1cd301a42, type: 3} 200 - m_Name: 201 - m_EditorClassIdentifier: 202 - --- !u!114 &513550414 203 - MonoBehaviour: 204 - m_ObjectHideFlags: 0 205 - m_PrefabParentObject: {fileID: 0} 206 - m_PrefabInternal: {fileID: 0} 207 - m_GameObject: {fileID: 513550412} 208 - m_Enabled: 0 209 - m_EditorHideFlags: 0 210 - m_Script: {fileID: 11500000, guid: 4739c22ef73ad62488fe344c8fe9addd, type: 3} 211 - m_Name: 212 - m_EditorClassIdentifier: 213 189 --- !u!20 &513550416 214 190 Camera: 215 191 m_ObjectHideFlags: 0 ··· 354 330 m_Name: 355 331 m_EditorClassIdentifier: 356 332 delay: .00999999978 357 - prefab: {fileID: 0} 333 + prefab: {fileID: 11409350, guid: 5c0c5bf0c434853449fa68def8d34e65, type: 2} 334 + grad: 335 + key0: 336 + serializedVersion: 2 337 + rgba: 4294967295 338 + key1: 339 + serializedVersion: 2 340 + rgba: 4294967295 341 + key2: 342 + serializedVersion: 2 343 + rgba: 0 344 + key3: 345 + serializedVersion: 2 346 + rgba: 0 347 + key4: 348 + serializedVersion: 2 349 + rgba: 0 350 + key5: 351 + serializedVersion: 2 352 + rgba: 0 353 + key6: 354 + serializedVersion: 2 355 + rgba: 0 356 + key7: 357 + serializedVersion: 2 358 + rgba: 0 359 + ctime0: 0 360 + ctime1: 65535 361 + ctime2: 0 362 + ctime3: 0 363 + ctime4: 0 364 + ctime5: 0 365 + ctime6: 0 366 + ctime7: 0 367 + atime0: 0 368 + atime1: 65535 369 + atime2: 0 370 + atime3: 0 371 + atime4: 0 372 + atime5: 0 373 + atime6: 0 374 + atime7: 0 375 + m_NumColorKeys: 2 376 + m_NumAlphaKeys: 2 358 377 --- !u!4 &1376768896 359 378 Transform: 360 379 m_ObjectHideFlags: 0