public void getEditorPref() { string version = InternalEditorUtility.GetFullUnityVersion(); version = version.Substring(0, version.LastIndexOf('.')); originalFilename = ""; orient = EditorPrefs.GetBool("PiXYZ.Orient", false); mapUV = EditorPrefs.GetBool("PiXYZ.MapUV", false); mapUV3dSize = EditorPrefs.GetFloat("PiXYZ.MapUV3dSize", 100.0f); scaleFactor = EditorPrefs.GetFloat("PiXYZ.ScaleFactor", 0.001f); isRightHanded = EditorPrefs.GetBool("PiXYZ.IsRightHanded", true); isZUp = EditorPrefs.GetBool("PiXYZ.IsZUp", true); treeProcess = (TreeProcessType)EditorPrefs.GetInt("PiXYZ.TreeProcess", 0); lodCurrentIndex = EditorPrefs.GetInt("PiXYZ.LODCurrentIndex", 0); lodSettingCount = EditorPrefs.GetInt("PiXYZ.LODSettingCount", 1); useLods = EditorPrefs.GetBool("PiXYZ.UseLods", false); lodsMode = (LODsMode)EditorPrefs.GetInt("PiXYZ.LODsMode", 2); lodSettings = new List <PiXYZLODSettings>(); for (int i = 0; i < lodSettingCount; ++i) { PiXYZLoDSettingsEditor lod = new PiXYZLoDSettingsEditor(); lod.index = i; lod.getEditorPref(); lodSettings.Add(lod); } splitTo16BytesIndex = EditorPrefs.GetBool("PiXYZ.SplitTo16BytesIndex", false); useMergeFinalAssemblies = EditorPrefs.GetBool("PiXYZ.UseMergeFinalAssemblies", false); }
static public void removeLod(int index, SerializedObject serializedObject, string prefix) { SerializedProperty serializedProperty = serializedObject.FindProperty(prefix); PiXYZLoDSettingsEditor.removeAt(index, serializedObject, prefix + "." + PiXYZLODSettings.serializePrefix); serializedProperty.FindPropertyRelative("lodSettingCount").intValue = serializedProperty.FindPropertyRelative("lodSettings").arraySize; serializedProperty.FindPropertyRelative("lodCurrentIndex").intValue = Math.Max(0, Math.Min(serializedProperty.FindPropertyRelative("lodCurrentIndex").intValue, serializedProperty.FindPropertyRelative("lodSettingCount").intValue - 1)); serializedObject.ApplyModifiedProperties(); PiXYZSettingsEditor.saveEditorPref(serializedObject, prefix); }
static public void addLod(int index, SerializedObject serializedObject, int insertModel, float insertStartLod, string prefix) { SerializedProperty serializedProperty = serializedObject.FindProperty(prefix); PiXYZLoDSettingsEditor.insertAt(index, serializedObject, insertModel); serializedProperty.FindPropertyRelative("lodCurrentIndex").intValue = index; serializedProperty.FindPropertyRelative("lodSettingCount").intValue = serializedProperty.FindPropertyRelative("lodSettings").arraySize; if (insertStartLod >= 0f) { serializedProperty.FindPropertyRelative("lodSettings").GetArrayElementAtIndex(insertModel).FindPropertyRelative("startLod").floatValue = insertStartLod; } serializedObject.ApplyModifiedProperties(); PiXYZSettingsEditor.saveEditorPref(serializedObject, prefix); }
public static void saveEditorPref(SerializedObject serializedObject, string prefix = PiXYZSettings.serializePrefix) { SerializedProperty serializedProperty = serializedObject.FindProperty(prefix); EditorPrefs.SetBool("PiXYZ.Orient", serializedProperty.FindPropertyRelative("orient").boolValue); EditorPrefs.SetBool("PiXYZ.MapUV", serializedProperty.FindPropertyRelative("mapUV").boolValue); EditorPrefs.SetFloat("PiXYZ.MapUV3dSize", serializedProperty.FindPropertyRelative("mapUV3dSize").floatValue); EditorPrefs.SetFloat("PiXYZ.ScaleFactor", serializedProperty.FindPropertyRelative("scaleFactor").floatValue); EditorPrefs.SetBool("PiXYZ.IsRightHanded", serializedProperty.FindPropertyRelative("isRightHanded").boolValue); EditorPrefs.SetBool("PiXYZ.IsZUp", serializedProperty.FindPropertyRelative("isZUp").boolValue); EditorPrefs.SetInt("PiXYZ.TreeProcess", serializedProperty.FindPropertyRelative("treeProcess").intValue); EditorPrefs.SetInt("PiXYZ.LODCurrentIndex", serializedProperty.FindPropertyRelative("lodCurrentIndex").intValue); EditorPrefs.SetBool("PiXYZ.UseLods", serializedProperty.FindPropertyRelative("useLods").boolValue); EditorPrefs.SetInt("PiXYZ.LODsMode", serializedProperty.FindPropertyRelative("lodsMode").intValue); EditorPrefs.SetInt("PiXYZ.LODSettingCount", serializedProperty.FindPropertyRelative("lodSettingCount").intValue); for (int i = 0; i < serializedProperty.FindPropertyRelative("lodSettingCount").intValue; ++i) { PiXYZLoDSettingsEditor.saveEditorPref(i, serializedObject, prefix + "." + PiXYZLODSettings.serializePrefix); } EditorPrefs.SetBool("PiXYZ.UseMergeFinalAssemblies", serializedProperty.FindPropertyRelative("useMergeFinalAssemblies").boolValue); EditorPrefs.SetBool("PiXYZ.SplitTo16BytesIndex", serializedProperty.FindPropertyRelative("splitTo16BytesIndex").boolValue); }
public void factoryReset() { EditorPrefs.DeleteKey("PiXYZ.Orient"); EditorPrefs.DeleteKey("PiXYZ.MapUV"); EditorPrefs.DeleteKey("PiXYZ.MapUV3dSize"); EditorPrefs.DeleteKey("PiXYZ.ScaleFactor"); EditorPrefs.DeleteKey("PiXYZ.IsRightHanded"); EditorPrefs.DeleteKey("PiXYZ.IsZUp"); EditorPrefs.DeleteKey("PiXYZ.TreeProcess"); EditorPrefs.DeleteKey("PiXYZ.LODCurrentIndex"); EditorPrefs.DeleteKey("PiXYZ.LODSettingCount"); EditorPrefs.DeleteKey("PiXYZ.UseLods"); EditorPrefs.DeleteKey("PiXYZ.LODsMode"); lodSettings = new List <PiXYZLODSettings>(); EditorPrefs.DeleteKey("PiXYZ.SplitTo16BytesIndex"); EditorPrefs.DeleteKey("PiXYZ.UseMergeFinalAssemblies"); EditorPrefs.DeleteKey("PiXYZ.ShowPopupLods"); EditorPrefs.DeleteKey("PiXYZ.AutoUpdate"); EditorPrefs.SetBool("PiXYZ.ShowPopupLods", true); EditorPrefs.SetBool("PiXYZ.AutoUpdate", true); EditorPrefs.SetBool("PiXYZ.DoNotShowAgainDocumentationPopup", false); PiXYZLoDSettingsEditor.factoryReset(); getEditorPref(); }
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; } }