public void DrawEditor() { foreach (string s in ColliderReports) { if (s.StartsWith("3")) { UnityEngine.GUI.color = Color.red; } else if (s.StartsWith("2")) { UnityEngine.GUI.color = Color.yellow; } else if (s.StartsWith("3")) { UnityEngine.GUI.color = Color.green; } else { UnityEngine.GUI.color = Color.white; } GUILayout.Label(s); } int numPrefabsInstantiated = 0; if (GUILayout.Button("Rebuild materials")) { foreach (UnityEngine.Object obj in UnityEditor.Selection.objects) { Material mat = obj as Material; if (mat != null) { if (mat.shader.name.Contains("BumpedSpecularWithDetail")) { Texture diff = mat.GetTexture("_MainDiffMap"); Texture bump = mat.GetTexture("_MainBumpMap"); Texture detailBump = mat.GetTexture("_DetailBumpMap"); Texture detailDiff = mat.GetTexture("_DetailDiffMap"); Vector2 bumpScale = mat.GetTextureScale("_DetailBumpMap"); Vector2 diffScale = mat.GetTextureScale("_DetailDiffMap"); Vector2 bumpOffset = mat.GetTextureOffset("_DetailBumpMap"); Vector2 diffOffset = mat.GetTextureOffset("_DetailDiffMap"); Vector2 detailBumpScale = mat.GetTextureScale("_DetailBumpMap"); Vector2 detailDiffScale = mat.GetTextureScale("_DetailDiffMap"); Vector2 detailBumpOffset = mat.GetTextureOffset("_DetailBumpMap"); Vector2 detailDiffOffset = mat.GetTextureOffset("_DetailDiffMap"); float bumpAmount = mat.GetFloat("_MainBumpiness"); float detailBumpAmount = mat.GetFloat("_DetailBumpiness"); float glossiness = mat.GetFloat("_MainGlosLvl"); float shininess = mat.GetFloat("_MainSpecLvl"); Color specColor = mat.GetColor("_MainSpecColor"); Color mainColor = mat.GetColor("_MainTintColor"); specColor = Color.Lerp(specColor, Color.black, 1f - glossiness); mat.shader = Shader.Find("Standard (Specular setup)"); mat.mainTexture = diff; mat.SetTexture("_BumpMap", bump); mat.SetTexture("_DetailNormalMap", detailBump); mat.SetTexture("_DetailAlbedoMap", detailDiff); mat.SetTexture("_DetailMask", diff); //mat.SetTextureScale("_BumpMap", bumpScale); //mat.SetTextureScale("_MainText", diffScale); //mat.SetTextureOffset("_BumpMap", bumpOffset); //mat.mainTextureOffset = diffOffset; mat.SetTextureScale("_DetailNormalMap", detailBumpScale); mat.SetTextureScale("_DetailAlbedoMap", detailDiffScale); mat.SetTextureOffset("_DetailNormalMap", detailBumpOffset); mat.SetTextureOffset("_DetailAlbedoMap", detailDiffOffset); mat.SetFloat("_GlossMapScale", shininess); mat.SetFloat("_BumpScale", bumpAmount); mat.SetFloat("_DetailNormalMapScale", detailBumpAmount); mat.SetColor("_Color", mainColor); mat.SetColor("_SpecColor", specColor); } } } } if (GUILayout.Button("Create LOD Prefabs")) { RefreshPaths(); //check to see if there's an LOD prefab for each LOD mesh available foreach (string lodMeshPath in LODMeshPaths) { Debug.Log("Checking " + lodMeshPath); bool foundPrefab = false; string cleanLodMeshPath = lodMeshPath.Replace(".obj", ""); cleanLodMeshPath = lodMeshPath.Replace(".fbx", ""); foreach (string lodPrefabPath in LODPrefabPaths) { string cleanLodPrefabPath = lodPrefabPath.Replace(".prefab", ""); if (cleanLodMeshPath.Equals(cleanLodPrefabPath)) { Debug.Log(lodMeshPath + " already exists as " + lodPrefabPath); foundPrefab = true; break; } } if (!foundPrefab) { numPrefabsInstantiated++; //create a prefab from the path string finalPath = ("Assets" + lodMeshPath); Debug.Log("NEED TO CREATE PREFAB FOR " + lodMeshPath); UnityEngine.Object prefab = AssetDatabase.LoadAssetAtPath(finalPath, typeof(UnityEngine.Object)) as UnityEngine.Object; GameObject prefabAsGameObject = prefab as GameObject; GameObject tempInstantiated = GameObject.Instantiate(prefabAsGameObject) as GameObject; MeshFilter prefabMf = tempInstantiated.GetComponent <MeshFilter> (); if (prefabMf == null) { prefabMf = tempInstantiated.GetComponentInChildren <MeshFilter> (); } Mesh mesh = prefabMf.sharedMesh; GameObject.DestroyImmediate(tempInstantiated); GameObject prefabInstantiated = new GameObject(prefabAsGameObject.name); prefabInstantiated.AddComponent <MeshFilter> ().sharedMesh = mesh; string prefabPath = lodMeshPath.Replace(LocalLODMeshesPath, LocalLODPrefabsPath); prefabPath = prefabPath.Replace(".obj", ".prefab"); prefabPath = prefabPath.Replace(".fbx", ".prefab"); finalPath = "Assets" + prefabPath; finalPath = finalPath.Trim(); finalPath = finalPath.Replace("\\", "/"); Debug.Log("Creating asset at: " + finalPath); EditorUtility.SetDirty(prefabInstantiated); PrefabUtility.CreatePrefab(finalPath, prefabInstantiated, ReplacePrefabOptions.ReplaceNameBased); GameObject.DestroyImmediate(prefabInstantiated); } } } if (GUILayout.Button("Report colliders")) { ColliderReports.Clear(); WakeUp(); RefreshPaths(); foreach (StructurePack pack in StructurePacks) { //check to see if there are any colliders associated with this object foreach (GameObject obj in pack.StaticPrefabs) { MeshCollider mc = obj.GetComponent <MeshCollider> (); Mesh colliderMesh = null; if (mc != null) { if (!mColliderMeshes.TryGetValue(mc.name, out colliderMesh) && !mLodMeshes.TryGetValue(mc.name, out colliderMesh)) { ColliderReports.Add("3: Prefab " + mc.name + " had a mesh collider but NO associated collider mesh"); } else if (colliderMesh.vertexCount > (3 * 1024)) { if (mc.sharedMesh != colliderMesh) { //mc.sharedMesh = colliderMesh; ColliderReports.Add("2: Prefab " + mc.name + " had an associated collider mesh, but it is not the mesh on the prefab"); } else { ColliderReports.Add("1: Prefab " + mc.name + " had an associated collider mesh, but vertex count was " + (colliderMesh.vertexCount / 3).ToString()); } } } } } } if (GUILayout.Button("Refresh prefab colliders")) { foreach (StructurePack pack in StructurePacks) { //pack.MeshColliderPrefabs.Clear (); foreach (GameObject prefab in pack.StaticPrefabs) { //see if a collider exists in the COL array already MeshCollider mc = prefab.GetComponent <MeshCollider> (); string mcName = prefab.name.ToLower(); if (mc != null && ( mcName.Contains("cliff") || mcName.Contains("rock") || mcName.Contains("mud") || mcName.Contains("statue") || mcName.Contains("bridge") || mcName.Contains("wall") || mcName.Contains("path") || mcName.Contains("wood") || mcName.Contains("module") || mcName.Contains("pipe") || mcName.Contains("crystal") || mcName.Contains("base") || mcName.Contains("roof") || mcName.Contains("castle") || mcName.Contains("dungeon") )) { pack.MeshColliderPrefabs.SafeAdd(prefab); } bool colliderExists = false; foreach (GameObject colMeshPrefab in ColliderMeshPrefabs) { if (colMeshPrefab.name.Contains(prefab.name)) { colliderExists = true; Debug.Log("Not adding " + prefab.name + ", already exists as " + colMeshPrefab.name); break; } } if (!colliderExists) { //see if this prefab should be added if (mc != null) { Debug.Log("Adding " + mc.name + " to mesh collider"); ColliderMeshPrefabs.Add(prefab); } } } } } if (GUILayout.Button("Disable object colliders")) { foreach (StructurePack pack in StructurePacks) { Debug.Log("Disabling colliders in " + pack.Name); foreach (GameObject prefab in pack.StaticPrefabs) { Collider[] colliders = prefab.GetComponents <Collider> (); Debug.Log("Disabling " + colliders.Length.ToString() + " in " + prefab.name); foreach (Collider c in colliders) { c.enabled = false; } foreach (Transform child in prefab.transform) { if (child.GetComponent <Collider>() != null) { child.GetComponent <Collider>().enabled = false; } } } } } if (GUILayout.Button("Refresh Structure Manager")) { RefreshPaths(); RebuildPacks(); UnityEditor.EditorUtility.SetDirty(this); UnityEditor.EditorUtility.SetDirty(gameObject); } if (GUILayout.Button("Prep LOD Prefabs")) { foreach (GameObject gObject in UnityEditor.Selection.gameObjects) { MeshFilter finalMFilter = gObject.GetOrAdd <MeshFilter> (); foreach (Transform child in gObject.transform) { MeshFilter childMFilter = child.gameObject.GetComponent <MeshFilter> (); finalMFilter.sharedMesh = childMFilter.sharedMesh; GameObject.DestroyImmediate(child.gameObject); break; } GameObject prefab = UnityEditor.PrefabUtility.CreatePrefab("Assets/Artwork/Packs/_LODPrefabs/" + gObject.name + ".prefab", gObject, ReplacePrefabOptions.Default); LodMeshPrefabs.Add(prefab); } } if (GUILayout.Button("Prep Material Substitutions")) { foreach (MaterialSubstitution m in Substitutions) { m.OriginalMaterials.Sort(delegate(Material m1, Material m2) { return(m1.name.CompareTo(m2.name)); }); //sort and get rid of all duplicates across the board for (int i = m.OriginalMaterials.LastIndex(); i >= 0; i--) { for (int j = m.OriginalMaterials.LastIndex(); j >= 0; j--) { if (j == i) { continue; } if (m.OriginalMaterials [j] == m.OriginalMaterials [i]) { m.OriginalMaterials.RemoveAt(i); } } foreach (MaterialSubstitution otherM in Substitutions) { if (m == otherM) { continue; } foreach (Material om in otherM.OriginalMaterials) { if (om == m.OriginalMaterials [i]) { m.OriginalMaterials.RemoveAt(i); } } } } } } if (GUILayout.Button("Convert materials to detail shader")) { foreach (UnityEngine.Object matObject in UnityEditor.Selection.objects) { /* * _DetailBlendBias ("Detail Blend Bias", Range (0, 1)) = 1 * _DetailBlend ("Detail Blend (R)", 2D) = "black" {} * * _MainSpecLvl ("Main Shininess", Range(0.01, 1.0)) = 0.8 * _MainGlosLvl ("Main Glossiness Level", Float) = 0.5 * _MainSpecColor ("Main Specular Color", Color) = (0.5, 0.5, 0.5, 1) * _MainTintColor ("Main Tint Color", Color) = (1,1,1,1) * _MainDiffMap ("Main Diffuse (RGB) Gloss (A)", 2D) = "white" {} * * _MainBumpiness ("Main Bumpiness", Range (0, 1)) = 1.0 * _MainBumpMap ("Main Bump Map (Normalmap)", 2D) = "bump" {} * * _DetailSpecLvl ("Detail Shininess", Range(0.01, 1.0)) = 0.8 * _DetailGlosLvl ("Detail Glossiness Level", Float) = 0.5 * _DetailSpecColor ("Detail Specular Color", Color) = (0.5, 0.5, 0.5, 1) * _DetailTintColor ("Detail Tint Color", Color) = (1,1,1,1) * _DetailDiffMap ("Detail Diffuse (RGB) Gloss (A)", 2D) = "black" {} * * _DetailBumpiness ("Detail Bumpiness", Range (0, 1)) = 1.0 * _DetailBumpMap ("Detail Bump Map (Normalmap)", 2D) = "bump" {} */ /* * _Color ("Main Color", Color) = (1,1,1,1) * _Opacity ("Color over opacity", Range (0, 1)) = 1 * _MainTex ("Color over (RGBA)", 2D) = "white" {} * _BumpMap ("Normalmap over", 2D) = "bump" {} * _MainTex2 ("Color under (RGBA)", 2D) = "white" {} * _BumpMap2 ("Normalmap under", 2D) = "bump" {} */ Material mat = matObject as Material; Texture mainTexure = mat.GetTexture("_MainTex2"); Texture mainBump = mat.GetTexture("_BumpMap2"); Texture detailTexture = mat.GetTexture("_MainTex"); Texture detailBump = mat.GetTexture("_BumpMap"); Color mainColor = Color.white; Color specColor = Color.white; Vector2 tilingDetail = new Vector2(5f, 5f); Vector2 tilingMain = new Vector2(1f, 1f); float opacity = 1.0f; float shininess = 0.5f; bool apply = true; if (mat != null) { if (mat.shader.name.Contains("BumpedDiffuseOverlay")) { mainTexure = mat.GetTexture("_MainTex2"); mainBump = mat.GetTexture("_BumpMap2"); detailTexture = mat.GetTexture("_MainTex"); detailBump = mat.GetTexture("_BumpMap"); mainColor = mat.GetColor("_Color"); opacity = mat.GetFloat("_Opacity"); tilingDetail = mat.GetTextureScale("_MainTex"); tilingMain = mat.GetTextureScale("_MainTex2"); } else if (mat.shader.name.Contains("Bumped Specular")) { mainTexure = mat.GetTexture("_MainTex"); tilingMain = mat.GetTextureScale("_MainTex"); mainBump = mat.GetTexture("_BumpMap"); mainColor = mat.GetColor("_Color"); specColor = mat.GetColor("_SpecColor"); shininess = mat.GetFloat("_Shininess"); detailTexture = DefaultDetailTexture; detailBump = DefaultDetailBump; } else if (mat.shader.name.Contains("Bumped Diffuse")) { mainTexure = mat.GetTexture("_MainTex"); tilingMain = mat.GetTextureScale("_MainTex"); mainBump = mat.GetTexture("_BumpMap"); mainColor = mat.GetColor("_Color"); detailTexture = DefaultDetailTexture; detailBump = DefaultDetailBump; } else if (mat.shader.name.Contains("Diffuse Detail")) { mainTexure = mat.GetTexture("_MainTex"); tilingMain = mat.GetTextureScale("_MainTex"); mainColor = mat.GetColor("_Color"); detailTexture = mat.GetTexture("_Detail"); tilingDetail = mat.GetTextureScale("_Detail"); detailBump = DefaultDetailBump; mainBump = DefaultBump; } else if (mat.shader.name.Contains("Diffuse")) { mainTexure = mat.GetTexture("_MainTex"); tilingMain = mat.GetTextureScale("_MainTex"); mainColor = mat.GetColor("_Color"); detailTexture = DefaultDetailTexture; detailBump = DefaultDetailBump; mainBump = DefaultBump; } else if (mat.shader.name.Contains("Specular")) { mainTexure = mat.GetTexture("_MainTex"); tilingMain = mat.GetTextureScale("_MainTex"); mainBump = DefaultBump; mainColor = mat.GetColor("_Color"); specColor = mat.GetColor("_SpecColor"); shininess = mat.GetFloat("_Shininess"); detailTexture = DefaultDetailTexture; detailBump = DefaultDetailBump; } else { apply = false; } if (apply) { mat.shader = Shader.Find("Detail/BumpedSpecularWithDetail"); mat.SetTexture("_MainDiffMap", mainTexure); mat.SetTexture("_MainBumpMap", mainBump); mat.SetTextureScale("_MainDiffMap", tilingMain); mat.SetTextureScale("_MainBumpMap", tilingMain); mat.SetFloat("_MainBumpiness", 1.0f); mat.SetColor("_DetailTintColor", mainColor); mat.SetColor("_MainTintColor", mainColor); mat.SetColor("_MainSpecColor", specColor); mat.SetColor("_DetailSpecColor", specColor); mat.SetTexture("_DetailDiffMap", detailTexture); mat.SetTexture("_DetailBumpMap", detailBump); mat.SetTextureScale("_DetailDiffMap", tilingDetail); mat.SetTextureScale("_DetailBumpMap", tilingDetail); mat.SetFloat("_DetailBumpiness", 1.0f); mat.SetTexture("_DetailBlend", mainTexure); mat.SetFloat("_DetailBlendBias", opacity); mat.SetFloat("_MainSpecLvl", shininess); mat.SetFloat("_DetailSpecLvl", shininess); } } } } if (!Application.isPlaying) { return; } UnityEngine.GUI.color = Color.green; GUILayout.Label("Exteriors waiting to load:"); foreach (Structure structure in ExteriorsWaitingToLoad) { //for (int i = ExteriorsWaitingToLoad.LastIndex(); i >= 0; i--) { //Structure structure = ExteriorsWaitingToLoad[i]; if (structure != null) { if (GUILayout.Button(structure.name + " - " + structure.LoadState.ToString())) { //ExteriorsWaitingToLoad.RemoveAt (i); } } } UnityEngine.GUI.color = Color.cyan; GUILayout.Label("\nInteriors waiting to load:"); foreach (Structure structure in InteriorsWaitingToLoad) { if (structure != null) { if (GUILayout.Button(structure.name + " - " + structure.LoadState.ToString())) { //InteriorsWaitingToLoad.RemoveAt (i); } } } UnityEngine.GUI.color = Color.blue; GUILayout.Label("\nMinor structures waiting to load:"); foreach (MinorStructure structure in MinorsWaitingToLoad) { if (structure != null) { if (GUILayout.Button(structure.TemplateName + " - " + structure.LoadState.ToString())) { //MinorsWaitingToLoad.RemoveAt (i); } } } UnityEngine.GUI.color = Color.red; GUILayout.Label("\nExteriors waiting to unload:"); foreach (Structure structure in ExteriorsWaitingToLoad) { if (structure != null) { if (GUILayout.Button(structure.name + " - " + structure.LoadState.ToString())) { //ExteriorsWaitingToUnload.RemoveAt (i); } } } UnityEngine.GUI.color = Color.yellow; GUILayout.Label("\nInteriors waiting to unload:"); foreach (Structure structure in InteriorsWaitingToLoad) { if (structure != null) { if (GUILayout.Button(structure.name + " - " + structure.LoadState.ToString())) { //InteriorsWaitingToUnload.RemoveAt (i); } } } UnityEngine.GUI.color = Color.yellow; GUILayout.Label("\nMinor structures waiting to unload:"); foreach (MinorStructure structure in MinorsWaitingToUnload) { if (structure != null) { if (GUILayout.Button(structure.TemplateName + " - " + structure.LoadState.ToString())) { //MinorsWaitingToUnload.RemoveAt (i); } } } UnityEditor.EditorUtility.SetDirty(gameObject); UnityEditor.EditorUtility.SetDirty(this); }
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); } } }