////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // MonoBehaviours ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void OnEnable() { if (isSnapshot || isLoading) return; thisInstance = this; thisLayer = particleSystemGameObject.layer; initialized = false; isYieldRefreshing = false; isSettingParticleCount = false; isSettingLifetime = false; hasActiveParticles = true; threadHadNoActiveParticles = false; isDoneThread = true; calculate = true; lastTimeUpdated = PlaygroundC.globalTime; localTime = lastTimeUpdated; emissionStopped = 0; queueEmissionHalt = false; hasEmitted = false; // Set new randoms RefreshSystemRandom(); // Set 0 size to avoid one-frame flash shurikenParticleSystem.startSize = 0f; if (shurikenParticleSystem.isPaused || shurikenParticleSystem.isStopped) shurikenParticleSystem.Play(); // Set initial values previousLifetimeValueMethod = lifetimeValueMethod; previousLifetime = lifetime; previousLifetimeMin = lifetimeMin; previousEmission = emit; previousLoop = loop; previousNearestNeighborOrigin = nearestNeighborOrigin; previousNearestNeighborOriginMethod = nearestNeighborOriginMethod; previousNearestNeighborOriginVector3 = nearestNeighborOriginVector3; previousNearestNeighborOriginTransform = nearestNeighborOriginTransform; previousSorting = sorting; previousParticleCount = particleCount; previousLifetimeEmission = lifetimeEmission; prevSource = source; loopExceeded = false; loopExceededOnParticle = -1; stRot = Quaternion.identity; stDir = new Vector3(); // Initiate all arrays by setting particle count if (particleCache==null) { SetParticleCount(thisInstance, particleCount); } else { // Clean up particle positions SetInitialTargetPosition(thisInstance, PlaygroundC.initialTargetPosition, true); // Clean up collision cache hasCollisionCache = false; collisionCache = null; // Refresh StartCoroutine(YieldedRefresh()); } }
/// <summary> /// Copies this CollisionCache. /// </summary> public CollisionCache Clone() { CollisionCache collisionCache = new CollisionCache(collisionPosition.Length); collisionCache.hasCollided = (bool[])hasCollided.Clone(); collisionCache.collisionPosition = (Vector3[])collisionPosition.Clone(); collisionCache.collisionNormal = (Vector3[])collisionNormal.Clone(); collisionCache.collisionTransform = (Transform[])collisionTransform.Clone(); collisionCache.collisionTransformPosition = (Vector3[])collisionTransformPosition.Clone(); collisionCache.stickyPosition = (Vector3[])stickyPosition.Clone(); return collisionCache; }
/// <summary> /// Sets the particle at index to stick onto a parent transform. /// </summary> /// <param name="index">Index.</param> /// <param name="position">Position.</param> /// <param name="normal">Normal.</param> /// <param name="parent">Parent.</param> public void SetSticky(int index, Vector3 position, Vector3 normal, float offset, Transform parent) { if (index<0||index>particleCount-1) return; if (!hasCollisionCache) { collisionCache = new CollisionCache(particleCount); hasCollisionCache = true; } collisionCache.SetSticky(index, position, normal, stickyCollisionsSurfaceOffset, parent); }