public override void OnInspectorGUI() { GUI.changed = false; GravityParticles nbp = (GravityParticles)target; Vector3 initialV = nbp.initialVelocity; bool addNBodyVelocity = nbp.addNBodyVelocity; IGravityParticlesInit particlesInit = nbp.GetComponent <IGravityParticlesInit>(); GravityScaler.Units units = GravityEngine.Instance().units; string prompt = string.Format("Initial Vel. ({0})", GravityScaler.VelocityUnits(units)); if (particlesInit == null) { EditorGUILayout.LabelField("No init script", EditorStyles.boldLabel); bool hasNBody = false; if (nbp.GetComponent <NBody>() != null) { hasNBody = true; } else if (nbp.transform.parent != null && nbp.transform.parent.gameObject.GetComponent <NBody>() != null) { hasNBody = true; } if (hasNBody) { addNBodyVelocity = EditorGUILayout.Toggle(new GUIContent("Use velocity from NBody", velTip), nbp.addNBodyVelocity); if (addNBodyVelocity) { EditorGUILayout.LabelField("Initial Velocity: (from NBody)", EditorStyles.boldLabel); } else { initialV = EditorGUILayout.Vector3Field(new GUIContent(prompt, iTip), nbp.initialVelocity); } } else { initialV = EditorGUILayout.Vector3Field(new GUIContent(prompt, iTip), nbp.initialVelocity); } } else { EditorGUILayout.LabelField("Initalize with: " + particlesInit.GetType().ToString(), EditorStyles.boldLabel); } if (GUI.changed) { Undo.RecordObject(nbp, "GravityParticles Change"); nbp.initialVelocity = initialV; nbp.addNBodyVelocity = addNBodyVelocity; EditorUtility.SetDirty(nbp); } }
void Start() { gravityEngine = GravityEngine.instance; dt = gravityEngine.GetParticleDt(); // outOfBoundsSquared = gravityEngine.outOfBounds * gravityEngine.outOfBounds; gravityParticles = GetComponent <ParticleSystem>(); InitParticleData(); // Had Play() here - but after Unity 5.3 this broke. Now moved to the update loop. // Get the Init Delegate (if there is one) particlesInit = GetComponent <IGravityParticlesInit>(); if (particlesInit == null && addNBodyVelocity) { // Find the associated NBody // Can either be directly attached (particleSystem is attached directly to object with NBody) OR // can be the parent (if ParticleSystem has its own Game Object and is a child) if (GetComponent <NBody>() != null) { nbodySource = transform.gameObject; } else if (transform.parent != null && transform.parent.gameObject.GetComponent <NBody>() != null) { nbodySource = transform.parent.gameObject; } } particleBySeed = new Dictionary <uint, int>(); // determine if this is a one-time burst scenario int burstCount = 0; ParticleSystem.Burst[] bursts = new ParticleSystem.Burst[gravityParticles.emission.burstCount]; gravityParticles.emission.GetBursts(bursts); foreach (ParticleSystem.Burst burst in bursts) { burstCount += burst.maxCount; } if (burstCount == gravityParticles.main.maxParticles) { oneTimeBurst = true; burstDone = false; } #pragma warning disable 162 // disable unreachable code warning if (debugLogs) { Debug.Log(this.name + " start: oneTimeBurst=" + oneTimeBurst + " burstCount=" + burstCount + " pc=" + gravityParticles.main.maxParticles); } #pragma warning restore 162 // self-register with NBE gravityEngine.RegisterParticles(this); #pragma warning disable 162 // disable unreachable code warning if (debugLogs) { Debug.Log("Registered with GE: self=" + transform.gameObject.name); } #pragma warning restore 162 }