Ejemplo n.º 1
0
        static public GameObject CreateEntityFromAsset(GameObject prefab)
        {
            GameObject entObj = null;
            // Create a custom game object
            GameObject go     = Instantiate(prefab);
            EntityData entity = go.GetComponent <EntityData>();

            if (entity)
            {
                entObj = go;
            }
            else
            {
                entObj = new GameObject(go.name);
                go.transform.SetParent(entObj.transform);
                var repr = go.AddComponent <EntityRepresentation>();
                repr.assetType = EntityRepresentation.AssetType.Prefab;
                string        path          = AssetDatabase.GetAssetPath(prefab);
                AssetImporter assetImporter = AssetImporter.GetAtPath(path);
                repr.assetBundleName = assetImporter.assetBundleName;
                repr.assetName       = prefab.name;
                entity = entObj.AddComponent <EntityData>();
                if (PrefabUtility.GetPrefabAssetType(prefab) == PrefabAssetType.Regular)
                {
                    entity.id = prefab.name;
                }
                entity.name = prefab.name;
            }
            entity.id   = DataUtil.CreateNewEntityId(entity);
            entObj.name = prefab.name;
            // Register the creation in the undo system
            Undo.RegisterCreatedObjectUndo(entObj, "Create " + entObj.name + " " + entity.id);
            return(entObj);
        }
Ejemplo n.º 2
0
        public static EntityData MakeGameObjectEntity(GameObject go)
        {
            EntityData entity = null;

            if (go)
            {
                entity = go.GetComponent <EntityData>();
                if (entity == null)
                {
                    GameObject entObj = new GameObject(go.name);
                    entity = entObj.AddComponent <EntityData>();
                    go.transform.SetParent(entObj.transform);
                    var repr = MakeGameObjectRepresentation(go);
                    entity.activeRepresentation = repr;
                    //entity = go.AddComponent<EntityData>();
                    entity.id = string.Empty;
                    //var prefab = PrefabUtility.GetPrefabObject(go);
                    GameObject prefabParent = PrefabUtility.GetCorrespondingObjectFromSource(go) as GameObject;
                    if (prefabParent)
                    {
                        entity.id = prefabParent.name;
                    }
                    else
                    {
                        entity.id = go.name;
                    }
                    go.name   = entity.id + "_repr";
                    entity.id = DataUtil.CreateNewEntityId(entity);
                }
            }
            return(entity);
        }