Esempio n. 1
0
    private void SpawnPrefabs(WorldSerialization blob, PrefabLookup prefabs)
    {
        foreach (var prefab in blob.world.prefabs)
        {
            var go = GameObject.Instantiate(prefabs[prefab.id], prefab.position, prefab.rotation);

            if (go)
            {
                go.transform.localScale = prefab.scale;
                go.SetActive(true);
            }
        }
    }
Esempio n. 2
0
        public GameObject GetOrCreate(string prefabName)
        {
            GameObject instance = Get(prefabName);

            if (instance)
            {
                return(instance);
            }
            PrefabLookup.TryGetValue(prefabName, out GameObject prefab);
            if (prefab)
            {
                instance = Instantiate(prefab);
                Add(instance);
            }
            else
            {
                Debug.LogWarningFormat(this, "Couldn't find asset '{0}' in {1}", prefabName, GetType().Name);
            }

            return(instance);
        }
Esempio n. 3
0
    private void SpawnPrefabs(WorldSerialization blob, PrefabLookup prefabs)
    {
        foreach (var prefab in blob.world.prefabs)
        {
            var prefabGameObject = prefabs[prefab.id];

            if (!prefabGameObject)
            {
                continue;
            }

            var instanceGameObject = GameObject.Instantiate(prefabGameObject, prefab.position, prefab.rotation);

            if (!instanceGameObject)
            {
                continue;
            }

            instanceGameObject.transform.localScale = prefab.scale;
            instanceGameObject.SetActive(true);
        }
    }
Esempio n. 4
0
    protected void OnGUI()
    {
        const float padding = 10;

        GUILayout.BeginArea(new Rect(padding, padding, Screen.width - padding - padding, Screen.height - padding - padding));
        GUILayout.BeginVertical();

        GUILayout.BeginHorizontal();
        {
            GUILayout.Label("Map File");

            filename = GUILayout.TextField(filename, GUILayout.MinWidth(100));

                        #if UNITY_EDITOR
            if (GUILayout.Button("Browse"))
            {
                filename = UnityEditor.EditorUtility.OpenFilePanel("Select Map File", filename, "map");
                world    = LoadWorld(filename);
            }
                        #endif

            if (GUILayout.Button("Load"))
            {
                world = LoadWorld(filename);
            }

            GUILayout.FlexibleSpace();
        }
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        if (world != null)
        {
            GUILayout.Label("Bundle File");

            bundlename = GUILayout.TextField(bundlename, GUILayout.MinWidth(100));

                        #if UNITY_EDITOR
            if (GUILayout.Button("Browse"))
            {
                bundlename = UnityEditor.EditorUtility.OpenFilePanel("Select Bundle File", bundlename, "");

                if (prefabs != null)
                {
                    prefabs.Dispose();
                    prefabs = null;
                }

                prefabs = new PrefabLookup(bundlename);
            }
                        #endif

            if (GUILayout.Button("Load"))
            {
                if (prefabs != null)
                {
                    prefabs.Dispose();
                    prefabs = null;
                }

                prefabs = new PrefabLookup(bundlename);
            }

            GUILayout.FlexibleSpace();
        }
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        if (world != null && prefabs != null)
        {
            if (prefabs.isLoaded)
            {
                GUILayout.Label("Tools");

                if (GUILayout.Button("Print Map Info"))
                {
                    result = GetInfo(world);
                }
                if (GUILayout.Button("Clear Map Info"))
                {
                    result = string.Empty;
                }
                if (GUILayout.Button("Spawn Map Prefabs"))
                {
                    SpawnPrefabs(world, prefabs);
                }
            }
            else
            {
                GUILayout.Label("Loading Prefabs...");
            }

            GUILayout.FlexibleSpace();
        }
        GUILayout.EndHorizontal();

        if (!string.IsNullOrEmpty(result))
        {
            GUILayout.TextArea(result);
        }

        GUILayout.EndVertical();
        GUILayout.EndArea();
    }
Esempio n. 5
0
 public void Awake()
 {
     Singleton = this;
     Mapping   = TypeToPrefabList.GroupBy(item => item.Type).ToDictionary(item => item.Key, item => item.First().Prefab);
 }