GUILayout.Label也可以支持Texture
之前一直不知道,GUILayout.Label 函数是支持 Texture 的,玩 The Illustrated Nature 的时候才发现。
代码好简单,如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
namespace IL3DN
{
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(IL3DN_Wind))]
public class IL3DN_WindEditor : Editor
{
SerializedProperty Wind;
SerializedProperty WindStrenght;
SerializedProperty WindSpeed;
SerializedProperty WindTurbulence;
SerializedProperty Wiggle;
SerializedProperty LeavesWiggle;
SerializedProperty GrassWiggle;
Texture2D IL3DN_WindLabel;
Texture2D IL3DN_LeavesLabel;
void OnEnable()
{
Wind = serializedObject.FindProperty("Wind");
WindStrenght = serializedObject.FindProperty("WindStrenght");
WindSpeed = serializedObject.FindProperty("WindSpeed");
WindTurbulence = serializedObject.FindProperty("WindTurbulence");
Wiggle = serializedObject.FindProperty("Wiggle");
LeavesWiggle = serializedObject.FindProperty("LeavesWiggle");
GrassWiggle = serializedObject.FindProperty("GrassWiggle");
IL3DN_WindLabel = AssetDatabase.LoadAssetAtPath<Texture2D>("Assets/IL3DN/EditorImages/IL3DN_Label_Wind_VertexAnimations.png");
IL3DN_LeavesLabel = AssetDatabase.LoadAssetAtPath<Texture2D>("Assets/IL3DN/EditorImages/IL3DN_Label_Wind_UVAnimations.png");
}
public override void OnInspectorGUI()
{
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
GUILayout.Label(IL3DN_WindLabel);
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
EditorGUILayout.BeginVertical(EditorStyles.helpBox);
EditorGUILayout.Space();
EditorGUILayout.PropertyField(Wind, new GUIContent("Wind"));
EditorGUILayout.PropertyField(WindStrenght, new GUIContent("Wind Strength"));
EditorGUILayout.PropertyField(WindSpeed, new GUIContent("Wind Speed"));
EditorGUILayout.PropertyField(WindTurbulence, new GUIContent("Wind Turbulence"));
EditorGUILayout.Space();
EditorGUILayout.EndVertical();
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
GUILayout.Label(IL3DN_LeavesLabel);
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
EditorGUILayout.BeginVertical(EditorStyles.helpBox);
EditorGUILayout.Space();
EditorGUILayout.PropertyField(Wiggle, new GUIContent("Wiggle"));
EditorGUILayout.PropertyField(LeavesWiggle, new GUIContent("Leaves Wiggle"));
EditorGUILayout.PropertyField(GrassWiggle, new GUIContent("Grass Wiggle"));
EditorGUILayout.Space();
EditorGUILayout.EndVertical();
serializedObject.ApplyModifiedProperties();
}
}
}