private void Awake() { if (instance != null) { Destroy(this); return; } instance = this; if (this.EntityObjectPool == null) { this.EntityObjectPool = (EntityObjectPool)FindObjectOfType(typeof(EntityObjectPool)); } if (this.GameBehaviour != null) { this.GameBehaviour.GameChanged += this.OnGameChanged; } }
private void OnDestroy() { if (this.GameBehaviour != null) { this.GameBehaviour.GameChanged -= this.OnGameChanged; } if (this.entities == null) { return; } foreach (KeyValuePair <int, GameObject> entityPair in this.entities) { GameObject entityObject = entityPair.Value; // Clear entity object. foreach (LogicToVisualMapping logicToVisualMapping in this.logicVisualMappings) { Component component = entityObject.GetComponent(logicToVisualMapping.VisualType); if (component != null) { Destroy(component); } } if (this.EntityObjectPool != null) { this.EntityObjectPool.Free(entityObject); } } this.entities.Clear(); if (instance == this) { instance = null; } }
private void OnDestroy() { if (this.GameBehaviour != null) { this.GameBehaviour.GameChanged -= this.OnGameChanged; } if (this.entities == null) { return; } foreach (KeyValuePair<int, GameObject> entityPair in this.entities) { GameObject entityObject = entityPair.Value; // Clear entity object. foreach (LogicToVisualMapping logicToVisualMapping in this.logicVisualMappings) { Component component = entityObject.GetComponent(logicToVisualMapping.VisualType); if (component != null) { Destroy(component); } } if (this.EntityObjectPool != null) { this.EntityObjectPool.Free(entityObject); } } this.entities.Clear(); if (instance == this) { instance = null; } }