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;
|
||||
}
|
||||
}
|
||||
|
||||
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.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
@ -301,11 +302,8 @@ namespace XNodeEditor {
|
||||
private static void DrawStyledPropertyField(SerializedProperty property, GUIContent label, GUIStyle style, bool showBacking = true, bool includeChildren = false) {
|
||||
label = label != null ? label : new GUIContent(property.displayName);
|
||||
|
||||
GUIStyle oldFoldout = EditorStylesHacks.Foldout;
|
||||
GUIStyle oldLabel = EditorStylesHacks.Label;
|
||||
|
||||
EditorStylesHacks.Label = style;
|
||||
EditorStylesHacks.Foldout = NodeEditorResources.styles.foldout;
|
||||
var oldSkin = GUI.skin;
|
||||
EditorStylesHacks.SetSkin(NodeEditorResources.styles.skin);
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
|
||||
@ -317,8 +315,7 @@ namespace XNodeEditor {
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
EditorStylesHacks.Label = oldLabel;
|
||||
EditorStylesHacks.Foldout = oldFoldout;
|
||||
EditorStylesHacks.SetSkin(oldSkin);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
namespace XNodeEditor {
|
||||
@ -19,6 +21,7 @@ namespace XNodeEditor {
|
||||
public static GUIStyle OutputPort { get { return styles.outputPort;} }
|
||||
public class Styles {
|
||||
public GUIStyle inputPort, nodeHeader, nodeBody, tooltip, nodeHighlight, nodeProperty, outputPort, foldout;
|
||||
public GUISkin skin;
|
||||
|
||||
public Styles() {
|
||||
GUIStyle baseStyle = new GUIStyle(EditorStyles.label);
|
||||
@ -53,6 +56,16 @@ namespace XNodeEditor {
|
||||
|
||||
tooltip = new GUIStyle("helpBox");
|
||||
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