public void printLoDSlider(SerializedObject serializedObject, string prefix, int winId, bool showLODMode = true, GameObject gameObject = null) { bool isInspector = serializedObject.FindProperty("isInspector") != null?serializedObject.FindProperty("isInspector").boolValue : false; SerializedProperty serializedProperty = serializedObject.FindProperty(prefix); tt = "Use the button “Add LOD level” to add multiple LODs (or Level of Detail, see documentation for more information).\n\nFor each LOD(up to 5, including LOD 0), choose a Quality preset.\n\nUse the horizontal bar to set screen size percentage for each LOD.\n\nRight-click in the horizontal bar to add / remove a new LOD."; PiXYZUtils.beginGroupBox("LODs Mesh Quality", tooltip: tt); { int currentLodIndex = -1; tt = "To insert or remove a LoD, right-click on the row"; EditorGUILayout.BeginVertical(); { EditorGUILayout.Space(); bool changed = false || reset; if (changed) { reset = false; } if (showLODMode) { EditorGUILayout.BeginHorizontal(); { GUILayout.Space(20); float width = GUI.skin.label.CalcSize(new GUIContent("Quality")).x; GUILayout.Label("Mode", GUILayout.Width(width)); List <string> propertyNames = new List <string>(3); propertyNames.Add("LOD Group put on root object"); propertyNames.Add("LOD Groups put on the parent of each mesh"); List <int> intValue = new List <int>(3); intValue.Add(1); intValue.Add(2); width = (float)Math.Truncate(Screen.width * 0.6); Rect rect = EditorGUILayout.GetControlRect(); rect.width = width; GUILayout.FlexibleSpace(); int originalValue = serializedProperty.FindPropertyRelative("lodsMode").intValue; serializedProperty.FindPropertyRelative("lodsMode").intValue = EditorGUI.IntPopup(rect, originalValue, propertyNames.ToArray(), intValue.ToArray()); if (isInspector && gameObject != null && originalValue != serializedProperty.FindPropertyRelative("lodsMode").intValue) { if (originalValue == 1) { LODGroup lodGroup = gameObject.GetComponent <LODGroup>(); Dictionary <LODGroup, Dictionary <float, List <Renderer> > > finalLods = new Dictionary <LODGroup, Dictionary <float, List <Renderer> > >(); foreach (LOD lod in lodGroup.GetLODs()) { foreach (Renderer renderer in lod.renderers) { LODGroup parentLODGroup = renderer.transform.parent.GetComponent <LODGroup>(); if (parentLODGroup == null) { parentLODGroup = renderer.transform.parent.gameObject.AddComponent <LODGroup>(); } if (!finalLods.ContainsKey(parentLODGroup)) { finalLods.Add(parentLODGroup, new Dictionary <float, List <Renderer> >()); } if (!finalLods[parentLODGroup].ContainsKey(lod.screenRelativeTransitionHeight)) { finalLods[parentLODGroup].Add(lod.screenRelativeTransitionHeight, new List <Renderer>()); } finalLods[parentLODGroup][lod.screenRelativeTransitionHeight].Add(renderer); } } UnityEngine.Object.DestroyImmediate(lodGroup); foreach (var groupPair in finalLods) { List <LOD> lods = new List <LOD>(); foreach (var pair in groupPair.Value) { lods.Add(new LOD(pair.Key, pair.Value.ToArray())); } lods.Sort(delegate(LOD x, LOD y) { if (x.screenRelativeTransitionHeight < y.screenRelativeTransitionHeight) { return(1); } else if (x.screenRelativeTransitionHeight == y.screenRelativeTransitionHeight) { return(0); } else { return(-1); } }); groupPair.Key.SetLODs(lods.ToArray()); } } else { Dictionary <float, List <Renderer> > newLods = new Dictionary <float, List <Renderer> >(); foreach (LODGroup lodGroup in gameObject.GetComponentsInChildren <LODGroup>()) { foreach (LOD lod in lodGroup.GetLODs()) { if (!newLods.ContainsKey(lod.screenRelativeTransitionHeight)) { newLods.Add(lod.screenRelativeTransitionHeight, new List <Renderer>()); } newLods[lod.screenRelativeTransitionHeight].AddRange(lod.renderers); } UnityEngine.Object.DestroyImmediate(lodGroup); } LODGroup parentLODGroup = gameObject.AddComponent <LODGroup>(); List <LOD> lods = new List <LOD>(); foreach (KeyValuePair <float, List <Renderer> > pair in newLods) { lods.Add(new LOD(pair.Key, pair.Value.ToArray())); } lods.Sort(delegate(LOD x, LOD y) { if (x.screenRelativeTransitionHeight < y.screenRelativeTransitionHeight) { return(1); } else if (x.screenRelativeTransitionHeight == y.screenRelativeTransitionHeight) { return(0); } else { return(-1); } }); parentLODGroup.SetLODs(lods.ToArray()); } } } EditorGUILayout.EndHorizontal(); GUILayout.Space(10); } EditorGUILayout.BeginHorizontal(); { GUILayout.Space(20); slider.show(serializedObject, gameObject); GUILayout.Space(20); } EditorGUILayout.EndHorizontal(); GUILayout.Space(10); if (!isInspector) { EditorGUILayout.BeginHorizontal(); { GUILayout.FlexibleSpace(); if (!serializedProperty.FindPropertyRelative("useLods").boolValue) { if (GUILayout.Button(new GUIContent("Activate LODs"))) { serializedProperty.FindPropertyRelative("useLods").boolValue = true; } } GUILayout.FlexibleSpace(); } EditorGUILayout.EndHorizontal(); } GUILayout.Space(10); } EditorGUILayout.EndVertical(); currentLodIndex = serializedProperty.FindPropertyRelative("lodCurrentIndex").intValue; if (GUI.changed) { serializedObject.ApplyModifiedProperties(); if (EditorWindow.focusedWindow != null) { EditorWindow.focusedWindow.Repaint(); } } if (!isInspector) { GUILayout.BeginHorizontal(); { GUILayout.BeginVertical(); { if (serializedProperty.FindPropertyRelative("useLods").boolValue) { printLoDSettings(currentLodIndex, serializedObject, prefix + "." + PiXYZLODSettings.serializePrefix); } serializedObject.ApplyModifiedProperties(); GUILayout.Space(10); } GUILayout.EndVertical(); } EditorGUILayout.EndHorizontal(); } else { GUILayout.BeginHorizontal(); { GUILayout.FlexibleSpace(); if (GUILayout.Button(new GUIContent("Propagate Materials from LOD0", "After applying a new material to one (or multiple) LOD0, use this button to propagate the material assignment to all the other LODs."))) { if (serializedProperty.FindPropertyRelative("lodsMode").intValue == 2) { foreach (var lodGroup in gameObject.GetComponentsInChildren <LODGroup>()) { for (int i = 1; i < lodGroup.lodCount; ++i) //foreach(LOD lod in lodGroup.GetLODs()) { if (lodGroup.GetLODs()[0].renderers.Length != lodGroup.GetLODs()[i].renderers.Length) { Debug.Log("The number of renderers on each LOD is not equal, can't synchronize !"); } else { for (int j = 0; j < lodGroup.GetLODs()[0].renderers.Length; ++j) { Renderer renderer = lodGroup.GetLODs()[i].renderers[j].gameObject.GetComponent <Renderer>(); renderer.sharedMaterial = lodGroup.GetLODs()[0].renderers[j].sharedMaterial; renderer.sharedMaterials = lodGroup.GetLODs()[0].renderers[j].sharedMaterials; } } } } } else { LODGroup lodGroup = gameObject.GetComponent <LODGroup>(); for (int i = 1; i < lodGroup.lodCount; ++i) //foreach(LOD lod in lodGroup.GetLODs()) { if (lodGroup.GetLODs()[0].renderers.Length != lodGroup.GetLODs()[i].renderers.Length) { Debug.Log("The number of renderers on each LOD is not equal, can't synchronize !"); } else { for (int j = 0; j < lodGroup.GetLODs()[0].renderers.Length; ++j) { Renderer renderer = lodGroup.GetLODs()[i].renderers[j].gameObject.GetComponent <Renderer>(); renderer.sharedMaterial = lodGroup.GetLODs()[0].renderers[j].sharedMaterial; renderer.sharedMaterials = lodGroup.GetLODs()[0].renderers[j].sharedMaterials; } } } } } GUILayout.FlexibleSpace(); } GUILayout.EndHorizontal(); } } PiXYZUtils.endGroupBox(); }
public static void showLicenseInfos(bool center = true) { EditorGUILayout.BeginVertical(); { if (center) { GUILayout.FlexibleSpace(); } if (PiXYZ4UnityWrapper.checkLicense()) { String[] names; String[] values; if (PiXYZ4UnityWrapper.isFloatingLicense()) { string server; int port; PiXYZ4UnityWrapper.getLicenseServer(out server, out port); names = new String[] { "License", "", "Server address", "Port" }; values = new String[] { "Floating", "", server, port.ToString() }; } else { names = new String[] { "Start date", "End date", "Company name", "Name", "E-mail" }; values = new String[] { PiXYZ4UnityWrapper.getCurrentLicenseStartDate(), PiXYZ4UnityWrapper.getCurrentLicenseEndDate().Length == 0 ? "Perpetual" : PiXYZ4UnityWrapper.getCurrentLicenseEndDate(), PiXYZ4UnityWrapper.getCurrentLicenseCompany(), PiXYZ4UnityWrapper.getCurrentLicenseName(), PiXYZ4UnityWrapper.getCurrentLicenseEmail(), }; } GUIStyle bold = new GUIStyle(EditorStyles.boldLabel); GUIStyle labelStyle = new GUIStyle(EditorStyles.label); labelStyle.alignment = TextAnchor.MiddleLeft; labelStyle.fontSize = 10; bold.alignment = TextAnchor.MiddleLeft; bold.fontSize = 10; PiXYZUtils.beginGroupBox("License informations"); for (int i = 0; i < names.Length; ++i) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(names[i].Length > 0 ? names[i] + ": " : "", labelStyle, GUILayout.Width((int)(Screen.width * 0.28))); EditorGUILayout.LabelField(values[i], bold); EditorGUILayout.EndHorizontal(); } PiXYZUtils.endGroupBox(); } else { GUIStyle boldRed = new GUIStyle(EditorStyles.boldLabel); boldRed.alignment = TextAnchor.MiddleCenter; boldRed.fontSize = 18; boldRed.wordWrap = true; PiXYZUtils.beginGroupBox(""); { EditorGUILayout.LabelField(""); EditorGUILayout.LabelField("Your license is inexistant or invalid.", boldRed); EditorGUILayout.LabelField(""); } PiXYZUtils.endGroupBox(); } if (center) { GUILayout.FlexibleSpace(); } } EditorGUILayout.EndVertical(); }
void OnGUI() { serializedObject.Update(); EditorGUILayout.BeginHorizontal(GUILayout.ExpandWidth(true), GUILayout.MaxWidth(Screen.width)); { GUILayout.Space(5); EditorGUI.indentLevel++; EditorGUILayout.BeginVertical(); { EditorGUI.BeginDisabledGroup(coroutineScheduler.HasCoroutines()); { GUILayout.Space(20); PiXYZUtils.beginGroupBox("Importing File"); { EditorGUILayout.BeginHorizontal(); { EditorGUILayout.TextField("File Name", Path.GetFileName(selectedFile)); GUIStyle btnStyle = new GUIStyle(GUI.skin.button); btnStyle.margin.top = 0; if (GUILayout.Button(new GUIContent("... ", "Open browser and choose the import to import"), btnStyle, GUILayout.Width(25))) { OnFileSelectionClicked(); } GUILayout.Space(40); } EditorGUILayout.EndHorizontal(); } PiXYZUtils.endGroupBox(); GUI.enabled = isFileNameValid && !coroutineScheduler.HasCoroutines(); if (isFileNameValid) { string ext = Path.GetExtension(selectedFile); utils.GUISettings(serializedObject, ext); if (maxSize.y == 110.0f || (maxSize.y > 300.0f && PiXYZUtils.isPiXYZExt(ext)) || (maxSize.y < 300.0f && !PiXYZUtils.isPiXYZExt(ext))) { minSize = new Vector2(430.0f, !PiXYZUtils.isPiXYZExt(ext) ? 660.0f : 240.0f); maxSize = new Vector2(430.0f, !PiXYZUtils.isPiXYZExt(ext) ? 700.0f : 260.0f); this.CenterOnMainWin(); } } else if (!isFileNameValid && maxSize.y > 110.0f) { minSize = new Vector2(430.0f, 100.0f); maxSize = new Vector2(430.0f, 110.0f); this.CenterOnMainWin(); } GUILayout.Space(10); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.BeginHorizontal(GUILayout.Width(Screen.width / 2)); { GUILayout.FlexibleSpace(); if (GUILayout.Button("Import", GUILayout.Width(80))) { OnImportClicked(); } GUI.enabled = true; GUILayout.Space(15); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { GUILayout.Space(15); if (GUILayout.Button("Cancel", GUILayout.Width(80))) { OnCancelClicked(); } GUILayout.FlexibleSpace(); if (isFileNameValid && !PiXYZUtils.isPiXYZExt(selectedFile)) { GUIStyle bs = new GUIStyle(GUI.skin.button); bs.normal.background = saveIconNormal; // Resources.Load("icon/save_32_Roll") as Texture2D; bs.hover.background = saveIconHover; // Resources.Load("icon/save_32_Roll1") as Texture2D; bs.active.background = saveIconActive; // Resources.Load("icon/Save_32_Roll2") as Texture2D; bs.border = new RectOffset(0, 0, 0, 0); bs.margin = new RectOffset(0, 0, 0, 0); bs.overflow = new RectOffset(0, 0, 0, 0); if (GUILayout.Button("", bs, GUILayout.Width(24), GUILayout.Height(24))) { PiXYZUtils.saveEditorPref(serializedObject); } bs.normal.background = resetIconNormal; // Resources.Load("icon/Reset_32_Roll") as Texture2D; bs.hover.background = resetIconHover; // Resources.Load("icon/Reset_32_Roll1") as Texture2D; bs.active.background = resetIconActive; // Resources.Load("icon/Reset_32_Roll2") as Texture2D; if (GUILayout.Button("", bs, GUILayout.Width(24), GUILayout.Height(24))) { importSettings = ScriptableObject.CreateInstance <ImportSettings>(); serializedObject = new SerializedObject(importSettings); importSettings.windowId = GetInstanceID(); PiXYZLods.reset = true; } bs.normal.background = resetFactoryIconNormal; // Resources.Load("icon/ResetUsine_32_Roll") as Texture2D; bs.hover.background = resetFactoryIconHover; // Resources.Load("icon/ResetUsine_32_Roll1") as Texture2D; bs.active.background = resetFactoryIconActive; // Resources.Load("icon/ResetUsine_32_Roll2") as Texture2D; if (GUILayout.Button("", bs, GUILayout.Width(24), GUILayout.Height(24))) { importSettings.settings.factoryReset(); serializedObject = new SerializedObject(importSettings); importSettings.windowId = GetInstanceID(); PiXYZLods.reset = true; } GUILayout.Space(10); } } EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndHorizontal(); } EditorGUI.EndDisabledGroup(); GUILayout.Space(10); } EditorGUILayout.EndVertical(); GUILayout.Space(5); EditorGUI.indentLevel--; } EditorGUILayout.EndHorizontal(); }