Ejemplo n.º 1
0
        private bool InternalAdd(GUIDEntity guidEntity)
        {
            Guid guid = guidEntity.GetGuid();

            GuidInfo info = new GuidInfo(guidEntity);

            if (!_guidToObjectMap.ContainsKey(guid))
            {
                _guidToObjectMap.Add(guid, info);
                return(true);
            }

            GuidInfo existingInfo = _guidToObjectMap[guid];

            if (existingInfo.go != null && existingInfo.go != guidEntity.gameObject)
            {
                // normally, a duplicate GUID is a big problem, means you won't necessarily be referencing what you expect
                if (Application.isPlaying)
                {
                    Debug.AssertFormat(false, guidEntity, "Guid Collision Detected between {0} and {1}.\nAssigning new Guid. Consider tracking runtime instances using a direct reference or other method.", (_guidToObjectMap[guid].go != null ? _guidToObjectMap[guid].go.name : "NULL"), (guidEntity != null ? guidEntity.name : "NULL"));
                }
                else
                {
                    // however, at editor time, copying an object with a GUID will duplicate the GUID resulting in a collision and repair.
                    // we warn about this just for pedantry reasons, and so you can detect if you are unexpectedly copying these components
                    Debug.LogWarningFormat(guidEntity, "Guid Collision Detected while creating {0}.\nAssigning new Guid.", (guidEntity != null ? guidEntity.name : "NULL"));
                }
                return(false);
            }

            // if we already tried to find this GUID, but haven't set the game object to anything specific, copy any OnAdd callbacks then call them
            existingInfo.go = info.go;
            existingInfo.HandleAddCallback();
            _guidToObjectMap[guid] = existingInfo;
            return(true);
        }
Ejemplo n.º 2
0
 public GUIDEntityReference(GUIDEntity target)
 {
     guid = target.GetGuid();
 }