コード例 #1
0
        public void Forget(int id, DataNode entity)
        {
            if (updating)
            {
                return;
            }

            #if LogRegistering
            Debug.Log($"DeregisterEntity {entity.ToString()} id={id}");
            #endif
            DataNode storedEntity;
            if (gameEntities.TryGetValue(id, out storedEntity))
            {
                if (object.ReferenceEquals(storedEntity, entity))
                {
                    #if LogRegistering
                    Debug.Log($"removing {id} {entity}");
                    #endif
                    gameEntities.Remove(id);
                }
                else
                {
                    #if LogRegistering
                    Debug.Log("different entity was stored with same id");
                    #endif
                }
            }
            else
            {
                #if LogRegistering
                Debug.Log("no entity was stored with this id");
                #endif
            }
        }
コード例 #2
0
 public void Remember(DataNode entity, int id)
 {
     if (id == 0)
     {
         throw new ZergRushException($"zero id for entity {entity}");
     }
     if (updating)
     {
         return;
     }
     if (gameEntities.ContainsKey(id))
     {
         Debug.LogError($"This id {id} of {entity} is already taken by entity: {gameEntities[id]} id={id}");
         return;
     }
     #if LogRegistering
     Debug.Log($"RegisterEntity {entity.ToString()} id={id}");
     #endif
     gameEntities.Add(id, entity);
 }
コード例 #3
0
        public void ChangeEntityId(int oldId, int newId, DataNode entity)
        {
            #if LogRegistering
            Debug.Log($"ChangeEntityId {entity.ToString()} prev id={oldId}, new id={newId}");
            #endif
            DataNode prevVal;
            if (oldId > 0 && gameEntities.TryGetValue(oldId, out prevVal))
            {
                if (object.ReferenceEquals(prevVal, entity))
                {
                    gameEntities.Remove(oldId);
                }
                else
                {
                    #if LogRegistering
                    Debug.Log($"different object was stored for old id, old entity = {prevVal.ToString()}");
                    #endif
                }
            }

            gameEntities[newId] = entity;
        }