public void Umath_RandomVector3Int() { for (int i = 0; i < 100; i++) { Debug.Log("RandomInt: " + Umath.RandomVector3Int(new Vector3Int(1, 5, 10), new Vector3Int(3, 7, 12))); } }
private void Start() { // Create the ppositions list to spawn var spawnPointsList = new List <PositionKeeper>(); var spawnTransformsList = new List <PositionKeeper>(); var spawnInChildsOfList = new List <PositionKeeper>(); if (spawnPoints != null) { spawnPointsList = spawnPoints.Where(s => s != null).Select(s => new PositionKeeper(s)).ToList(); } if (spawnTransforms != null) { spawnTransformsList = spawnTransforms.Where(t => t != null).Select(t => new PositionKeeper(t)).ToList(); } if (spawnInChildsOf != null) { spawnInChildsOfList = spawnInChildsOf.GetChildsTransforms().Select(t => new PositionKeeper(t)).ToList(); } spawnsPositionsList = spawnPointsList.Union(spawnTransformsList).Union(spawnInChildsOfList).ToList(); // Create the max spawns if (spawnMode == SpawnMode.RandomCount || spawnMode == SpawnMode.RandomTrack) { totalSpawns = Umath.RandomInt(minSpawns, maxSpawns); } else if (spawnMode == SpawnMode.Count || spawnMode == SpawnMode.Track) { totalSpawns = maxSpawns; } }
public void Umath_RandomVector2() { for (int i = 0; i < 100; i++) { Debug.Log("RandomInt: " + Umath.RandomVector2(new Vector2(1, 5), new Vector2(3, 7))); } }
public void Umath_RandomVector4() { for (int i = 0; i < 100; i++) { Debug.Log("RandomInt: " + Umath.RandomVector4(new Vector4(1, 5, 10, 15), new Vector4(3, 7, 12, 17))); } }
public void Umath_RandomFloat() { for (int i = 0; i < 100; i++) { Debug.Log("RandomInt: " + Umath.RandomFloat(0, 5)); } }
public void Umath_RandomInt_Negative() { for (int i = 0; i < 100; i++) { Debug.Log("RandomInt: " + Umath.RandomInt(-5, 0)); } }
private void Start() { if (!pausedBeforeStart) { isPaused = !playOnAwake; } // Set the duration if (betweenActions == TimeBetweenActions.Random) { duration = Umath.RandomFloat(minDuration, maxDuration); } else { duration = maxDuration; } // Set the iterations if (iterateMode == IterateMode.RandomCount) { iterations = Umath.RandomInt(minIterations, maxIterations); } else { iterations = maxIterations; } }
protected void Update() { if (isPaused) { return; } // If iterations are completed if (iterateMode == IterateMode.Count || iterateMode == IterateMode.RandomCount) { if (completedIterations >= iterations) { enabled = false; return; } } // If the current time count is completed if (time >= duration) { completedIterations++; time -= duration; if (betweenActions == TimeBetweenActions.Random) { duration = Umath.RandomFloat(minDuration, maxDuration); } else { duration = maxDuration; } // Execute the delegates try { onTimeEvent?.Invoke(); } catch (Exception e) { Debug.LogError("OnTimeEventImplementer: Error in OnTime, " + e); } } if (timeMode == TimeMode.DeltaTime) { time += Time.deltaTime; } else { time += Time.unscaledDeltaTime; } }
public void Restart() { isPaused = !playOnAwake; time = 0; // Set the duration if (betweenActions == TimeBetweenActions.Random) { duration = Umath.RandomFloat(minDuration, maxDuration); } else { duration = maxDuration; } // Enable the component if disabled this.enabled = true; }
private Vector3 SelectSpawnPoint() { if (spawnsPositionsList.Count < 1) { throw new ArgumentNullException("Spawner: No available positions to spawn"); } if (sortBetwenPoints == SortMode.Random) { if (spawnsPositionsList == null || spawnsPositionsList.Count() < 1) { return(Vector3.zero); } var position = Umath.RandomInt(0, spawnsPositionsList.Count() - 1); return(spawnsPositionsList[position].Position); } else if (sortBetwenPoints == SortMode.Order) { if (spawnsPositionsList == null || spawnsPositionsList.Count() < 1) { return(Vector3.zero); } // Check if exist some point in queue or renew the queue if (spawnsPositionsQueue.Count() < 1) { foreach (var point in spawnsPositionsList) { spawnsPositionsQueue.Enqueue(point); } } // Get the next oint return(spawnsPositionsQueue.Dequeue().Position); } else if (sortBetwenPoints == SortMode.InverseOrder) { if (spawnsPositionsList == null || spawnsPositionsList.Count() < 1) { return(Vector3.zero); } // Check if exist some point in queue or renew the queue if (spawnsPositionsQueue.Count() < 1) { // Create the reversed list var reversedList = new List <PositionKeeper>(spawnsPositionsList); reversedList.Reverse(); foreach (var point in reversedList) { spawnsPositionsQueue.Enqueue(point); } } // Get the next point return(spawnsPositionsQueue.Dequeue().Position); } else if (sortBetwenPoints == SortMode.RandomDontRepeat) { if (spawnsPositionsList == null || spawnsPositionsList.Count() < 1) { return(Vector3.zero); } // Check if exist some point in queue or renew the queue if (spawnsPositionsQueue.Count() < 1) { // Create the randomList list var randomList = new List <PositionKeeper>(spawnsPositionsList).Shuffle(); foreach (var point in randomList) { spawnsPositionsQueue.Enqueue(point); } } // Get the next point return(spawnsPositionsQueue.Dequeue().Position); } return(Vector3.zero); }
} // Random Spawn public GameObject[] SpawnAndSelect(int min, int max) { return(SpawnAndSelect(Umath.RandomInt(min, max))); } // Random Spawn
public GameObject[] SpawnAndSelect(Vector3 position, int min, int max) { return(SpawnAndSelect(position, Umath.RandomInt(min, max))); } // Random Spawn
} // Random spawn public void Spawn(Vector3 position, int min, int max) { Spawn(position, Umath.RandomInt(min, max)); } // Random spawn
public void Spawn(int min, int max) { Spawn(Umath.RandomInt(min, max)); } // Random spawn
// Original Spawn Function public GameObject SpawnAndSelect(Vector3 position) { var obj = SelectSpawnObject(); if (obj == null) { throw new System.ArgumentNullException("Spawner: Cant find a Gameobject prefab to spawn"); } // Revisa si puede hacer el spawn o no puede GameObject clone = null; if (spawnMode == SpawnMode.Infinite) { //Debug.Log("Spawn by Infinite"); clone = Instantiate(obj, position, Quaternion.identity); } else if ((spawnMode == SpawnMode.Count || spawnMode == SpawnMode.RandomCount) && spawned < totalSpawns) { //Debug.Log("Spawn by Count, current: " + spawned + " max: " + totalSpawns); clone = Instantiate(obj, position, Quaternion.identity); } else if ((spawnMode == SpawnMode.Track || spawnMode == SpawnMode.RandomTrack) && spawnedInScene < totalSpawns) { //Debug.Log("Spawn by Track, current: " + spawnedInScene + " max: " + totalSpawns); clone = Instantiate(obj, position, Quaternion.identity); } if (clone == null) { return(null); } spawned++; spawnedInScene++; var tracker = ActionOnDestroy.AddComponent(clone, new ActionOnDestroy.Properties { onDestroy = () => spawnedInScene = Umath.Min(spawnedInScene - 1, 0) }); // Revisa si debe ser hijo de alguno if (setAsChildOf != null) { clone.transform.SetParent(setAsChildOf); } // Ejecuta los delegates en el objeto try { onSpawn?.Invoke(clone); } catch (Exception e) { Debug.LogError("Spawner: Error in delegate applied to objects, " + e); } return(clone); }
private GameObject SelectSpawnObject() { if (sortBetwenObjects == SortMode.Random) { if (objectsList == null || objectsList.Count() < 1) { return(null); } var obj = Umath.RandomInt(0, objectsList.Count() - 1); return(objectsList[obj]); } else if (sortBetwenObjects == SortMode.Order) { if (objectsList == null || objectsList.Count() < 1) { return(null); } // Check if exist some point in queue or renew the queue if (objectsToSpawnQueue.Count() < 1) { foreach (var obj in objectsList) { objectsToSpawnQueue.Enqueue(obj); } } // Get the next oint return(objectsToSpawnQueue.Dequeue()); } else if (sortBetwenObjects == SortMode.InverseOrder) { if (objectsList == null || objectsList.Count() < 1) { return(null); } // Check if exist some point in queue or renew the queue if (objectsToSpawnQueue.Count() < 1) { // Create the reversed list var reversedList = new List <GameObject>(objectsList); reversedList.Reverse(); foreach (var obj in reversedList) { objectsToSpawnQueue.Enqueue(obj); } } // Get the next point return(objectsToSpawnQueue.Dequeue()); } else if (sortBetwenObjects == SortMode.RandomDontRepeat) { if (objectsList == null || objectsList.Count() < 1) { return(null); } // Check if exist some point in queue or renew the queue if (objectsToSpawnQueue.Count() < 1) { // Create the randomList list var randomList = new List <GameObject>(objectsList).Shuffle(); foreach (var obj in randomList) { objectsToSpawnQueue.Enqueue(obj); } } // Get the next point return(objectsToSpawnQueue.Dequeue()); } return(null); }