public void SelectKey(int key) { sounds.PlayNote(key, 95, 1.0f); PianoSoundItem item = itemPool.GetObject(); item.Initialize(0.0f, 0.0f, key, 0, this); items.Add(item); }
public void Initialize() { while (pooledObjects.Count < pooledAmount) { GameObject newObject = Instantiate(prefab, parent); PianoSoundItem itemObject = newObject.GetComponent <PianoSoundItem>(); pooledObjects.Add(itemObject); objectAvailable.Add(true); newObject.SetActive(false); } }
public void Activate(EditorController edit, List <PianoSound> sounds) { editor = edit; CurrentState.ignoreAllInput = true; foreach (PianoSound sound in sounds) { PianoSoundItem item = itemPool.GetObject(); item.Initialize(sound.duration, sound.delay, sound.pitch, sound.volume, this); items.Add(item); } }
public void ReturnObject(PianoSoundItem returnObject) { for (int i = 0; i < pooledObjects.Count; i++) { if (pooledObjects[i] == returnObject) { returnObject.gameObject.SetActive(false); objectAvailable[i] = true; return; } } Debug.LogError("Try to return an object that's not from the pool. Destroying the object."); Destroy(returnObject.gameObject); return; }
public PianoSoundItem GetObject() { for (int i = 0; i < pooledObjects.Count; i++) { if (objectAvailable[i]) { objectAvailable[i] = false; return(pooledObjects[i]); } } GameObject newObject = Instantiate(prefab, parent); PianoSoundItem itemObject = newObject.GetComponent <PianoSoundItem>(); pooledObjects.Add(itemObject); newObject.SetActive(false); objectAvailable.Add(false); return(itemObject); }
public void DeleteItem(PianoSoundItem item) { items.Remove(item); }