using UnityEngine;
using System.Collections;
using UnityEditor;
[CustomEditor(typeof(TestScript))]
public class TestScriptEditor : Editor {
TestScript targetScript;
GUIStyle headerStyle = new GUIStyle();
GUIStyle footerStyle = new GUIStyle();
GUIStyle bgBoxStyle = new GUIStyle();
GUIStyle titleAstyle = new GUIStyle();
GUIStyle titleBstyle = new GUIStyle();
GUIStyle titleCstyle = new GUIStyle();
GUIStyle ButtonStyle = new GUIStyle();
GUIStyle SliderThumbStyle = new GUIStyle();
GUIStyle SliderTroughStyle = new GUIStyle();
GUISkin testSkin;
void OnEnable()
{
targetScript = target as TestScript;
GenerateStyles();
if(testSkin==null)
{
testSkin = Resources.Load("TestSkin") as GUISkin;
}
}
public override void OnInspectorGUI()
{
EditorGUILayout.TextField("Unity5.0", testSkin.customStyles[0], GUILayout.Height(60));
GUILayout.BeginVertical("", bgBoxStyle);
GUILayout.Space(10);
EditorGUILayout.LabelField("属性:", testSkin.label);
GUILayout.Space(18);
EditorGUILayout.LabelField("任务:", titleBstyle);
GUILayout.Space(10);
EditorGUILayout.LabelField("特性:", titleCstyle);
GUILayout.Space(10);
GUILayout.BeginHorizontal();
if(GUILayout.Button("确认",ButtonStyle,GUILayout.Height(70)))
{
}
if (GUILayout.Button("取消", ButtonStyle, GUILayout.Height(70)))
{
}
GUILayout.EndHorizontal();
GUILayout.Space(10);
GUILayout.BeginHorizontal();
GUILayout.Label("滑动条", titleAstyle, GUILayout.Width(110));
targetScript.speedValue = GUILayout.HorizontalSlider(targetScript.speedValue, 0.0f, 20.0f, SliderTroughStyle, SliderThumbStyle);
//EditorGUILayout.Slider("速度滑动条", targetScript.speedValue, 0.0f, 10.0f);
GUILayout.EndHorizontal();
GUILayout.Space(40);
GUILayout.EndVertical();
EditorGUILayout.LabelField("I love unity", footerStyle, GUILayout.Height(30));
Repaint();
}
void GenerateStyles()
{
Texture2D SliderThrough=Resources.Load("Slider_thumb") as Texture2D;
Texture2D SliderThumb=Resources.Load("thumb")as Texture2D;
Texture2D ButtonBg = Resources.Load("button_bg") as Texture2D;
Texture2D ButtonBg_hover = Resources.Load("button_bg_hover") as Texture2D;
Texture2D ButtonBg_active = Resources.Load("button_bg_active") as Texture2D;
Texture2D Background = Resources.Load("bg_red") as Texture2D;
Texture2D bgBoxtex = Resources.Load("bg_gray") as Texture2D;
Font bg_font = Resources.Load("Fonts/BUXTONSKETCH") as Font;
headerStyle.normal.background = Background;
headerStyle.font = bg_font;
headerStyle.fontSize = 34;
headerStyle.normal.textColor = Color.white;
headerStyle.alignment = TextAnchor.MiddleCenter;
footerStyle.normal.background = Background;
footerStyle.font = bg_font;
footerStyle.fontSize = 18;
footerStyle.normal.textColor = Color.white;
footerStyle.alignment = TextAnchor.LowerRight;
footerStyle.margin = new RectOffset(0, 2, 0, 2);
bgBoxStyle.normal.background = bgBoxtex;
bgBoxStyle.overflow = new RectOffset(1, 1, 1, 1);
titleAstyle.font = bg_font;
titleAstyle.fontSize = 25;
titleAstyle.normal.textColor = Color.white;
titleBstyle.font = bg_font;
titleBstyle.fontSize = 18;
titleBstyle.normal.textColor = Color.white;
titleCstyle.font = bg_font;
titleCstyle.fontSize = 12;
titleCstyle.normal.textColor = Color.white;
ButtonStyle.normal.background = ButtonBg;
ButtonStyle.normal.textColor = Color.white;
ButtonStyle.hover.background = ButtonBg_hover;
ButtonStyle.hover.textColor = Color.white;
ButtonStyle.active.background = ButtonBg_active;
ButtonStyle.active.textColor = Color.black;
ButtonStyle.fontSize = 25;
ButtonStyle.font = bg_font;
ButtonStyle.alignment = TextAnchor.MiddleCenter;
ButtonStyle.border = new RectOffset(20, 20, 20, 20);
SliderTroughStyle.normal.background = SliderThrough;
SliderTroughStyle.border = new RectOffset(8, 8, 0, 0);
SliderTroughStyle.overflow = new RectOffset(0, 0, 0, 0);
SliderTroughStyle.fixedHeight = 16;
SliderTroughStyle.stretchWidth = true;
SliderTroughStyle.padding = new RectOffset(8,8,0,0);
SliderTroughStyle.margin = new RectOffset(4,4,4,4);
SliderThumbStyle.normal.background = SliderThumb;
SliderThumbStyle.border = new RectOffset(1, 1, 1, 1);
SliderThumbStyle.overflow = new RectOffset(-10,-10,4,4);
}
}
using System.Collections;
using UnityEditor;
[CustomEditor(typeof(TestScript))]
public class TestScriptEditor : Editor {
TestScript targetScript;
GUIStyle headerStyle = new GUIStyle();
GUIStyle footerStyle = new GUIStyle();
GUIStyle bgBoxStyle = new GUIStyle();
GUIStyle titleAstyle = new GUIStyle();
GUIStyle titleBstyle = new GUIStyle();
GUIStyle titleCstyle = new GUIStyle();
GUIStyle ButtonStyle = new GUIStyle();
GUIStyle SliderThumbStyle = new GUIStyle();
GUIStyle SliderTroughStyle = new GUIStyle();
GUISkin testSkin;
void OnEnable()
{
targetScript = target as TestScript;
GenerateStyles();
if(testSkin==null)
{
testSkin = Resources.Load("TestSkin") as GUISkin;
}
}
public override void OnInspectorGUI()
{
EditorGUILayout.TextField("Unity5.0", testSkin.customStyles[0], GUILayout.Height(60));
GUILayout.BeginVertical("", bgBoxStyle);
GUILayout.Space(10);
EditorGUILayout.LabelField("属性:", testSkin.label);
GUILayout.Space(18);
EditorGUILayout.LabelField("任务:", titleBstyle);
GUILayout.Space(10);
EditorGUILayout.LabelField("特性:", titleCstyle);
GUILayout.Space(10);
GUILayout.BeginHorizontal();
if(GUILayout.Button("确认",ButtonStyle,GUILayout.Height(70)))
{
}
if (GUILayout.Button("取消", ButtonStyle, GUILayout.Height(70)))
{
}
GUILayout.EndHorizontal();
GUILayout.Space(10);
GUILayout.BeginHorizontal();
GUILayout.Label("滑动条", titleAstyle, GUILayout.Width(110));
targetScript.speedValue = GUILayout.HorizontalSlider(targetScript.speedValue, 0.0f, 20.0f, SliderTroughStyle, SliderThumbStyle);
//EditorGUILayout.Slider("速度滑动条", targetScript.speedValue, 0.0f, 10.0f);
GUILayout.EndHorizontal();
GUILayout.Space(40);
GUILayout.EndVertical();
EditorGUILayout.LabelField("I love unity", footerStyle, GUILayout.Height(30));
Repaint();
}
void GenerateStyles()
{
Texture2D SliderThrough=Resources.Load("Slider_thumb") as Texture2D;
Texture2D SliderThumb=Resources.Load("thumb")as Texture2D;
Texture2D ButtonBg = Resources.Load("button_bg") as Texture2D;
Texture2D ButtonBg_hover = Resources.Load("button_bg_hover") as Texture2D;
Texture2D ButtonBg_active = Resources.Load("button_bg_active") as Texture2D;
Texture2D Background = Resources.Load("bg_red") as Texture2D;
Texture2D bgBoxtex = Resources.Load("bg_gray") as Texture2D;
Font bg_font = Resources.Load("Fonts/BUXTONSKETCH") as Font;
headerStyle.normal.background = Background;
headerStyle.font = bg_font;
headerStyle.fontSize = 34;
headerStyle.normal.textColor = Color.white;
headerStyle.alignment = TextAnchor.MiddleCenter;
footerStyle.normal.background = Background;
footerStyle.font = bg_font;
footerStyle.fontSize = 18;
footerStyle.normal.textColor = Color.white;
footerStyle.alignment = TextAnchor.LowerRight;
footerStyle.margin = new RectOffset(0, 2, 0, 2);
bgBoxStyle.normal.background = bgBoxtex;
bgBoxStyle.overflow = new RectOffset(1, 1, 1, 1);
titleAstyle.font = bg_font;
titleAstyle.fontSize = 25;
titleAstyle.normal.textColor = Color.white;
titleBstyle.font = bg_font;
titleBstyle.fontSize = 18;
titleBstyle.normal.textColor = Color.white;
titleCstyle.font = bg_font;
titleCstyle.fontSize = 12;
titleCstyle.normal.textColor = Color.white;
ButtonStyle.normal.background = ButtonBg;
ButtonStyle.normal.textColor = Color.white;
ButtonStyle.hover.background = ButtonBg_hover;
ButtonStyle.hover.textColor = Color.white;
ButtonStyle.active.background = ButtonBg_active;
ButtonStyle.active.textColor = Color.black;
ButtonStyle.fontSize = 25;
ButtonStyle.font = bg_font;
ButtonStyle.alignment = TextAnchor.MiddleCenter;
ButtonStyle.border = new RectOffset(20, 20, 20, 20);
SliderTroughStyle.normal.background = SliderThrough;
SliderTroughStyle.border = new RectOffset(8, 8, 0, 0);
SliderTroughStyle.overflow = new RectOffset(0, 0, 0, 0);
SliderTroughStyle.fixedHeight = 16;
SliderTroughStyle.stretchWidth = true;
SliderTroughStyle.padding = new RectOffset(8,8,0,0);
SliderTroughStyle.margin = new RectOffset(4,4,4,4);
SliderThumbStyle.normal.background = SliderThumb;
SliderThumbStyle.border = new RectOffset(1, 1, 1, 1);
SliderThumbStyle.overflow = new RectOffset(-10,-10,4,4);
}
}