An open source Danmaku development kit for Unity3D.
0
fork

Configure Feed

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

Danmaku Inspector

An EditorWindow for viewing and editing data on individual danmaku while in playmode.
Currently WIP.

Also fixed several bugs involving collision detection after switching the
execution model.

james713 5deb3918 b2028585

+402 -200
+3
.gitignore
··· 5 5 /[Bb]uild/ 6 6 /[Dd]ocs/html 7 7 8 + # Ignore UnityVS assets 9 + *UnityVS* 10 + 8 11 # Autogenerated VS/MD solution and project files 9 12 /*.csproj 10 13 /*.unityproj
+1 -1
Assets/Dependencies/DanmakU/Colliders/AccelerationCollider.cs
··· 34 34 /// <param name="info">additional information about the collision</param> 35 35 protected override void DanmakuCollision(Danmaku danmaku, 36 36 RaycastHit2D info) { 37 - danmaku.Speed += _acceleration*Dt; 37 + danmaku.Speed += _acceleration * dt; 38 38 } 39 39 40 40 #endregion
+1 -1
Assets/Dependencies/DanmakU/Colliders/ConstantForceCollider.cs
··· 36 36 /// <param name="info">additional information about the collision</param> 37 37 protected override void DanmakuCollision(Danmaku danmaku, 38 38 RaycastHit2D info) { 39 - danmaku.Position += force*Dt; 39 + danmaku.Position += force * dt; 40 40 } 41 41 42 42 #endregion
+25 -6
Assets/Dependencies/DanmakU/Colliders/RedirectionCollider.cs
··· 13 13 [AddComponentMenu("Hourai.DanmakU/Colliders/Redirection Collider")] 14 14 public class RedirectionCollider : DanmakuCollider { 15 15 16 + 17 + public enum RotationType 18 + { 19 + Absolute, 20 + Relative, 21 + Reflection, 22 + Object 23 + } 24 + 16 25 private DanmakuGroup affected; 17 26 18 27 [SerializeField] ··· 21 30 //TODO Document 22 31 23 32 [SerializeField] 24 - private RotationMode rotationMode; 33 + private RotationType rotationMode; 25 34 26 35 [Serialize] 27 36 public Transform Target { get; set; } 28 37 29 - public RotationMode RotationMode { 38 + public RotationType RotationMode { 30 39 get { return rotationMode; } 31 40 set { rotationMode = value; } 32 41 } ··· 40 49 /// Called on Component instantiation 41 50 /// </summary> 42 51 protected override void Awake() { 43 - base.Awake(); 52 + base.Awake(); 44 53 affected = DanmakuGroup.Set(); 45 54 } 46 55 ··· 55 64 RaycastHit2D info) { 56 65 if (affected.Contains(danmaku)) 57 66 return; 67 + if (rotationMode == RotationType.Reflection) 68 + { 69 + Vector2 normal = info.normal; 70 + Vector2 direction = danmaku.direction; 71 + danmaku.Direction = direction - 72 + 2 * Vector2.Dot(normal, direction) * normal; 73 + affected.Add(danmaku); 74 + return; 75 + } 76 + 58 77 float baseAngle = angle; 59 78 switch (rotationMode) { 60 - case RotationMode.Relative: 79 + case RotationType.Relative: 61 80 baseAngle += danmaku.Rotation; 62 81 break; 63 - case RotationMode.Object: 82 + case RotationType.Object: 64 83 if (Target != null) { 65 84 baseAngle += DanmakuUtil.AngleBetween2D( 66 85 danmaku.Position, ··· 70 89 "Trying to direct at an object but no Target object assinged"); 71 90 } 72 91 break; 73 - case RotationMode.Absolute: 92 + case RotationType.Absolute: 74 93 break; 75 94 } 76 95 danmaku.Rotation = baseAngle;
-52
Assets/Dependencies/DanmakU/Colliders/ReflectionCollider.cs
··· 1 - // Copyright (c) 2015 James Liu 2 - // 3 - // See the LISCENSE file for copying permission. 4 - 5 - using UnityEngine; 6 - 7 - namespace Hourai.DanmakU.Collider { 8 - 9 - /// <summary> 10 - /// A DanmakuCollider implementation that uses vector reflection to redirect bullets. 11 - /// </summary> 12 - /// 13 - /// <remarks> 14 - /// The resultant direction that valid bullets face after coming into contact with this collider is based 15 - /// on the vector reflection calculated from the incoming direction of the bullet and the normal to the collider at the point of collision. 16 - /// </remarks> 17 - [AddComponentMenu("Hourai.DanmakU/Colliders/Reflection Collider")] 18 - public class ReflectionCollider : DanmakuCollider { 19 - 20 - private DanmakuGroup affected; 21 - 22 - /// <summary> 23 - /// Called on Component instantiation 24 - /// </summary> 25 - protected override void Awake() { 26 - base.Awake(); 27 - affected = DanmakuGroup.Set(); 28 - } 29 - 30 - #region implemented abstract members of DanmakuCollider 31 - 32 - /// <summary> 33 - /// Handles a Danmaku collision. Only ever called with Danmaku that pass the filter. 34 - /// </summary> 35 - /// <param name="danmaku">the danmaku that hit the collider.</param> 36 - /// <param name="info">additional information about the collision</param> 37 - protected override void DanmakuCollision(Danmaku danmaku, 38 - RaycastHit2D info) { 39 - if (affected.Contains(danmaku)) 40 - return; 41 - Vector2 normal = info.normal; 42 - Vector2 direction = danmaku.direction; 43 - danmaku.Direction = direction - 44 - 2*Vector2.Dot(normal, direction)*normal; 45 - danmaku.position = info.point; 46 - affected.Add(danmaku); 47 - } 48 - 49 - #endregion 50 - } 51 - 52 - }
+2 -2
Assets/Dependencies/DanmakU/Colliders/ReflectionCollider.cs.meta Assets/Dependencies/HouraiLib/Editor/Util/HandleUtil.cs.meta
··· 1 1 fileFormatVersion: 2 2 - guid: 5a1200496191ca74c8184189f4da76f6 3 - timeCreated: 1441237559 2 + guid: 9f338efc93962b74e97b2eaa917f0862 3 + timeCreated: 1441521310 4 4 licenseType: Free 5 5 MonoImporter: 6 6 serializedVersion: 2
+43 -31
Assets/Dependencies/DanmakU/_Core_/Danmaku.cs
··· 14 14 /// The base object that represents a single bullet in a bullet hell game. 15 15 /// </summary> 16 16 public sealed partial class Danmaku { 17 - 17 + 18 18 /// <summary> 19 19 /// The supported collider shapes used by danmaku. 20 20 /// </summary> ··· 27 27 28 28 } 29 29 30 - private Action<Danmaku> _onUpdate; 30 + internal Action<Danmaku> _onUpdate; 31 + private DanmakuType type; 31 32 32 - internal Danmaku(int poolIndex) { 33 + internal Danmaku(int poolIndex, DanmakuType type) { 33 34 PoolIndex = poolIndex; 35 + this.type = type; 36 + prefab = type.Prefab; 34 37 } 35 38 36 39 /// <summary> ··· 38 41 /// </summary> 39 42 /// <value><c>true</c> if this instance is active; otherwise, <c>false</c>.</value> 40 43 public bool IsActive { 41 - get { return PoolIndex <= Type._activeCount; } 44 + get { return PoolIndex < Type._activeCount; } 42 45 } 43 46 44 47 /// <summary> ··· 93 96 94 97 movementVector.x = position.x - _originalPosition.x; 95 98 movementVector.y = position.y - _originalPosition.y; 96 - 97 - //Debug.DrawRay(originalPosition, movementVector); 98 99 99 100 if (CollisionCheck) 100 101 { ··· 158 159 colliderMask); 159 160 break; 160 161 } 161 - if (hits != null && hits.Length > 0) { 162 + if (hits != null && hits.Length > 0) 163 + { 162 164 foreach (RaycastHit2D hit in hits) { 163 165 Collider2D collider = hit.collider; 164 166 ··· 204 206 public void Activate() { 205 207 if (IsActive) 206 208 return; 207 - 208 - if(OnActivate != null) 209 + Type.Activate(this); 210 + if (OnActivate != null) 209 211 OnActivate(this); 210 - 211 - Type.Activate(this); 212 - 213 212 frames = 0; 214 213 time = 0f; 214 + } 215 + 216 + internal void ActivateImpl() 217 + { 215 218 } 216 219 217 220 /// <summary> ··· 220 223 /// </summary> 221 224 public void Destroy() 222 225 { 223 - Type.toDestroy.Add(this); 224 - } 225 - 226 - internal void DestroyImpl() { 227 226 if (!IsActive) 228 227 return; 229 - 228 + Type.Return(this); 230 229 if (OnDestroy != null) 231 230 OnDestroy(this); 232 231 ··· 235 234 OnDestroy = null; 236 235 _controllerCheck = false; 237 236 Damage = 0; 237 + Speed = 0; 238 + AngularSpeed = 0; 239 + position.x = 0; 240 + position.y = 0; 241 + rotation = 0; 238 242 CollisionCheck = true; 239 - 240 - Type.Return(this); 241 - } 242 - 243 - /// <summary> 244 - /// Serves as a hash function for a <see cref="Hourai.DanmakU.Danmaku"/> object. 245 - /// </summary> 246 - /// <returns>A hash code for this instance that is suitable for use in hashing algorithms and data structures such as a hash table.</returns> 247 - public override int GetHashCode() { 248 - return PoolIndex; 249 243 } 250 244 251 245 #region Private and Internal Fields ··· 292 286 /// <summary> 293 287 /// Whether or not to perform collision detection with the Danmaku instance. 294 288 /// </summary> 295 - public bool CollisionCheck; 289 + public bool CollisionCheck = true; 296 290 297 291 public float Speed; 298 292 ··· 355 349 get { return direction; } 356 350 set { 357 351 direction = value.normalized; 358 - rotation = Mathf.Atan2(direction.y, direction.x)*Mathf.Rad2Deg - 359 - 90f; 352 + rotation = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg; 360 353 } 361 354 } 362 355 ··· 364 357 get { return direction * Speed; } 365 358 } 366 359 367 - public float Scale; 360 + public float Size; 368 361 369 362 /// <summary> 370 363 /// The amount of time that has passed since this bullet has been fired. ··· 409 402 set { 410 403 layer = value; 411 404 colliderMask = collisionMask[layer]; 405 + } 406 + } 407 + 408 + public Vector2 ColliderSize 409 + { 410 + get { return colliderSize; } 411 + set 412 + { 413 + colliderSize = value; 414 + sizeSquared = value.x * value.x; 415 + } 416 + } 417 + 418 + public Vector2 ColliderOffset 419 + { 420 + get { return colliderOffset; } 421 + set 422 + { 423 + colliderOffset = prefab.cachedScale.Hadamard2(value); 412 424 } 413 425 } 414 426
+1 -1
Assets/Dependencies/DanmakU/_Core_/DanmakuBehavior.cs
··· 13 13 /// <summary> 14 14 /// Shorthand for <c>TimeUtil.DeltaTime</c>. 15 15 /// </summary> 16 - protected static float Dt { 16 + protected static float dt { 17 17 get { return TimeUtil.DeltaTime; } 18 18 } 19 19 }
+85 -80
Assets/Dependencies/DanmakU/_Core_/DanmakuPrefab.cs
··· 19 19 [RequireComponent(typeof(ParticleSystem))] 20 20 public abstract class DanmakuType : MonoBehaviour, IEnumerable<Danmaku> 21 21 { 22 - private DanmakuPrefab prefab; 22 + internal static List<DanmakuType> activeTypes; 23 23 24 - public List<Danmaku> toDestroy; 24 + internal DanmakuPrefab prefab; 25 + public DanmakuPrefab Prefab 26 + { 27 + get { return prefab; } 28 + } 25 29 26 30 // Pool variables 27 31 internal Danmaku[] all; ··· 38 42 // Rendedring variables 39 43 internal Mesh mesh; 40 44 internal Color color; 45 + internal float size; 41 46 internal Material material; 42 47 internal int sortingLayer; 43 48 internal int sortingOrder; 49 + 50 + private int updateIndex; 51 + 52 + Action PostUpdate; 44 53 45 54 #region Public Properties 46 55 public int IotalCount { ··· 80 89 get { return color; } 81 90 set { 82 91 color = value; 83 - danmakuSystem.startColor = value; 92 + if(danmakuSystem) 93 + danmakuSystem.startColor = value; 84 94 } 85 95 } 86 96 97 + public float Size 98 + { 99 + get { return size; } 100 + set { size = value; } 101 + } 102 + 87 103 public Material Material { 88 104 get { return material; } 89 105 } ··· 92 108 #region Initialization 93 109 void Awake() 94 110 { 111 + if (activeTypes == null) 112 + activeTypes = new List<DanmakuType>(); 113 + activeTypes.Add(this); 114 + 95 115 DontDestroyOnLoad(this); 116 + 96 117 danmakuSystem = GetComponent<ParticleSystem>(); 97 118 dRenderer = GetComponent<ParticleSystemRenderer>(); 98 - 119 + 99 120 Transform root = transform.root; 100 121 transform.parent = null; 101 122 transform.localPosition = Vector3.zero; 102 123 103 124 danmakuSystem.simulationSpace = ParticleSystemSimulationSpace.World; 104 125 danmakuSystem.startSize = 1; 105 - danmakuSystem.startLifetime = float.PositiveInfinity; 126 + danmakuSystem.startLifetime = Mathf.Infinity; 127 + danmakuSystem.maxParticles = int.MaxValue; 106 128 danmakuSystem.gravityModifier = 0f; 107 129 danmakuSystem.startSpeed = 0; 108 130 danmakuSystem.enableEmission = false; ··· 115 137 dRenderer.shadowCastingMode = ShadowCastingMode.Off; 116 138 dRenderer.useLightProbes = false; 117 139 118 - //gameObject.hideFlags = HideFlags.HideInHierarchy; 140 + gameObject.hideFlags = HideFlags.HideInHierarchy; 119 141 120 142 // Destroy rest of hiearchy 121 143 if(root != transform) ··· 136 158 137 159 this.prefab = prefab; 138 160 161 + size = prefab.cachedScale.Max(); 139 162 _totalCount = 0; 140 163 _activeCount = 0; 141 164 _spawnCount = prefab.spawnCount; ··· 143 166 _spawnCount = 1; 144 167 all = new Danmaku[prefab.initialCount * 2]; 145 168 Spawn(prefab.initialCount); 146 - toDestroy = new List<Danmaku>(); 147 169 148 170 material = renderer.sharedMaterial; 149 171 sortingLayer = renderer.sortingLayerID; ··· 170 192 171 193 internal abstract void OnInit(Renderer renderer); 172 194 #endregion 173 - public bool updating; 174 195 175 196 void Update() 176 197 { 177 - //-------------------------------------------------------------------- 178 - // Rendering Update 179 - //-------------------------------------------------------------------- 198 + if (_activeCount <= 0) 199 + return; 200 + 180 201 int particleCount = danmakuSystem.particleCount; 181 202 if (_activeCount > particleCount) 182 - { 183 - danmakuSystem.maxParticles = Mathf.NextPowerOfTwo(_activeCount); 184 203 danmakuSystem.Emit(_activeCount - particleCount); 185 - } 186 204 if (_activeCount > particles.Length) 187 205 Array.Resize(ref particles, Mathf.NextPowerOfTwo(_activeCount + 1)); 188 206 189 - if (_activeCount <= 0 && particleCount <= 0) 190 - return; 191 - 192 207 danmakuSystem.GetParticles(particles); 193 - int staticActiveCount = _activeCount; 194 - 195 - updating = true; 196 208 197 209 // For some reason, new ParticleSystem.Particle breaks bullet systems 198 210 // but accessing a 199 211 ParticleSystem.Particle particle = particles[0]; 200 212 particle.axisOfRotation = Vector3.forward; 201 - int i = 0; 213 + updateIndex = 0; 202 214 if (prefab.fixedAngle) { 203 - while (i < staticActiveCount) { 204 - Danmaku danmaku = all[i]; 215 + while (updateIndex < _activeCount) { 216 + Danmaku danmaku = all[updateIndex]; 205 217 danmaku.Update(); 206 218 particle.position = danmaku.position; 207 - particle.size = danmaku.Scale; 219 + particle.size = danmaku.Size; 208 220 particle.color = danmaku.Color; 209 - particles[i] = particle; 210 - i++; 221 + particles[updateIndex++] = particle; 211 222 } 212 223 } 213 224 else 214 225 { 215 - while (i < staticActiveCount) 226 + while (updateIndex < _activeCount) 216 227 { 217 - Danmaku danmaku = all[i]; 228 + Danmaku danmaku = all[updateIndex]; 218 229 danmaku.Update(); 219 230 particle.position = danmaku.position; 220 231 particle.rotation = danmaku.rotation; 221 - particle.size = danmaku.Scale; 232 + particle.size = danmaku.Size; 222 233 particle.color = danmaku.Color; 223 - particles[i] = particle; 224 - i++; 234 + particles[updateIndex++] = particle; 225 235 } 226 236 } 227 - updating = false; 228 - // Destroy extra particles 229 - while (i < particleCount) { 230 - particles[i].lifetime = 0; 231 - i++; 232 - } 237 + updateIndex = -1; 233 238 234 - int destroyedCount = toDestroy.Count; 235 - // Remove destroyed particles 236 - for (i = 0; i < destroyedCount; i++) 237 - toDestroy[i].DestroyImpl(); 238 - toDestroy.Clear(); 239 + danmakuSystem.SetParticles(particles, _activeCount); 239 240 240 - danmakuSystem.SetParticles(particles, _activeCount); 241 + if(PostUpdate != null) { 242 + PostUpdate(); 243 + PostUpdate = null; 244 + } 241 245 } 242 246 243 247 protected virtual void OnDestroy() { 248 + activeTypes.Remove(this); 244 249 Destroy(mesh); 245 250 } 246 251 252 + void OnLevelWasLoaded(int level) { 253 + _activeCount = 0; 254 + _releasedCount = 0; 255 + } 256 + 247 257 public void DestroyAll() 248 258 { 249 - for (int i = 0; i < _activeCount; i++) 250 - all[i].Destroy(); 259 + PostUpdate += delegate() 260 + { 261 + for (int i = 0; i < _activeCount; i++) 262 + all[i].Destroy(); 263 + _activeCount = 0; 264 + _releasedCount = 0; 265 + }; 251 266 } 252 267 253 268 void Spawn(int count) ··· 256 271 if (all.Length < endCount) 257 272 Array.Resize(ref all, Mathf.NextPowerOfTwo(endCount + 1)); 258 273 for (int i = _totalCount; i < all.Length; i++) 259 - all[i] = new Danmaku(i); 274 + all[i] = new Danmaku(i, this); 260 275 _totalCount = endCount; 261 276 } 262 277 ··· 273 288 Danmaku inactive = all[_releasedCount]; 274 289 inactive.Color = color; 275 290 inactive.prefab = prefab; 276 - inactive.Scale = 1f; 291 + inactive.Size = size; 292 + inactive.Layer = prefab.cachedLayer; 293 + inactive.ColliderSize = prefab.colliderSize; 294 + inactive.colliderOffset = prefab.colliderOffset; 277 295 _releasedCount++; 278 296 return inactive; 279 297 } 280 298 281 299 internal void Activate(Danmaku danmaku) 282 300 { 283 - Danmaku active = all[_activeCount]; // This should be a released but not active bullet 284 - all[danmaku.PoolIndex] = active; 285 - all[active.PoolIndex] = danmaku; 301 + Danmaku active = all[_activeCount]; 286 302 287 303 active.PoolIndex = danmaku.PoolIndex; 288 304 danmaku.PoolIndex = _activeCount; 305 + 306 + all[_activeCount] = danmaku; 307 + all[active.PoolIndex] = active; 308 + 289 309 _activeCount++; 290 310 } 291 311 292 312 internal void Return(Danmaku danmaku) 293 313 { 294 - Danmaku released = all[_releasedCount]; 295 - Danmaku active = all[_activeCount]; 296 - 297 - all[_releasedCount] = danmaku; 298 - all[_activeCount] = released; 299 - all[danmaku.PoolIndex] = active; 300 - 301 - released.PoolIndex = active.PoolIndex; 302 - active.PoolIndex = danmaku.PoolIndex; 303 - danmaku.PoolIndex = _releasedCount; 314 + int index = danmaku.PoolIndex; 304 315 305 316 _activeCount--; 306 317 _releasedCount--; 318 + 319 + Danmaku active = all[_activeCount]; // Last active Danmaku 320 + Danmaku released = all[_releasedCount]; // Last released Danmaku 321 + 322 + all[danmaku.PoolIndex = _releasedCount] = danmaku; 323 + all[released.PoolIndex = _activeCount] = released; 324 + all[active.PoolIndex = index] = active; 307 325 } 308 326 #endregion 309 327 ··· 414 432 415 433 void Init() 416 434 { 435 + cachedScale = transform.localScale; 436 + cachedLayer = gameObject.layer; 437 + 417 438 var singleRenderer = GetComponent<Renderer>(); 418 439 var spriteRenderer = singleRenderer as SpriteRenderer; 419 440 var meshRenderer = singleRenderer as MeshRenderer; ··· 476 497 danmaku.colliderOffset = cachedScale.Hadamard2(colliderOffset); 477 498 } 478 499 479 - danmaku.Color = cachedColor; 480 - danmaku.Scale = 1f; 500 + danmaku.Color = type.Color; 501 + danmaku.Size = 1f; 481 502 danmaku.Layer = cachedLayer; 482 503 } 483 504 484 - void Initialize() 485 - { 486 - cachedScale = transform.localScale; 487 - cachedTag = gameObject.tag; 488 - cachedLayer = gameObject.layer; 489 - } 490 - 491 - #if UNITY_EDITOR 505 + #if UNITY_EDITOR 492 506 private void OnDrawGizmosSelected() { 493 507 Matrix4x4 oldGizmoMatrix = Gizmos.matrix; 494 508 Matrix4x4 oldHandlesMatrix = Handles.matrix; ··· 528 542 Gizmos.color = oldGizmosColor; 529 543 Handles.color = oldHandlesColor; 530 544 } 531 - #endif 545 + #endif 532 546 533 547 private void OnDestroy() { 534 548 if (type) ··· 588 602 internal int spawnCount; 589 603 590 604 internal Vector3 cachedScale; 591 - internal string cachedTag; 592 605 internal int cachedLayer; 593 606 594 - internal Sprite cachedSprite; 595 - internal Color cachedColor; 596 - internal Material cachedMaterial; 597 - internal int cachedSortingLayer; 598 - internal int cachedSortingOrder; 599 - 600 607 #endregion 601 608 602 609 #region Runtime fields 603 610 604 611 internal DanmakuType type; 605 - private HashSet<Danmaku> currentDanmaku; 606 - internal DanmakuGroup currentGroup; 607 612 608 613 #endregion 609 614
+12
Assets/Dependencies/DanmakU/_Core_/DanmakuStatic.cs
··· 59 59 colliderMap.Clear(); 60 60 } 61 61 62 + public static IEnumerable<Danmaku> All 63 + { 64 + get 65 + { 66 + if (DanmakuType.activeTypes == null) 67 + yield break; 68 + foreach (DanmakuType type in DanmakuType.activeTypes) 69 + foreach (Danmaku danmaku in type) 70 + yield return danmaku; 71 + } 72 + } 73 + 62 74 internal static void Setup(float angRes = 0.1f) { 63 75 colliderMap = new Dictionary<Collider2D, IDanmakuCollider[]>(); 64 76 collisionMask = Util.CollisionLayers2D();
+105
Assets/Dependencies/DanmakU/_Core_/Editor/DanmakuInspector.cs
··· 1 + using UnityEngine; 2 + using UnityEditor; 3 + using Hourai.Editor; 4 + 5 + namespace Hourai.DanmakU.Editor 6 + { 7 + [InitializeOnLoad] 8 + public class DanmakuInspector : EditorWindow 9 + { 10 + const string selectorDisplayKey = "showDanmakuSelectors"; 11 + 12 + static bool showSelectors; 13 + static Danmaku selectedDanmaku; 14 + 15 + static DanmakuInspector() 16 + { 17 + SceneView.onSceneGUIDelegate += OnSceneGUI; 18 + 19 + if(EditorPrefs.HasKey(selectorDisplayKey)) 20 + showSelectors = EditorPrefs.GetBool(selectorDisplayKey); 21 + else 22 + EditorPrefs.SetBool(selectorDisplayKey, showSelectors = true); 23 + } 24 + 25 + [MenuItem("Hourai/DanmakU/Danmaku Inspector")] 26 + public static void CreateWindow() 27 + { 28 + EditorWindow.GetWindow<DanmakuInspector>("Danmaku"); 29 + } 30 + 31 + static void OnSceneGUI(SceneView sceneView) 32 + { 33 + if(!EditorApplication.isPlaying || !showSelectors) 34 + return; 35 + Vector3 forward = Vector3.forward; 36 + using (HandleUtil.With(Color.green)) { 37 + foreach (Danmaku danmaku in Danmaku.All) { 38 + if(danmaku == null || !danmaku.IsActive) 39 + continue; 40 + selectedDanmaku = danmaku; 41 + Handles.matrix = Matrix4x4.TRS(danmaku.Position, Quaternion.Euler(0f, 0f, danmaku.Rotation), danmaku.Size * Vector3.one); 42 + float colliderSize = danmaku.Prefab.ColliderSize.Max(); 43 + Handles.DrawWireDisc(danmaku.Prefab.ColliderOffset, forward, colliderSize); 44 + Handles.DrawLine(Vector3.zero, colliderSize * Vector3.right); 45 + } 46 + } 47 + } 48 + 49 + void OnEnable() 50 + { 51 + EditorApplication.update += Repaint; 52 + } 53 + 54 + void OnDisable() 55 + { 56 + EditorApplication.update -= Repaint; 57 + } 58 + 59 + void OnGUI() 60 + { 61 + if (!EditorApplication.isPlaying) 62 + NotPlaying(); 63 + DanmakuDisplay(); 64 + } 65 + 66 + void DanmakuDisplay() 67 + { 68 + if (selectedDanmaku == null) 69 + return; 70 + 71 + EditorGUILayout.LabelField("Danmaku Properties"); 72 + EditorGUI.indentLevel++; 73 + selectedDanmaku.Position = EditorGUILayout.Vector2Field("Position", selectedDanmaku.Position); 74 + float rotation = (selectedDanmaku.Rotation % 360f + 360f) % 360f - 180f; 75 + selectedDanmaku.Rotation = EditorGUILayout.Slider("Rotation", rotation, -180f, 180f); 76 + selectedDanmaku.Size = EditorGUILayout.FloatField("Size", selectedDanmaku.Size); 77 + selectedDanmaku.Color = EditorGUILayout.ColorField("Color", selectedDanmaku.Color); 78 + selectedDanmaku.Speed = EditorGUILayout.FloatField("Speed", selectedDanmaku.Speed); 79 + selectedDanmaku.AngularSpeed = EditorGUILayout.FloatField("Angular Speed", selectedDanmaku.AngularSpeed); 80 + 81 + EditorGUILayout.LabelField("Frames", selectedDanmaku.Frames.ToString()); 82 + EditorGUILayout.LabelField("Time", selectedDanmaku.Time.ToString()); 83 + EditorGUI.indentLevel--; 84 + EditorGUILayout.LabelField("Prefab Properties"); 85 + EditorGUI.indentLevel++; 86 + DanmakuPrefab prefab = selectedDanmaku.Prefab; 87 + DanmakuType type = selectedDanmaku.Type; 88 + EditorGUILayout.ObjectField("Prefab", prefab, typeof(DanmakuPrefab)); 89 + type.Size = EditorGUILayout.FloatField("Size", type.Size); 90 + type.Color = EditorGUILayout.ColorField("Color", type.Color); 91 + EditorGUILayout.LabelField("Tag", prefab.tag); 92 + EditorGUILayout.LabelField("Layer", LayerMask.LayerToName(selectedDanmaku.Prefab.gameObject.layer)); 93 + } 94 + 95 + void NotPlaying() 96 + { 97 + } 98 + 99 + [MenuItem("Tools/MyTool/Do It in C#")] 100 + static void DoIt() 101 + { 102 + EditorUtility.DisplayDialog("MyTool", "Do It in C# !", "OK", ""); 103 + } 104 + } 105 + }
+12
Assets/Dependencies/DanmakU/_Core_/Editor/DanmakuInspector.cs.meta
··· 1 + fileFormatVersion: 2 2 + guid: 4f718582a04e3db4aa2f686d44aa74b8 3 + timeCreated: 1441519851 4 + licenseType: Free 5 + MonoImporter: 6 + serializedVersion: 2 7 + defaultReferences: [] 8 + executionOrder: 0 9 + icon: {instanceID: 0} 10 + userData: 11 + assetBundleName: 12 + assetBundleVariant:
+1 -1
Assets/Dependencies/DanmakU/_Core_/Util/DanmakuUtil.cs
··· 12 12 public static class DanmakuUtil { 13 13 14 14 public static float AngleBetween2D(Vector2 v1, Vector2 v2) { 15 - return Mathf.Atan2(v2.y - v1.y, v2.x - v1.x)*180f/Mathf.PI - 90f; 15 + return Mathf.Atan2(v2.y - v1.y, v2.x - v1.x) * Mathf.Rad2Deg; 16 16 } 17 17 18 18 public static Quaternion RotationBetween2D(Vector2 v1, Vector2 v2) {
-11
Assets/Dependencies/DanmakU/_Core_/Util/RotationMode.cs
··· 1 - namespace Hourai.DanmakU { 2 - 3 - public enum RotationMode { 4 - 5 - Absolute, 6 - Relative, 7 - Object 8 - 9 - } 10 - 11 - }
+1 -1
Assets/Dependencies/DanmakU/_Core_/Util/RotationMode.cs.meta
··· 1 1 fileFormatVersion: 2 2 2 guid: e2a57245c329a974688fe0580f7db263 3 - timeCreated: 1441237562 3 + timeCreated: 1441529821 4 4 licenseType: Free 5 5 MonoImporter: 6 6 serializedVersion: 2
+87
Assets/Dependencies/HouraiLib/Editor/Util/HandleUtil.cs
··· 1 + using UnityEngine; 2 + using UnityEditor; 3 + using System; 4 + using System.Collections; 5 + 6 + namespace Hourai.Editor 7 + { 8 + internal class HandleDisposable : IDisposable 9 + { 10 + 11 + private readonly Color? _oldColor; 12 + private readonly Matrix4x4? _oldTransform; 13 + 14 + public HandleDisposable() 15 + { 16 + } 17 + 18 + public HandleDisposable(Color color) { 19 + //Cache the old color 20 + _oldColor = Handles.color; 21 + Handles.color = color; 22 + } 23 + 24 + public HandleDisposable(Matrix4x4 matrix) { 25 + //Cache the old matrix 26 + _oldTransform = Handles.matrix; 27 + Handles.matrix = matrix; 28 + } 29 + 30 + public HandleDisposable(Color color, Matrix4x4 matrix) 31 + { 32 + //Cache the old color 33 + _oldColor = Handles.color; 34 + Handles.color = color; 35 + 36 + //Cache the old matrix 37 + _oldTransform = Handles.matrix; 38 + Handles.matrix = matrix; 39 + } 40 + 41 + public void Dispose() { 42 + if (_oldColor != null) 43 + Handles.color = (Color)_oldColor; 44 + if (_oldTransform != null) 45 + Handles.matrix = (Matrix4x4)_oldTransform; 46 + } 47 + } 48 + 49 + 50 + public static class HandleUtil 51 + { 52 + public static IDisposable Save() 53 + { 54 + return new HandleDisposable(); 55 + } 56 + 57 + public static IDisposable With(Color color) 58 + { 59 + return new HandleDisposable(color); 60 + } 61 + 62 + public static IDisposable With(Matrix4x4 transform) 63 + { 64 + return new HandleDisposable(transform); 65 + } 66 + 67 + public static IDisposable With(Color color, Matrix4x4 transform) 68 + { 69 + return new HandleDisposable(color, transform); 70 + } 71 + 72 + public static IDisposable With(Transform transform) 73 + { 74 + if (transform == null) 75 + throw new ArgumentNullException("transform"); 76 + return new HandleDisposable(transform.localToWorldMatrix); 77 + } 78 + 79 + public static IDisposable With(Color color, Transform transform) 80 + { 81 + if (transform == null) 82 + throw new ArgumentNullException("transform"); 83 + return new HandleDisposable(color, transform.localToWorldMatrix); 84 + } 85 + } 86 + 87 + }
-2
Assets/Dependencies/HouraiLib/General/Singleton.cs
··· 15 15 if (_instance == null) { 16 16 _instance = FindObjectOfType<T>(); 17 17 if (_instance == null) { 18 - Debug.LogError("Something is trying to access the " + typeof(T) + 19 - " Singleton instance, but none exists."); 20 18 _instance = new GameObject(typeof(T).Name).AddComponent<T>(); 21 19 } 22 20 }
+10 -1
Assets/Dependencies/HouraiLib/Util/GizmoUtil.cs
··· 4 4 5 5 namespace Hourai { 6 6 7 - public sealed class GizmoDisposable : IDisposable { 7 + internal sealed class GizmoDisposable : IDisposable { 8 8 9 9 private readonly Color? _oldColor; 10 10 private readonly Matrix4x4? _oldTransform; 11 + 12 + public GizmoDisposable() 13 + { 14 + } 11 15 12 16 public GizmoDisposable(Color color) { 13 17 //Cache the old color ··· 42 46 43 47 44 48 public static class GizmoUtil { 49 + 50 + public static IDisposable Save() 51 + { 52 + return new GizmoDisposable(); 53 + } 45 54 46 55 public static IDisposable With(Color color) { 47 56 return new GizmoDisposable(color);
+10 -8
Assets/Test/BasicFireTest.cs
··· 24 24 [SerializeField] 25 25 private int burstCount; 26 26 27 + [SerializeField] 28 + private float rotation; 29 + 27 30 private Task test; 28 - private DanmakuGroup group; 31 + private DanmakuGroup group; 32 + private DanmakuField field; 29 33 30 34 private void Start() { 31 35 TimeUtil.FrameRateIndependent = false; 32 - DanmakuField field = DanmakuField.FindClosest(this); 33 - //group = DanmakuGroup.List(); 36 + field = DanmakuField.FindClosest(this); 37 + group = DanmakuGroup.List(); 34 38 FireData data = prefab; 35 - //group.Bind(data); 36 - Debug.Log(field); 39 + group.Bind(data); 37 40 if (field) 38 41 field.Bind(data); 39 42 40 - Spiral(data.Infinite(Modifier.Rotate(5f))).Execute(); 43 + Spiral(data.Infinite(Modifier.Rotate(rotation))).Execute(); 41 44 //Spiral(data.Infinite(Modifier.Rotate(-3f)).WithColor(Color.blue)).Execute(); 42 45 //InvokeRepeating("DAALL", 10, 10); 43 46 } ··· 49 52 50 53 IEnumerable Spiral(IEnumerable pos) 51 54 { 52 - return pos 53 - .WithSpeed(speed) 55 + return pos .WithSpeed(speed) 54 56 .Delay(delay) 55 57 .RadialBurst(burstCount); 56 58 }
+3 -2
Assets/Test/Test Scene.unity
··· 436 436 m_NumAlphaKeys: 2 437 437 speed: 5 438 438 burstCount: 20 439 + rotation: 5 439 440 --- !u!4 &1376768896 440 441 Transform: 441 442 m_ObjectHideFlags: 0 ··· 545 546 m_Script: {fileID: 11500000, guid: 8700f30fe9e49ad4fb2ed407eba26a75, type: 3} 546 547 m_Name: 547 548 m_EditorClassIdentifier: 548 - camera2D: {fileID: 0} 549 - clipBoundary: 1 549 + camera2D: {fileID: 513550416} 550 + clipBoundary: 0 550 551 fieldSize: {x: 20, y: 20} 551 552 otherCameras: [] 552 553 useClipBoundary: 1