static void UpdateCoroutine() { ++ticks; if (ticks > 20) { ticks = 0; if (loader != null) { if (coroutineScheduler.HasCoroutines()) { if (Time.frameCount == lastFrame) { ++frameSkip; } else { lastFrame = Time.frameCount; } coroutineScheduler.UpdateAllCoroutines((Time.frameCount + frameSkip), Time.time); if (loader != null) { PiXYZUtils.displayProgressBar("PiXYZ Import", loader.progressStatus, loader.progress); } return; } } } }
void OnGUI() { EditorGUILayout.BeginHorizontal(); EditorGUILayout.BeginVertical(GUILayout.Height(Screen.width - 40)); EditorGUILayout.LabelField(""); EditorGUILayout.EndVertical(); Rect rectangle = GUILayoutUtility.GetLastRect(); EditorGUILayout.EndHorizontal(); { rectangle.y = (rectangle.height - rectangle.width) / 2; rectangle.height = rectangle.width; GUI.DrawTexture(rectangle, Resources.Load("Icon/pixyz_banner", typeof(Texture2D)) as Texture2D); //PiXYZUtils.drawGroupBox(rectangle, "test"); } showLicenseInfos(false); GUILayout.FlexibleSpace(); EditorGUILayout.BeginVertical(); { GUIStyle centeredBold = new GUIStyle(EditorStyles.boldLabel); centeredBold.alignment = TextAnchor.UpperCenter; EditorGUILayout.LabelField("Plugin version: " + PiXYZ4UnityWrapper.getVersion(), centeredBold); } { GUIStyle boldRich = new GUIStyle(EditorStyles.boldLabel); boldRich.alignment = TextAnchor.MiddleCenter; boldRich.normal.textColor = Color.blue; //GUI.Label(new Rect(0, Screen.height * 3 / 4 - 10, Screen.width, Screen.height / 4), "Click to see Terms & Conditions", boldRich); string str = "Click to see Terms & Conditions"; TextGenerationSettings settings = new TextGenerationSettings(); settings.fontSize = boldRich.fontSize; settings.fontStyle = boldRich.fontStyle; settings.font = boldRich.font; settings.color = boldRich.normal.textColor; settings.pivot = Vector2.zero; if (GUILayout.Button(str, boldRich)) { Application.OpenURL("https://www.pixyz-software.com/general-and-products-terms-and-conditions/"); } TextGenerator a = new TextGenerator(); Rect buttonRect = GUILayoutUtility.GetLastRect(); EditorGUIUtility.AddCursorRect(buttonRect, MouseCursor.Link); Rect underlineRect = new Rect(buttonRect); underlineRect.width = a.GetPreferredWidth(str, settings); underlineRect.x = Screen.width / 2 - underlineRect.width / 2; underlineRect.y += underlineRect.height - 2; underlineRect.height = 1; PiXYZUtils.GUIDrawRect(underlineRect, Color.blue); } { GUIStyle italic = new GUIStyle(); italic.fontStyle = FontStyle.Italic; italic.alignment = TextAnchor.MiddleCenter; italic.fontSize = 10; italic.wordWrap = true; EditorGUILayout.LabelField("PiXYZ Software solutions are edited by Metaverse Technologies France", italic); } EditorGUILayout.EndVertical(); }
public IEnumerator ImportModel() { PiXYZImportSettings settings = target as PiXYZImportSettings; GameObject gameObject = settings.gameObject; //Find the gameobject the script is attached to Vector3 eulerAngles = new Vector3() + gameObject.transform.rotation.eulerAngles; Vector3 scale = new Vector3() + gameObject.transform.lossyScale; if (gameObject.transform.childCount > 0) { foreach (Transform child in gameObject.transform) { DestroyImmediate(child.gameObject); } } UnityEngine.Object prefab; prefab = PrefabUtility.CreateEmptyPrefab("Assets/3DModels/" + settings.settings.prefabName + ".prefab"); loader = new PiXYZ4UnityLoader(); loader.setSourceCoordinatesSystem(settings.settings.isRightHanded, settings.settings.isZUp, settings.settings.scaleFactor); double mapUV3dSize = settings.settings.mapUV ? settings.settings.mapUV3dSize : -1; loader.configure(settings.settings.orient, mapUV3dSize, settings.settings.treeProcess, settings.settings.useLods ? settings.settings.lodsMode : LODsMode.NONE, settings.settings.lodSettings, !settings.settings.splitTo16BytesIndex, settings.settings.useMergeFinalAssemblies); CoroutineNode coco = coroutineScheduler.StartCoroutine(loader.loadFileRuntime(gameObject, settings.settings.originalFilename, true, prefab)); yield return(coco); PiXYZUtils.clearProgressBar(); if (loader.getErrorMessage().Length > 0) { Debug.LogError("PiXYZAssetImporter: loader.loadfile failed"); } else { Debug.Log("Success"); } #if UNITY_EDITOR foreach (UnityEngine.Object obj in loader.loadedObject) { AssetDatabase.AddObjectToAsset(obj, prefab); } #endif gameObject.transform.Rotate(-gameObject.transform.rotation.eulerAngles); gameObject.transform.Rotate(eulerAngles); gameObject.transform.localScale = scale; PrefabUtility.ReplacePrefab(gameObject, prefab, ReplacePrefabOptions.ConnectToPrefab); loader = null; }
public void OnCancelClicked() { if (coroutineScheduler != null) { coroutineScheduler.StopAllCoroutines(); } if (loader != null) { PiXYZUtils.clearProgressBar(); } this.Close(); }
void OnEnable() { instanceCount++; saveIconNormal = Resources.Load("icon/save_32_Roll") as Texture2D; saveIconHover = Resources.Load("icon/save_32_Roll1") as Texture2D; saveIconActive = Resources.Load("icon/save_32_Roll2") as Texture2D; resetIconNormal = Resources.Load("icon/reset_32_Roll") as Texture2D; resetIconHover = Resources.Load("icon/reset_32_Roll1") as Texture2D; resetIconActive = Resources.Load("icon/reset_32_Roll2") as Texture2D; resetFactoryIconNormal = Resources.Load("icon/resetUsine_32_Roll") as Texture2D; resetFactoryIconHover = Resources.Load("icon/resetUsine_32_Roll1") as Texture2D; resetFactoryIconActive = Resources.Load("icon/resetUsine_32_Roll2") as Texture2D; EditorApplication.update += UpdateCoroutine; importSettings = ScriptableObject.CreateInstance <ImportSettings>();// new ImportSettings(); coroutineScheduler = coroutineScheduler == null?ScriptableObject.CreateInstance <CoroutineScheduler>() : coroutineScheduler; importSettings.windowId = GetInstanceID(); serializedObject = new SerializedObject(importSettings); utils = new PiXYZUtils(); //selectedFile = ""; //isFileNameValid = false; pluginName = "PiXYZ4Unity.dll"; pluginPath = Path.Combine(Application.dataPath, "PiXYZ/Plugins"); #if UNITY_EDITOR_WIN //On windows, copy .dll to project root try { string[] lPluginFiles = Directory.GetFiles(pluginPath); foreach (string lFile in lPluginFiles) { if (Path.GetExtension(lFile) == ".dll" && Path.GetFileName(lFile) != "PiXYZ4Unity.dll") { string lExportFile = Path.Combine(Application.dataPath + "/..", Path.GetFileName(lFile)); if (!File.Exists(lExportFile)) { File.Copy(lFile, lExportFile); } } } } catch (System.Exception e) { Debug.LogException(e); } #endif }
public void OnImportFinished() { PiXYZUtils.clearProgressBar(); //Display success PopUp if (loader.getErrorMessage().Length > 0) { EditorUtility.DisplayDialog("PiXYZImporter", "File import failed.\n\nReasons : " + loader.getErrorMessage(), "ok"); } else { EditorUtility.DisplayDialog("PiXYZImporter", "File successfully imported in Scene.\nPrefab created in Assets/3DModels.", "ok"); } loader = null; frameSkip = 0; //window.Close(); DestroyImmediate(this); importing = false; isFileNameValid = false; }
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(); }
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 printLoDSettings(int index, SerializedObject serializedObject, string prefix = "settings.lodSettings", bool showTessellation = true) { int winId = serializedObject.FindProperty("windowId").intValue; string tt = ""; serializedObject.Update(); SerializedProperty lodProperties = serializedObject.FindProperty(prefix); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.BeginVertical(); { tt = PiXYZUtils.getTooltipText <PiXYZLODSettings>("preset"); for (int i = 0; i < lodProperties.arraySize; i++) { if (lodProperties.GetArrayElementAtIndex(i).FindPropertyRelative("preset").intValue > 4) { int j = lodProperties.arraySize - 1; while (j >= i) { removeLod(j, serializedObject, "settings"); j--; } break; } EditorGUILayout.BeginHorizontal(); { GUILayout.FlexibleSpace(); GUILayout.Label(new GUIContent("LOD " + i, tt)); EditorGUILayout.PropertyField(lodProperties.GetArrayElementAtIndex(i).FindPropertyRelative("preset"), GUIContent.none, GUILayout.ExpandWidth(true)); for (int j = i; j < lodProperties.arraySize - 1; j++) { while (lodProperties.GetArrayElementAtIndex(j).FindPropertyRelative("preset").intValue >= lodProperties.GetArrayElementAtIndex(j + 1).FindPropertyRelative("preset").intValue) { lodProperties.GetArrayElementAtIndex(j + 1).FindPropertyRelative("preset").intValue++; } } if (GUILayout.Button(new GUIContent("-"), GUILayout.MaxHeight(13))) { if (lodProperties.arraySize == 1) { if (EditorPrefs.GetBool("PiXYZ.ShowPopupLods", true)) { if (EditorUtility.DisplayDialog("PiXYZImporter", "If you remove the last LOD, the functionality will be disabled.", "Continue", "Cancel")) { serializedObject.FindProperty("settings.useLods").boolValue = false; EditorPrefs.SetBool("PiXYZ.ShowPopupLods", false); } } else { serializedObject.FindProperty("settings.useLods").boolValue = false; } } else { removeLod(i, serializedObject, "settings"); } } GUILayout.FlexibleSpace(); } EditorGUILayout.EndHorizontal(); } if (lodProperties.GetArrayElementAtIndex(lodProperties.arraySize - 1).FindPropertyRelative("preset").intValue < 4) { EditorGUILayout.BeginHorizontal(); { GUILayout.FlexibleSpace(); if (GUILayout.Button(new GUIContent("Add LOD level"))) { addLod(lodProperties.arraySize, serializedObject, lodProperties.arraySize - 1, 1f - lodProperties.arraySize * 0.2f, "settings"); } GUILayout.FlexibleSpace(); } EditorGUILayout.EndHorizontal(); } } EditorGUILayout.EndVertical(); } EditorGUILayout.EndHorizontal(); }
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(); }
public void show(SerializedObject serializedObject, GameObject gameObject = null) { GUIStyle sliderStyle = new GUIStyle(GUI.skin.horizontalSlider); GUIStyle thumbStyle = new GUIStyle(GUI.skin.horizontalSliderThumb); Texture2D tex = new Texture2D(2, 300); var fillColorArray = tex.GetPixels(); for (var i = 0; i < fillColorArray.Length; ++i) { fillColorArray[i] = Color.black; } tex.SetPixels(fillColorArray); tex.Apply(); sliderStyle.normal.background = null; thumbStyle.fixedWidth = 1f; thumbStyle.fixedHeight = 1f; thumbStyle.normal.background = null; int maxLod = serializedObject.FindProperty("settings").FindPropertyRelative("lodSettingCount").intValue; Rect sliderRect = EditorGUILayout.GetControlRect(); sliderRect.height = 30; Rect labelRect = new Rect(sliderRect); float lodValue = 1f; float nextLodValue = PiXYZLoDSettingsEditor.getIndexProperty(0, serializedObject, "startLod", "settings.lodSettings").floatValue; float start = 0; for (int i = 0; i < maxLod; i++) { labelRect.width = sliderRect.width * (lodValue - nextLodValue); labelRect.position = new Vector2(sliderRect.position.x + start, sliderRect.position.y); if (Event.current.type == EventType.MouseUp && nextLodValue < currentValue && currentValue < lodValue) { selectedLOD = i; } if (i < maxLod) { PiXYZUtils.GUIDrawRect(labelRect, selectedLOD == i ? highlightColors[i] : normalColors[i], highlightColors[highlightColors.Length - 1], selectedLOD == i ? 2 : 0, " LOD " + i + "\n " + (Math.Round(lodValue * 100)) + "%", TextAnchor.MiddleLeft); } Rect movePos = new Rect(labelRect.x + labelRect.width - 5, labelRect.y, 10, labelRect.height); EditorGUIUtility.AddCursorRect(movePos, MouseCursor.ResizeHorizontal); if (movePos.Contains(Event.current.mousePosition) && (Event.current.type == EventType.MouseDown && Event.current.button == 0)) { grabbing = i; } else if (grabbing != -1 && Event.current.type == EventType.MouseUp && Event.current.button == 0) { if (gameObject != null) { foreach (LODGroup lodGroup in gameObject.GetComponentsInChildren <LODGroup>()) { LOD[] lods = lodGroup.GetLODs(); lods[grabbing].screenRelativeTransitionHeight = PiXYZLoDSettingsEditor.getIndexProperty(grabbing, serializedObject, "startLod", "settings.lodSettings").floatValue; lodGroup.SetLODs(lods); } } grabbing = -1; } lodValue = nextLodValue; nextLodValue = i < maxLod - 1 ? PiXYZLoDSettingsEditor.getIndexProperty(i + 1, serializedObject, "startLod", "settings.lodSettings").floatValue : -1; start += labelRect.width; } labelRect.width = sliderRect.width - start; labelRect.position = new Vector2(sliderRect.position.x + start, sliderRect.position.y); PiXYZUtils.GUIDrawRect(labelRect, normalColors[normalColors.Length - 1], highlightColors[highlightColors.Length - 1], 0, " Culled\n " + (Math.Round(lodValue * 100)) + "%", TextAnchor.MiddleLeft); currentValue = GUI.Slider(sliderRect, currentValue, 0, 1, 0, sliderStyle, thumbStyle, true, 0); if (grabbing != -1) { if (grabbing == 2 && currentValue < 0.01f) { return; } else if (grabbing == 0 && currentValue > 0.99f) { return; } else if (grabbing > 0 && currentValue > PiXYZLoDSettingsEditor.getIndexProperty(grabbing - 1, serializedObject, "startLod", "settings.lodSettings").floatValue - 0.01f) { return; } else if (grabbing < maxLod - 1 && currentValue < PiXYZLoDSettingsEditor.getIndexProperty(grabbing + 1, serializedObject, "startLod", "settings.lodSettings").floatValue + 0.01f) { return; } PiXYZLoDSettingsEditor.getIndexProperty(grabbing, serializedObject, "startLod", "settings.lodSettings").floatValue = currentValue <= 0f?1f: currentValue; } }
void OnGUI() { string[] titles = { "Current license", "Online", "Offline", "License server", "Tokens" }; selectedTab = PiXYZUtils.Tabs(titles, selectedTab); switch (selectedTab) { case 0: //current { currentLicenseTab(); break; } case 1: //online { showCredentials.target = !connected; showOnlineTab.target = connected; if (!connected) { if (EditorGUILayout.BeginFadeGroup(showCredentials.faded)) { connected = creds(); EditorGUILayout.EndFadeGroup(); } } else { if (EditorGUILayout.BeginFadeGroup(showOnlineTab.faded)) { onlineTab(); EditorGUILayout.EndFadeGroup(); } } break; } case 2: //offline { offlineTab(); break; } case 3: //server { licenseServer(); break; } case 4: //tokens { tokens(); break; } } //Outter calls if (doRelease) { doRelease = false; if (PiXYZ4UnityWrapper.releaseLicense(username, password, index)) { EditorUtility.DisplayDialog("Release complete", "The license release has been completed.", "Ok"); } else { EditorUtility.DisplayDialog("Release failed", "An error has occured while releasing the license: " + PiXYZ4UnityWrapper.getLastError(), "Ok"); PiXYZ4UnityWrapper.requestLicense(username, password, index); } } else if (doRequest) { doRequest = false; if (PiXYZ4UnityWrapper.requestLicense(username, password, index)) { EditorUtility.DisplayDialog("Installation complete", "The license installation has been completed.", "Ok"); } else { EditorUtility.DisplayDialog("Installation failed", "An error occured while installing the license: " + PiXYZ4UnityWrapper.getLastError(), "Ok"); } } }
void printSettingsGUI(SerializedObject serializedObject, string prefix = PiXYZSettings.serializePrefix, string fileExt = "", GameObject gameObject = null) { serializedObject.Update(); int winId = serializedObject.FindProperty("windowId").intValue; bool isInspector = serializedObject.FindProperty("isInspector") != null?serializedObject.FindProperty("isInspector").boolValue : false; string tt = ""; Vector2 scrollViewPosition; int focusId = EditorWindow.focusedWindow != null?EditorWindow.focusedWindow.GetInstanceID() : lastFocusedId; if (winId != focusId) { winId = 0; } if (!g_scrollViewPosition.ContainsKey(winId)) //winId = 0 is shared { scrollViewPosition = new Vector2(0, 0); g_scrollViewPosition[winId] = scrollViewPosition; } else { scrollViewPosition = g_scrollViewPosition[winId]; } if (!UvAnim.ContainsKey(winId) && winId != 0) { UvAnim[winId] = new AnimBool(false); UvAnim[winId].valueChanged.AddListener(EditorWindow.focusedWindow.Repaint); } if (!lodAnim.ContainsKey(winId) && winId != 0) { lodAnim[winId] = new AnimBool(false); lodAnim[winId].valueChanged.AddListener(EditorWindow.focusedWindow.Repaint); } if (!advancedToggle.ContainsKey(winId)) { advancedToggle[winId] = false; } SerializedProperty serializedProperty = serializedObject.FindProperty(prefix); int lastShown = 0; scrollViewPosition = GUILayout.BeginScrollView(scrollViewPosition, GUILayout.MaxHeight(Screen.height - 30)); { g_scrollViewPosition[winId] = scrollViewPosition; EditorGUI.indentLevel = 0; EditorGUILayout.BeginVertical(); { GUILayout.Space(10); tt = "Use the following settings to adapt the imported model’s units/transforms to Unity3D’s units/coordinate system (meters/left-handed).\n\nDefault settings change a millimeters / Z-up axis scene to Unity configuration."; beginGroupBox("Coordinate System", isInspector, tt); { EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); { tt = PiXYZUtils.getTooltipText <PiXYZSettings>("scaleFactor"); EditorGUILayout.PropertyField(serializedProperty.FindPropertyRelative("scaleFactor"), new GUIContent("Scale", tt)); GUILayout.Space(10); } EditorGUILayout.EndHorizontal(); tt = PiXYZUtils.getTooltipText <PiXYZSettings>("isRightHanded"); EditorGUILayout.PropertyField(serializedProperty.FindPropertyRelative("isRightHanded"), new GUIContent("Right Handed", tt)); tt = PiXYZUtils.getTooltipText <PiXYZSettings>("isZUp"); EditorGUILayout.PropertyField(serializedProperty.FindPropertyRelative("isZUp"), new GUIContent("Z-up", tt)); EditorGUILayout.Space(); } endGroupBox(); if (!isPiXYZExt(fileExt)) { GUILayout.Space(10); tt = "Choose one of the following mode to optimize the imported model’s hierarchy (or tree)\n\n\nNone: No modification of the hierarchy (default mode)\n\nClean-up intermediary nodes: Compresses the hierarchy by removing empty nodes, or any node containing only one sub-node.\n\nTransfer all objects under root: Simplifies the hierarchy by transferring all imported 3D objects (or GameObject) under the root node."; beginGroupBox("Hierarchy Optimization", isInspector, tooltip: tt); { tt = PiXYZUtils.getTooltipText <PiXYZSettings>("treeProcess"); EditorGUILayout.Space(); 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("None"); propertyNames.Add("Clean-up intermediary nodes"); propertyNames.Add("Transfer all objects under root"); propertyNames.Add("Merge all objects"); propertyNames.Add("Merge objects by material"); List <int> intValue = new List <int>(3); intValue.Add(0); intValue.Add(1); intValue.Add(2); intValue.Add(3); intValue.Add(4); width = (float)Math.Truncate(Screen.width * 0.6); Rect rect = EditorGUILayout.GetControlRect(); rect.width = width; GUILayout.FlexibleSpace(); serializedProperty.FindPropertyRelative("treeProcess").intValue = EditorGUI.IntPopup(rect, serializedProperty.FindPropertyRelative("treeProcess").intValue, propertyNames.ToArray(), intValue.ToArray()); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); } endGroupBox(); GUILayout.Space(10); if (!serializedObject.FindProperty("settings.useLods").boolValue) { tt = "Choose the quality level (preset) for the imported model.\nQuality defines the density of the mesh that PiXYZ creates.\nDepending if you import a CAD model (exact geometry) or a mesh model (tessellated geometry), PiXYZ will either perform a Tessellation or a Decimation on the model (see documentation for more information and presets details)."; beginGroupBox("Mesh Quality", isInspector, tooltip: tt); { EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); { GUILayout.Space(20); tt = PiXYZUtils.getTooltipText <PiXYZLODSettings>("preset"); GUILayout.Label(new GUIContent("Quality", tt)); int width = (int)(Math.Truncate(Screen.width * 0.5)); EditorGUILayout.PropertyField(serializedObject.FindProperty("settings.lodSettings").GetArrayElementAtIndex(0).FindPropertyRelative("preset"), GUIContent.none, GUILayout.Width(width)); EditorGUILayout.BeginHorizontal(); { GUILayout.Space(5); GUILayout.Label("Use LODs"); EditorGUILayout.PropertyField(serializedObject.FindProperty("settings.useLods"), GUIContent.none, GUILayout.Width(40)); } EditorGUILayout.EndHorizontal(); GUILayout.FlexibleSpace(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); } endGroupBox(); } else { pixyzLods.printLoDSlider(serializedObject, prefix, winId, serializedProperty.FindPropertyRelative("treeProcess").intValue < 3, gameObject); } GUILayout.Space(10); beginGroupBox("Post Process", isInspector, tooltip: "Generate UV : Use this setting to add a new primary UV set (channel #0). Set the size of the projection box used to create UVs.\n\nCaution: PiXYZ will override the existing UV set, do not Use this setting if you wish to preserve the UVs embedded in the imported model.\n\nOrient… : Use this setting for PiXYZ to perform a unification of all triangles orientation.\n\nCaution: Do not Use this setting if the imported model is a mesh (tessellated geometry) and is already correctly oriented."); { EditorGUILayout.BeginHorizontal(); { tt = PiXYZUtils.getTooltipText <PiXYZSettings>("mapUV"); EditorGUILayout.PropertyField(serializedProperty.FindPropertyRelative("mapUV"), GUIContent.none, true, GUILayout.Width(40)); GUILayout.Label(new GUIContent("Generate UV (size)", tt)); //GUILayout.FlexibleSpace(); EditorGUILayout.PropertyField(serializedProperty.FindPropertyRelative("mapUV3dSize"), GUIContent.none, true, GUILayout.Width(100)); GUILayout.Label(new GUIContent("millimeters", tt)); serializedProperty.FindPropertyRelative("mapUV3dSize").floatValue = Mathf.Clamp(serializedProperty.FindPropertyRelative("mapUV3dSize").floatValue, 1.0f, 1000f); GUILayout.Space(10); } EditorGUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { tt = PiXYZUtils.getTooltipText <PiXYZSettings>("orient"); EditorGUILayout.PropertyField(serializedProperty.FindPropertyRelative("orient"), GUIContent.none, true, GUILayout.Width(40)); GUILayout.Label(new GUIContent("Orient normals of adjacent faces consistently", tt), GUILayout.ExpandWidth(true)); GUILayout.FlexibleSpace(); } GUILayout.EndHorizontal(); } endGroupBox(); GUILayout.Space(10); bool before = advancedToggle[winId]; advancedToggle[winId] = EditorGUILayout.Foldout(advancedToggle[winId], "Advanced", true); if (advancedToggle[winId]) { if (!before) { g_scrollViewPosition[winId] = new Vector2(0, Screen.height); } GUILayout.Space(10); EditorGUI.indentLevel++; string version = InternalEditorUtility.GetFullUnityVersion(); version = version.Substring(0, version.LastIndexOf('.')); if (float.Parse(version) >= 2017.3) //Cannot change before 2017.3 { EditorGUI.BeginDisabledGroup(isInspector); { EditorGUILayout.BeginHorizontal(); { GUILayout.Space(10); tt = PiXYZUtils.getTooltipText <PiXYZSettings>("useMergeFinalAssemblies"); serializedProperty.FindPropertyRelative("useMergeFinalAssemblies").boolValue = EditorGUILayout.Toggle(serializedProperty.FindPropertyRelative("useMergeFinalAssemblies").boolValue, GUILayout.Width(40)); GUILayout.Label(new GUIContent("Stitch unconnected surfaces", tt)); GUILayout.FlexibleSpace(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { GUILayout.Space(10); tt = PiXYZUtils.getTooltipText <PiXYZSettings>("splitTo16BytesIndex"); serializedProperty.FindPropertyRelative("splitTo16BytesIndex").boolValue = EditorGUILayout.Toggle(serializedProperty.FindPropertyRelative("splitTo16BytesIndex").boolValue, GUILayout.Width(40)); GUILayout.Label(new GUIContent("Split to limit vertex count per mesh", tt)); GUILayout.FlexibleSpace(); } EditorGUILayout.EndHorizontal(); } EditorGUI.EndDisabledGroup(); } EditorGUILayout.Space(); } EditorGUILayout.EndFadeGroup(); Rect boxRect = GUILayoutUtility.GetLastRect(); lastShown = (int)(boxRect.y + boxRect.height); } } EditorGUILayout.EndVertical(); } GUILayout.EndScrollView(); Rect scrollRect = GUILayoutUtility.GetLastRect(); int gradientHeight = 15; //up if (scrollViewPosition.y > 0f) { PiXYZUtils.gradientBox(new Rect(scrollRect.x, scrollRect.y, scrollRect.width, gradientHeight), new Vector2(0.5f, 1f)); } //down if (scrollViewPosition.y < (lastShown - scrollRect.height)) { PiXYZUtils.gradientBox(new Rect(scrollRect.x, scrollRect.y + scrollRect.height - gradientHeight, scrollRect.width, gradientHeight), new Vector2(0.5f, 0f)); } }