public void Invoke() { if (randomizeOrder && random == null) { random = new RandomEssentials(); } if (nextEvent == null) { if (!randomizeOrder) { nextEvent = events[0]; nextEventIndex = nextEventIndex.GetLooped(events.Length); } else { nextEventIndex = random.GetRandomInt(events.Length); nextEvent = events[nextEventIndex]; } } nextEvent?.Invoke(); if (!randomizeOrder) { nextEventIndex = nextEventIndex.GetLooped(events.Length); } else { nextEventIndex = random.GetRandomInt(events.Length); } nextEvent = events[nextEventIndex]; }
private void Start() { // The pool is created poolEssentials = new UnityEngine.PoolEssentials(objectsToSpawn, 10, Vector3.zero, Quaternion.identity, false, randomInstantiationSequence); randomEssentials = new UnityEngine.RandomEssentials(); Debug.Log($"Press '{keyToSpawn}' to spawn a new object from the pool."); }
/// <summary> /// Creates a Pool instance. /// </summary> /// <param name="baseObjects">The object that will be instantiated by the pool.</param> /// <param name="size">The maximum number of objects that can be instantiated at the same time.</param> /// <param name="instantiationPosition">The position where the objects must be instantiated.</param> /// <param name="instantiationRotation">The rotation that the objects must have when instantiated.</param> /// <param name="instantiateAllAtCreation">If the pool should instantiate all the objects in the scene right away (true) or if they should be instantiated when they are needed (false, default value).</param> /// <param name="randomInstantiationSequence">If false, the objects will be instantiated in the appearing order in the 'baseObjects array. If true, the order of instantiation of the pooled objects is going to be random./param> /// <param name="intantiationRandomizationSeed">The seed used to randomly pick the baseObjects in the first instantiation process</param> public Pool(GameObject[] baseObjects, int size, Vector3 instantiationPosition, Quaternion instantiationRotation, bool instantiateAllAtCreation = false, bool randomInstantiationSequence = false, int intantiationRandomizationSeed = -1) : this(baseObjects, size, instantiateAllAtCreation) { defaultPositionAndRotation = new DefaultPositionAndRotation(instantiationPosition, instantiationRotation); this.randomInstantiationSequence = randomInstantiationSequence; if (intantiationRandomizationSeed != -1) { this.randomEssentialsInstantiation = new RandomEssentials(intantiationRandomizationSeed); } }
public Sequence(UnityEvent[] events, bool randomizeOrder = false, int randomizationSeed = -1) { this.events = events; this.randomizeOrder = randomizeOrder; if (randomizationSeed == -1) { random = new RandomEssentials(); } else { random = new RandomEssentials(randomizationSeed); } }
private IEnumerator coroutineHolder; // Keeps track of the coroutine private void Start() { // The pool is created pool = new UnityEngine.Pool(objectToSpawn, 100, false); randomEssentials = new UnityEngine.RandomEssentials(); Debug.Log($"Press '{keyToSpawn}' to spawn a new object from the pool."); //Assign the coroutine to the holder coroutineHolder = LoadingCoroutine(); //Run the coroutine StartCoroutine(coroutineHolder); }
private void Start() { randomEssentials = new UnityEngine.RandomEssentials(); //EXAMPLES: bool randomBool = randomEssentials.GetRandomBool(0.75f); int randomInt = randomEssentials.GetRandomInt(3, 10); float randomFloat = randomEssentials.GetRandomFloat(0.5f, 0.1f); Vector3 randomVector3 = randomEssentials.GetRandomVector3(0.5f, 0.1f); Vector2 randomVector2 = randomEssentials.GetRandomVector2(0.5f, 0.1f); int randomSign = randomEssentials.GetRandomSign(0.4f); bool randomBoolTrueEnsured = randomEssentials.GetRandomBoolTrueEnsured(3, 10); bool randomDistributedBool = randomEssentials.GetPseudoRandomDistributedBool(5, 0.25f); // This variables are not used anywhere, they exist only to help the example. }
private void Start() { randomEssentials = new UnityEngine.RandomEssentials(); //EXAMPLES: bool randomBool = randomEssentials.GetRandomBool(0.75f); int randomInt = randomEssentials.GetRandomInt(3, 10); float randomFloat = randomEssentials.GetRandomFloat(0.5f, 0.1f); Vector3 randomVector3 = randomEssentials.GetRandomVector3(0.5f, 0.1f); Vector2 randomVector2 = randomEssentials.GetRandomVector2(0.5f, 0.1f); int randomSign = randomEssentials.GetRandomSign(0.4f); bool randomBoolTrueEnsured = randomEssentials.GetRandomBoolTrueEnsured(3, 10); bool randomDistributedBool = randomEssentials.GetPseudoRandomDistributedBool(5, 0.25f); // To make easier the single use of RandomEssentials, the object can be created and used as follows: randomBool = UnityEngine.RandomEssentials.GetNew().GetRandomBool(); randomBool = UnityEngine.RandomEssentials.GetNew(123456).GetRandomBool(); // With custom seed // This variables are not used anywhere, they exist only to help the example. }
/// <summary> /// Creates a Pool instance. /// </summary> /// <param name="baseObjects">The object that will be instantiated by the pool.</param> /// <param name="size">The maximum number of objects that can be instantiated at the same time.</param> /// <param name="instantiateAllAtCreation">If the pool should instantiate all the objects in the scene right away (true) or if they should be instantiated when they are needed (false, default value).</param> /// <param name="randomInstantiationSequence">If false, the objects will be instantiated in the appearing order in the 'baseObjects array. If true, the order of instantiation of the pooled objects is going to be random.</param> /// <param name="intantiationRandomizationSeed">The seed used to randomly pick the baseObjects in the first instantiation process</param> public PoolEssentials(GameObject[] baseObjects, int size, bool instantiateAllAtCreation = false, bool randomInstantiationSequence = false, int intantiationRandomizationSeed = -1) { this.baseObjects = baseObjects; this.size = size; referencedObjects = new List <GameObject>(); activeIndex = 0; this.randomInstantiationSequence = randomInstantiationSequence; if (intantiationRandomizationSeed != -1) { this.randomEssentialsInstantiation = new RandomEssentials(intantiationRandomizationSeed); } if (instantiateAllAtCreation) { for (int i = 0; i < size; i++) { InstantiateNewAt(i); } } }
public Sequence(UnityAction[] actions, bool randomizeOrder = false, int randomizationSeed = -1) { List <UnityEvent> events = new List <UnityEvent>(); foreach (UnityAction unityAction in actions) { UnityEvent unityEvent = new UnityEvent(); unityEvent.AddListener(unityAction); events.Add(unityEvent); } this.events = events.ToArray(); this.randomizeOrder = randomizeOrder; if (randomizationSeed == -1) { random = new RandomEssentials(); } else { random = new RandomEssentials(randomizationSeed); } }
private void Start() { randomEssentials = new UnityEngine.RandomEssentials(); Debug.Log($"Press '{keyToSpawn}' to spawn a new object from the pool."); }