internal void AddObject(BaseGameObject obj) { // called only from within World class so no lock is required // GameDebugger.Log("Map added object"); m_Objects.Add(obj.UID, obj); OnObjectAddedInternal(obj); obj.OnMapEnterInternal(); }
internal void ActivateObject(BaseGameObject obj) { // called only from within World class so no lock is required if (!obj.m_ObjectActive) { // GameDebugger.Log("Map activated object"); ActiveObjects.Add(obj); obj.m_ObjectActive = true; obj.OnActivateObjectInternal(); } }
internal void DeactivateObject(BaseGameObject obj) { // called only from within World class and RemoveObject method so no lock is required if (obj.m_ObjectActive) { // GameDebugger.Log("Map deactivated object"); ActiveObjects.Remove(obj); obj.m_ObjectActive = false; obj.OnDeactivateObjectInternal(); } }
internal void RemoveObject(BaseGameObject obj) { // called only from within World class so no lock is required if (m_Objects.ContainsKey(obj.UID)) { // GameDebugger.Log("Map removed object"); m_Objects.Remove(obj.UID); DeactivateObject(obj); OnObjectRemovedInternal(obj); obj.OnMapLeaveInternal(); } }
internal static void MoveObjectAcrossMaps(BaseGameObject obj, BaseGameMap map) { lock ( Objects ) { if (obj.BaseGameMap != map) { if (Objects.ContainsKey(obj.UID)) { // GameDebugger.Log("World moved object across maps"); bool wasActive = obj.m_ObjectActive; if (obj.m_BaseGameMap != null) { obj.m_BaseGameMap.RemoveObject(obj); } else if (wasActive) { // GameDebugger.Log("World deactivated object (moam)"); ActiveObjects.Remove(obj); obj.m_ObjectActive = false; obj.OnDeactivateObjectInternal(); } obj.m_BaseGameMap = map; if (map != null) { map.AddObject(obj); if (wasActive) { map.ActivateObject(obj); } } else if (wasActive) { // GameDebugger.Log("World activated object (moam)"); ActiveObjects.Add(obj); obj.m_ObjectActive = true; obj.OnActivateObjectInternal(); } } else { // GameDebugger.Log("World updated object map"); obj.m_BaseGameMap = map; } } } }
public static void AddObject(BaseGameObject obj) { lock ( Objects ) { if (Objects.ContainsKey(obj.UID)) { throw new UserFriendlyException(String.Format("Object {0} is already in the world", obj.UID), "The game tried to add same object into the world twice"); } obj.OnBeforeAddObjectInternal(); // GameDebugger.Log("World added object"); Objects.Add(obj.UID, obj); if (obj.BaseGameMap != null) { obj.BaseGameMap.AddObject(obj); } obj.OnAfterAddObjectInternal(); } }
public static void DeactivateObject(BaseGameObject obj) { lock ( Objects ) { if (Objects.ContainsKey(obj.UID)) { if (obj.BaseGameMap != null) { obj.BaseGameMap.DeactivateObject(obj); } else if (obj.m_ObjectActive) { // GameDebugger.Log("World deactivated object"); ActiveObjects.Remove(obj); obj.m_ObjectActive = false; obj.OnDeactivateObjectInternal(); } } // else // throw new UserFriendlyException(String.Format("Cannot deactivate object {0}: it is not added to the world yet", obj.UID), "The game tried to deactivate that was not added into the world"); } }
public static void ActivateObject(BaseGameObject obj) { lock ( Objects ) { if (Objects.ContainsKey(obj.UID)) { if (obj.BaseGameMap != null) { obj.BaseGameMap.ActivateObject(obj); } else if (!obj.m_ObjectActive) { // GameDebugger.Log("World activated object"); ActiveObjects.Add(obj); obj.m_ObjectActive = true; obj.OnActivateObjectInternal(); } } // else // throw new UserFriendlyException(String.Format("Cannot activate object {0}: it is not in the world", obj.UID), "The game tried to activate an object that was not added into the world"); } }
public static void RemoveObject(BaseGameObject obj) { lock ( Objects ) { if (Objects.ContainsKey(obj.UID)) { obj.OnBeforeRemoveObjectInternal(); // GameDebugger.Log("World removed object"); Objects.Remove(obj.UID); BaseGameMap map = obj.BaseGameMap; if (map != null) { map.RemoveObject(obj); } else if (obj.m_ObjectActive) { // GameDebugger.Log("World deactivated object (on remove)"); ActiveObjects.Remove(obj); obj.m_ObjectActive = false; obj.OnDeactivateObjectInternal(); } obj.OnAfterRemoveObjectInternal(); } } }
protected virtual void OnObjectRemoved(BaseGameObject obj) { }
protected virtual void OnObjectAdded(BaseGameObject obj) { }
internal virtual void OnObjectRemovedInternal(BaseGameObject obj) { OnObjectRemoved(obj); }