예제 #1
0
        private static IdentifiedGameObject ensureAssetGUID(GameObject obj)
        {
                        #if UNITY_EDITOR
            IdentifiedGameObject ret;
            GameObject           instantiated;
            SerializedGameObject marker;
            String guid, path;

            path = AssetDatabase.GetAssetPath(obj);
            if (String.IsNullOrEmpty(path))
            {
                return(null);
            }

            // this is definitely an asset, see if it's already invisibly in the scene.
            guid = AssetDatabase.AssetPathToGUID(path);
            ret  = StatemapDefinition.getHeldObject(guid);
            if (ret != null)
            {
                return(ret);
            }

            // doesn't yet exist. Instantiate an invisible copy in the instance, make sure the guid is discoverable from the prefab.
            guid = GUID.Generate().ToString().Replace("-", "");

            instantiated = (GameObject)GameObject.Instantiate(obj);
            instantiated.transform.SetParent(StatemapDefinition.getGUIDHolder().transform, false);
            marker      = instantiated.AddComponent <SerializedGameObject>();
            marker.guid = guid;
            instantiated.SetActive(false);

            ret = new IdentifiedGameObject(guid, obj);
            SerializedGameObject.identifiedObjects[guid] = ret;
            return(ret);
                        #endif
        }