static Material ConvertToStaticLighting(Material material) { Shader destShader = null; Texture cubeMap = null; if (material.HasProperty("_Cube")) { cubeMap = material.GetTexture("_Cube"); } // if there is a cube map use the reflection shader if (cubeMap != null) { destShader = Shader.Find("Daydream/DiffuseAndReflections"); } else { destShader = Shader.Find("Daydream/Standard"); } if (!DaydreamMenu.StandardToDaydreamSingleMaterial(material, material.shader, destShader)) { Debug.LogWarning("No Conversion"); material.shader = destShader; } // enable static vertex lighting material.EnableKeyword("STATIC_LIGHTING"); material.DisableKeyword("LIGHTMAP"); material.EnableKeyword("VERTEX_LIGHTING"); EditorUtility.SetDirty(material); return(material); }
static Material ConvertToDynamicLighting(Material material) { // load main asset string path = AssetDatabase.GetAssetPath(material); Material mainMaterial = AssetDatabase.LoadMainAssetAtPath(path) as Material; if (mainMaterial == null) { return(null); } Shader destShader = null; Texture cubeMap = material.GetTexture("_Cube"); // if there is a cube map use the reflection shader if (cubeMap != null) { destShader = Shader.Find("Daydream/DiffuseAndReflections"); } else { destShader = Shader.Find("Daydream/Standard"); } if (!DaydreamMenu.StandardToDaydreamSingleMaterial(material, material.shader, destShader)) { Debug.Log("No Conversion for " + material.shader.name); } EditorUtility.SetDirty(material); return(material); }
static Material ConvertToStaticLighting(Material material) { Shader destShader = Shader.Find("Daydream/Standard"); if (!DaydreamMenu.StandardToDaydreamSingleMaterial(material, material.shader, destShader)) { Debug.LogWarning("No Conversion"); material.shader = destShader; } // enable static vertex lighting material.EnableKeyword("STATIC_LIGHTING"); material.DisableKeyword("LIGHTMAP"); material.EnableKeyword("VERTEX_LIGHTING"); EditorUtility.SetDirty(material); return(material); }
static Material ConvertToDynamicLighting(Material material) { // load main asset string path = AssetDatabase.GetAssetPath(material); Material mainMaterial = AssetDatabase.LoadMainAssetAtPath(path) as Material; if (mainMaterial == null) { return(null); } Shader destShader = Shader.Find("Daydream/Standard"); if (!DaydreamMenu.StandardToDaydreamSingleMaterial(material, material.shader, destShader)) { Debug.Log("No Conversion for " + material.shader.name); } EditorUtility.SetDirty(material); return(material); }
static Vector2 DrawMaterialList(Vector2 scrollPosition, List <Material> list, int listHeight) { // Split and converted materials int linesPerEntry = 2; float height = DaydreamRendererImportManager.Styles.s_defaultLabel.fixedHeight * linesPerEntry; scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition, GUILayout.Height(listHeight)); for (int i = 0, c = list.Count; i < c; i++) { // create a 'window' of items to actually fill in, otherwise rendering the list is too slow int topIndex = (int)(scrollPosition.y / height); int start = (int)(Mathf.Max(0f, topIndex - 4f)); int end = (int)(Mathf.Min(list.Count - 1, topIndex + 40f)); if (i < start || i > end) { // fill this item with blank space to save time GUILayout.Space(DaydreamRendererImportManager.Styles.s_defaultLabel.fixedHeight * linesPerEntry); continue; } Material material = list[i]; if (material == null) { continue; } EditorGUILayout.BeginHorizontal(); // print index int numberWidth = (int)Mathf.Max(2f, Mathf.Log10(i) + 1); GUILayout.Label("" + i, DaydreamRendererImportManager.Styles.s_defaultLabel, GUILayout.Width(numberWidth * 10)); EditorGUILayout.ObjectField(material, typeof(Material), true, GUILayout.Height(DaydreamRendererImportManager.Styles.s_defaultLabel.fixedHeight)); GUIContent content = Styles.notInSceneContent; List <MaterialInfo> matInfos = null; GUIStyle elStyle = Styles.notInSceneIcon; uint state = 0; if (m_infoMap.TryGetValue(material.name, out matInfos) && matInfos.Count > 0) { state = matInfos[0].sceneType & StaticSceneState.kMask; if (state == StaticSceneState.kStatic) { content = Styles.staticMatContent; elStyle = Styles.staticMatIcon; } else if (state == StaticSceneState.kNotStatic) { content = Styles.dynamicMatContent; elStyle = Styles.dynmcMatIcon; } else { content = Styles.mixedMatContent; elStyle = Styles.mixedMatIcon; } } bool enabled = true; if (material.name.StartsWith(kBackupPrefix)) { enabled = false; content = Styles.backupContent; } bool nonDaydream = !material.shader.name.ToLower().Contains("daydream"); elStyle = nonDaydream ? elStyle : Styles.daydrmMatIcon; content = nonDaydream ? content : Styles.daydreamMatContent; // if its not a daydream material check to see if it is convertible bool convertible = true; if (nonDaydream) { convertible = DaydreamMenu.IsConvertible(material.shader); elStyle = convertible ? elStyle : Styles.notConvertibleIcon; content = convertible ? content : Styles.notConvertibleContent; } EditorGUILayout.LabelField(content, elStyle, GUILayout.Width(16)); EditorGUI.BeginDisabledGroup(!enabled || !convertible); if (nonDaydream) { // if it has a backup dont offer conversion EditorGUI.BeginDisabledGroup(HasBackup(material)); if (GUILayout.Button("Convert", GUILayout.Width(80), GUILayout.Height(DaydreamRendererImportManager.Styles.s_defaultLabel.fixedHeight))) { // force repaint m_repaint = true; DoConvertMaterial(state, material, matInfos != null ? matInfos[0] : null); } EditorGUI.EndDisabledGroup(); } else { // if it has a backup dont offer conversion EditorGUI.BeginDisabledGroup(!HasBackup(material)); if (GUILayout.Button("Revert", GUILayout.Width(80), GUILayout.Height(DaydreamRendererImportManager.Styles.s_defaultLabel.fixedHeight))) { // force repaint m_repaint = true; material = DoRevertMaterial(material, matInfos != null ? matInfos[0] : null); // if last item is visible and we delete something Unity throws a repaint exception, trying to repaint a list item thats not there anymore if (list.Count - 1 == end) { scrollPosition.y -= height; } } EditorGUI.EndDisabledGroup(); } EditorGUI.EndDisabledGroup(); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.Space(28); EditorGUILayout.LabelField("Path:", GUILayout.Width(32)); EditorGUILayout.LabelField(GetMaterialPath(material), GUILayout.Height(DaydreamRendererImportManager.Styles.s_defaultLabel.fixedHeight)); EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndScrollView(); return(scrollPosition); }