public void AddEntityAddedListener(OnEntityAddedCallback callback) { for (int i = 0; i < this._onEntityAddedCallbackCount; i++) { if (this._onEntityAddedCallbacks[i] == callback) { throw new Exception("Callback already added."); } } if (this._onEntityAddedCallbackCount == this._onEntityAddedCallbacks.Length) { Array.Resize(ref this._onEntityAddedCallbacks, 2 * this._onEntityAddedCallbackCount); } this._onEntityAddedCallbacks[this._onEntityAddedCallbackCount++] = callback; }
public bool RemoveEntityAddedListener(OnEntityAddedCallback callback) { for (int i = 0; i < this._onEntityAddedCallbackCount; i++) { if (this._onEntityAddedCallbacks[i] == callback) { this._onEntityAddedCallbackCount--; // Can't swap with last because listeners are ordered. Array.Copy(this._onEntityAddedCallbacks, i + 1, this._onEntityAddedCallbacks, i, this._onEntityAddedCallbackCount - i); return(true); } } // Not found. return(false); }