private static AudioClip[] TryGetFromRandomCache(string folder) { RandomCache soundList = _randomCache.FirstOrDefault(x => x.folderName == folder); AudioClip[] sounds = null; if (soundList != null) { sounds = soundList.clips; } if (sounds == null) { sounds = Resources.LoadAll <AudioClip>("Audio/" + folder); } if (sounds.Length > 0) { _randomCache.Add(new RandomCache(folder, sounds)); } else { sounds = new AudioClip[] { IncorrectClipName }; } return(sounds); }
/// <summary> /// this is where the actual logic of the job is held and carried out, such as the example spawning the game objects /// </summary> /// <param name="entity">the entity that needs the job done</param> /// <param name="index"> the index of the job itself</param> /// <param name="testEntity">the component matching the first entity type specified</param> /// <param name="location">the component matching the second entity type specified</param> public void Execute(Entity entity, int index, [ReadOnly] ref TestEntity testEntity, [ReadOnly] ref LocalToWorld location) { SpawnerPos = location.Position; for (var x = 0; x < testEntity.CountX; x++) { for (var y = 0; y < testEntity.CountY; y++) { for (var z = 0; z < testEntity.CountZ; z++) { var instance = CommandBuffer.Instantiate(index, testEntity.PrefabObject); // Place the instantiated in a grid with some noise float angle = RandomCache.GetAngle(); float xpos = SpawnerPos.x + Mathf.Sin(angle) * RandomCache.GetCenterDistance(); float zpos = SpawnerPos.z + Mathf.Cos(angle) * RandomCache.GetCenterDistance(); var position = math.transform(location.Value, new float3(xpos, 2 * y / testEntity.CountY, zpos)); CommandBuffer.SetComponent(index, instance, new Translation { Value = position }); //the +1 is to account for the fact that the upper limit is exclusive //this one doesn't use the cache to allow the number of random blocks to vary more uint BlockType = RandomCache.GetCubeType(); if (BlockType == 1) { CommandBuffer.AddComponent(index, instance, new MoveUp(RandomCache.GetLifeSpan())); } else { CommandBuffer.AddComponent(index, instance, new MoveRandom(RandomCache.GetLifeSpan(), GetRandComponentfloat3())); } CommandBuffer.AddComponent(index, instance, new MovingCube()); } } } ///uncommenting this line means the entity that runs this job is deleted, so the above line won't happen every frame CommandBuffer.DestroyEntity(index, entity); }
// The [ReadOnly] attribute tells the job scheduler that this job will not write to rotSpeedSpawnAndRemove public void Execute(Entity entity, int index, ref Translation translation, ref MoveUp moving) { // Rotate something about its up vector at the speed given by RotationSpeed_SpawnAndRemove. //if(RandomCache.GetSubOneCount() < RandomCache.CacheSize) //{ // RandomCache.AddSubOne(MoveSystem.rand.NextFloat()); //} float randfloat = RandomCache.GetSubOne(); translation.Value = new float3(translation.Value.x + DeltaTime * randfloat, translation.Value.y + DeltaTime * randfloat, translation.Value.z);// + DeltaTime * RandomCache.GetSubOne()); moving.LifeSpan -= DeltaTime; if (translation.Value.y > 7.0f || moving.LifeSpan <= 0f || translation.Value.x > 20f) { CommandBuffer.RemoveComponent <MoveUp>(index, entity); CommandBuffer.AddComponent <ResetCube>(index, entity); } }
public void Execute(Entity entity, int index, ref Translation translation) { float angle = RandomCache.GetAngle(); float newX = SpawnerSystem.SpawnerPos.x + Mathf.Sin(angle) * RandomCache.GetCenterDistance(); float newZ = SpawnerSystem.SpawnerPos.z + Mathf.Cos(angle) * RandomCache.GetCenterDistance(); translation.Value = new float3(newX, SpawnerSystem.SpawnerPos.y, newZ); CommandBuffer.RemoveComponent <ResetCube>(index, entity); uint BlockType = RandomCache.GetCubeType(); if (BlockType == 1) { CommandBuffer.AddComponent(index, entity, new MoveUp(RandomCache.GetLifeSpan())); } else { CommandBuffer.AddComponent(index, entity, new MoveRandom(RandomCache.GetLifeSpan(), SpawnerSystem.GetRandComponentfloat3())); } }
public static float3 GetRandComponentfloat3() { return(RandomCache.GetDirection()); }