/// <summary> /// Instantiates a preset by name reference. /// </summary> /// <returns>The preset.</returns> /// <param name="presetName">Preset name.</param> public static PlaygroundParticlesC InstantiatePreset (string presetName) { GameObject presetGo = ResourceInstantiate("Presets/"+presetName); PlaygroundParticlesC presetParticles = presetGo.GetComponent<PlaygroundParticlesC>(); if (presetParticles!=null) { if (reference==null) reference = PlaygroundC.ResourceInstantiate("Playground Manager").GetComponent<PlaygroundC>(); if (reference) { if (reference.autoGroup && presetParticles.particleSystemTransform.parent==null) presetParticles.particleSystemTransform.parent = referenceTransform; particlesQuantity++; presetParticles.particleSystemId = particlesQuantity-1; } presetGo.name = presetName; return presetParticles; } else { if (presetGo.name.Contains("Presets/")) presetGo.name = presetGo.name.Remove(0, 8); return null; } }
/// <summary> /// Initializes the Playground Manager. /// </summary> public IEnumerator InitializePlayground () { // Check for duplicates of the Playground Manager if (reference!=null && reference!=this) { yield return null; Debug.Log("There can only be one instance of the Playground Manager in the scene."); // Save all children! foreach (Transform child in transform) child.parent = null; DestroyImmediate(gameObject); yield break; } else if (reference==null) reference = this; // Check events availability CheckEvents(); // New random random = new System.Random(); // Reset time TimeReset(); // Remove any null particle systems for (int i = 0; i<particleSystems.Count; i++) { if (particleSystems[i]!=null) { particleSystems[i].particleSystemId = i; } else { particleSystems.RemoveAt(i); i--; } } // Set quantity counter particlesQuantity = particleSystems.Count; // Spline preview #if UNITY_EDITOR PlaygroundSpline.drawSplinePreviews = drawSplinePreview; #endif // Get ready frameCount = 0; threadAggregatorRuns = 0; isReady = true; isDoneThread = true; isDoneThreadLocal = true; isDoneThreadSkinned = true; isDoneThreadTurbulence = true; maxThreads = Mathf.Clamp (maxThreads, 1, 128); processorCount = SystemInfo.processorCount; threads = Mathf.Clamp (processorCount>1?processorCount-1:1, 1, maxThreads); }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // MonoBehaviours ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // OnEnable is called in both Edit- and Play Mode // Initializes all particle systems void OnEnable () { // Cache the Playground reference reference = this; referenceTransform = transform; referenceGameObject = gameObject; // Initialize StartCoroutine(InitializePlayground()); }