public override void OnInspectorGUI() { // Check Warnings //Debug.Log("OnInspectorGUI Called."); Event currentEvent = Event.current; serializedObject.Update(); GUILayout.Label("<b>TextMesh Pro! Font Asset</b>", TMP_UIStyleManager.Section_Label); // TextMeshPro Font Info Panel GUILayout.Label("Face Info", TMP_UIStyleManager.Section_Label); EditorGUI.indentLevel = 1; GUI.enabled = false; // Lock UI float labelWidth = EditorGUIUtility.labelWidth = 150f; float fieldWidth = EditorGUIUtility.fieldWidth; EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("Name"), new GUIContent("Font Source")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("PointSize")); GUI.enabled = true; EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("Scale")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("LineHeight")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("Ascender")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("CapHeight")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("Baseline")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("Descender")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("Underline"), new GUIContent("Underline Offset")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("strikethrough"), new GUIContent("Strikethrough Offset")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("SuperscriptOffset")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("SubscriptOffset")); SerializedProperty subSize_prop = m_fontInfo_prop.FindPropertyRelative("SubSize"); EditorGUILayout.PropertyField(subSize_prop, new GUIContent("Super / Subscript Size")); subSize_prop.floatValue = Mathf.Clamp(subSize_prop.floatValue, 0.25f, 1f); GUI.enabled = false; //EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("Padding")); //GUILayout.Label("Atlas Size"); EditorGUI.indentLevel = 1; GUILayout.Space(18); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("Padding")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("AtlasWidth"), new GUIContent("Width")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("AtlasHeight"), new GUIContent("Height")); GUI.enabled = true; EditorGUI.indentLevel = 0; GUILayout.Space(20); GUILayout.Label("Font Sub-Assets", TMP_UIStyleManager.Section_Label); GUI.enabled = false; EditorGUI.indentLevel = 1; EditorGUILayout.PropertyField(font_atlas_prop, new GUIContent("Font Atlas:")); EditorGUILayout.PropertyField(font_material_prop, new GUIContent("Font Material:")); GUI.enabled = true; string evt_cmd = Event.current.commandName; // Get Current Event CommandName to check for Undo Events // FONT SETTINGS EditorGUI.indentLevel = 0; if (GUILayout.Button("Font Weights\t" + (UI_PanelState.fontWeightPanel ? uiStateLabel[1] : uiStateLabel[0]), TMP_UIStyleManager.Section_Label)) { UI_PanelState.fontWeightPanel = !UI_PanelState.fontWeightPanel; } if (UI_PanelState.fontWeightPanel) { EditorGUIUtility.labelWidth = 120; EditorGUILayout.BeginVertical(TMP_UIStyleManager.SquareAreaBox85G); EditorGUI.indentLevel = 0; GUILayout.Label("Select the Font Assets that will be used for the following font weights.", TMP_UIStyleManager.Label); GUILayout.Space(10f); EditorGUILayout.BeginHorizontal(); GUILayout.Label("<b>Font Weight</b>", TMP_UIStyleManager.Label, GUILayout.Width(117)); GUILayout.Label("<b>Normal Style</b>", TMP_UIStyleManager.Label); GUILayout.Label("<b>Italic Style</b>", TMP_UIStyleManager.Label); EditorGUILayout.EndHorizontal(); //EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(1), new GUIContent("100 - Thin")); //EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(2), new GUIContent("200 - Extra-Light")); //EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(3), new GUIContent("300 - Light")); EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(4), new GUIContent("400 - Regular")); //EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(5), new GUIContent("500 - Medium")); //EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(6), new GUIContent("600 - Demi-Bold")); EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(7), new GUIContent("700 - Bold")); //EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(8), new GUIContent("800 - Heavy")); //EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(9), new GUIContent("900 - Black")); EditorGUILayout.EndVertical(); //EditorGUI.indentLevel = 1; EditorGUIUtility.labelWidth = 120f; EditorGUILayout.BeginVertical(TMP_UIStyleManager.SquareAreaBox85G); GUILayout.Label("Settings used to simulate a typeface when no font asset is available.", TMP_UIStyleManager.Label); GUILayout.Space(5f); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(font_normalStyle_prop, new GUIContent("Normal Weight")); font_normalStyle_prop.floatValue = Mathf.Clamp(font_normalStyle_prop.floatValue, -3.0f, 3.0f); if (GUI.changed || evt_cmd == k_UndoRedo) { GUI.changed = false; // Modify the material property on matching material presets. for (int i = 0; i < m_materialPresets.Length; i++) { m_materialPresets[i].SetFloat("_WeightNormal", font_normalStyle_prop.floatValue); } } EditorGUILayout.PropertyField(font_boldStyle_prop, new GUIContent("Bold Weight"), GUILayout.MinWidth(100)); font_boldStyle_prop.floatValue = Mathf.Clamp(font_boldStyle_prop.floatValue, -3.0f, 3.0f); if (GUI.changed || evt_cmd == k_UndoRedo) { GUI.changed = false; // Modify the material property on matching material presets. for (int i = 0; i < m_materialPresets.Length; i++) { m_materialPresets[i].SetFloat("_WeightBold", font_boldStyle_prop.floatValue); } } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(font_normalSpacing_prop, new GUIContent("Spacing Offset")); font_normalSpacing_prop.floatValue = Mathf.Clamp(font_normalSpacing_prop.floatValue, -100, 100); if (GUI.changed || evt_cmd == k_UndoRedo) { GUI.changed = false; } EditorGUILayout.PropertyField(font_boldSpacing_prop, new GUIContent("Bold Spacing")); font_boldSpacing_prop.floatValue = Mathf.Clamp(font_boldSpacing_prop.floatValue, 0, 100); if (GUI.changed || evt_cmd == k_UndoRedo) { GUI.changed = false; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(font_italicStyle_prop, new GUIContent("Italic Style: ")); font_italicStyle_prop.intValue = Mathf.Clamp(font_italicStyle_prop.intValue, 15, 60); EditorGUILayout.PropertyField(font_tabSize_prop, new GUIContent("Tab Multiple: ")); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); } GUILayout.Space(5); // FALLBACK FONT ASSETS EditorGUI.indentLevel = 0; if (GUILayout.Button("Fallback Font Assets\t" + (UI_PanelState.fallbackFontAssetPanel ? uiStateLabel[1] : uiStateLabel[0]), TMP_UIStyleManager.Section_Label)) { UI_PanelState.fallbackFontAssetPanel = !UI_PanelState.fallbackFontAssetPanel; } if (UI_PanelState.fallbackFontAssetPanel) { EditorGUIUtility.labelWidth = 120; EditorGUILayout.BeginVertical(TMP_UIStyleManager.SquareAreaBox85G); EditorGUI.indentLevel = 0; GUILayout.Label("Select the Font Assets that will be searched and used as fallback when characters are missing from this font asset.", TMP_UIStyleManager.Label); GUILayout.Space(10f); m_list.DoLayoutList(); EditorGUILayout.EndVertical(); } // GLYPH INFO TABLE EditorGUIUtility.labelWidth = labelWidth; EditorGUIUtility.fieldWidth = fieldWidth; GUILayout.Space(5); EditorGUI.indentLevel = 0; if (GUILayout.Button("Glyph Info\t" + (UI_PanelState.glyphInfoPanel ? uiStateLabel[1] : uiStateLabel[0]), TMP_UIStyleManager.Section_Label)) { UI_PanelState.glyphInfoPanel = !UI_PanelState.glyphInfoPanel; } if (UI_PanelState.glyphInfoPanel) { int arraySize = m_glyphInfoList_prop.arraySize; int itemsPerPage = 15; // Display Glyph Management Tools EditorGUILayout.BeginVertical(TMP_UIStyleManager.Group_Label, GUILayout.ExpandWidth(true)); { // Search Bar implementation #region DISPLAY SEARCH BAR EditorGUILayout.BeginHorizontal(); { EditorGUIUtility.labelWidth = 110f; EditorGUI.BeginChangeCheck(); string searchPattern = EditorGUILayout.TextField("Glyph Search", m_searchPattern, "SearchTextField"); if (EditorGUI.EndChangeCheck() || m_isSearchDirty) { if (string.IsNullOrEmpty(searchPattern) == false) { //GUIUtility.keyboardControl = 0; m_searchPattern = searchPattern; //.ToLower(System.Globalization.CultureInfo.InvariantCulture).Trim(); // Search Glyph Table for potential matches SearchGlyphTable(m_searchPattern, ref m_searchList); } m_isSearchDirty = false; } string styleName = string.IsNullOrEmpty(m_searchPattern) ? "SearchCancelButtonEmpty" : "SearchCancelButton"; if (GUILayout.Button(GUIContent.none, styleName)) { GUIUtility.keyboardControl = 0; m_searchPattern = string.Empty; } } EditorGUILayout.EndHorizontal(); #endregion // Display Page Navigation if (!string.IsNullOrEmpty(m_searchPattern)) { arraySize = m_searchList.Count; } DisplayGlyphPageNavigation(arraySize, itemsPerPage); } EditorGUILayout.EndVertical(); // Display Glyph Table Elements #region Glyph Table if (arraySize > 0) { // Display each GlyphInfo entry using the GlyphInfo property drawer. for (int i = itemsPerPage * m_GlyphPage; i < arraySize && i < itemsPerPage * (m_GlyphPage + 1); i++) { // Define the start of the selection region of the element. Rect elementStartRegion = GUILayoutUtility.GetRect(0f, 0f, GUILayout.ExpandWidth(true)); int elementIndex = i; if (!string.IsNullOrEmpty(m_searchPattern)) { elementIndex = m_searchList[i]; } SerializedProperty glyphInfo = m_glyphInfoList_prop.GetArrayElementAtIndex(elementIndex); EditorGUI.BeginDisabledGroup(i != m_selectedElement); { EditorGUILayout.BeginVertical(TMP_UIStyleManager.Group_Label); EditorGUILayout.PropertyField(glyphInfo); EditorGUILayout.EndVertical(); } EditorGUI.EndDisabledGroup(); // Define the end of the selection region of the element. Rect elementEndRegion = GUILayoutUtility.GetRect(0f, 0f, GUILayout.ExpandWidth(true)); // Check for Item selection Rect selectionArea = new Rect(elementStartRegion.x, elementStartRegion.y, elementEndRegion.width, elementEndRegion.y - elementStartRegion.y); if (DoSelectionCheck(selectionArea)) { m_selectedElement = i; m_AddGlyphWarning.isEnabled = false; m_unicodeHexLabel = k_placeholderUnicodeHex; GUIUtility.keyboardControl = 0; } // Draw Selection Highlight and Glyph Options if (m_selectedElement == i) { TMP_EditorUtility.DrawBox(selectionArea, 2f, new Color32(40, 192, 255, 255)); // Draw Glyph management options Rect controlRect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight * 1f); float optionAreaWidth = controlRect.width * 0.6f; float btnWidth = optionAreaWidth / 3; Rect position = new Rect(controlRect.x + controlRect.width * .4f, controlRect.y, btnWidth, controlRect.height); // Copy Selected Glyph to Target Glyph ID GUI.enabled = !string.IsNullOrEmpty(m_dstGlyphID); if (GUI.Button(position, new GUIContent("Copy to"))) { GUIUtility.keyboardControl = 0; // Convert Hex Value to Decimal int dstGlyphID = TMP_TextUtilities.StringToInt(m_dstGlyphID); //Add new glyph at target Unicode hex id. if (!AddNewGlyph(elementIndex, dstGlyphID)) { m_AddGlyphWarning.isEnabled = true; m_AddGlyphWarning.expirationTime = EditorApplication.timeSinceStartup + 1; } m_dstGlyphID = string.Empty; m_isSearchDirty = true; TMPro_EventManager.ON_FONT_PROPERTY_CHANGED(true, m_fontAsset); } // Target Glyph ID GUI.enabled = true; position.x += btnWidth; GUI.SetNextControlName("GlyphID_Input"); m_dstGlyphID = EditorGUI.TextField(position, m_dstGlyphID); // Placeholder text EditorGUI.LabelField(position, new GUIContent(m_unicodeHexLabel, "The Unicode (Hex) ID of the duplicated Glyph"), TMP_UIStyleManager.Label); // Only filter the input when the destination glyph ID text field has focus. if (GUI.GetNameOfFocusedControl() == "GlyphID_Input") { m_unicodeHexLabel = string.Empty; //Filter out unwanted characters. char chr = Event.current.character; if ((chr < '0' || chr > '9') && (chr < 'a' || chr > 'f') && (chr < 'A' || chr > 'F')) { Event.current.character = '\0'; } } else { m_unicodeHexLabel = k_placeholderUnicodeHex; } // Remove Glyph position.x += btnWidth; if (GUI.Button(position, "Remove")) { GUIUtility.keyboardControl = 0; RemoveGlyphFromList(elementIndex); m_selectedElement = -1; m_isSearchDirty = true; TMPro_EventManager.ON_FONT_PROPERTY_CHANGED(true, m_fontAsset); return; } if (m_AddGlyphWarning.isEnabled && EditorApplication.timeSinceStartup < m_AddGlyphWarning.expirationTime) { EditorGUILayout.HelpBox("The Destination Glyph ID already exists", MessageType.Warning); } } } } DisplayGlyphPageNavigation(arraySize, itemsPerPage); } #endregion // KERNING TABLE PANEL #region Kerning Table GUILayout.Space(5); if (GUILayout.Button("Kerning Table Info\t" + (UI_PanelState.kerningInfoPanel ? uiStateLabel[1] : uiStateLabel[0]), TMP_UIStyleManager.Section_Label)) { UI_PanelState.kerningInfoPanel = !UI_PanelState.kerningInfoPanel; } if (UI_PanelState.kerningInfoPanel) { Rect pos; SerializedProperty kerningPairs_prop = m_kerningInfo_prop.FindPropertyRelative("kerningPairs"); EditorGUILayout.BeginHorizontal(); GUILayout.Label("Left Char", TMP_UIStyleManager.TMP_GUISkin.label); GUILayout.Label("Right Char", TMP_UIStyleManager.TMP_GUISkin.label); GUILayout.Label("Offset Value", TMP_UIStyleManager.TMP_GUISkin.label); GUILayout.Label(GUIContent.none, GUILayout.Width(20)); EditorGUILayout.EndHorizontal(); GUILayout.BeginVertical(TMP_UIStyleManager.TMP_GUISkin.label); int arraySize = kerningPairs_prop.arraySize; int itemsPerPage = 25; if (arraySize > 0) { // Display each GlyphInfo entry using the GlyphInfo property drawer. for (int i = itemsPerPage * m_KerningPage; i < arraySize && i < itemsPerPage * (m_KerningPage + 1); i++) { SerializedProperty kerningPair_prop = kerningPairs_prop.GetArrayElementAtIndex(i); pos = EditorGUILayout.BeginHorizontal(); EditorGUI.PropertyField(new Rect(pos.x, pos.y, pos.width - 20f, pos.height), kerningPair_prop, GUIContent.none); // Button to Delete Kerning Pair if (GUILayout.Button("-", GUILayout.ExpandWidth(false))) { m_kerningTable.RemoveKerningPair(i); m_fontAsset.ReadFontDefinition(); // Reload Font Definition. serializedObject.Update(); // Get an updated version of the SerializedObject. isAssetDirty = true; break; } EditorGUILayout.EndHorizontal(); } } Rect pagePos = EditorGUILayout.GetControlRect(false, 20); pagePos.width /= 3; int shiftMultiplier = currentEvent.shift ? 10 : 1; // Previous Page if (m_KerningPage > 0) { GUI.enabled = true; } else { GUI.enabled = false; } if (GUI.Button(pagePos, "Previous Page")) { m_KerningPage -= 1 * shiftMultiplier; } // Page Counter GUI.enabled = true; pagePos.x += pagePos.width; int totalPages = (int)(arraySize / (float)itemsPerPage + 0.999f); GUI.Label(pagePos, "Page " + (m_KerningPage + 1) + " / " + totalPages, GUI.skin.button); // Next Page pagePos.x += pagePos.width; if (itemsPerPage * (m_GlyphPage + 1) < arraySize) { GUI.enabled = true; } else { GUI.enabled = false; } if (GUI.Button(pagePos, "Next Page")) { m_KerningPage += 1 * shiftMultiplier; } m_KerningPage = Mathf.Clamp(m_KerningPage, 0, arraySize / itemsPerPage); GUILayout.EndVertical(); GUILayout.Space(10); // Add New Kerning Pair Section GUILayout.BeginVertical(TMP_UIStyleManager.SquareAreaBox85G); pos = EditorGUILayout.BeginHorizontal(); // Draw Empty Kerning Pair EditorGUI.PropertyField(new Rect(pos.x, pos.y, pos.width - 20f, pos.height), m_kerningPair_prop); GUILayout.Label(GUIContent.none, GUILayout.Height(19)); EditorGUILayout.EndHorizontal(); GUILayout.Space(5); if (GUILayout.Button("Add New Kerning Pair")) { int asci_left = m_kerningPair_prop.FindPropertyRelative("AscII_Left").intValue; int asci_right = m_kerningPair_prop.FindPropertyRelative("AscII_Right").intValue; float xOffset = m_kerningPair_prop.FindPropertyRelative("XadvanceOffset").floatValue; errorCode = m_kerningTable.AddKerningPair(asci_left, asci_right, xOffset); // Sort Kerning Pairs & Reload Font Asset if new kerning pair was added. if (errorCode != -1) { m_kerningTable.SortKerningPairs(); m_fontAsset.ReadFontDefinition(); // Reload Font Definition. serializedObject.Update(); // Get an updated version of the SerializedObject. isAssetDirty = true; } else { timeStamp = System.DateTime.Now.AddSeconds(5); } } if (errorCode == -1) { GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUILayout.Label("Kerning Pair already <color=#ffff00>exists!</color>", TMP_UIStyleManager.Label); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); if (System.DateTime.Now > timeStamp) { errorCode = 0; } } GUILayout.EndVertical(); } #endregion if (serializedObject.ApplyModifiedProperties() || evt_cmd == k_UndoRedo || isAssetDirty) { //Debug.Log("Serialized properties have changed."); TMPro_EventManager.ON_FONT_PROPERTY_CHANGED(true, m_fontAsset); isAssetDirty = false; EditorUtility.SetDirty(target); //TMPro_EditorUtility.RepaintAll(); // Consider SetDirty } // Clear selection if mouse event was not consumed. GUI.enabled = true; if (currentEvent.type == EventType.MouseDown && currentEvent.button == 0) { m_selectedElement = -1; } }
private void DoToolbarGUI() { ScriptableSingleton <GameViewSizes> .instance.RefreshStandaloneAndRemoteDefaultSizes(); if (ScriptableSingleton <GameViewSizes> .instance.GetChangeID() != this.m_SizeChangeID) { this.EnsureSelectedSizeAreValid(); this.m_SizeChangeID = ScriptableSingleton <GameViewSizes> .instance.GetChangeID(); } GUILayout.BeginHorizontal(EditorStyles.toolbar, new GUILayoutOption[0]); if (this.ShouldShowMultiDisplayOption()) { int num = EditorGUILayout.Popup(this.m_TargetDisplay, DisplayUtility.GetDisplayNames(), EditorStyles.toolbarPopup, new GUILayoutOption[] { GUILayout.Width(80f) }); EditorGUILayout.Space(); if (num != this.m_TargetDisplay) { this.m_TargetDisplay = num; this.UpdateZoomAreaAndParent(); } } EditorGUILayout.GameViewSizePopup(GameView.currentSizeGroupType, this.selectedSizeIndex, new Action <int, object>(this.SizeSelectionCallback), EditorStyles.toolbarDropDown, new GUILayoutOption[] { GUILayout.Width(160f) }); this.DoZoomSlider(); if (FrameDebuggerUtility.IsLocalEnabled()) { GUILayout.FlexibleSpace(); Color color = GUI.color; GUI.color *= AnimationMode.animatedPropertyColor; GUILayout.Label(GameView.Styles.frameDebuggerOnContent, EditorStyles.miniLabel, new GUILayoutOption[0]); GUI.color = color; if (Event.current.type == EventType.Repaint) { FrameDebuggerWindow.RepaintAll(); } } GUILayout.FlexibleSpace(); if (RenderDoc.IsLoaded()) { using (new EditorGUI.DisabledScope(!RenderDoc.IsSupported())) { if (GUILayout.Button(GameView.Styles.renderdocContent, EditorStyles.toolbarButton, new GUILayoutOption[0])) { this.m_Parent.CaptureRenderDoc(); GUIUtility.ExitGUI(); } } } this.m_MaximizeOnPlay = GUILayout.Toggle(this.m_MaximizeOnPlay, GameView.Styles.maximizeOnPlayContent, EditorStyles.toolbarButton, new GUILayoutOption[0]); EditorUtility.audioMasterMute = GUILayout.Toggle(EditorUtility.audioMasterMute, GameView.Styles.muteContent, EditorStyles.toolbarButton, new GUILayoutOption[0]); this.m_Stats = GUILayout.Toggle(this.m_Stats, GameView.Styles.statsContent, EditorStyles.toolbarButton, new GUILayoutOption[0]); Rect rect = GUILayoutUtility.GetRect(GameView.Styles.gizmosContent, GameView.Styles.gizmoButtonStyle); Rect position = new Rect(rect.xMax - (float)GameView.Styles.gizmoButtonStyle.border.right, rect.y, (float)GameView.Styles.gizmoButtonStyle.border.right, rect.height); if (EditorGUI.ButtonMouseDown(position, GUIContent.none, FocusType.Passive, GUIStyle.none)) { Rect last = GUILayoutUtility.topLevel.GetLast(); if (AnnotationWindow.ShowAtPosition(last, true)) { GUIUtility.ExitGUI(); } } this.m_Gizmos = GUI.Toggle(rect, this.m_Gizmos, GameView.Styles.gizmosContent, GameView.Styles.gizmoButtonStyle); GUILayout.EndHorizontal(); }
public static void DrawSprite(Sprite sprite, params GUILayoutOption[] options) { Rect controlRect = GUILayoutUtility.GetRect(GUIContent.none, new GUIStyle(), options); GUIEx.DrawSprite(sprite, controlRect); }
// Draw the graph at the current position public void DrawGraph() { using (new GUILayout.HorizontalScope()) { GUILayout.Space(EditorGUI.indentLevel * 15f): m_RectGraph = GUILayoutUtility.GetRect(128, 80): } // Background DrawRect(0, 0, m_RangeX, m_RangeY, 0.1f, 0.4f): // Soft-knee range DrawRect(m_GraphThreshold - m_GraphKnee, 0, m_GraphThreshold + m_GraphKnee, m_RangeY, 0.25f, -1): // Horizontal lines for (var i = 1: i < m_RangeY: i++) DrawLine(0, i, m_RangeX, i, 0.4f): // Vertical lines for (var i = 1: i < m_RangeX: i++) DrawLine(i, 0, i, m_RangeY, 0.4f): // Label Handles.Label( PointInRect(0, m_RangeY) + Vector3.right, "Brightness Response (linear)", EditorStyles.miniLabel ): // Threshold line DrawLine(m_GraphThreshold, 0, m_GraphThreshold, m_RangeY, 0.6f): // Response curve var vcount = 0: while (vcount < k_CurveResolution) { var x = m_RangeX * vcount / (k_CurveResolution - 1): var y = ResponseFunction(x): if (y < m_RangeY) { m_CurveVertices[vcount++] = PointInRect(x, y): } else { if (vcount > 1) { // Extend the last segment to the top edge of the rect. var v1 = m_CurveVertices[vcount - 2]: var v2 = m_CurveVertices[vcount - 1]: var clip = (m_RectGraph.y - v1.y) / (v2.y - v1.y): m_CurveVertices[vcount - 1] = v1 + (v2 - v1) * clip: } break: } } if (vcount > 1) { Handles.color = Color.white * 0.9f: Handles.DrawAAPolyLine(2.0f, vcount, m_CurveVertices): } }
public override void OnInspectorGUI() { // Check Warnings //Debug.Log("OnInspectorGUI Called."); Event currentEvent = Event.current; serializedObject.Update(); // TextMeshPro Font Info Panel Rect rect = EditorGUILayout.GetControlRect(); GUI.Label(rect, "Face Info", EditorStyles.boldLabel); rect.x += rect.width - 130f; rect.width = 130f; if (GUI.Button(rect, "Update Atlas Texture")) { TMPro_FontAssetCreatorWindow.ShowFontAtlasCreatorWindow(target as TMP_FontAsset); } EditorGUI.indentLevel = 1; GUI.enabled = false; // Lock UI float labelWidth = EditorGUIUtility.labelWidth; float fieldWidth = EditorGUIUtility.fieldWidth; EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("Name"), new GUIContent("Font Source")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("PointSize")); GUI.enabled = true; EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("Scale")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("LineHeight")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("Ascender")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("CapHeight")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("Baseline")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("Descender")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("Underline"), new GUIContent("Underline Offset")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("strikethrough"), new GUIContent("Strikethrough Offset")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("SuperscriptOffset")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("SubscriptOffset")); SerializedProperty subSize_prop = m_fontInfo_prop.FindPropertyRelative("SubSize"); EditorGUILayout.PropertyField(subSize_prop, new GUIContent("Super / Subscript Size")); subSize_prop.floatValue = Mathf.Clamp(subSize_prop.floatValue, 0.25f, 1f); GUI.enabled = false; //EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("Padding")); //GUILayout.label("Atlas Size"); EditorGUI.indentLevel = 1; EditorGUILayout.Space(); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("Padding")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("AtlasWidth"), new GUIContent("Width")); EditorGUILayout.PropertyField(m_fontInfo_prop.FindPropertyRelative("AtlasHeight"), new GUIContent("Height")); GUI.enabled = true; EditorGUILayout.Space(); EditorGUI.indentLevel = 0; UI_PanelState.fontSubAssetsPanel = EditorGUILayout.Foldout(UI_PanelState.fontSubAssetsPanel, new GUIContent("Font Sub-Assets"), true, TMP_UIStyleManager.boldFoldout); if (UI_PanelState.fontSubAssetsPanel) { GUI.enabled = false; EditorGUI.indentLevel = 1; EditorGUILayout.PropertyField(font_atlas_prop, new GUIContent("Font Atlas")); EditorGUILayout.PropertyField(font_material_prop, new GUIContent("Font Material")); GUI.enabled = true; EditorGUILayout.Space(); } string evt_cmd = Event.current.commandName; // Get Current Event CommandName to check for Undo Events // FONT SETTINGS EditorGUI.indentLevel = 0; UI_PanelState.fontWeightPanel = EditorGUILayout.Foldout(UI_PanelState.fontWeightPanel, new GUIContent("Font Weights", "The Font Assets that will be used for different font weights and the settings used to simulate a typeface when no asset is available."), true, TMP_UIStyleManager.boldFoldout); if (UI_PanelState.fontWeightPanel) { EditorGUIUtility.labelWidth *= 0.75f; EditorGUIUtility.fieldWidth *= 0.25f; EditorGUILayout.BeginVertical(); EditorGUI.indentLevel = 1; rect = EditorGUILayout.GetControlRect(true); rect.x += EditorGUIUtility.labelWidth; rect.width = (rect.width - EditorGUIUtility.labelWidth) / 2f; GUI.Label(rect, "Normal Style", EditorStyles.boldLabel); rect.x += rect.width; GUI.Label(rect, "Italic Style", EditorStyles.boldLabel); EditorGUI.indentLevel = 1; //EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(1), new GUIContent("100 - Thin")); //EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(2), new GUIContent("200 - Extra-Light")); //EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(3), new GUIContent("300 - Light")); EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(4), new GUIContent("400 - Regular")); //EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(5), new GUIContent("500 - Medium")); //EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(6), new GUIContent("600 - Demi-Bold")); EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(7), new GUIContent("700 - Bold")); //EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(8), new GUIContent("800 - Heavy")); //EditorGUILayout.PropertyField(fontWeights_prop.GetArrayElementAtIndex(9), new GUIContent("900 - Black")); EditorGUILayout.EndVertical(); EditorGUILayout.Space(); EditorGUILayout.BeginVertical(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(font_normalStyle_prop, new GUIContent("Normal Weight")); font_normalStyle_prop.floatValue = Mathf.Clamp(font_normalStyle_prop.floatValue, -3.0f, 3.0f); if (GUI.changed || evt_cmd == k_UndoRedo) { GUI.changed = false; // Modify the material property on matching material presets. for (int i = 0; i < m_materialPresets.Length; i++) { m_materialPresets[i].SetFloat("_WeightNormal", font_normalStyle_prop.floatValue); } } EditorGUILayout.PropertyField(font_boldStyle_prop, new GUIContent("Bold Weight")); font_boldStyle_prop.floatValue = Mathf.Clamp(font_boldStyle_prop.floatValue, -3.0f, 3.0f); if (GUI.changed || evt_cmd == k_UndoRedo) { GUI.changed = false; // Modify the material property on matching material presets. for (int i = 0; i < m_materialPresets.Length; i++) { m_materialPresets[i].SetFloat("_WeightBold", font_boldStyle_prop.floatValue); } } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(font_normalSpacing_prop, new GUIContent("Spacing Offset")); font_normalSpacing_prop.floatValue = Mathf.Clamp(font_normalSpacing_prop.floatValue, -100, 100); if (GUI.changed || evt_cmd == k_UndoRedo) { GUI.changed = false; } EditorGUILayout.PropertyField(font_boldSpacing_prop, new GUIContent("Bold Spacing")); font_boldSpacing_prop.floatValue = Mathf.Clamp(font_boldSpacing_prop.floatValue, 0, 100); if (GUI.changed || evt_cmd == k_UndoRedo) { GUI.changed = false; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(font_italicStyle_prop, new GUIContent("Italic Style")); font_italicStyle_prop.intValue = Mathf.Clamp(font_italicStyle_prop.intValue, 15, 60); EditorGUILayout.PropertyField(font_tabSize_prop, new GUIContent("Tab Multiple")); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); EditorGUILayout.Space(); } EditorGUIUtility.labelWidth = 0; EditorGUIUtility.fieldWidth = 0; // FALLBACK FONT ASSETS EditorGUI.indentLevel = 0; UI_PanelState.fallbackFontAssetPanel = EditorGUILayout.Foldout(UI_PanelState.fallbackFontAssetPanel, new GUIContent("Fallback Font Assets", "Select the Font Assets that will be searched and used as fallback when characters are missing from this font asset."), true, TMP_UIStyleManager.boldFoldout); if (UI_PanelState.fallbackFontAssetPanel) { EditorGUIUtility.labelWidth = 120; EditorGUI.indentLevel = 0; m_list.DoLayoutList(); EditorGUILayout.Space(); } // GLYPH INFO TABLE #region Glyph Table EditorGUIUtility.labelWidth = labelWidth; EditorGUIUtility.fieldWidth = fieldWidth; EditorGUI.indentLevel = 0; UI_PanelState.glyphInfoPanel = EditorGUILayout.Foldout(UI_PanelState.glyphInfoPanel, new GUIContent("Glyph Table"), true, TMP_UIStyleManager.boldFoldout); if (UI_PanelState.glyphInfoPanel) { int arraySize = m_glyphInfoList_prop.arraySize; int itemsPerPage = 15; // Display Glyph Management Tools EditorGUILayout.BeginVertical(EditorStyles.helpBox); { // Search Bar implementation #region DISPLAY SEARCH BAR EditorGUILayout.BeginHorizontal(); { EditorGUIUtility.labelWidth = 130f; EditorGUI.BeginChangeCheck(); string searchPattern = EditorGUILayout.TextField("Glyph Search", m_GlyphSearchPattern, "SearchTextField"); if (EditorGUI.EndChangeCheck() || m_isSearchDirty) { if (string.IsNullOrEmpty(searchPattern) == false) { m_GlyphSearchPattern = searchPattern; // Search Glyph Table for potential matches SearchGlyphTable(m_GlyphSearchPattern, ref m_GlyphSearchList); } else { m_GlyphSearchPattern = null; } m_isSearchDirty = false; } string styleName = string.IsNullOrEmpty(m_GlyphSearchPattern) ? "SearchCancelButtonEmpty" : "SearchCancelButton"; if (GUILayout.Button(GUIContent.none, styleName)) { GUIUtility.keyboardControl = 0; m_GlyphSearchPattern = string.Empty; } } EditorGUILayout.EndHorizontal(); #endregion // Display Page Navigation if (!string.IsNullOrEmpty(m_GlyphSearchPattern)) { arraySize = m_GlyphSearchList.Count; } DisplayPageNavigation(ref m_CurrentGlyphPage, arraySize, itemsPerPage); } EditorGUILayout.EndVertical(); // Display Glyph Table Elements if (arraySize > 0) { // Display each GlyphInfo entry using the GlyphInfo property drawer. for (int i = itemsPerPage * m_CurrentGlyphPage; i < arraySize && i < itemsPerPage * (m_CurrentGlyphPage + 1); i++) { // Define the start of the selection region of the element. Rect elementStartRegion = GUILayoutUtility.GetRect(0f, 0f, GUILayout.ExpandWidth(true)); int elementIndex = i; if (!string.IsNullOrEmpty(m_GlyphSearchPattern)) { elementIndex = m_GlyphSearchList[i]; } SerializedProperty glyphInfo = m_glyphInfoList_prop.GetArrayElementAtIndex(elementIndex); EditorGUILayout.BeginVertical(EditorStyles.helpBox); EditorGUI.BeginDisabledGroup(i != m_SelectedGlyphRecord); { EditorGUILayout.PropertyField(glyphInfo); } EditorGUI.EndDisabledGroup(); EditorGUILayout.EndVertical(); // Define the end of the selection region of the element. Rect elementEndRegion = GUILayoutUtility.GetRect(0f, 0f, GUILayout.ExpandWidth(true)); // Check for Item selection Rect selectionArea = new Rect(elementStartRegion.x, elementStartRegion.y, elementEndRegion.width, elementEndRegion.y - elementStartRegion.y); if (DoSelectionCheck(selectionArea)) { if (m_SelectedGlyphRecord == i) { m_SelectedGlyphRecord = -1; } else { m_SelectedGlyphRecord = i; m_AddGlyphWarning.isEnabled = false; m_unicodeHexLabel = k_placeholderUnicodeHex; GUIUtility.keyboardControl = 0; } } // Draw Selection Highlight and Glyph Options if (m_SelectedGlyphRecord == i) { TMP_EditorUtility.DrawBox(selectionArea, 2f, new Color32(40, 192, 255, 255)); // Draw Glyph management options Rect controlRect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight * 1f); float optionAreaWidth = controlRect.width * 0.6f; float btnWidth = optionAreaWidth / 3; Rect position = new Rect(controlRect.x + controlRect.width * .4f, controlRect.y, btnWidth, controlRect.height); // Copy Selected Glyph to Target Glyph ID GUI.enabled = !string.IsNullOrEmpty(m_dstGlyphID); if (GUI.Button(position, new GUIContent("Copy to"))) { GUIUtility.keyboardControl = 0; // Convert Hex Value to Decimal int dstGlyphID = TMP_TextUtilities.StringToInt(m_dstGlyphID); //Add new glyph at target Unicode hex id. if (!AddNewGlyph(elementIndex, dstGlyphID)) { m_AddGlyphWarning.isEnabled = true; m_AddGlyphWarning.expirationTime = EditorApplication.timeSinceStartup + 1; } m_dstGlyphID = string.Empty; m_isSearchDirty = true; TMPro_EventManager.ON_FONT_PROPERTY_CHANGED(true, m_fontAsset); } // Target Glyph ID GUI.enabled = true; position.x += btnWidth; GUI.SetNextControlName("GlyphID_Input"); m_dstGlyphID = EditorGUI.TextField(position, m_dstGlyphID); // Placeholder text EditorGUI.LabelField(position, new GUIContent(m_unicodeHexLabel, "The Unicode (Hex) ID of the duplicated Glyph"), TMP_UIStyleManager.label); // Only filter the input when the destination glyph ID text field has focus. if (GUI.GetNameOfFocusedControl() == "GlyphID_Input") { m_unicodeHexLabel = string.Empty; //Filter out unwanted characters. char chr = Event.current.character; if ((chr < '0' || chr > '9') && (chr < 'a' || chr > 'f') && (chr < 'A' || chr > 'F')) { Event.current.character = '\0'; } } else { m_unicodeHexLabel = k_placeholderUnicodeHex; } // Remove Glyph position.x += btnWidth; if (GUI.Button(position, "Remove")) { GUIUtility.keyboardControl = 0; RemoveGlyphFromList(elementIndex); isAssetDirty = true; m_SelectedGlyphRecord = -1; m_isSearchDirty = true; break; } if (m_AddGlyphWarning.isEnabled && EditorApplication.timeSinceStartup < m_AddGlyphWarning.expirationTime) { EditorGUILayout.HelpBox("The Destination Glyph ID already exists", MessageType.Warning); } } } } DisplayPageNavigation(ref m_CurrentGlyphPage, arraySize, itemsPerPage); EditorGUILayout.Space(); } #endregion // KERNING TABLE PANEL #region Kerning Table EditorGUIUtility.labelWidth = labelWidth; EditorGUIUtility.fieldWidth = fieldWidth; EditorGUI.indentLevel = 0; UI_PanelState.kerningInfoPanel = EditorGUILayout.Foldout(UI_PanelState.kerningInfoPanel, new GUIContent("Glyph Adjustment Table"), true, TMP_UIStyleManager.boldFoldout); if (UI_PanelState.kerningInfoPanel) { int arraySize = m_kerningPairs_prop.arraySize; int itemsPerPage = 20; // Display Kerning Pair Management Tools EditorGUILayout.BeginVertical(EditorStyles.helpBox); { // Search Bar implementation #region DISPLAY SEARCH BAR EditorGUILayout.BeginHorizontal(); { EditorGUIUtility.labelWidth = 150f; EditorGUI.BeginChangeCheck(); string searchPattern = EditorGUILayout.TextField("Adjustment Pair Search", m_KerningTableSearchPattern, "SearchTextField"); if (EditorGUI.EndChangeCheck() || m_isSearchDirty) { if (string.IsNullOrEmpty(searchPattern) == false) { m_KerningTableSearchPattern = searchPattern; // Search Glyph Table for potential matches SearchKerningTable(m_KerningTableSearchPattern, ref m_KerningTableSearchList); } else { m_KerningTableSearchPattern = null; } m_isSearchDirty = false; } string styleName = string.IsNullOrEmpty(m_KerningTableSearchPattern) ? "SearchCancelButtonEmpty" : "SearchCancelButton"; if (GUILayout.Button(GUIContent.none, styleName)) { GUIUtility.keyboardControl = 0; m_KerningTableSearchPattern = string.Empty; } } EditorGUILayout.EndHorizontal(); #endregion // Display Page Navigation if (!string.IsNullOrEmpty(m_KerningTableSearchPattern)) { arraySize = m_KerningTableSearchList.Count; } DisplayPageNavigation(ref m_CurrentKerningPage, arraySize, itemsPerPage); } EditorGUILayout.EndVertical(); //Rect pos; //pos = EditorGUILayout.GetControlRect(false, 20); //pos.x += 5; //EditorGUI.LabelField(pos, "First Glyph", TMP_UIStyleManager.TMP_GUISkin.label); //pos.x += 100; //EditorGUI.LabelField(pos, "Adjustment Values", TMP_UIStyleManager.TMP_GUISkin.label); //pos.x = pos.width / 2 + 5; //EditorGUI.LabelField(pos, "Second Glyph", TMP_UIStyleManager.TMP_GUISkin.label); //pos.x += 100; //EditorGUI.LabelField(pos, "Adjustment Values", TMP_UIStyleManager.TMP_GUISkin.label); if (arraySize > 0) { // Display each GlyphInfo entry using the GlyphInfo property drawer. for (int i = itemsPerPage * m_CurrentKerningPage; i < arraySize && i < itemsPerPage * (m_CurrentKerningPage + 1); i++) { // Define the start of the selection region of the element. Rect elementStartRegion = GUILayoutUtility.GetRect(0f, 0f, GUILayout.ExpandWidth(true)); int elementIndex = i; if (!string.IsNullOrEmpty(m_KerningTableSearchPattern)) { elementIndex = m_KerningTableSearchList[i]; } SerializedProperty kerningInfo = m_kerningPairs_prop.GetArrayElementAtIndex(elementIndex); EditorGUILayout.BeginVertical(EditorStyles.helpBox); EditorGUI.BeginDisabledGroup(i != m_SelectedAdjustmentRecord); { EditorGUILayout.PropertyField(kerningInfo, new GUIContent("Selectable")); } EditorGUI.EndDisabledGroup(); EditorGUILayout.EndVertical(); // Define the end of the selection region of the element. Rect elementEndRegion = GUILayoutUtility.GetRect(0f, 0f, GUILayout.ExpandWidth(true)); // Check for Item selection Rect selectionArea = new Rect(elementStartRegion.x, elementStartRegion.y, elementEndRegion.width, elementEndRegion.y - elementStartRegion.y); if (DoSelectionCheck(selectionArea)) { if (m_SelectedAdjustmentRecord == i) { m_SelectedAdjustmentRecord = -1; } else { m_SelectedAdjustmentRecord = i; GUIUtility.keyboardControl = 0; } } // Draw Selection Highlight and Kerning Pair Options if (m_SelectedAdjustmentRecord == i) { TMP_EditorUtility.DrawBox(selectionArea, 2f, new Color32(40, 192, 255, 255)); // Draw Glyph management options Rect controlRect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight * 1f); float optionAreaWidth = controlRect.width; float btnWidth = optionAreaWidth / 4; Rect position = new Rect(controlRect.x + controlRect.width - btnWidth, controlRect.y, btnWidth, controlRect.height); // Remove Kerning pair GUI.enabled = true; if (GUI.Button(position, "Remove")) { GUIUtility.keyboardControl = 0; m_kerningTable.RemoveKerningPair(i); m_fontAsset.ReadFontDefinition(); isAssetDirty = true; m_SelectedAdjustmentRecord = -1; m_isSearchDirty = true; break; } } } } DisplayPageNavigation(ref m_CurrentKerningPage, arraySize, itemsPerPage); GUILayout.Space(5); // Add new kerning pair EditorGUILayout.BeginVertical(EditorStyles.helpBox); { EditorGUILayout.PropertyField(m_kerningPair_prop); } EditorGUILayout.EndVertical(); if (GUILayout.Button("Add New Kerning Pair")) { int firstGlyph = m_kerningPair_prop.FindPropertyRelative("m_FirstGlyph").intValue; int secondGlyph = m_kerningPair_prop.FindPropertyRelative("m_SecondGlyph").intValue; GlyphValueRecord firstGlyphAdjustments = GetGlyphAdjustments(m_kerningPair_prop.FindPropertyRelative("m_FirstGlyphAdjustments")); GlyphValueRecord secondGlyphAdjustments = GetGlyphAdjustments(m_kerningPair_prop.FindPropertyRelative("m_SecondGlyphAdjustments")); errorCode = m_kerningTable.AddGlyphPairAdjustmentRecord((uint)firstGlyph, firstGlyphAdjustments, (uint)secondGlyph, secondGlyphAdjustments); // Sort Kerning Pairs & Reload Font Asset if new kerning pair was added. if (errorCode != -1) { m_kerningTable.SortKerningPairs(); m_fontAsset.ReadFontDefinition(); serializedObject.ApplyModifiedProperties(); isAssetDirty = true; m_isSearchDirty = true; } else { timeStamp = System.DateTime.Now.AddSeconds(5); } // Clear Add Kerning Pair Panel // TODO } if (errorCode == -1) { GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUILayout.Label("Kerning Pair already <color=#ffff00>exists!</color>", TMP_UIStyleManager.label); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); if (System.DateTime.Now > timeStamp) { errorCode = 0; } } } #endregion if (serializedObject.ApplyModifiedProperties() || evt_cmd == k_UndoRedo || isAssetDirty) { TMPro_EventManager.ON_FONT_PROPERTY_CHANGED(true, m_fontAsset); isAssetDirty = false; EditorUtility.SetDirty(target); } // Clear selection if mouse event was not consumed. GUI.enabled = true; if (currentEvent.type == EventType.MouseDown && currentEvent.button == 0) { m_SelectedAdjustmentRecord = -1; } }
public void OnGUI() { var resourcePath = GetResourcePath(); var logo = AssetDatabase.LoadAssetAtPath <Texture2D>(resourcePath + "logo.png"); var rect = GUILayoutUtility.GetRect(position.width, 150, GUI.skin.box); if (logo) { GUI.DrawTexture(rect, logo, ScaleMode.ScaleToFit); } EditorGUILayout.HelpBox("Recommended project settings for SteamVR:", MessageType.Warning); scrollPosition = GUILayout.BeginScrollView(scrollPosition); int numItems = 0; if (!EditorPrefs.HasKey(ignore + buildTarget) && EditorUserBuildSettings.activeBuildTarget != recommended_BuildTarget) { ++numItems; GUILayout.Label(buildTarget + string.Format(currentValue, EditorUserBuildSettings.activeBuildTarget)); GUILayout.BeginHorizontal(); if (GUILayout.Button(string.Format(useRecommended, recommended_BuildTarget))) { #if (UNITY_5_5 || UNITY_5_4 || UNITY_5_3 || UNITY_5_2 || UNITY_5_1 || UNITY_5_0) EditorUserBuildSettings.SwitchActiveBuildTarget(recommended_BuildTarget); #else EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Standalone, recommended_BuildTarget); #endif } GUILayout.FlexibleSpace(); if (GUILayout.Button("Ignore")) { EditorPrefs.SetBool(ignore + buildTarget, true); } GUILayout.EndHorizontal(); } #if (UNITY_5_4 || UNITY_5_3 || UNITY_5_2 || UNITY_5_1 || UNITY_5_0) if (!EditorPrefs.HasKey(ignore + showUnitySplashScreen) && PlayerSettings.showUnitySplashScreen != recommended_ShowUnitySplashScreen) { ++numItems; GUILayout.Label(showUnitySplashScreen + string.Format(currentValue, PlayerSettings.showUnitySplashScreen)); GUILayout.BeginHorizontal(); if (GUILayout.Button(string.Format(useRecommended, recommended_ShowUnitySplashScreen))) { PlayerSettings.showUnitySplashScreen = recommended_ShowUnitySplashScreen; } GUILayout.FlexibleSpace(); if (GUILayout.Button("Ignore")) { EditorPrefs.SetBool(ignore + showUnitySplashScreen, true); } GUILayout.EndHorizontal(); } #else if (!EditorPrefs.HasKey(ignore + showUnitySplashScreen) && PlayerSettings.SplashScreen.show != recommended_ShowUnitySplashScreen) { ++numItems; GUILayout.Label(showUnitySplashScreen + string.Format(currentValue, PlayerSettings.SplashScreen.show)); GUILayout.BeginHorizontal(); if (GUILayout.Button(string.Format(useRecommended, recommended_ShowUnitySplashScreen))) { PlayerSettings.SplashScreen.show = recommended_ShowUnitySplashScreen; } GUILayout.FlexibleSpace(); if (GUILayout.Button("Ignore")) { EditorPrefs.SetBool(ignore + showUnitySplashScreen, true); } GUILayout.EndHorizontal(); } #endif if (!EditorPrefs.HasKey(ignore + defaultIsFullScreen) && #pragma warning disable CS0618 // Typ oder Element ist veraltet PlayerSettings.defaultIsFullScreen != recommended_DefaultIsFullScreen) #pragma warning restore CS0618 // Typ oder Element ist veraltet { ++numItems; #pragma warning disable CS0618 // Typ oder Element ist veraltet GUILayout.Label(defaultIsFullScreen + string.Format(currentValue, PlayerSettings.defaultIsFullScreen)); #pragma warning restore CS0618 // Typ oder Element ist veraltet GUILayout.BeginHorizontal(); if (GUILayout.Button(string.Format(useRecommended, recommended_DefaultIsFullScreen))) { #pragma warning disable CS0618 // Typ oder Element ist veraltet PlayerSettings.defaultIsFullScreen = recommended_DefaultIsFullScreen; #pragma warning restore CS0618 // Typ oder Element ist veraltet } GUILayout.FlexibleSpace(); if (GUILayout.Button("Ignore")) { EditorPrefs.SetBool(ignore + defaultIsFullScreen, true); } GUILayout.EndHorizontal(); } if (!EditorPrefs.HasKey(ignore + defaultScreenSize) && (PlayerSettings.defaultScreenWidth != recommended_DefaultScreenWidth || PlayerSettings.defaultScreenHeight != recommended_DefaultScreenHeight)) { ++numItems; GUILayout.Label(defaultScreenSize + string.Format(" ({0}x{1})", PlayerSettings.defaultScreenWidth, PlayerSettings.defaultScreenHeight)); GUILayout.BeginHorizontal(); if (GUILayout.Button(string.Format("Use recommended ({0}x{1})", recommended_DefaultScreenWidth, recommended_DefaultScreenHeight))) { PlayerSettings.defaultScreenWidth = recommended_DefaultScreenWidth; PlayerSettings.defaultScreenHeight = recommended_DefaultScreenHeight; } GUILayout.FlexibleSpace(); if (GUILayout.Button("Ignore")) { EditorPrefs.SetBool(ignore + defaultScreenSize, true); } GUILayout.EndHorizontal(); } if (!EditorPrefs.HasKey(ignore + runInBackground) && PlayerSettings.runInBackground != recommended_RunInBackground) { ++numItems; GUILayout.Label(runInBackground + string.Format(currentValue, PlayerSettings.runInBackground)); GUILayout.BeginHorizontal(); if (GUILayout.Button(string.Format(useRecommended, recommended_RunInBackground))) { PlayerSettings.runInBackground = recommended_RunInBackground; } GUILayout.FlexibleSpace(); if (GUILayout.Button("Ignore")) { EditorPrefs.SetBool(ignore + runInBackground, true); } GUILayout.EndHorizontal(); } if (!EditorPrefs.HasKey(ignore + displayResolutionDialog) && PlayerSettings.displayResolutionDialog != recommended_DisplayResolutionDialog) { ++numItems; GUILayout.Label(displayResolutionDialog + string.Format(currentValue, PlayerSettings.displayResolutionDialog)); GUILayout.BeginHorizontal(); if (GUILayout.Button(string.Format(useRecommended, recommended_DisplayResolutionDialog))) { PlayerSettings.displayResolutionDialog = recommended_DisplayResolutionDialog; } GUILayout.FlexibleSpace(); if (GUILayout.Button("Ignore")) { EditorPrefs.SetBool(ignore + displayResolutionDialog, true); } GUILayout.EndHorizontal(); } if (!EditorPrefs.HasKey(ignore + resizableWindow) && PlayerSettings.resizableWindow != recommended_ResizableWindow) { ++numItems; GUILayout.Label(resizableWindow + string.Format(currentValue, PlayerSettings.resizableWindow)); GUILayout.BeginHorizontal(); if (GUILayout.Button(string.Format(useRecommended, recommended_ResizableWindow))) { PlayerSettings.resizableWindow = recommended_ResizableWindow; } GUILayout.FlexibleSpace(); if (GUILayout.Button("Ignore")) { EditorPrefs.SetBool(ignore + resizableWindow, true); } GUILayout.EndHorizontal(); } if (!EditorPrefs.HasKey(ignore + fullscreenMode) && #pragma warning disable CS0618 // Typ oder Element ist veraltet PlayerSettings.d3d11FullscreenMode != recommended_FullscreenMode) #pragma warning restore CS0618 // Typ oder Element ist veraltet { ++numItems; #pragma warning disable CS0618 // Typ oder Element ist veraltet GUILayout.Label(fullscreenMode + string.Format(currentValue, PlayerSettings.d3d11FullscreenMode)); #pragma warning restore CS0618 // Typ oder Element ist veraltet GUILayout.BeginHorizontal(); if (GUILayout.Button(string.Format(useRecommended, recommended_FullscreenMode))) { #pragma warning disable CS0618 // Typ oder Element ist veraltet PlayerSettings.d3d11FullscreenMode = recommended_FullscreenMode; #pragma warning restore CS0618 // Typ oder Element ist veraltet } GUILayout.FlexibleSpace(); if (GUILayout.Button("Ignore")) { EditorPrefs.SetBool(ignore + fullscreenMode, true); } GUILayout.EndHorizontal(); } if (!EditorPrefs.HasKey(ignore + visibleInBackground) && PlayerSettings.visibleInBackground != recommended_VisibleInBackground) { ++numItems; GUILayout.Label(visibleInBackground + string.Format(currentValue, PlayerSettings.visibleInBackground)); GUILayout.BeginHorizontal(); if (GUILayout.Button(string.Format(useRecommended, recommended_VisibleInBackground))) { PlayerSettings.visibleInBackground = recommended_VisibleInBackground; } GUILayout.FlexibleSpace(); if (GUILayout.Button("Ignore")) { EditorPrefs.SetBool(ignore + visibleInBackground, true); } GUILayout.EndHorizontal(); } #if (UNITY_5_4 || UNITY_5_3 || UNITY_5_2 || UNITY_5_1 || UNITY_5_0) if (!EditorPrefs.HasKey(ignore + renderingPath) && PlayerSettings.renderingPath != recommended_RenderPath) { ++numItems; GUILayout.Label(renderingPath + string.Format(currentValue, PlayerSettings.renderingPath)); GUILayout.BeginHorizontal(); if (GUILayout.Button(string.Format(useRecommended, recommended_RenderPath) + " - required for MSAA")) { PlayerSettings.renderingPath = recommended_RenderPath; } GUILayout.FlexibleSpace(); if (GUILayout.Button("Ignore")) { EditorPrefs.SetBool(ignore + renderingPath, true); } GUILayout.EndHorizontal(); } #endif if (!EditorPrefs.HasKey(ignore + colorSpace) && PlayerSettings.colorSpace != recommended_ColorSpace) { ++numItems; GUILayout.Label(colorSpace + string.Format(currentValue, PlayerSettings.colorSpace)); GUILayout.BeginHorizontal(); if (GUILayout.Button(string.Format(useRecommended, recommended_ColorSpace) + " - requires reloading scene")) { PlayerSettings.colorSpace = recommended_ColorSpace; } GUILayout.FlexibleSpace(); if (GUILayout.Button("Ignore")) { EditorPrefs.SetBool(ignore + colorSpace, true); } GUILayout.EndHorizontal(); } if (!EditorPrefs.HasKey(ignore + gpuSkinning) && PlayerSettings.gpuSkinning != recommended_GpuSkinning) { ++numItems; GUILayout.Label(gpuSkinning + string.Format(currentValue, PlayerSettings.gpuSkinning)); GUILayout.BeginHorizontal(); if (GUILayout.Button(string.Format(useRecommended, recommended_GpuSkinning))) { PlayerSettings.gpuSkinning = recommended_GpuSkinning; } GUILayout.FlexibleSpace(); if (GUILayout.Button("Ignore")) { EditorPrefs.SetBool(ignore + gpuSkinning, true); } GUILayout.EndHorizontal(); } #if false if (!EditorPrefs.HasKey(ignore + singlePassStereoRendering) && PlayerSettings.singlePassStereoRendering != recommended_SinglePassStereoRendering) { ++numItems; GUILayout.Label(singlePassStereoRendering + string.Format(currentValue, PlayerSettings.singlePassStereoRendering)); GUILayout.BeginHorizontal(); if (GUILayout.Button(string.Format(useRecommended, recommended_SinglePassStereoRendering))) { PlayerSettings.singlePassStereoRendering = recommended_SinglePassStereoRendering; } GUILayout.FlexibleSpace(); if (GUILayout.Button("Ignore")) { EditorPrefs.SetBool(ignore + singlePassStereoRendering, true); } GUILayout.EndHorizontal(); } #endif GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Clear All Ignores")) { EditorPrefs.DeleteKey(ignore + buildTarget); EditorPrefs.DeleteKey(ignore + showUnitySplashScreen); EditorPrefs.DeleteKey(ignore + defaultIsFullScreen); EditorPrefs.DeleteKey(ignore + defaultScreenSize); EditorPrefs.DeleteKey(ignore + runInBackground); EditorPrefs.DeleteKey(ignore + displayResolutionDialog); EditorPrefs.DeleteKey(ignore + resizableWindow); EditorPrefs.DeleteKey(ignore + fullscreenMode); EditorPrefs.DeleteKey(ignore + visibleInBackground); #if (UNITY_5_4 || UNITY_5_3 || UNITY_5_2 || UNITY_5_1 || UNITY_5_0) EditorPrefs.DeleteKey(ignore + renderingPath); #endif EditorPrefs.DeleteKey(ignore + colorSpace); EditorPrefs.DeleteKey(ignore + gpuSkinning); #if false EditorPrefs.DeleteKey(ignore + singlePassStereoRendering); #endif } GUILayout.EndHorizontal(); GUILayout.EndScrollView(); GUILayout.FlexibleSpace(); GUILayout.BeginHorizontal(); if (numItems > 0) { if (GUILayout.Button("Accept All")) { // Only set those that have not been explicitly ignored. if (!EditorPrefs.HasKey(ignore + buildTarget)) #if (UNITY_5_5 || UNITY_5_4 || UNITY_5_3 || UNITY_5_2 || UNITY_5_1 || UNITY_5_0) { EditorUserBuildSettings.SwitchActiveBuildTarget(recommended_BuildTarget); } #else { EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Standalone, recommended_BuildTarget); } #endif if (!EditorPrefs.HasKey(ignore + showUnitySplashScreen)) #if (UNITY_5_4 || UNITY_5_3 || UNITY_5_2 || UNITY_5_1 || UNITY_5_0) { PlayerSettings.showUnitySplashScreen = recommended_ShowUnitySplashScreen; } #else { PlayerSettings.SplashScreen.show = recommended_ShowUnitySplashScreen; } #endif if (!EditorPrefs.HasKey(ignore + defaultIsFullScreen)) #pragma warning disable CS0618 // Typ oder Element ist veraltet { PlayerSettings.defaultIsFullScreen = recommended_DefaultIsFullScreen; } #pragma warning restore CS0618 // Typ oder Element ist veraltet if (!EditorPrefs.HasKey(ignore + defaultScreenSize)) { PlayerSettings.defaultScreenWidth = recommended_DefaultScreenWidth; PlayerSettings.defaultScreenHeight = recommended_DefaultScreenHeight; } if (!EditorPrefs.HasKey(ignore + runInBackground)) { PlayerSettings.runInBackground = recommended_RunInBackground; } if (!EditorPrefs.HasKey(ignore + displayResolutionDialog)) { PlayerSettings.displayResolutionDialog = recommended_DisplayResolutionDialog; } if (!EditorPrefs.HasKey(ignore + resizableWindow)) { PlayerSettings.resizableWindow = recommended_ResizableWindow; } if (!EditorPrefs.HasKey(ignore + fullscreenMode)) #pragma warning disable CS0618 // Typ oder Element ist veraltet { PlayerSettings.d3d11FullscreenMode = recommended_FullscreenMode; } #pragma warning restore CS0618 // Typ oder Element ist veraltet if (!EditorPrefs.HasKey(ignore + visibleInBackground)) { PlayerSettings.visibleInBackground = recommended_VisibleInBackground; } #if (UNITY_5_4 || UNITY_5_3 || UNITY_5_2 || UNITY_5_1 || UNITY_5_0) if (!EditorPrefs.HasKey(ignore + renderingPath)) { PlayerSettings.renderingPath = recommended_RenderPath; } #endif if (!EditorPrefs.HasKey(ignore + colorSpace)) { PlayerSettings.colorSpace = recommended_ColorSpace; } if (!EditorPrefs.HasKey(ignore + gpuSkinning)) { PlayerSettings.gpuSkinning = recommended_GpuSkinning; } #if false if (!EditorPrefs.HasKey(ignore + singlePassStereoRendering)) { PlayerSettings.singlePassStereoRendering = recommended_SinglePassStereoRendering; } #endif EditorUtility.DisplayDialog("Accept All", "You made the right choice!", "Ok"); Close(); } if (GUILayout.Button("Ignore All")) { if (EditorUtility.DisplayDialog("Ignore All", "Are you sure?", "Yes, Ignore All", "Cancel")) { // Only ignore those that do not currently match our recommended settings. if (EditorUserBuildSettings.activeBuildTarget != recommended_BuildTarget) { EditorPrefs.SetBool(ignore + buildTarget, true); } #if (UNITY_5_4 || UNITY_5_3 || UNITY_5_2 || UNITY_5_1 || UNITY_5_0) if (PlayerSettings.showUnitySplashScreen != recommended_ShowUnitySplashScreen) #else if (PlayerSettings.SplashScreen.show != recommended_ShowUnitySplashScreen) #endif { EditorPrefs.SetBool(ignore + showUnitySplashScreen, true); } #pragma warning disable CS0618 // Typ oder Element ist veraltet if (PlayerSettings.defaultIsFullScreen != recommended_DefaultIsFullScreen) #pragma warning restore CS0618 // Typ oder Element ist veraltet { EditorPrefs.SetBool(ignore + defaultIsFullScreen, true); } if (PlayerSettings.defaultScreenWidth != recommended_DefaultScreenWidth || PlayerSettings.defaultScreenHeight != recommended_DefaultScreenHeight) { EditorPrefs.SetBool(ignore + defaultScreenSize, true); } if (PlayerSettings.runInBackground != recommended_RunInBackground) { EditorPrefs.SetBool(ignore + runInBackground, true); } if (PlayerSettings.displayResolutionDialog != recommended_DisplayResolutionDialog) { EditorPrefs.SetBool(ignore + displayResolutionDialog, true); } if (PlayerSettings.resizableWindow != recommended_ResizableWindow) { EditorPrefs.SetBool(ignore + resizableWindow, true); } #pragma warning disable CS0618 // Typ oder Element ist veraltet if (PlayerSettings.d3d11FullscreenMode != recommended_FullscreenMode) #pragma warning restore CS0618 // Typ oder Element ist veraltet { EditorPrefs.SetBool(ignore + fullscreenMode, true); } if (PlayerSettings.visibleInBackground != recommended_VisibleInBackground) { EditorPrefs.SetBool(ignore + visibleInBackground, true); } #if (UNITY_5_4 || UNITY_5_3 || UNITY_5_2 || UNITY_5_1 || UNITY_5_0) if (PlayerSettings.renderingPath != recommended_RenderPath) { EditorPrefs.SetBool(ignore + renderingPath, true); } #endif if (PlayerSettings.colorSpace != recommended_ColorSpace) { EditorPrefs.SetBool(ignore + colorSpace, true); } if (PlayerSettings.gpuSkinning != recommended_GpuSkinning) { EditorPrefs.SetBool(ignore + gpuSkinning, true); } #if false if (PlayerSettings.singlePassStereoRendering != recommended_SinglePassStereoRendering) { EditorPrefs.SetBool(ignore + singlePassStereoRendering, true); } #endif Close(); } } } else if (GUILayout.Button("Close")) { Close(); } GUILayout.EndHorizontal(); }
/// <summary> /// Draw the overlay of a Camera /// </summary> /// <param name="target">The Camera that we want a preview</param> /// <param name="sceneView">The scene view where to draw it</param> /// <param name="previewCameraGetter">The way to get the preview camera corresponding to the target</param> public static void DrawCameraSceneViewOverlay(Object target, SceneView sceneView, GetPreviewCamera previewCameraGetter) { if (target == null) { return; } // cache some deep values var c = (Camera)target; var previewSize = Handles.GetMainGameViewSize(); if (previewSize.x < 0f) { // Fallback to Scene View of not a valid game view size previewSize.x = sceneView.position.width; previewSize.y = sceneView.position.height; } // Apply normalizedviewport rect of camera var normalizedViewPortRect = c.rect; previewSize.x *= Mathf.Max(normalizedViewPortRect.width, 0f); previewSize.y *= Mathf.Max(normalizedViewPortRect.height, 0f); // Prevent using invalid previewSize if (previewSize.x <= 0f || previewSize.y <= 0f) { return; } var aspect = previewSize.x / previewSize.y; // Scale down (fit to scene view) previewSize.y = k_PreviewNormalizedSize * sceneView.position.height; previewSize.x = previewSize.y * aspect; if (previewSize.y > sceneView.position.height * 0.5f) { previewSize.y = sceneView.position.height * 0.5f; previewSize.x = previewSize.y * aspect; } if (previewSize.x > sceneView.position.width * 0.5f) { previewSize.x = sceneView.position.width * 0.5f; previewSize.y = previewSize.x / aspect; } // Get and reserve rect Rect cameraRect = GUILayoutUtility.GetRect(previewSize.x, previewSize.y); if (Event.current.type == EventType.Repaint) { var previewCamera = previewCameraGetter(c, previewSize); if (previewCamera.targetTexture == null) { Debug.LogError("The preview camera must render in a render target"); return; } bool drawGizmo = sceneView.drawGizmos; sceneView.drawGizmos = false; previewCamera.Render(); sceneView.drawGizmos = drawGizmo; Graphics.DrawTexture(cameraRect, previewCamera.targetTexture, new Rect(0, 0, 1, 1), 0, 0, 0, 0, GUI.color, GUITextureBlit2SRGBMaterial); // We set target texture to null after this call otherwise if both sceneview and gameview are visible and we have a preview camera wwe // get this error: "Releasing render texture that is set as Camera.targetTexture!" previewCamera.targetTexture = null; } }
private void OnGUI() { if (wizardData == null) { return; } if (!inited) { inited = true; biggerButton = new GUIStyle("button"); biggerButton.padding = new RectOffset(12, 12, 6, 6); urlIcon = EditorGUIUtility.IconContent("_Help"); eyeIcon = EditorGUIUtility.IconContent(EditorGUIUtility.isProSkin ? "ViewToolOrbit On" : "ViewToolOrbit"); header = new GUIStyle(EditorStyles.boldLabel); header.fontSize = 14; header.alignment = TextAnchor.MiddleCenter; questionContainer = new GUIStyle(); answer = new GUIStyle(EditorStyles.label); answer.normal.textColor = EditorStyles.label.normal.textColor; answer.wordWrap = true; answer.alignment = TextAnchor.MiddleLeft; answer.stretchWidth = false; // var c = answer.normal.textColor; // c.a = 0.8f; // answer.normal.textColor = c; answer.padding = new RectOffset(4, 4, 4, 4); message = new GUIStyle(answer); // message.normal.textColor = EditorStyles.label.normal.textColor; // message.fontSize = 12; // message.stretchWidth = true; message.alignment = TextAnchor.MiddleCenter; message.stretchWidth = true; question = new GUIStyle("box"); question.fontSize = 14; question.normal.textColor = EditorStyles.label.normal.textColor; question.font = EditorStyles.boldFont; var c = question.normal.textColor; c.a = 0.9f; question.normal.textColor = c; } void DrawButtonLinks() { EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); foreach (var wAction in wizardData.buttonLinks) { urlIcon.text = wAction.actionText; if (GUILayout.Button(urlIcon, biggerButton)) { Application.OpenURL(wAction.url); } } EditorGUILayout.EndHorizontal(); // EditorGUILayout.Space(); } scroll = EditorGUILayout.BeginScrollView(scroll, GUILayout.Width(position.width)); EditorGUILayout.Space(); EditorGUILayout.LabelField(wizardData.header, header); EditorUtils.HorizontalLine(1, header.CalcSize(new GUIContent(wizardData.header)).x); EditorGUILayout.Space(); var backgroundColor = EditorGUIUtility.isProSkin ? new Color(30 / 255f, 30 / 255f, 30 / 255f) : new Color(1f, 1f, 1f); backgroundColor.a = 0.3f; var messageRect = GUILayoutUtility.GetRect(new GUIContent(wizardData.message), message); // EditorGUILayout.LabelField(, message); EditorGUI.DrawRect(messageRect, backgroundColor); EditorGUI.LabelField(messageRect, wizardData.message, message); EditorGUILayout.Separator(); void CloseOtherGroup(WizardData.WizardActionGroup onGroup) { foreach (var group in wizardData.wizardActionGroups) { if (group != onGroup) { group.visible.target = false; } } } foreach (var group in wizardData.wizardActionGroups) { if (group.visible == null) { Refresh(); } EditorGUI.BeginChangeCheck(); group.visible.target = EditorUtils.Foldout(group.visible.target, group.groupName); if (EditorGUI.EndChangeCheck() && group.visible.target) { CloseOtherGroup(group); } if (EditorGUILayout.BeginFadeGroup(group.visible.faded)) { EditorUtils.Indent(); foreach (var action in group.actions) { EditorGUILayout.BeginVertical(questionContainer); GUILayout.Space(2); using (new EditorUtils.GUIColorScope(Color.yellow)) using (new EditorUtils.BackgroundColorScope(EditorGUIUtility.isProSkin ? Color.yellow : new Color(1, 1, 171 / 255f, 0.34f))) EditorGUILayout.LabelField($"Q: {action.question}", question); GUILayout.Space(2); var offset = question.CalcSize(new GUIContent("Q: ")); EditorGUILayout.BeginHorizontal(); GUILayout.Space(offset.x); // using (new EditorUtils.BackgroundColorScope(EditorGUIUtility.isProSkin ? Color.black : Color.white)) var answerSize = GUILayoutUtility.GetRect(new GUIContent(action.answer), answer); EditorGUI.DrawRect(answerSize, backgroundColor); // GUILayout.Label(, answer); EditorGUI.LabelField(answerSize, action.answer, answer); EditorGUILayout.EndHorizontal(); GUILayout.Space(2); if (action.wActions != null) { EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); foreach (var wAction in action.wActions) { var isUrl = !string.IsNullOrWhiteSpace(wAction.url); if (isUrl) { urlIcon.text = wAction.actionText; if (GUILayout.Button(urlIcon, biggerButton)) { Application.OpenURL(wAction.url); } } else { eyeIcon.text = wAction.actionText; if (GUILayout.Button(eyeIcon, biggerButton)) { if (!string.IsNullOrWhiteSpace(wAction.referenceAssetPath)) { if (wAction.referenceAssetPath.EndsWith(".unity")) { LoadScene(wAction.referenceAssetPath); } else { PingAsset(LoadAsset <UnityEngine.Object>(wAction.referenceAssetPath)); } } if (!string.IsNullOrWhiteSpace(wAction.referenceSceneObjectName)) { LocateGameObject(GameObject.Find(wAction.referenceSceneObjectName)); } GUIUtility.ExitGUI(); } } } EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndVertical(); //Draw vertical line var rect = GUILayoutUtility.GetLastRect(); rect.x += 10; rect.y += offset.y + 6; rect.height -= offset.y + 6; rect.width = 2; var color = answer.normal.textColor; color.a = 0.5f; EditorGUI.DrawRect(rect, color); // EditorGUILayout.Separator(); } EditorUtils.EndIndent(); } EditorGUILayout.EndFadeGroup(); } GUILayout.FlexibleSpace(); EditorGUILayout.EndScrollView(); DrawButtonLinks(); }
void OnGUI () { GUILayout.Space( 3 ); int oldValue = GUI.skin.window.padding.bottom; GUI.skin.window.padding.bottom = -20; Rect windowRect = GUILayoutUtility.GetRect( 1, 17 ); windowRect.x += 4; windowRect.width -= 7; editorMode = GUI.SelectionGrid( windowRect, editorMode, modes, 2, "Window" ); GUI.skin.window.padding.bottom = oldValue; if ( editorModeOld != editorMode ) { editorModeOld = editorMode; listResult = new List<string>(); componentName = targetComponent == null ? "" : targetComponent.name; lastChecked = null; } switch ( editorMode ) { case 0: targetComponent = (MonoScript) EditorGUILayout.ObjectField( targetComponent, typeof( MonoScript ), false ); if ( targetComponent != lastChecked ) { lastChecked = targetComponent; componentName = targetComponent.name; AssetDatabase.SaveAssets(); string targetPath = AssetDatabase.GetAssetPath( targetComponent ); string[] allPrefabs = GetAllPrefabs(); listResult = new List<string>(); foreach ( string prefab in allPrefabs ) { string[] single = new string[] { prefab }; string[] dependencies = AssetDatabase.GetDependencies( single ); foreach ( string dependedAsset in dependencies ) { if ( dependedAsset == targetPath ) { listResult.Add( prefab ); } } } } break; case 1: if ( GUILayout.Button( "Search!" ) ) { string[] allPrefabs = GetAllPrefabs(); listResult = new List<string>(); foreach ( string prefab in allPrefabs ) { UnityEngine.Object o = AssetDatabase.LoadMainAssetAtPath( prefab ); GameObject go; try { go = (GameObject) o; Component[] components = go.GetComponentsInChildren<Component>( true ); foreach ( Component c in components ) { if ( c == null ) { listResult.Add( prefab ); } } } catch { Debug.Log( "For some reason, prefab " + prefab + " won't cast to GameObject" ); } } } break; } if ( listResult != null ) { if ( listResult.Count == 0 ) { GUILayout.Label( editorMode == 0 ? ( componentName == "" ? "Choose a component" : "No prefabs use component " + componentName ) : ( "No prefabs have missing components!\nClick Search to check again" ) ); } else { GUILayout.Label( editorMode == 0 ? ( "The following prefabs use component " + componentName + ":" ) : ( "The following prefabs have missing components:" ) ); scroll = GUILayout.BeginScrollView( scroll ); foreach ( string s in listResult ) { GUILayout.BeginHorizontal(); GUILayout.Label( s, GUILayout.Width( position.width / 2 ) ); if ( GUILayout.Button( "Select", GUILayout.Width( position.width / 2 - 10 ) ) ) { Selection.activeObject = AssetDatabase.LoadMainAssetAtPath( s ); } GUILayout.EndHorizontal(); } GUILayout.EndScrollView(); } } }
public FadeArea BeginFadeArea(bool open, string id, float minHeight, GUIStyle areaStyle) { if (editor == null) { Debug.LogError("You need to set the 'EditorGUIx.editor' variable before calling this function"); return(null); } if (stretchStyle == null) { stretchStyle = new GUIStyle(); stretchStyle.stretchWidth = true; //stretchStyle.padding = new RectOffset (0,0,4,14); //stretchStyle.margin = new RectOffset (0,0,4,4); } if (stack == null) { stack = new Stack <FadeArea>(); } if (fadeAreas == null) { fadeAreas = new Dictionary <string, FadeArea> (); } if (!fadeAreas.ContainsKey(id)) { fadeAreas.Add(id, new FadeArea(open)); } FadeArea fadeArea = fadeAreas[id]; stack.Push(fadeArea); fadeArea.open = open; //Make sure the area fills the full width areaStyle.stretchWidth = true; Rect lastRect = fadeArea.lastRect; if (!fancyEffects) { fadeArea.value = open ? 1F : 0F; lastRect.height -= minHeight; lastRect.height = open ? lastRect.height : 0; lastRect.height += minHeight; } else { //GUILayout.Label (lastRect.ToString ()+"\n"+fadeArea.tmp.ToString (),EditorStyles.miniLabel); lastRect.height = lastRect.height < minHeight ? minHeight : lastRect.height; lastRect.height -= minHeight; float faded = Hermite(0F, 1F, fadeArea.value); lastRect.height *= faded; lastRect.height += minHeight; lastRect.height = Mathf.Round(lastRect.height); //lastRect.height *= 2; //if (Event.current.type == EventType.Repaint) { // isLayout = false; //} } //Rect stretchWidthRect = GUILayoutUtility.GetRect (new GUIContent (), stretchStyle,GUILayout.Height (0)); Rect gotLastRect = GUILayoutUtility.GetRect(new GUIContent(), areaStyle, GUILayout.Height(lastRect.height)); //Debug.Log (Event.current.type +" "+lastRect); //The clipping area, also drawing background GUILayout.BeginArea(lastRect, areaStyle); Rect newRect = EditorGUILayout.BeginVertical(); if (Event.current.type == EventType.Repaint || Event.current.type == EventType.ScrollWheel) { newRect.x = gotLastRect.x; newRect.y = gotLastRect.y; newRect.width = gotLastRect.width; //stretchWidthRect.width; newRect.height += areaStyle.padding.top + areaStyle.padding.bottom; fadeArea.currentRect = newRect; if (fadeArea.lastRect != newRect) { //@Fix - duplicate //fadeArea.lastUpdate = Time.realtimeSinceStartup; editor.Repaint(); } fadeArea.Switch(); } if (Event.current.type == EventType.Repaint) { float value = fadeArea.value; float targetValue = open ? 1F : 0F; float newRectHeight = fadeArea.lastRect.height; float deltaHeight = 400F / newRectHeight; float deltaTime = Mathf.Clamp(Time.realtimeSinceStartup - fadeAreas[id].lastUpdate, 0.00001F, 0.05F); deltaTime *= Mathf.Lerp(deltaHeight * deltaHeight * 0.01F, 0.8F, 0.9F); fadeAreas[id].lastUpdate = Time.realtimeSinceStartup; //Useless, but fun feature if (Event.current.shift) { deltaTime *= 0.05F; } if (Mathf.Abs(targetValue - value) > 0.001F) { float time = Mathf.Clamp01(deltaTime * speed); value += time * Mathf.Sign(targetValue - value); editor.Repaint(); } else { value = Mathf.Round(value); } fadeArea.value = Mathf.Clamp01(value); //if (oldValue != value) { // editor.Repaint (); //} } if (fade) { Color c = GUI.color; fadeArea.preFadeColor = c; c.a *= fadeArea.value; GUI.color = c; } fadeArea.open = open; //GUILayout.Label ("Alpha : "+fadeArea.value); //GUILayout.Label ("Alpha : "+fadeArea.value);GUILayout.Label ("Alpha : "+fadeArea.value);GUILayout.Label ("Alpha : "+fadeArea.value);GUILayout.Label ("Alpha : "+fadeArea.value); /*GUILayout.Label ("Testing"); * GUILayout.Label ("Testing"); * GUILayout.Label ("Testing"); * GUILayout.Label ("Testing");*/ return(fadeArea); }
public override void OnInspectorGUI() { serializedObject.Update(); if (m_prevTileset != m_brush.Tileset) { OnDisable(); OnEnable(); } m_prevTileset = m_brush.Tileset; base.OnInspectorGUI(); if (!m_brush.Tileset) { return; } Vector2 visualTileSize = m_brush.Tileset.VisualTileSize; EditorGUILayout.PropertyField(serializedObject.FindProperty("AnimFPS")); TileSelection tileSelection = ((TilesetBrush)target).Tileset.TileSelection; if (tileSelection != null) { if (GUILayout.Button("Add tile selection as animation frames")) { ((AnimBrush)target).AnimFrames.AddRange(tileSelection.selectionData.Select(x => new AnimBrush.TileAnimFrame() { tileId = x })); } } EditorGUILayout.Space(); // Draw animation GUILayoutUtility.GetRect(1f, 1f, GUILayout.Width(visualTileSize.x), GUILayout.Height(visualTileSize.y)); Rect rAnimFrame = GUILayoutUtility.GetLastRect(); uint tileData = m_brush.GetAnimTileData(); rAnimFrame.center = new Vector2(EditorGUIUtility.currentViewWidth / 2, rAnimFrame.center.y); GUI.Box(new Rect(rAnimFrame.position - Vector2.one, rAnimFrame.size + 2 * Vector2.one), ""); TilesetEditor.DoGUIDrawTileFromTileData(rAnimFrame, tileData, m_brush.Tileset, m_brush.GetAnimUV()); EditorGUILayout.Space(); uint brushTileData = m_frameList.index >= 0 ? m_brush.AnimFrames[m_frameList.index].tileId : Tileset.k_TileData_Empty; brushTileData = BrushTileGridControl.DoTileDataPropertiesLayout(brushTileData, m_brush.Tileset, false); if (m_frameList.index >= 0) { m_brush.AnimFrames[m_frameList.index].tileId = brushTileData; } EditorGUILayout.Space(); // Draw Frames List m_frameList.elementHeight = visualTileSize.y + 10f; m_frameList.DoLayoutList(); EditorGUILayout.HelpBox("Select a frame from list and then select a tile from tile selection window.", MessageType.Info); EditorGUILayout.HelpBox("Add and Remove tiles with '+' and '-' buttons.", MessageType.Info); Repaint(); serializedObject.ApplyModifiedProperties(); if (GUI.changed) { EditorUtility.SetDirty(target); } }
void DrawSpriteCollection(tk2dSpriteCollectionData spriteCollection) { Event ev = Event.current; int tileSize = presentParams.TileSize; scroll = GUILayout.BeginScrollView(scroll); Rect r = GUILayoutUtility.GetRect(presentParams.rectDims.x, presentParams.rectDims.y); if (ev.type == EventType.MouseDown && ev.button == 0 && r.Contains(ev.mousePosition)) { int selX = ((int)ev.mousePosition.x - presentParams.border) / presentParams.tileWidth; int selY = ((int)ev.mousePosition.y - presentParams.border) / presentParams.tileHeight; int selId = selY * presentParams.numTilesPerRow + selX; if (selX < presentParams.numTilesPerRow && selY < presentParams.numRows) { selectedIndex = Mathf.Clamp(selId, 0, selectedDefinitions.Count - 1); Repaint(); } if (ev.clickCount == 2) { PerformSelection(); Close(); } ev.Use(); } r.x += presentParams.border; r.y += presentParams.border; int ix = 0; float x = r.x; float y = r.y; int index = 0; foreach (tk2dSpriteDefinition def in selectedDefinitions) { Rect spriteRect = new Rect(x, y, tileSize, tileSize); tk2dGrid.Draw(spriteRect, Vector2.zero); tk2dSpriteThumbnailCache.DrawSpriteTextureInRect(spriteRect, def, Color.white); Rect labelRect = new Rect(x, y + tileSize + presentParams.labelOffset, tileSize, presentParams.labelHeight); if (selectedIndex == index) { GUI.Label(labelRect, "", tk2dEditorSkin.Selection); } GUI.Label(labelRect, def.name, EditorStyles.miniLabel); if (++ix >= presentParams.numTilesPerRow) { ix = 0; x = r.x; y += presentParams.tileHeight; } else { x += presentParams.tileWidth; } index++; } GUILayout.EndScrollView(); }
void OnGUI() { if (boldFoldoutStyle == null) { boldFoldoutStyle = new GUIStyle(EditorStyles.foldout); boldFoldoutStyle.fontStyle = FontStyle.Bold; } EditorGUIUtility.labelWidth = DEFAULT_LABEL_WIDTH; GUILayout.Label("OVR Platform Tool", EditorStyles.boldLabel); this.titleContent.text = "OVR Platform Tool"; GUIContent TargetPlatformLabel = new GUIContent("Target Oculus Platform"); OVRPlatformToolSettings.TargetPlatform = (TargetPlatform)MakePopup(TargetPlatformLabel, (int)OVRPlatformToolSettings.TargetPlatform, platformOptions); SetDirtyOnGUIChange(); commandMenuScroll = EditorGUILayout.BeginScrollView(commandMenuScroll, GUILayout.Height(Screen.height / 2)); { // Add the UI Form EditorGUI.BeginChangeCheck(); GUILayout.Space(15.0f); // App ID GUIContent AppIDLabel = new GUIContent("Oculus Application ID [?]: ", "This AppID will be used when uploading the build."); OVRPlatformToolSettings.AppID = MakeTextBox(AppIDLabel, OVRPlatformToolSettings.AppID); // App Token GUIContent AppTokenLabel = new GUIContent("Oculus App Token [?]: ", "You can get your app token from your app's Oculus API Dashboard."); OVRPlatformToolSettings.AppToken = MakePasswordBox(AppTokenLabel, OVRPlatformToolSettings.AppToken); // Release Channel GUIContent ReleaseChannelLabel = new GUIContent("Release Channel [?]: ", "Specify the releaes channel of the new build, you can reassign to other channels after upload."); OVRPlatformToolSettings.ReleaseChannel = MakeTextBox(ReleaseChannelLabel, OVRPlatformToolSettings.ReleaseChannel); // Releaes Note GUIContent ReleaseNoteLabel = new GUIContent("Release Note: "); OVRPlatformToolSettings.ReleaseNote = MakeTextBox(ReleaseNoteLabel, OVRPlatformToolSettings.ReleaseNote); // Platform specific fields if (OVRPlatformToolSettings.TargetPlatform == TargetPlatform.Rift) { GUIContent BuildDirLabel = new GUIContent("Rift Build Directory [?]: ", "The full path to the directory containing your Rift build files."); OVRPlatformToolSettings.RiftBuildDirectory = MakeFileDirectoryField(BuildDirLabel, OVRPlatformToolSettings.RiftBuildDirectory, "Choose Rifle Build Directory"); GUIContent BuildVersionLabel = new GUIContent("Build Version [?]: ", "The version number shown to users."); OVRPlatformToolSettings.RiftBuildVersion = MakeTextBox(BuildVersionLabel, OVRPlatformToolSettings.RiftBuildVersion); GUIContent LaunchFileLabel = new GUIContent("Launch File Path [?]: ", "The full path to the executable that launches your app."); OVRPlatformToolSettings.RiftLaunchFile = MakeFileDirectoryField(LaunchFileLabel, OVRPlatformToolSettings.RiftLaunchFile, "Choose Launch File", true, "exe"); } else { GUIContent ApkPathLabel = new GUIContent("Build APK File Path [?]: ", "The full path to the APK file."); OVRPlatformToolSettings.ApkBuildPath = MakeFileDirectoryField(ApkPathLabel, OVRPlatformToolSettings.ApkBuildPath, "Choose APK File", true, "apk"); if (OVRPlatformToolSettings.TargetPlatform == TargetPlatform.OculusGoGearVR) { // Go and Gear VR specific fields } else if (OVRPlatformToolSettings.TargetPlatform == TargetPlatform.Quest) { // Quest specific fields } } showOptionalCommands = EditorGUILayout.Foldout(showOptionalCommands, "Optional Commands", boldFoldoutStyle); if (showOptionalCommands) { IncrementIndent(); if (OVRPlatformToolSettings.TargetPlatform == TargetPlatform.Rift) { // Launch Parameters GUIContent LaunchParamLabel = new GUIContent("Launch Parameters [?]: ", "Specifies any arguments passed to the launcher."); OVRPlatformToolSettings.RiftLaunchParams = MakeTextBox(LaunchParamLabel, OVRPlatformToolSettings.RiftLaunchParams); GUIContent FirewallExceptionLabel = new GUIContent("Firewall Exception [?]: ", "Specifies if a Windows Firewall exception is required."); OVRPlatformToolSettings.RiftFirewallException = MakeToggleBox(FirewallExceptionLabel, OVRPlatformToolSettings.RiftFirewallException); GUIContent GamepadEmulationLabel = new GUIContent("Gamepad Emulation [?]: ", "Specifies the type of gamepad emulation used by the Oculus Touch controllers."); OVRPlatformToolSettings.RiftGamepadEmulation = (OVRPlatformToolSettings.GamepadType)MakePopup(GamepadEmulationLabel, (int)OVRPlatformToolSettings.RiftGamepadEmulation, gamepadOptions); show2DCommands = EditorGUILayout.Foldout(show2DCommands, "2D", boldFoldoutStyle); if (show2DCommands) { IncrementIndent(); // 2D Launch File GUIContent LaunchFile2DLabel = new GUIContent("2D Launch File [?]: ", "The full path to the executable that launches your app in 2D mode."); OVRPlatformToolSettings.Rift2DLaunchFile = MakeFileDirectoryField(LaunchFile2DLabel, OVRPlatformToolSettings.Rift2DLaunchFile, "Choose 2D Launch File", true, "exe"); // 2D Launch Parameters GUIContent LaunchParam2DLabel = new GUIContent("2D Launch Parameters [?]: ", "Specifies any arguments passed to the launcher in 2D mode."); OVRPlatformToolSettings.Rift2DLaunchParams = MakeTextBox(LaunchParam2DLabel, OVRPlatformToolSettings.Rift2DLaunchParams); DecrementIndent(); } showRedistCommands = EditorGUILayout.Foldout(showRedistCommands, "Redistributable Packages", boldFoldoutStyle); if (showRedistCommands) { IncrementIndent(); for (int i = 0; i < OVRPlatformToolSettings.RiftRedistPackages.Count; i++) { GUIContent RedistPackageLabel = new GUIContent(OVRPlatformToolSettings.RiftRedistPackages[i].name); OVRPlatformToolSettings.RiftRedistPackages[i].include = MakeToggleBox(RedistPackageLabel, OVRPlatformToolSettings.RiftRedistPackages[i].include); } DecrementIndent(); } showExpansionFileCommands = EditorGUILayout.Foldout(showExpansionFileCommands, "Expansion Files", boldFoldoutStyle); if (showExpansionFileCommands) { IncrementIndent(); // Language Pack Directory GUIContent LanguagePackLabel = new GUIContent("Language Pack Directory [?]: ", "The full path to the directory containing the language packs"); OVRPlatformToolSettings.LanguagePackDirectory = MakeFileDirectoryField(LanguagePackLabel, OVRPlatformToolSettings.LanguagePackDirectory, "Choose Language Pack Directory"); } } else { if (OVRPlatformToolSettings.TargetPlatform == TargetPlatform.OculusGoGearVR) { // Go and Gear VR specific optional fields } else if (OVRPlatformToolSettings.TargetPlatform == TargetPlatform.Quest) { // Quest specific optional fields } showExpansionFileCommands = EditorGUILayout.Foldout(showExpansionFileCommands, "Expansion Files", boldFoldoutStyle); if (showExpansionFileCommands) { IncrementIndent(); // OBB File Path GUIContent ObbPathLabel = new GUIContent("OBB File Path [?]: ", "The full path to the OBB file."); OVRPlatformToolSettings.ObbFilePath = MakeFileDirectoryField(ObbPathLabel, OVRPlatformToolSettings.ObbFilePath, "Choose OBB File", true, "obb"); } } if (showExpansionFileCommands) { // Assets Directory GUIContent AssetsDirLabel = new GUIContent("Assets Directory [?]: ", "The full path to the directory with DLCs for this build."); string assetsDirectory = MakeFileDirectoryField(AssetsDirLabel, OVRPlatformToolSettings.AssetsDirectory, "Choose Assets Directory"); if (assetsDirectory != OVRPlatformToolSettings.AssetsDirectory) { OVRPlatformToolSettings.AssetsDirectory = assetsDirectory; OVRPlatformToolSettings.AssetConfigs.Clear(); if (!string.IsNullOrEmpty(OVRPlatformToolSettings.AssetsDirectory)) { DirectoryInfo dirInfo = new DirectoryInfo(OVRPlatformToolSettings.AssetsDirectory); FileInfo[] assetFiles = dirInfo.GetFiles(); foreach (FileInfo f in assetFiles) { OVRPlatformToolSettings.AssetConfigs.Add(new AssetConfig(f.Name)); } } EditorUtility.SetDirty(OVRPlatformToolSettings.Instance); } // Display bordered asset configuration list GUILayout.Space(3f); Rect rect = GUILayoutUtility.GetRect(0, GetAssetConfigElementHeight() + (ASSET_CONFIG_BACKGROUND_PADDING * 2), GUILayout.ExpandWidth(true)); rect.x += (EditorGUI.indentLevel * INDENT_SPACING + 5); rect.width -= (EditorGUI.indentLevel * INDENT_SPACING + 10); DrawAssetConfigList(rect); DecrementIndent(); } EditorGUI.indentLevel--; } if (EditorGUI.EndChangeCheck()) { EditorUtility.SetDirty(OVRPlatformToolSettings.Instance); } } EditorGUILayout.EndScrollView(); GUILayout.Space(SINGLE_LINE_SPACING); GUILayout.FlexibleSpace(); // Add an Upload button GUI.enabled = !activeProcess; GUIContent btnTxt = new GUIContent("Upload"); var rt = GUILayoutUtility.GetRect(btnTxt, GUI.skin.button, GUILayout.ExpandWidth(false)); var btnYPos = rt.center.y; rt.center = new Vector2(EditorGUIUtility.currentViewWidth / 2 - rt.width / 2 - buttonPadding, btnYPos); if (GUI.Button(rt, btnTxt, GUI.skin.button)) { OVRPlugin.SendEvent("oculus_platform_tool", "upload"); OVRPlatformTool.log = string.Empty; OnUpload(OVRPlatformToolSettings.TargetPlatform); } // Add a cancel button GUI.enabled = activeProcess; btnTxt = new GUIContent("Cancel"); rt = GUILayoutUtility.GetRect(btnTxt, GUI.skin.button, GUILayout.ExpandWidth(false)); rt.center = new Vector2(EditorGUIUtility.currentViewWidth / 2 + rt.width / 2 + buttonPadding, btnYPos); if (GUI.Button(rt, btnTxt, GUI.skin.button)) { if (EditorUtility.DisplayDialog("Cancel Upload Process", "Are you sure you want to cancel the upload process?", "Yes", "No")) { if (ovrPlatUtilProcess != null) { ovrPlatUtilProcess.Kill(); OVRPlatformTool.log += "Upload process was canceled\n"; } } } GUI.enabled = true; GUILayout.FlexibleSpace(); GUILayout.Space(SINGLE_LINE_SPACING); debugLogScroll = EditorGUILayout.BeginScrollView(debugLogScroll); GUIStyle logBoxStyle = new GUIStyle(); logBoxStyle.wordWrap = true; logBoxStyle.normal.textColor = logBoxStyle.focused.textColor = EditorStyles.label.normal.textColor; EditorGUILayout.SelectableLabel(OVRPlatformTool.log, logBoxStyle, GUILayout.Height(position.height - 30)); EditorGUILayout.EndScrollView(); }
public override void OnInspectorGUI() { oldSkin = GUI.skin; serializedObject.Update(); if (skin) { GUI.skin = skin; } GUILayout.BeginVertical("Item Manager", "window"); GUILayout.Label(m_Logo, GUILayout.MaxHeight(25)); openCloseWindow = GUILayout.Toggle(openCloseWindow, openCloseWindow ? "Close" : "Open", EditorStyles.toolbarButton); if (openCloseWindow) { GUI.skin = oldSkin; DrawPropertiesExcluding(serializedObject, ignoreProperties.Append(ignore_vMono)); GUI.skin = skin; if (GUILayout.Button("Open Item List")) { ItemListWindow.CreateWindow(manager.itemListData); } if (manager.itemListData) { GUILayout.BeginVertical("box"); if (itemReferenceList.arraySize > manager.itemListData.items.Count) { manager.startItems.Resize(manager.itemListData.items.Count); } GUILayout.Box("Start Items " + manager.startItems.Count); filteredItems = manager.itemsFilter.Count > 0 ? GetItemByFilter(manager.itemListData.items, manager.itemsFilter) : manager.itemListData.items; if (!inAddItem && filteredItems.Count > 0 && GUILayout.Button("Add Item", EditorStyles.miniButton)) { inAddItem = true; } if (inAddItem && filteredItems.Count > 0) { GUILayout.BeginVertical("box"); selectedItem = EditorGUILayout.Popup(new GUIContent("SelectItem"), selectedItem, GetItemContents(filteredItems)); bool isValid = true; var indexSelected = manager.itemListData.items.IndexOf(filteredItems[selectedItem]); if (manager.startItems.Find(i => i.id == manager.itemListData.items[indexSelected].id) != null) { isValid = false; EditorGUILayout.HelpBox("This item already exist", MessageType.Error); } GUILayout.BeginHorizontal(); if (isValid && GUILayout.Button("Add", EditorStyles.miniButton)) { itemReferenceList.arraySize++; itemReferenceList.GetArrayElementAtIndex(itemReferenceList.arraySize - 1).FindPropertyRelative("id").intValue = manager.itemListData.items[indexSelected].id; itemReferenceList.GetArrayElementAtIndex(itemReferenceList.arraySize - 1).FindPropertyRelative("amount").intValue = 1; EditorUtility.SetDirty(manager); serializedObject.ApplyModifiedProperties(); inAddItem = false; } if (GUILayout.Button("Cancel", EditorStyles.miniButton)) { inAddItem = false; } GUILayout.EndHorizontal(); GUILayout.EndVertical(); } GUIStyle boxStyle = new GUIStyle(GUI.skin.box); scroll = GUILayout.BeginScrollView(scroll, GUILayout.MinHeight(200), GUILayout.ExpandHeight(false), GUILayout.ExpandWidth(false)); for (int i = 0; i < manager.startItems.Count; i++) { var item = manager.itemListData.items.Find(t => t.id.Equals(manager.startItems[i].id)); if (item) { GUILayout.BeginVertical("box"); GUILayout.BeginHorizontal(); GUILayout.BeginHorizontal(); var rect = GUILayoutUtility.GetRect(50, 50); if (item.icon != null) { DrawTextureGUI(rect, item.icon, new Vector2(50, 50)); } var name = " ID " + item.id.ToString("00") + "\n - " + item.name + "\n - " + item.type.ToString(); var content = new GUIContent(name, null, "Click to Open"); GUILayout.Label(content, EditorStyles.miniLabel); GUILayout.BeginVertical("box"); GUILayout.BeginHorizontal(); GUILayout.Label("Auto Equip", EditorStyles.miniLabel); manager.startItems[i].autoEquip = EditorGUILayout.Toggle("", manager.startItems[i].autoEquip, GUILayout.Width(30)); if (manager.startItems[i].autoEquip) { GUILayout.Label("IndexArea", EditorStyles.miniLabel); manager.startItems[i].indexArea = EditorGUILayout.IntField("", manager.startItems[i].indexArea, GUILayout.Width(30)); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Amount", EditorStyles.miniLabel); manager.startItems[i].amount = EditorGUILayout.IntField(manager.startItems[i].amount, GUILayout.Width(30)); if (manager.startItems[i].amount < 1) { manager.startItems[i].amount = 1; } GUILayout.EndHorizontal(); if (item.attributes.Count > 0) { manager.startItems[i].changeAttributes = GUILayout.Toggle(manager.startItems[i].changeAttributes, new GUIContent("Change Attributes", "This is a override of the original item attributes"), EditorStyles.miniButton, GUILayout.ExpandWidth(true)); } GUILayout.EndVertical(); GUILayout.EndHorizontal(); if (GUILayout.Button("x", GUILayout.Width(25), GUILayout.Height(25))) { itemReferenceList.DeleteArrayElementAtIndex(i); EditorUtility.SetDirty(target); serializedObject.ApplyModifiedProperties(); break; } GUILayout.EndHorizontal(); Color backgroundColor = GUI.backgroundColor; GUI.backgroundColor = Color.clear; var _rec = GUILayoutUtility.GetLastRect(); _rec.width -= 100; EditorGUIUtility.AddCursorRect(_rec, MouseCursor.Link); if (GUI.Button(_rec, "")) { if (manager.itemListData.inEdition) { if (ItemListWindow.Instance != null) { ItemListWindow.SetCurrentSelectedItem(manager.itemListData.items.IndexOf(item)); } else { ItemListWindow.CreateWindow(manager.itemListData, manager.itemListData.items.IndexOf(item)); } } else { ItemListWindow.CreateWindow(manager.itemListData, manager.itemListData.items.IndexOf(item)); } } GUILayout.Space(7); GUI.backgroundColor = backgroundColor; if (item.attributes != null && item.attributes.Count > 0) { if (manager.startItems[i].changeAttributes) { if (GUILayout.Button("Reset", EditorStyles.miniButton)) { manager.startItems[i].attributes = null; } if (manager.startItems[i].attributes == null) { manager.startItems[i].attributes = item.attributes.CopyAsNew(); } else if (manager.startItems[i].attributes.Count != item.attributes.Count) { manager.startItems[i].attributes = item.attributes.CopyAsNew(); } else { for (int a = 0; a < manager.startItems[i].attributes.Count; a++) { GUILayout.BeginHorizontal(); GUILayout.Label(manager.startItems[i].attributes[a].name.ToString()); manager.startItems[i].attributes[a].value = EditorGUILayout.IntField(manager.startItems[i].attributes[a].value, GUILayout.MaxWidth(60)); GUILayout.EndHorizontal(); } } } } GUILayout.EndVertical(); } else { itemReferenceList.DeleteArrayElementAtIndex(i); EditorUtility.SetDirty(manager); serializedObject.ApplyModifiedProperties(); break; } } GUILayout.EndScrollView(); GUI.skin.box = boxStyle; GUILayout.EndVertical(); if (GUI.changed) { EditorUtility.SetDirty(manager); serializedObject.ApplyModifiedProperties(); } } var equipPoints = serializedObject.FindProperty("equipPoints"); var applyAttributeEvents = serializedObject.FindProperty("applyAttributeEvents"); var onUseItem = serializedObject.FindProperty("onUseItem"); var onAddItem = serializedObject.FindProperty("onAddItem"); var onLeaveItem = serializedObject.FindProperty("onLeaveItem"); var onDropItem = serializedObject.FindProperty("onDropItem"); var onOpenCloseInventoty = serializedObject.FindProperty("onOpenCloseInventory"); var onEquipItem = serializedObject.FindProperty("onEquipItem"); var onUnequipItem = serializedObject.FindProperty("onUnequipItem"); var onCollectItems = serializedObject.FindProperty("onCollectItems"); if (equipPoints.arraySize != inEdition.Length) { inEdition = new bool[equipPoints.arraySize]; newPointNames = new string[manager.equipPoints.Count]; } if (equipPoints != null) { DrawEquipPoints(equipPoints); } if (applyAttributeEvents != null) { DrawAttributeEvents(applyAttributeEvents); } GUILayout.BeginVertical("box"); showManagerEvents = GUILayout.Toggle(showManagerEvents, showManagerEvents ? "Close Events" : "Open Events", EditorStyles.miniButton); GUI.skin = oldSkin; if (showManagerEvents) { if (onOpenCloseInventoty != null) { EditorGUILayout.PropertyField(onOpenCloseInventoty); } if (onAddItem != null) { EditorGUILayout.PropertyField(onAddItem); } if (onUseItem != null) { EditorGUILayout.PropertyField(onUseItem); } if (onDropItem != null) { EditorGUILayout.PropertyField(onDropItem); } if (onLeaveItem != null) { EditorGUILayout.PropertyField(onLeaveItem); } if (onCollectItems != null) { EditorGUILayout.PropertyField(onCollectItems); } if (onEquipItem != null) { EditorGUILayout.PropertyField(onEquipItem); } if (onUnequipItem != null) { EditorGUILayout.PropertyField(onUnequipItem); } } GUI.skin = skin; GUILayout.EndVertical(); } GUILayout.EndVertical(); if (GUI.changed) { EditorUtility.SetDirty(manager); serializedObject.ApplyModifiedProperties(); } GUI.skin = oldSkin; }
void DrawField(Field field, bool withOverride) { int indentLevel = attributes[field.field].indentLevel; if (indentLevel == 0) { --EditorGUI.indentLevel; //alignment provided by the space for override checkbox } else { for (int i = indentLevel - 1; i > 0; --i) { ++EditorGUI.indentLevel; } } bool enabled = field.IsOverrideableWithDependencies(serializedFrameSettings, defaultFrameSettings); withOverride &= enabled & GUI.enabled; bool shouldBeDisabled = withOverride || !enabled || !GUI.enabled; const int k_IndentPerLevel = 15; const int k_CheckBoxWidth = 15; const int k_CheckboxLabelSeparator = 5; const int k_LabelFieldSeparator = 2; float indentValue = k_IndentPerLevel * EditorGUI.indentLevel; Rect lineRect = GUILayoutUtility.GetRect(1, EditorGUIUtility.singleLineHeight); Rect overrideRect = lineRect; overrideRect.width = k_CheckBoxWidth; Rect labelRect = lineRect; labelRect.x += k_CheckBoxWidth + k_CheckboxLabelSeparator; labelRect.width = EditorGUIUtility.labelWidth - indentValue; Rect fieldRect = lineRect; fieldRect.x = labelRect.xMax + k_LabelFieldSeparator; fieldRect.width -= fieldRect.x - lineRect.x; if (withOverride) { int currentIndent = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; bool mixedValue = serializedFrameSettings.HaveMultipleOverride(field.field); bool originalValue = serializedFrameSettings.GetOverrides(field.field) && !mixedValue; overrideRect.yMin += 4f; // MixedValueState is handled by style for small tickbox for strange reason //EditorGUI.showMixedValue = mixedValue; bool modifiedValue = EditorGUI.Toggle(overrideRect, overrideTooltip, originalValue, mixedValue ? CoreEditorStyles.smallMixedTickbox : CoreEditorStyles.smallTickbox); //EditorGUI.showMixedValue = false; if (originalValue ^ modifiedValue) { serializedFrameSettings.SetOverrides(field.field, modifiedValue); } shouldBeDisabled = !modifiedValue; EditorGUI.indentLevel = currentIndent; } using (new SerializedFrameSettings.TitleDrawingScope(labelRect, field.label, serializedFrameSettings)) { HDEditorUtils.HandlePrefixLabelWithIndent(lineRect, labelRect, field.label); } using (new EditorGUI.DisabledScope(shouldBeDisabled)) { EditorGUI.showMixedValue = serializedFrameSettings.HaveMultipleValue(field.field) || field.hasMixedValues; using (new EditorGUILayout.VerticalScope()) { //the following block will display a default value if provided instead of actual value (case if(true)) if (shouldBeDisabled) { if (field.overridedDefaultValue == null) { switch (attributes[field.field].type) { case FrameSettingsFieldAttribute.DisplayType.BoolAsCheckbox: DrawFieldShape(fieldRect, defaultFrameSettings.IsEnabled(field.field)); break; case FrameSettingsFieldAttribute.DisplayType.BoolAsEnumPopup: //shame but it is not possible to use Convert.ChangeType to convert int into enum in current C# //rely on string parsing for the moment var oldEnumValue = Enum.Parse(attributes[field.field].targetType, defaultFrameSettings.IsEnabled(field.field) ? "1" : "0"); DrawFieldShape(fieldRect, oldEnumValue); break; case FrameSettingsFieldAttribute.DisplayType.Others: var oldValue = field.customGetter(); DrawFieldShape(fieldRect, oldValue); break; default: throw new ArgumentException("Unknown FrameSettingsFieldAttribute"); } } else { DrawFieldShape(fieldRect, field.overridedDefaultValue); } } else { switch (attributes[field.field].type) { case FrameSettingsFieldAttribute.DisplayType.BoolAsCheckbox: bool oldBool = serializedFrameSettings.IsEnabled(field.field) ?? false; bool newBool = (bool)DrawFieldShape(fieldRect, oldBool); if (oldBool ^ newBool) { Undo.RecordObject(serializedFrameSettings.serializedObject.targetObject, "Changed FrameSettings " + field.field); serializedFrameSettings.SetEnabled(field.field, newBool); } break; case FrameSettingsFieldAttribute.DisplayType.BoolAsEnumPopup: //shame but it is not possible to use Convert.ChangeType to convert int into enum in current C# //Also, Enum.Equals and Enum operator!= always send true here. As it seams to compare object reference instead of value. var oldBoolValue = serializedFrameSettings.IsEnabled(field.field); int oldEnumIntValue = -1; int newEnumIntValue; object newEnumValue; if (oldBoolValue.HasValue) { var oldEnumValue = Enum.GetValues(attributes[field.field].targetType).GetValue(oldBoolValue.Value ? 1 : 0); newEnumValue = Convert.ChangeType(DrawFieldShape(fieldRect, oldEnumValue), attributes[field.field].targetType); oldEnumIntValue = ((IConvertible)oldEnumValue).ToInt32(System.Globalization.CultureInfo.CurrentCulture); newEnumIntValue = ((IConvertible)newEnumValue).ToInt32(System.Globalization.CultureInfo.CurrentCulture); } else //in multi edition, do not assume any previous value { newEnumIntValue = EditorGUI.Popup(fieldRect, -1, Enum.GetNames(attributes[field.field].targetType)); newEnumValue = newEnumIntValue < 0 ? null : Enum.GetValues(attributes[field.field].targetType).GetValue(newEnumIntValue); } if (oldEnumIntValue != newEnumIntValue) { Undo.RecordObject(serializedFrameSettings.serializedObject.targetObject, "Changed FrameSettings " + field.field); serializedFrameSettings.SetEnabled(field.field, Convert.ToInt32(newEnumValue) == 1); } break; case FrameSettingsFieldAttribute.DisplayType.Others: var oldValue = field.customGetter(); EditorGUI.BeginChangeCheck(); var newValue = DrawFieldShape(fieldRect, oldValue); // We need an extensive check here, otherwise in some case with boxing or polymorphism // the != operator won't be accurate. (This is the case for enum types). var valuesAreEquals = oldValue == null && newValue == null || oldValue != null && oldValue.Equals(newValue); // If the UI reported a change, we also assign values. // When assigning to a multiple selection, the equals check may fail while there was indeed a change. if (EditorGUI.EndChangeCheck() || !valuesAreEquals) { Undo.RecordObject(serializedFrameSettings.serializedObject.targetObject, "Changed FrameSettings " + field.field); field.customSetter(newValue); } break; default: throw new ArgumentException("Unknown FrameSettingsFieldAttribute"); } } } EditorGUI.showMixedValue = false; } if (indentLevel == 0) { ++EditorGUI.indentLevel; } else { for (int i = indentLevel - 1; i > 0; --i) { --EditorGUI.indentLevel; } } }
public override void OnInspectorGUI() { if (Application.isPlaying) { GUILayout.Label("Mover settings can't be changed in the inspector while the game is running.", EditorStyles.centeredGreyMiniLabel); return; } if (mover == null) { Setup(); return; } GUILayout.Label("Mover Options", EditorStyles.boldLabel); Rect _space; EditorGUI.BeginChangeCheck(); mover.stepHeightRatio = EditorGUILayout.Slider("Step Height Ratio", mover.stepHeightRatio, 0f, 1f); GUILayout.Label("Collider Options", EditorStyles.boldLabel); mover.colliderHeight = EditorGUILayout.FloatField("Collider Height", mover.colliderHeight); mover.colliderThickness = EditorGUILayout.FloatField("Collider Thickness", mover.colliderThickness); mover.colliderOffset = EditorGUILayout.Vector3Field("Collider Offset", mover.colliderOffset); if (EditorGUI.EndChangeCheck()) { mover.RecalculateColliderDimensions(); OnEditorVariableChanged(); } GUILayout.Label("Sensor Options", EditorStyles.boldLabel); EditorGUI.BeginChangeCheck(); mover.sensorType = (Sensor.CastType)EditorGUILayout.EnumPopup("Sensor Type", mover.sensorType); mover.sensorLayermask = EditorGUILayout.MaskField("Layermask", mover.sensorLayermask, physicsLayers); mover.isInDebugMode = EditorGUILayout.Toggle("Debug Mode", mover.isInDebugMode); if (EditorGUI.EndChangeCheck()) { OnEditorVariableChanged(); } if (mover.sensorType == Sensor.CastType.RaycastArray) { GUILayout.Label("Advanced Options", EditorStyles.centeredGreyMiniLabel); } GUILayout.Space(5); if (mover.sensorType == Sensor.CastType.Raycast) { } else if (mover.sensorType == Sensor.CastType.Spherecast) { } else if (mover.sensorType == Sensor.CastType.RaycastArray) { if (raycastArrayPositions == null) { raycastArrayPositions = Sensor.GetRaycastStartPositions(mover.sensorArrayRows, mover.sensorArrayRayCount, mover.sensorArrayRowsAreOffset, 1f); } EditorGUI.BeginChangeCheck(); mover.sensorArrayRayCount = EditorGUILayout.IntSlider("Number", mover.sensorArrayRayCount, 3, 9); mover.sensorArrayRows = EditorGUILayout.IntSlider("Rows", mover.sensorArrayRows, 1, 5); mover.sensorArrayRowsAreOffset = EditorGUILayout.Toggle("Offset Rows", mover.sensorArrayRowsAreOffset); if (EditorGUI.EndChangeCheck()) { raycastArrayPositions = Sensor.GetRaycastStartPositions(mover.sensorArrayRows, mover.sensorArrayRayCount, mover.sensorArrayRowsAreOffset, 1f); OnEditorVariableChanged(); } GUILayout.Space(5); _space = GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none, GUILayout.Height(100)); Rect background = new Rect(_space.x + (_space.width - _space.height) / 2f, _space.y, _space.height, _space.height); EditorGUI.DrawRect(background, Color.grey); float point_size = 3f; Vector2 center = new Vector2(background.x + background.width / 2f, background.y + background.height / 2f); if (raycastArrayPositions != null && raycastArrayPositions.Length != 0) { for (int i = 0; i < raycastArrayPositions.Length; i++) { Vector2 position = center + new Vector2(raycastArrayPositions[i].x, raycastArrayPositions[i].z) * background.width / 2f * 0.9f; EditorGUI.DrawRect(new Rect(position.x - point_size / 2f, position.y - point_size / 2f, point_size, point_size), Color.white); } } if (raycastArrayPositions != null && raycastArrayPositions.Length != 0) { GUILayout.Label("Number of rays = " + raycastArrayPositions.Length, EditorStyles.centeredGreyMiniLabel); } } }
private void DoTreeView() { Rect rect = GUILayoutUtility.GetRect(0, 0, GUILayout.MaxHeight((Screen.height - 280) * 0.5f)); TreeView.OnGUI(rect); }
public override void OnInspectorGUI() { //DrawDefaultInspector(); tk2dCamera _target = (tk2dCamera)target; var frameBorderStyle = EditorStyles.textField; // sanity if (_target.resolutionOverride == null) { _target.resolutionOverride = new tk2dCameraResolutionOverride[0]; GUI.changed = true; } _target.enableResolutionOverrides = EditorGUILayout.Toggle("Resolution overrides", _target.enableResolutionOverrides); if (_target.enableResolutionOverrides) { EditorGUILayout.LabelField("Native resolution", EditorStyles.boldLabel); EditorGUI.indentLevel++; _target.nativeResolutionWidth = EditorGUILayout.IntField("Width", _target.nativeResolutionWidth); _target.nativeResolutionHeight = EditorGUILayout.IntField("Height", _target.nativeResolutionHeight); EditorGUI.indentLevel--; // Overrides EditorGUILayout.LabelField("Overrides", EditorStyles.boldLabel); EditorGUI.indentLevel++; int deleteId = -1; for (int i = 0; i < _target.resolutionOverride.Length; ++i) { var ovr = _target.resolutionOverride[i]; EditorGUILayout.BeginVertical(frameBorderStyle); GUILayout.Space(8); ovr.name = EditorGUILayout.TextField("Name", ovr.name); ovr.width = EditorGUILayout.IntField("Width", ovr.width); ovr.height = EditorGUILayout.IntField("Height", ovr.height); ovr.autoScaleMode = (tk2dCameraResolutionOverride.AutoScaleMode)EditorGUILayout.EnumPopup("Auto Scale", ovr.autoScaleMode); if (ovr.autoScaleMode == tk2dCameraResolutionOverride.AutoScaleMode.None) { EditorGUI.indentLevel++; ovr.scale = EditorGUILayout.FloatField("Scale", ovr.scale); EditorGUI.indentLevel--; } ovr.fitMode = (tk2dCameraResolutionOverride.FitMode)EditorGUILayout.EnumPopup("Fit Mode", ovr.fitMode); if (ovr.fitMode == tk2dCameraResolutionOverride.FitMode.Constant) { EditorGUI.indentLevel++; ovr.offsetPixels.x = EditorGUILayout.FloatField("X", ovr.offsetPixels.x); ovr.offsetPixels.y = EditorGUILayout.FloatField("Y", ovr.offsetPixels.y); EditorGUI.indentLevel--; } GUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(" "); if (GUILayout.Button("Delete", EditorStyles.miniButton)) { deleteId = i; } GUILayout.EndHorizontal(); GUILayout.Space(4); EditorGUILayout.EndVertical(); } if (deleteId != -1) { List <tk2dCameraResolutionOverride> ovr = new List <tk2dCameraResolutionOverride>(_target.resolutionOverride); ovr.RemoveAt(deleteId); _target.resolutionOverride = ovr.ToArray(); GUI.changed = true; Repaint(); } EditorGUILayout.BeginVertical(frameBorderStyle); GUILayout.Space(32); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Add override", GUILayout.ExpandWidth(false))) { tk2dCameraResolutionOverride ovr = new tk2dCameraResolutionOverride(); ovr.name = "Wildcard Override"; ovr.width = -1; ovr.height = -1; ovr.autoScaleMode = tk2dCameraResolutionOverride.AutoScaleMode.FitVisible; ovr.fitMode = tk2dCameraResolutionOverride.FitMode.Center; System.Array.Resize(ref _target.resolutionOverride, _target.resolutionOverride.Length + 1); _target.resolutionOverride[_target.resolutionOverride.Length - 1] = ovr; GUI.changed = true; } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.Space(32); EditorGUILayout.EndVertical(); EditorGUI.indentLevel--; } EditorGUILayout.Space(); EditorGUILayout.LabelField("Camera resolution", EditorStyles.boldLabel); GUIContent toggleLabel = new GUIContent("Force Editor Resolution", "When enabled, forces the resolution in the editor regardless of the size of the game window."); EditorGUI.indentLevel++; bool cameraOverrideChanged = false; tk2dGuiUtility.BeginChangeCheck(); _target.forceResolutionInEditor = EditorGUILayout.Toggle(toggleLabel, _target.forceResolutionInEditor); if (tk2dGuiUtility.EndChangeCheck()) { cameraOverrideChanged = true; } if (_target.forceResolutionInEditor) { tk2dGuiUtility.BeginChangeCheck(); int selectedResolution = EditorGUILayout.Popup("Preset", 0, presetListStr); if (selectedResolution != 0) { var preset = presets[selectedResolution - 1]; _target.forceResolution.x = preset.width; _target.forceResolution.y = preset.height; GUI.changed = true; } _target.forceResolution.x = EditorGUILayout.IntField("Width", (int)_target.forceResolution.x); _target.forceResolution.y = EditorGUILayout.IntField("Height", (int)_target.forceResolution.y); // clamp to a sensible value _target.forceResolution.x = Mathf.Max(_target.forceResolution.x, 50); _target.forceResolution.y = Mathf.Max(_target.forceResolution.y, 50); Rect r = GUILayoutUtility.GetRect(1, 1, GUILayout.ExpandWidth(true), GUILayout.MinHeight(43)); EditorGUI.HelpBox(new Rect(r.x + 4, r.y, r.width - 8, r.height), "Ensure that the the game view resolution is the same as the override chosen here, otherwise the game window will not display correctly.", MessageType.Warning); if (tk2dGuiUtility.EndChangeCheck()) { cameraOverrideChanged = true; } } else { EditorGUILayout.FloatField("Width", _target.TargetResolution.x); EditorGUILayout.FloatField("Height", _target.TargetResolution.y); } EditorGUI.indentLevel--; if (cameraOverrideChanged) { // Propagate values to all tk2dCameras in scene tk2dCamera[] otherCameras = Resources.FindObjectsOfTypeAll(typeof(tk2dCamera)) as tk2dCamera[]; foreach (tk2dCamera thisCamera in otherCameras) { thisCamera.forceResolutionInEditor = _target.forceResolutionInEditor; thisCamera.forceResolution = _target.forceResolution; thisCamera.UpdateCameraMatrix(); } // Update all anchors after that tk2dCameraAnchor[] anchors = Resources.FindObjectsOfTypeAll(typeof(tk2dCameraAnchor)) as tk2dCameraAnchor[]; foreach (var anchor in anchors) { anchor.ForceUpdateTransform(); } } if (GUI.changed) { EditorUtility.SetDirty(target); tk2dCameraAnchor[] allAlignmentObjects = GameObject.FindObjectsOfType(typeof(tk2dCameraAnchor)) as tk2dCameraAnchor[]; foreach (var v in allAlignmentObjects) { EditorUtility.SetDirty(v); } } GUILayout.Space(16.0f); EditorGUILayout.LabelField("Tools", EditorStyles.boldLabel); EditorGUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); if (GUILayout.Button("Create Anchor", EditorStyles.miniButton, GUILayout.ExpandWidth(false))) { tk2dCamera cam = (tk2dCamera)target; GameObject go = new GameObject("Anchor"); go.transform.parent = cam.transform; tk2dCameraAnchor cameraAnchor = go.AddComponent <tk2dCameraAnchor>(); cameraAnchor.tk2dCamera = cam; EditorGUIUtility.PingObject(go); } EditorGUILayout.EndHorizontal(); }
public override void OnInspectorGUI() { //Debug.Log("OnInspectorGUI Called."); Event currentEvent = Event.current; string evt_cmd = currentEvent.commandName; // Get Current Event CommandName to check for Undo Events serializedObject.Update(); EditorGUIUtility.labelWidth = 135; // HEADER GUILayout.Label("<b>TextMeshPro - Sprite Asset</b>", TMP_UIStyleManager.Section_Label); // TEXTMESHPRO SPRITE INFO PANEL GUILayout.Label("Sprite Info", TMP_UIStyleManager.Section_Label); EditorGUI.indentLevel = 1; //GUI.enabled = false; // Lock UI EditorGUILayout.PropertyField(m_spriteAtlas_prop, new GUIContent("Sprite Atlas")); GUI.enabled = true; EditorGUILayout.PropertyField(m_material_prop, new GUIContent("Default Material")); // SPRITE LIST GUI.enabled = true; // Unlock UI GUILayout.Space(10); EditorGUI.indentLevel = 0; if (GUILayout.Button("Sprite List\t\t" + (UI_PanelState.spriteInfoPanel ? uiStateLabel[1] : uiStateLabel[0]), TMP_UIStyleManager.Section_Label)) { UI_PanelState.spriteInfoPanel = !UI_PanelState.spriteInfoPanel; } if (UI_PanelState.spriteInfoPanel) { int arraySize = m_spriteInfoList_prop.arraySize; int itemsPerPage = 10; // (Screen.height - 292) / 80; // Display Glyph Management Tools EditorGUILayout.BeginVertical(TMP_UIStyleManager.Group_Label, GUILayout.ExpandWidth(true)); { // Search Bar implementation #region DISPLAY SEARCH BAR EditorGUILayout.BeginHorizontal(); { EditorGUIUtility.labelWidth = 110f; EditorGUI.BeginChangeCheck(); string searchPattern = EditorGUILayout.TextField("Sprite Search", m_searchPattern, "SearchTextField"); if (EditorGUI.EndChangeCheck() || m_isSearchDirty) { if (string.IsNullOrEmpty(searchPattern) == false) { //GUIUtility.keyboardControl = 0; m_searchPattern = searchPattern.ToLower(System.Globalization.CultureInfo.InvariantCulture).Trim(); // Search Glyph Table for potential matches SearchGlyphTable(m_searchPattern, ref m_searchList); } m_isSearchDirty = false; } string styleName = string.IsNullOrEmpty(m_searchPattern) ? "SearchCancelButtonEmpty" : "SearchCancelButton"; if (GUILayout.Button(GUIContent.none, styleName)) { GUIUtility.keyboardControl = 0; m_searchPattern = string.Empty; } } EditorGUILayout.EndHorizontal(); #endregion // Display Page Navigation if (!string.IsNullOrEmpty(m_searchPattern)) { arraySize = m_searchList.Count; } // Display Page Navigation DisplayGlyphPageNavigation(arraySize, itemsPerPage); } EditorGUILayout.EndVertical(); if (arraySize > 0) { // Display each SpriteInfo entry using the SpriteInfo property drawer. for (int i = itemsPerPage * m_page; i < arraySize && i < itemsPerPage * (m_page + 1); i++) { // Define the start of the selection region of the element. Rect elementStartRegion = GUILayoutUtility.GetRect(0f, 0f, GUILayout.ExpandWidth(true)); int elementIndex = i; if (!string.IsNullOrEmpty(m_searchPattern)) { elementIndex = m_searchList[i]; } SerializedProperty spriteInfo = m_spriteInfoList_prop.GetArrayElementAtIndex(elementIndex); EditorGUI.BeginDisabledGroup(i != m_selectedElement); { EditorGUILayout.BeginVertical(TMP_UIStyleManager.Group_Label, GUILayout.Height(60)); { EditorGUILayout.PropertyField(spriteInfo); } EditorGUILayout.EndVertical(); } EditorGUI.EndDisabledGroup(); // Define the end of the selection region of the element. Rect elementEndRegion = GUILayoutUtility.GetRect(0f, 0f, GUILayout.ExpandWidth(true)); // Check for Item selection Rect selectionArea = new Rect(elementStartRegion.x, elementStartRegion.y, elementEndRegion.width, elementEndRegion.y - elementStartRegion.y); if (DoSelectionCheck(selectionArea)) { m_selectedElement = i; GUIUtility.keyboardControl = 0; } // Draw & Handle Section Area if (m_selectedElement == i) { // Draw selection highlight TMP_EditorUtility.DrawBox(selectionArea, 2f, new Color32(40, 192, 255, 255)); // Draw options to Add or Remove Sprites Rect controlRect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight * 1f); controlRect.width /= 8; // Add new Sprite controlRect.x += controlRect.width * 6; if (GUI.Button(controlRect, "+")) { m_spriteInfoList_prop.arraySize += 1; int index = m_spriteInfoList_prop.arraySize - 1; SerializedProperty spriteInfo_prop = m_spriteInfoList_prop.GetArrayElementAtIndex(index); // Copy properties of the selected element CopySerializedProperty(m_spriteInfoList_prop.GetArrayElementAtIndex(elementIndex), ref spriteInfo_prop); spriteInfo_prop.FindPropertyRelative("id").intValue = index; serializedObject.ApplyModifiedProperties(); m_isSearchDirty = true; } // Delete selected Sprite controlRect.x += controlRect.width; if (m_selectedElement == -1) { GUI.enabled = false; } if (GUI.Button(controlRect, "-")) { m_spriteInfoList_prop.DeleteArrayElementAtIndex(elementIndex); m_selectedElement = -1; serializedObject.ApplyModifiedProperties(); m_isSearchDirty = true; return; } } } } DisplayGlyphPageNavigation(arraySize, itemsPerPage); EditorGUIUtility.labelWidth = 40f; EditorGUIUtility.fieldWidth = 20f; GUILayout.Space(5f); // GLOBAL TOOLS #region Global Tools GUI.enabled = true; EditorGUILayout.BeginVertical(TMP_UIStyleManager.Group_Label); Rect rect = EditorGUILayout.GetControlRect(false, 40); float width = (rect.width - 75f) / 4; EditorGUI.LabelField(rect, "Global Offsets & Scale", EditorStyles.boldLabel); rect.x += 70; bool old_ChangedState = GUI.changed; GUI.changed = false; m_xOffset = EditorGUI.FloatField(new Rect(rect.x + 5f + width * 0, rect.y + 20, width - 5f, 18), new GUIContent("OX:"), m_xOffset); if (GUI.changed) { UpdateGlobalProperty("xOffset", m_xOffset); } m_yOffset = EditorGUI.FloatField(new Rect(rect.x + 5f + width * 1, rect.y + 20, width - 5f, 18), new GUIContent("OY:"), m_yOffset); if (GUI.changed) { UpdateGlobalProperty("yOffset", m_yOffset); } m_xAdvance = EditorGUI.FloatField(new Rect(rect.x + 5f + width * 2, rect.y + 20, width - 5f, 18), new GUIContent("ADV."), m_xAdvance); if (GUI.changed) { UpdateGlobalProperty("xAdvance", m_xAdvance); } m_scale = EditorGUI.FloatField(new Rect(rect.x + 5f + width * 3, rect.y + 20, width - 5f, 18), new GUIContent("SF."), m_scale); if (GUI.changed) { UpdateGlobalProperty("scale", m_scale); } EditorGUILayout.EndVertical(); #endregion GUI.changed = old_ChangedState; } if (serializedObject.ApplyModifiedProperties() || evt_cmd == k_UndoRedo || isAssetDirty) { isAssetDirty = false; EditorUtility.SetDirty(target); //TMPro_EditorUtility.RepaintAll(); // Consider SetDirty } // Clear selection if mouse event was not consumed. GUI.enabled = true; if (currentEvent.type == EventType.mouseDown && currentEvent.button == 0) { m_selectedElement = -1; } }
public void OnGUI() { #if UNITY_2017_1_OR_NEWER if (EditorApplication.isCompiling) { EditorGUILayout.LabelField("Compiling..."); return; } #endif if (viuLogo == null) { var currentDir = Path.GetDirectoryName(AssetDatabase.GetAssetPath(MonoScript.FromScriptableObject(this))); var texturePath = currentDir.Substring(0, currentDir.Length - "Scripts/Editor".Length) + "Textures/VIU_logo.png"; viuLogo = AssetDatabase.LoadAssetAtPath <Texture2D>(texturePath); } if (viuLogo != null) { GUI.DrawTexture(GUILayoutUtility.GetRect(position.width, 124, GUI.skin.box), viuLogo, ScaleMode.ScaleToFit); } if (showNewVersion) { EditorGUILayout.HelpBox("New version available:", MessageType.Warning); GUILayout.Label("Current version: " + VIUVersion.current); GUILayout.Label("New version: " + latestVersion); if (!string.IsNullOrEmpty(latestRepoInfo.body)) { GUILayout.Label("Release notes:"); releaseNoteScrollPosition = GUILayout.BeginScrollView(releaseNoteScrollPosition, GUILayout.Height(250f)); EditorGUILayout.HelpBox(latestRepoInfo.body, MessageType.None); GUILayout.EndScrollView(); } GUILayout.BeginHorizontal(); { if (GUILayout.Button(new GUIContent("Get Latest Version", "Goto " + pluginUrl))) { Application.OpenURL(pluginUrl); } GUILayout.FlexibleSpace(); toggleSkipThisVersion = GUILayout.Toggle(toggleSkipThisVersion, "Do not prompt for this version again."); } GUILayout.EndHorizontal(); } UpdateIgnoredNotifiedSettingsCount(true); if (notifiedSettingsCount > 0) { GUILayout.EndScrollView(); if (ignoredSettingsCount > 0) { if (GUILayout.Button("Clear All Ignores(" + ignoredSettingsCount + ")")) { foreach (var setting in s_settings) { setting.DeleteIgnore(); } } } GUILayout.BeginHorizontal(); { if (GUILayout.Button("Accept All(" + notifiedSettingsCount + ")")) { for (int i = 10; i >= 0 && notifiedSettingsCount > 0; --i) { foreach (var setting in s_settings) { if (!setting.SkipCheck() && !setting.IsIgnored()) { setting.AcceptRecommendValue(); } } VIUSettingsEditor.ApplySDKChanges(); UpdateIgnoredNotifiedSettingsCount(false); } } if (GUILayout.Button("Ignore All(" + notifiedSettingsCount + ")")) { foreach (var setting in s_settings) { if (!setting.SkipCheck() && !setting.IsIgnored() && !setting.IsUsingRecommendedValue()) { setting.DoIgnore(); } } } } GUILayout.EndHorizontal(); } else if (shouldNotifiedSettingsCount > 0) { EditorGUILayout.HelpBox("Some recommended settings ignored.", MessageType.Warning); GUILayout.FlexibleSpace(); if (GUILayout.Button("Clear All Ignores(" + ignoredSettingsCount + ")")) { foreach (var setting in s_settings) { setting.DeleteIgnore(); } } } else { EditorGUILayout.HelpBox("All recommended settings applied.", MessageType.Info); GUILayout.FlexibleSpace(); } VIUSettingsEditor.ApplySDKChanges(); if (VIUProjectSettings.hasChanged) { // save ignore keys VIUProjectSettings.Save(); } if (GUILayout.Button("Close")) { Close(); } }
public override void OnInspectorGUI() { m_object.Update(); DrawDefaultInspector(); _2dxFX_GrassFX _2dxScript = (_2dxFX_GrassFX)target; Texture2D icon = Resources.Load("2dxfxinspector-anim") as Texture2D; if (icon) { Rect r; float ih = icon.height; float iw = icon.width; float result = ih / iw; float w = Screen.width; result = result * w; r = GUILayoutUtility.GetRect(ih, result); EditorGUI.DrawTextureTransparent(r, icon); } EditorGUILayout.PropertyField(m_object.FindProperty("ActiveUpdate"), new GUIContent("Active Update", "Active Update, for animation / Animator only")); EditorGUILayout.PropertyField(m_object.FindProperty("ForceMaterial"), new GUIContent("Shared Material", "Use a unique material, reduce drastically the use of draw call")); if (_2dxScript.ForceMaterial == null) { _2dxScript.ActiveChange = true; } else { if (GUILayout.Button("Remove Shared Material")) { _2dxScript.ForceMaterial = null; _2dxScript.ShaderChange = 1; _2dxScript.ActiveChange = true; _2dxScript.CallUpdate(); } EditorGUILayout.PropertyField(m_object.FindProperty("ActiveChange"), new GUIContent("Change Material Property", "Change The Material Property")); } if (_2dxScript.ActiveChange) { EditorGUILayout.BeginVertical("Box"); Texture2D icone = Resources.Load("2dxfx-icon-distortion") as Texture2D; EditorGUILayout.PropertyField(m_object.FindProperty("Heat"), new GUIContent("Heat Distortion", icone, "Change the distortion of the heat")); icone = Resources.Load("2dxfx-icon-time") as Texture2D; EditorGUILayout.PropertyField(m_object.FindProperty("Speed"), new GUIContent("Time Speed", icone, "Change the time speed")); EditorGUILayout.BeginVertical("Box"); icone = Resources.Load("2dxfx-icon-fade") as Texture2D; EditorGUILayout.PropertyField(m_object.FindProperty("_Alpha"), new GUIContent("Fading", icone, "Fade from nothing to showing")); EditorGUILayout.EndVertical(); EditorGUILayout.EndVertical(); } m_object.ApplyModifiedProperties(); }
void ConnectionStateGUI() { if (s_ConnectedTexture == null) { s_ConnectedTexture = EditorGUIUtility.LoadIconRequired("sv_icon_dot3_sml"); s_ConnectingTexture = EditorGUIUtility.LoadIconRequired("sv_icon_dot4_sml"); s_DisconnectedTexture = EditorGUIUtility.LoadIconRequired("sv_icon_dot6_sml"); } Texture2D iconTexture; GUIContent labelContent; GUIContent buttonContent; HolographicStreamerConnectionState connectionState = PerceptionRemoting.GetConnectionState(); switch (connectionState) { case HolographicStreamerConnectionState.Disconnected: default: iconTexture = s_DisconnectedTexture; labelContent = s_ConnectionStateDisconnectedText; buttonContent = s_ConnectionButtonConnectText; break; case HolographicStreamerConnectionState.Connecting: iconTexture = s_ConnectingTexture; labelContent = s_ConnectionStateConnectingText; buttonContent = s_ConnectionButtonDisconnectText; break; case HolographicStreamerConnectionState.Connected: iconTexture = s_ConnectedTexture; labelContent = s_ConnectionStateConnectedText; buttonContent = s_ConnectionButtonDisconnectText; break; } EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(s_ConnectionStatusText, "Button"); float iconSize = EditorGUIUtility.singleLineHeight; Rect iconRect = GUILayoutUtility.GetRect(iconSize, iconSize, GUILayout.ExpandWidth(false)); GUI.DrawTexture(iconRect, iconTexture); EditorGUILayout.LabelField(labelContent); EditorGUILayout.EndHorizontal(); EditorGUI.BeginDisabledGroup(m_InPlayMode); bool pressed = EditorGUILayout.DropdownButton(buttonContent, FocusType.Passive, EditorStyles.miniButton); EditorGUI.EndDisabledGroup(); if (pressed) { if (EditorGUIUtility.editingTextField) { EditorGUIUtility.editingTextField = false; GUIUtility.keyboardControl = 0; } //we delay the call to let the RemoteMachineAddress control commit the value EditorApplication.CallDelayed(() => { HandleButtonPress(); }, 0f); } }
public static bool Foldout(ref bool display, bool value, bool hasToggle, string title) { var style = new GUIStyle("ShurikenModuleTitle");// BG style.font = EditorStyles.boldLabel.font; style.fontSize = EditorStyles.boldLabel.fontSize + 3; style.border = new RectOffset(15, 7, 4, 4); style.fixedHeight = 30; style.contentOffset = new Vector2(50f, 0f); var rect = GUILayoutUtility.GetRect(16f, 25f, style);// Box rect.yMin -= 10; rect.yMax += 10; GUI.Box(rect, "", style); GUIStyle titleStyle = new GUIStyle(EditorStyles.boldLabel);// Font titleStyle.fontSize += 2; EditorGUI.PrefixLabel( new Rect( hasToggle ? rect.x + 50f : rect.x + 25f, rect.y + 6f, 13f, 13f),// title pos new GUIContent(title), titleStyle); var triangleRect = new Rect(rect.x + 4f, rect.y + 8f, 13f, 13f); // triangle var clickRect = new Rect(rect); // click clickRect.height -= 15f; var toggleRect = new Rect(triangleRect.x + 20f, triangleRect.y + 0f, 13f, 13f); var e = Event.current; if (e.type == EventType.Repaint) { EditorStyles.foldout.Draw(triangleRect, false, false, display, false); if (hasToggle) { if (EditorGUI.showMixedValue) { GUI.Toggle(toggleRect, false, "", new GUIStyle("ToggleMixed")); } else { GUI.Toggle(toggleRect, value, ""); } } } if (hasToggle && e.type == EventType.MouseDown && toggleRect.Contains(e.mousePosition)) { value = !value; e.Use(); } else if (e.type == EventType.MouseDown && clickRect.Contains(e.mousePosition)) { display = !display; e.Use(); } return(value); }
private void ListGUI(Element[] tree, GroupElement parent) { parent.scroll = GUILayout.BeginScrollView(parent.scroll); EditorGUIUtility.SetIconSize(new Vector2(16, 16)); List <Element> children = GetChildren(tree, parent); var hasDouble = false; if (hasSearch) { for (int i = 0; i < children.Count; i++) { var name = children[i].content.text; for (int j = i + 1; j < children.Count; j++) { var name2 = children[j].content.text; if (name == name2) { hasDouble = true; break; } } } } var rect1 = new Rect(); for (int index = 0; index < children.Count; index++) { var e = children[index]; var rect2 = GUILayoutUtility.GetRect(16, 20, GUILayout.ExpandWidth(true)); if ((Event.current.type == EventType.MouseMove || Event.current.type == EventType.MouseDown) && (parent.selectedIndex != index && rect2.Contains(Event.current.mousePosition))) { parent.selectedIndex = index; currentSelectedIndex = index; tooltip = e.content.tooltip; Repaint(); } var flag = false; if (index == parent.selectedIndex) { flag = true; rect1 = rect2; } if (Event.current.type == EventType.Repaint) { var isExecuteElement = e is ExecuteElement; if (isExecuteElement) { styles.componentButton.Draw(rect2, hasDouble ? (e as ExecuteElement).content2 : e.content, false, false, flag, flag); } else { styles.groupButton.Draw(rect2, e.content, false, false, flag, flag); var position = new Rect(rect2.x + rect2.width - 13, rect2.y + 4, 13, 13); styles.rightArrow.Draw(position, false, false, false, false); } } if (Event.current.type == EventType.MouseDown && rect2.Contains(Event.current.mousePosition)) { Event.current.Use(); parent.selectedIndex = index; GoToChild(e, true); } } EditorGUIUtility.SetIconSize(Vector2.zero); GUILayout.EndScrollView(); if (!scrollToSelected || Event.current.type != EventType.Repaint) { return; } scrollToSelected = false; var lastRect = GUILayoutUtility.GetLastRect(); if (rect1.yMax - lastRect.height > parent.scroll.y) { parent.scroll.y = rect1.yMax - lastRect.height; Repaint(); } if (rect1.y >= parent.scroll.y) { return; } parent.scroll.y = rect1.y; Repaint(); }
void OnGUI() { using (var scroll = new EditorGUILayout.ScrollViewScope(_scroll, GUILayout.Width(position.width), GUILayout.Height(position.height))) { using (new EditorGUILayout.HorizontalScope()) { GUILayout.Label(_set.name, EditorStyles.boldLabel); GUILayout.FlexibleSpace(); if (GUILayout.Button("Refresh")) { BuildTree(); } } var right = 0.0f; var bottom = 0.0f; BeginWindows(); foreach (var node in _nodes) { node.Rect = GUI.Window(node.Id, node.Rect, WindowFunction, node.Instruction.name); if (GUI.Button(node.Rect, node.Instruction.name)) { Selection.activeObject = node.Instruction; } if (node.Rect.xMax > right) { right = node.Rect.xMax; } if (node.Rect.yMax > bottom) { bottom = node.Rect.yMax; } } EndWindows(); foreach (var node in _nodes) { if (node.Children != null) { var fromX = node.Rect.xMax; var fromY = node.Rect.center.y; foreach (var child in node.Children) { var toX = child.Rect.xMin; var toY = child.Rect.center.y; Handles.DrawLine(new Vector3(fromX, fromY), new Vector3(toX, toY)); } } if (node.NextSibling != null) { var fromX = node.Rect.center.x; var fromY = node.Rect.yMax; var toX = node.NextSibling.Rect.center.x; var toY = node.NextSibling.Rect.yMin; Handles.DrawLine(new Vector3(fromX, fromY), new Vector3(toX, toY)); } } GUILayoutUtility.GetRect(right, bottom); _scroll = scroll.scrollPosition; } }
private void OnGUI() { if (!initializedGUI) { InitializeGUI(); initializedGUI = true; } if (fakeSearchResultTree != null && Event.current.type == EventType.Layout) { searchResultTree = fakeSearchResultTree; fakeSearchResultTree = null; stack.Clear(); stack.Add(searchResultTree[0] as GroupElement); if (GetChildren(activeTree, activeParent).Count < 1) { activeParent.selectedIndex = -1; } else { activeParent.selectedIndex = 0; } } GUI.Label(new Rect(0, 0, position.width, position.height), GUIContent.none, styles.background); if (dirtyList) { CreateTree(); } HandleKeyboard(); GUILayout.Space(7); var rect = GUILayoutUtility.GetRect(10, 20); rect.x += 8; rect.width -= 16; var str = SearchField(rect, search); if (str != search || delayedSearch != null) { if (!isAnimating) { search = delayedSearch ?? str; RebuildSearch(); delayedSearch = null; } else { delayedSearch = str; } } if (searchState == SearchState.Searching) { var pos1 = position; pos1.x = position.width * (1 - anim) + 1f; pos1.y = 30; pos1.height -= 30; pos1.width -= 2; GUILayout.BeginArea(pos1); rect = GUILayoutUtility.GetRect(10, 25); GUI.Label(rect, "Searching", styles.header); GUILayout.EndArea(); } else { ListGUI(activeTree, anim, GetElementRelative(0), GetElementRelative(-1)); if (anim < 1) { ListGUI(activeTree, anim + 1, GetElementRelative(-1), GetElementRelative(-2)); } if (tooltipTimer > 0.5f && !string.IsNullOrEmpty(tooltip)) { var pos = Event.current.mousePosition; if (pos.y > 55) { var size = styles.tooltip.CalcSize(new GUIContent(tooltip)); pos.y -= size.y; var tooltipRect = new Rect(pos, size); GUI.Box(tooltipRect, GUIContent.none, styles.background); GUI.Box(new Rect(tooltipRect.x - 1, tooltipRect.y - 1, tooltipRect.width + 2, tooltipRect.height + 2), GUIContent.none, styles.background); GUI.Label(tooltipRect, tooltip, styles.tooltip); } } if (!isAnimating || Event.current.type != EventType.Repaint) { return; } var ticks = DateTime.Now.Ticks; var num = (ticks - lastTime) / 1E+07f; lastTime = ticks; anim = Mathf.MoveTowards(anim, animTarget, num * 4); if (animTarget == 0 && anim == 0) { anim = 1; animTarget = 1; stack.RemoveAt(stack.Count - 1); } Repaint(); } }
protected bool VectorGUI() { bool changed = false; EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(m_VectorGraphics, m_VectorContent); if (EditorGUI.EndChangeCheck()) { MethodInfo Refresh = typeof(SVGImage).GetMethod("Refresh", BindingFlags.NonPublic | BindingFlags.Instance); Refresh.Invoke(target, null); changed = true; SVGImage.Type oldType = (SVGImage.Type)m_Type.enumValueIndex; SVGAsset vectorGraphics = m_VectorGraphics.objectReferenceValue as SVGAsset; if (vectorGraphics != null) { if (vectorGraphics.border.SqrMagnitude() > 0) { m_Type.enumValueIndex = (int)SVGImage.Type.Sliced; } else if (oldType == SVGImage.Type.Sliced) { m_Type.enumValueIndex = (int)SVGImage.Type.Simple; } } } #if DEBUG_MATERIALS EditorGUILayout.ObjectField("Default Material", image.defaultMaterialTest, typeof(Material), true); EditorGUILayout.ObjectField("Mask Material", image.maskMaterialTest, typeof(Material), true); EditorGUILayout.ObjectField("Current Material", image.currenttMaterialTest, typeof(Material), true); EditorGUILayout.ObjectField("Render Material", image.renderMaterialTest, typeof(Material), true); EditorGUILayout.ObjectField("Canvas Render Material", image.canvasRenderer.GetMaterial(), typeof(Material), true); #endif SVGAsset newVectorGraphics = m_VectorGraphics.objectReferenceValue as SVGAsset; if (newVectorGraphics) { if (newVectorGraphics.format != SVGAssetFormat.uGUI) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.HelpBox("Vector Graphics Asset must be set to uGUI format", MessageType.Error); if (GUILayout.Button("Apply")) { FieldInfo _editor_format = typeof(SVGAsset).GetField("_format", BindingFlags.NonPublic | BindingFlags.Instance); _editor_format.SetValue(newVectorGraphics, (int)SVGAssetFormat.uGUI); MethodInfo _editor_ApplyChanges = typeof(SVGAsset).GetMethod("_editor_ApplyChanges", BindingFlags.NonPublic | BindingFlags.Instance); _editor_ApplyChanges.Invoke(newVectorGraphics, new object[] { false }); SVGAssetEditor.UpdateInstances(new SVGAsset[] { newVectorGraphics }); changed = true; } EditorGUILayout.EndHorizontal(); } else { #if UNITY_4_6 || UNITY_4_7 || UNITY_4_8 || UNITY_4_9 || UNITY_5_0 || UNITY_5_1 int vertexCount = newVectorGraphics.uiVertexCount; int percent = Mathf.RoundToInt(((float)vertexCount / 65534f) * 100f); if (vertexCount > 128) { GUIContent infoContent = new GUIContent("Asset takes " + percent + "% of this Canvas, " + vertexCount + " vertices" + "\nUI Canvas has limit of 65,534 vertices in total."); EditorStyles s_Current = (EditorStyles)typeof(EditorStyles).GetField("s_Current", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null); GUIStyle helpBoxStyle = (GUIStyle)typeof(EditorStyles).GetField("m_HelpBox", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(s_Current); Rect helpRect = GUILayoutUtility.GetRect(infoContent, helpBoxStyle); EditorGUI.ProgressBar(helpRect, percent * 0.01f, ""); EditorGUI.HelpBox(helpRect, infoContent.text, MessageType.Warning); } #endif } } return(changed); }
void OnGUI() { if (m_Info != null && m_DebugGui) { GUI.depth = s_GuiDepth; GUI.matrix = Matrix4x4.TRS(new Vector3(m_GuiPositionX, 10f, 0f), Quaternion.identity, new Vector3(s_GuiScale, s_GuiScale, 1.0f)); GUILayout.BeginVertical("box", GUILayout.MaxWidth(s_GuiWidth)); GUILayout.Label(System.IO.Path.GetFileName(m_VideoPath)); GUILayout.Label("Dimensions: " + m_Info.GetVideoWidth() + "x" + m_Info.GetVideoHeight() + "@" + m_Info.GetVideoFrameRate().ToString("F2")); GUILayout.Label("Time: " + (m_Control.GetCurrentTimeMs() * 0.001f).ToString("F1") + "s / " + (m_Info.GetDurationMs() * 0.001f).ToString("F1") + "s"); GUILayout.Label("Rate: " + m_Info.GetVideoDisplayRate().ToString("F2") + "Hz"); if (TextureProducer != null && TextureProducer.GetTexture() != null) { // Show texture without and with alpha blending GUILayout.BeginHorizontal(); Rect r1 = GUILayoutUtility.GetRect(32f, 32f); GUILayout.Space(8f); Rect r2 = GUILayoutUtility.GetRect(32f, 32f); Matrix4x4 prevMatrix = GUI.matrix; if (TextureProducer.RequiresVerticalFlip()) { GUIUtility.ScaleAroundPivot(new Vector2(1f, -1f), new Vector2(0, r1.y + (r1.height / 2))); } GUI.DrawTexture(r1, TextureProducer.GetTexture(), ScaleMode.ScaleToFit, false); GUI.DrawTexture(r2, TextureProducer.GetTexture(), ScaleMode.ScaleToFit, true); GUI.matrix = prevMatrix; GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } #if AVPROVIDEO_DEBUG_DISPLAY_EVENTS // Dirty code to hack in an event monitor if (Event.current.type == EventType.Repaint) { this.Events.RemoveListener(OnMediaPlayerEvent); this.Events.AddListener(OnMediaPlayerEvent); UpdateEventLogs(); } if (_eventLog != null && _eventLog.Count > 0) { GUILayout.Label("Recent Events: "); GUILayout.BeginVertical("box"); int eventIndex = 0; foreach (string eventString in _eventLog) { GUI.color = Color.white; if (eventIndex == 0) { GUI.color = new Color(1f, 1f, 1f, _eventTimer); } GUILayout.Label(eventString); eventIndex++; } GUILayout.EndVertical(); GUI.color = Color.white; } #endif GUILayout.EndVertical(); } }
public override void OnInspectorGUI() { serializedObject.Update(); EditorGUILayout.PropertyField(m_IsGlobal); if (!m_IsGlobal.boolValue) // Blend radius is not needed for global volumes { EditorGUILayout.PropertyField(m_BlendRadius); } EditorGUILayout.PropertyField(m_Weight); EditorGUILayout.PropertyField(m_Priority); var assetHasChanged = false; var showCopy = m_Profile.objectReferenceValue != null; var multiEdit = m_Profile.hasMultipleDifferentValues; // The layout system sort of break alignement when mixing inspector fields with custom // layouted fields, do the layout manually instead var buttonWidth = showCopy ? 45 : 60; var indentOffset = EditorGUI.indentLevel * 15f; var lineRect = GUILayoutUtility.GetRect(1, EditorGUIUtility.singleLineHeight); var labelRect = new Rect(lineRect.x, lineRect.y, EditorGUIUtility.labelWidth - indentOffset, lineRect.height); var fieldRect = new Rect(labelRect.xMax, lineRect.y, lineRect.width - labelRect.width - buttonWidth * (showCopy ? 2 : 1), lineRect.height); var buttonNewRect = new Rect(fieldRect.xMax, lineRect.y, buttonWidth, lineRect.height); var buttonCopyRect = new Rect(buttonNewRect.xMax, lineRect.y, buttonWidth, lineRect.height); EditorGUI.PrefixLabel(labelRect, EditorUtilities.GetContent("Profile|A reference to a profile asset.")); using (var scope = new EditorGUI.ChangeCheckScope()) { EditorGUI.BeginProperty(fieldRect, GUIContent.none, m_Profile); var profile = (PostProcessProfile)EditorGUI.ObjectField(fieldRect, m_Profile.objectReferenceValue, typeof(PostProcessProfile), false); if (scope.changed) { assetHasChanged = true; m_Profile.objectReferenceValue = profile; } EditorGUI.EndProperty(); } using (new EditorGUI.DisabledScope(multiEdit)) { if (GUI.Button(buttonNewRect, EditorUtilities.GetContent("New|Create a new profile."), showCopy ? EditorStyles.miniButtonLeft : EditorStyles.miniButton)) { // By default, try to put assets in a folder next to the currently active // scene file. If the user isn't a scene, put them in root instead. var targetName = m_Target.name; var scene = m_Target.gameObject.scene; var asset = ProfileFactory.CreatePostProcessProfile(scene, targetName); m_Profile.objectReferenceValue = asset; assetHasChanged = true; } if (showCopy && GUI.Button(buttonCopyRect, EditorUtilities.GetContent( "Clone|Create a new profile and copy the content of the currently assigned profile."), EditorStyles.miniButtonRight)) { // Duplicate the currently assigned profile and save it as a new profile var origin = (PostProcessProfile)m_Profile.objectReferenceValue; var path = AssetDatabase.GetAssetPath(origin); path = AssetDatabase.GenerateUniqueAssetPath(path); var asset = Instantiate(origin); asset.settings.Clear(); AssetDatabase.CreateAsset(asset, path); foreach (var item in origin.settings) { var itemCopy = Instantiate(item); itemCopy.hideFlags = HideFlags.HideInInspector | HideFlags.HideInHierarchy; itemCopy.name = item.name; asset.settings.Add(itemCopy); AssetDatabase.AddObjectToAsset(itemCopy, asset); } AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); m_Profile.objectReferenceValue = asset; assetHasChanged = true; } } EditorGUILayout.Space(); if (m_Profile.objectReferenceValue == null) { if (assetHasChanged) { m_EffectList.Clear(); // Asset wasn't null before, do some cleanup } EditorGUILayout.HelpBox( "Assign a Post-process Profile to this volume using the \"Asset\" field or create one automatically by clicking the \"New\" button.\nAssets are automatically put in a folder next to your scene file. If you scene hasn't been saved yet they will be created at the root of the Assets folder.", MessageType.Info); } else { if (assetHasChanged) { RefreshEffectListEditor((PostProcessProfile)m_Profile.objectReferenceValue); } if (!multiEdit) { m_EffectList.OnGUI(); } } serializedObject.ApplyModifiedProperties(); }
public override void OnInspectorGUI() { m_object.Update(); DrawDefaultInspector(); _2dxFX_AL_PixelDie _2dxScript = (_2dxFX_AL_PixelDie)target; Texture2D icon = Resources.Load("2dxfxinspector") as Texture2D; if (icon) { Rect r; float ih = icon.height; float iw = icon.width; float result = ih / iw; float w = Screen.width; result = result * w; r = GUILayoutUtility.GetRect(ih, result); EditorGUI.DrawTextureTransparent(r, icon); } EditorGUILayout.LabelField("Advanced Lightning may work on mobile high-end devices and may be slower than the Standard 2DxFX effects due to is lightning system. Use it only if you need it.", EditorStyles.helpBox); EditorGUILayout.PropertyField(m_object.FindProperty("AddShadow"), new GUIContent("Add Shadow", "Use a unique material, reduce drastically the use of draw call")); if (_2dxScript.AddShadow) { EditorGUILayout.PropertyField(m_object.FindProperty("ReceivedShadow"), new GUIContent("Received Shadow : No Transparency and Use Z Buffering instead of Sprite Order Layers", "Received Shadow, No Transparency and Use Z Buffering instead of Sprite Order Layers")); if (_2dxScript.ReceivedShadow) { EditorGUILayout.LabelField("Note 1: Blend Fusion work but without transparency\n", EditorStyles.helpBox); } } // Mode Blend string BlendMethode = "Normal"; if (_2dxScript.BlendMode == 0) { BlendMethode = "Normal"; } if (_2dxScript.BlendMode == 1) { BlendMethode = "Additive"; } if (_2dxScript.BlendMode == 2) { BlendMethode = "Darken"; } if (_2dxScript.BlendMode == 3) { BlendMethode = "Lighten"; } if (_2dxScript.BlendMode == 4) { BlendMethode = "Linear Burn"; } if (_2dxScript.BlendMode == 5) { BlendMethode = "Linear Dodge"; } if (_2dxScript.BlendMode == 6) { BlendMethode = "Multiply"; } if (_2dxScript.BlendMode == 7) { BlendMethode = "Soft Aditive"; } if (_2dxScript.BlendMode == 8) { BlendMethode = "2x Multiplicative"; } EditorGUILayout.PropertyField(m_object.FindProperty("ForceMaterial"), new GUIContent("Shared Material", "Use a unique material, reduce drastically the use of draw call")); if (_2dxScript.ForceMaterial == null) { _2dxScript.ActiveChange = true; } else { if (GUILayout.Button("Remove Shared Material")) { _2dxScript.ForceMaterial = null; _2dxScript.ShaderChange = 1; _2dxScript.ActiveChange = true; _2dxScript.CallUpdate(); } EditorGUILayout.PropertyField(m_object.FindProperty("ActiveChange"), new GUIContent("Change Material Property", "Change The Material Property")); } if (_2dxScript.ActiveChange) { EditorGUILayout.BeginVertical("Box"); Texture2D icone = Resources.Load("2dxfx-icon-time") as Texture2D; EditorGUILayout.PropertyField(m_object.FindProperty("_Value1"), new GUIContent("Pixel Dead Value", icone, "Change the pixel value 0 = Full / 1 = Nothing")); EditorGUILayout.BeginVertical("Box"); icone = Resources.Load("2dxfx-icon-fade") as Texture2D; EditorGUILayout.PropertyField(m_object.FindProperty("_Alpha"), new GUIContent("Fading", icone, "Fade from nothing to showing")); EditorGUILayout.EndVertical(); EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical("Box"); EditorGUILayout.LabelField("Change Blend Fusion = " + BlendMethode, EditorStyles.whiteLargeLabel); if (_2dxScript.ReceivedShadow) { EditorGUILayout.LabelField("Note: Blend Fusion is not working correctly with Received Shadow", EditorStyles.helpBox); } EditorGUILayout.BeginHorizontal("Box"); if (GUILayout.Button("Normal", EditorStyles.toolbarButton)) { _2dxScript.BlendMode = 0; _2dxScript.CallUpdate(); } if (GUILayout.Button("Additive", EditorStyles.toolbarButton)) { _2dxScript.BlendMode = 1; _2dxScript.CallUpdate(); } if (GUILayout.Button("Darken", EditorStyles.toolbarButton)) { _2dxScript.BlendMode = 2; _2dxScript.CallUpdate(); } if (GUILayout.Button("Lighten", EditorStyles.toolbarButton)) { _2dxScript.BlendMode = 3; _2dxScript.CallUpdate(); } if (GUILayout.Button("Linear Burn", EditorStyles.toolbarButton)) { _2dxScript.BlendMode = 4; _2dxScript.CallUpdate(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal("Box"); if (GUILayout.Button("Linear Dodge", EditorStyles.toolbarButton)) { _2dxScript.BlendMode = 5; _2dxScript.CallUpdate(); } if (GUILayout.Button("Multiply", EditorStyles.toolbarButton)) { _2dxScript.BlendMode = 6; _2dxScript.CallUpdate(); } if (GUILayout.Button("Soft Aditive", EditorStyles.toolbarButton)) { _2dxScript.BlendMode = 7; _2dxScript.CallUpdate(); } if (GUILayout.Button("2x Multiplicative", EditorStyles.toolbarButton)) { _2dxScript.BlendMode = 8; _2dxScript.CallUpdate(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); } m_object.ApplyModifiedProperties(); }