//Instantiate the ObjectRecyler that will control my OneShotAudioSources private void InstantiateRecycler() { GameObject go = new GameObject(); go.AddComponent <AudioSource>(); go.name = "OneShotAudioSource"; this.oneshotAudioRecycler = new ObjectRecycler(go, 2); Destroy(go); }
//Gets a Recycler. If there isn't one, make it! private ObjectRecycler GetRecycler(int recyclerID, GameObject goToMake) { if (this.recyclerDictionary.ContainsKey(recyclerID)) { return(this.recyclerDictionary[recyclerID]); } else { ObjectRecycler newOR = new ObjectRecycler(goToMake, 0); this.recyclerDictionary.Add(recyclerID, newOR); return(newOR); } }
private GameObject GetNextFreeObject(GameObject goToGet) { if (!IsRecycleable(goToGet)) //Make sure it has an ID { this.MakeRecycleable(goToGet); } int id = this.GetRecyclerID(goToGet); //Get the ID so we can get the corresponding Recycler ObjectRecycler oR = this.GetRecycler(id, goToGet); //Get the Recycler, send GO incase we need to make a new one GameObject tempGO = oR.nextFreeObject; this.AttachRO(tempGO, id); return(tempGO); //Return nextFree! }
//Gets a Recycler. If there isn't one, make it! private ObjectRecycler GetRecycler(int recyclerID, GameObject goToMake) { if(this.recyclerDictionary.ContainsKey(recyclerID)) return this.recyclerDictionary[recyclerID]; else { ObjectRecycler newOR = new ObjectRecycler(goToMake,0); this.recyclerDictionary.Add(recyclerID, newOR); return newOR; } }
//Instantiate the ObjectRecyler that will control my OneShotAudioSources private void InstantiateRecycler() { GameObject go = new GameObject(); go.AddComponent<AudioSource>(); go.name = "OneShotAudioSource"; this.oneshotAudioRecycler = new ObjectRecycler(go, 2); Destroy(go); }