コード例 #1
0
        private bool InternalAdd(GuidComponent guidComponent)
        {
            Guid guid = guidComponent.GetGuid();

            GuidInfo info = new GuidInfo(guidComponent);

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

            GuidInfo existingInfo = guidToObjectMap[guid];

            if (existingInfo.go != null && existingInfo.go != guidComponent.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, guidComponent,
                                       "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"), (guidComponent != null ? guidComponent.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(guidComponent, "Guid Collision Detected while creating {0}.\nAssigning new Guid.",
                                           (guidComponent != null ? guidComponent.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);
        }
コード例 #2
0
 public GuidReference(GuidComponent target)
 {
     guid = target.GetGuid();
 }