EditorGUI

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);
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值