public void EditorInstantiateChunkPrefab(ChunkPrefab chunkPrefab, Transform tr) { StructurePack pack = null; if (mStructurePackLookup.TryGetValue(chunkPrefab.PackName, out pack)) { StructurePackPrefab prefab = null; if (pack.StaticPrefabLookup.TryGetValue(chunkPrefab.PrefabName, out prefab)) { GameObject scenery = GameObject.Instantiate(prefab.Prefab) as GameObject; scenery.transform.parent = tr; chunkPrefab.Transform.ApplyTo(scenery.transform, true); scenery.name = chunkPrefab.Name; scenery.tag = chunkPrefab.Tag; List <Material> materials = new List <Material> (); foreach (string materialName in chunkPrefab.SharedMaterialNames) { Material mat = null; if (mSharedMaterialLookup.TryGetValue(materialName, out mat)) { materials.Add(mat); } } MeshRenderer mr = scenery.GetComponent <MeshRenderer> (); mr.sharedMaterials = materials.ToArray(); } } }
public void RebuildPacks() { if (!Manager.IsAwake <Mods> ()) { Manager.WakeUp <Mods> ("__MODS"); Mods.Get.Editor.InitializeEditor(); } if (!Manager.IsAwake <Structures> ()) { Manager.WakeUp <Structures> ("Frontiers_Structures"); } //Debug.Log ("Rebuilding structure manager packs from paths"); Structures.Get.StructurePacks.Clear(); foreach (StructurePackPaths packPaths in Structures.Get.PackPaths) { //Debug.Log ("Loading pack " + packPaths.PackPath); StructurePack structurePack = new StructurePack(); structurePack.Name = System.IO.Path.GetFileName(packPaths.PackPath); foreach (string staticPrefabPath in packPaths.StaticPrefabs) { string finalPath = ("Assets" + staticPrefabPath); //Debug.Log ("Adding statpre " + finalPath); UnityEngine.Object prefab = AssetDatabase.LoadAssetAtPath(finalPath, typeof(UnityEngine.Object)) as UnityEngine.Object; GameObject prefabAsGameObject = prefab as GameObject; if (prefabAsGameObject != null) { structurePack.StaticPrefabs.Add(prefabAsGameObject); } } foreach (string dynamicPrefab in packPaths.DynamicPrefabs) { string finalPath = ("Assets" + dynamicPrefab); //Debug.Log ("Adding dynpre " + finalPath); UnityEngine.Object prefab = AssetDatabase.LoadAssetAtPath(finalPath, typeof(UnityEngine.Object)) as UnityEngine.Object; if (prefab != null) { GameObject prefabGameObject = prefab as GameObject; DynamicPrefab dynPrefab = prefabGameObject.GetComponent <DynamicPrefab> (); if (dynPrefab != null && dynPrefab.worlditem != null) { dynPrefab.worlditem.OnEditorRefresh(); dynPrefab.worlditem.Props.Name.FileName = prefabGameObject.name; dynPrefab.worlditem.Props.Name.PrefabName = prefabGameObject.name; dynPrefab.worlditem.Props.Name.PackName = structurePack.Name; } structurePack.DynamicPrefabs.Add(prefabGameObject); } else { //Debug.Log ("PREFAB WAS NULL " + System.IO.Path.GetFileName (dynamicPrefab)); } } //Debug.Log ("Added structure pack FINISHED"); Structures.Get.StructurePacks.Add(structurePack); } ColliderMeshPrefabs.Clear(); foreach (string colliderMeshPrefabPath in ColliderMeshPaths) { string finalPath = ("Assets" + colliderMeshPrefabPath); //Debug.Log ("Adding statpre " + finalPath); UnityEngine.Object prefab = AssetDatabase.LoadAssetAtPath(finalPath, typeof(UnityEngine.Object)) as UnityEngine.Object; GameObject prefabAsGameObject = prefab as GameObject; if (prefabAsGameObject != null) { ColliderMeshPrefabs.SafeAdd(prefabAsGameObject); } } LodMeshPrefabs.Clear(); foreach (string lodMeshPrefabPath in LODPrefabPaths) { string finalPath = ("Assets" + lodMeshPrefabPath); //Debug.Log ("Adding statpre " + finalPath); UnityEngine.Object prefab = AssetDatabase.LoadAssetAtPath(finalPath, typeof(UnityEngine.Object)) as UnityEngine.Object; GameObject prefabAsGameObject = prefab as GameObject; if (prefabAsGameObject != null) { LodMeshPrefabs.SafeAdd(prefabAsGameObject); } } SharedMaterials.Clear(); foreach (string sharedMaterialPath in SharedMaterialPaths) { string finalPath = ("Assets" + sharedMaterialPath); //Debug.Log ("Adding statpre " + finalPath); UnityEngine.Object prefab = AssetDatabase.LoadAssetAtPath(finalPath, typeof(UnityEngine.Object)) as UnityEngine.Object; Material prefabAsMaterial = prefab as Material; if (prefabAsMaterial != null) { SharedMaterials.SafeAdd(prefabAsMaterial); } } }