mirror of
https://github.com/Siccity/xNode.git
synced 2026-03-26 22:49:02 +08:00
Experimental: Apply custom GUISkin
This commit is contained in:
parent
d481075e66
commit
491383e031
@ -45,5 +45,22 @@ namespace XNodeEditor {
|
|||||||
EditorStylesInstance = EditorStylesInstanceField.GetValue(null) as EditorStyles;
|
EditorStylesInstance = EditorStylesInstanceField.GetValue(null) as EditorStyles;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void SetSkin(GUISkin skin)
|
||||||
|
{
|
||||||
|
InvalidateCache();
|
||||||
|
GUI.skin = skin;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void InvalidateCache()
|
||||||
|
{
|
||||||
|
var field = typeof(EditorStyles).GetField("s_CachedStyles", EditorStylesBindingFlags);
|
||||||
|
if (field == null)
|
||||||
|
{
|
||||||
|
Debug.LogError("No CachedStyles!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
field.SetValue(null, new EditorStyles[] { null, null });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2,6 +2,7 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEditorInternal;
|
using UnityEditorInternal;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@ -301,11 +302,8 @@ namespace XNodeEditor {
|
|||||||
private static void DrawStyledPropertyField(SerializedProperty property, GUIContent label, GUIStyle style, bool showBacking = true, bool includeChildren = false) {
|
private static void DrawStyledPropertyField(SerializedProperty property, GUIContent label, GUIStyle style, bool showBacking = true, bool includeChildren = false) {
|
||||||
label = label != null ? label : new GUIContent(property.displayName);
|
label = label != null ? label : new GUIContent(property.displayName);
|
||||||
|
|
||||||
GUIStyle oldFoldout = EditorStylesHacks.Foldout;
|
var oldSkin = GUI.skin;
|
||||||
GUIStyle oldLabel = EditorStylesHacks.Label;
|
EditorStylesHacks.SetSkin(NodeEditorResources.styles.skin);
|
||||||
|
|
||||||
EditorStylesHacks.Label = style;
|
|
||||||
EditorStylesHacks.Foldout = NodeEditorResources.styles.foldout;
|
|
||||||
|
|
||||||
EditorGUILayout.BeginHorizontal();
|
EditorGUILayout.BeginHorizontal();
|
||||||
|
|
||||||
@ -317,8 +315,7 @@ namespace XNodeEditor {
|
|||||||
|
|
||||||
EditorGUILayout.EndHorizontal();
|
EditorGUILayout.EndHorizontal();
|
||||||
|
|
||||||
EditorStylesHacks.Label = oldLabel;
|
EditorStylesHacks.SetSkin(oldSkin);
|
||||||
EditorStylesHacks.Foldout = oldFoldout;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ReorderableList CreateReorderableList(string fieldName, List<XNode.NodePort> instancePorts, SerializedProperty arrayData, Type type, SerializedObject serializedObject, XNode.NodePort.IO io, XNode.Node.ConnectionType connectionType, XNode.Node.TypeConstraint typeConstraint, Action<ReorderableList> onCreation) {
|
private static ReorderableList CreateReorderableList(string fieldName, List<XNode.NodePort> instancePorts, SerializedProperty arrayData, Type type, SerializedObject serializedObject, XNode.NodePort.IO io, XNode.Node.ConnectionType connectionType, XNode.Node.TypeConstraint typeConstraint, Action<ReorderableList> onCreation) {
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
using UnityEditor;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace XNodeEditor {
|
namespace XNodeEditor {
|
||||||
@ -19,6 +21,7 @@ namespace XNodeEditor {
|
|||||||
public static GUIStyle OutputPort { get { return styles.outputPort;} }
|
public static GUIStyle OutputPort { get { return styles.outputPort;} }
|
||||||
public class Styles {
|
public class Styles {
|
||||||
public GUIStyle inputPort, nodeHeader, nodeBody, tooltip, nodeHighlight, nodeProperty, outputPort, foldout;
|
public GUIStyle inputPort, nodeHeader, nodeBody, tooltip, nodeHighlight, nodeProperty, outputPort, foldout;
|
||||||
|
public GUISkin skin;
|
||||||
|
|
||||||
public Styles() {
|
public Styles() {
|
||||||
GUIStyle baseStyle = new GUIStyle(EditorStyles.label);
|
GUIStyle baseStyle = new GUIStyle(EditorStyles.label);
|
||||||
@ -53,6 +56,16 @@ namespace XNodeEditor {
|
|||||||
|
|
||||||
tooltip = new GUIStyle("helpBox");
|
tooltip = new GUIStyle("helpBox");
|
||||||
tooltip.alignment = TextAnchor.MiddleCenter;
|
tooltip.alignment = TextAnchor.MiddleCenter;
|
||||||
|
|
||||||
|
skin = GUISkin.Instantiate(EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector));
|
||||||
|
List<GUIStyle> custom = skin.customStyles == null ? new List<GUIStyle>() : skin.customStyles.ToList();
|
||||||
|
|
||||||
|
GUIStyle controlLabel = new GUIStyle(baseStyle);
|
||||||
|
controlLabel.name = "ControlLabel";
|
||||||
|
custom.Add(controlLabel);
|
||||||
|
custom.Add(foldout);
|
||||||
|
skin.customStyles = custom.ToArray();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user