• unity, GUIStyle and Skin


    例1:

    using UnityEngine;

    using System.Collections;

    using UnityEditor;

    using System.Collections.Generic;

    [CustomEditor(typeof(CmyScriptableObject))]

    public class myScriptableObjectCustomEditor : Editor 

    {

      public Vector2 scrollPosition = Vector2.zero;

      public int selGridInt = 0;

      public string[] selStrings = new string[] {"item1", "item2", "item3", "item4", "item5", "item6", "item7", "item8"};

      public override void OnInspectorGUI()

      {

        DrawDefaultInspector ();

        CmyScriptableObject data = CmyScriptableObject)target;

        scrollPosition = EditorGUILayout.BeginScrollView (scrollPosition,"box",GUILayout.MaxHeight(90));

        {

          //ref: http://answers.unity3d.com/questions/37223/how-do-i-center-a-gui-label.html

          //ref: http://iaimstar.iteye.com/blog/2222128

          GUIStyle _style = GUI.skin.GetStyle ("MenuItemMixed");

          selGridInt = GUILayout.SelectionGrid(selGridInt, selStrings, 1,_style);

        }

        EditorGUILayout.EndScrollView ();

      }

    }

    例2:

    using UnityEngine;

    using System.Collections;

    using UnityEditor;

    using System.Collections.Generic;

    [CustomEditor(typeof(CmyScriptableObject))]

    public class myScriptableObjectCustomEditor : Editor 

    {

      public Vector2 scrollPosition = Vector2.zero;

      public int selGridInt = 0;

      public string[] selStrings = new string[] {"item1", "item2", "item3", "item4", "item5", "item6", "item7", "item8"};

      public override void OnInspectorGUI()

      {

        DrawDefaultInspector ();

        CmyScriptableObject data = CmyScriptableObject)target;

        scrollPosition = EditorGUILayout.BeginScrollView (scrollPosition,"box",GUILayout.MaxHeight(90));

        {

          //ref: http://answers.unity3d.com/questions/37223/how-do-i-center-a-gui-label.html

          //ref: http://iaimstar.iteye.com/blog/2222128

          GUIStyle _style = GUI.skin.GetStyle ("helpbox");
            _style.onNormal.textColor=Color.blue;

          selGridInt = GUILayout.SelectionGrid(selGridInt, selStrings, 1,_style);

        }

        EditorGUILayout.EndScrollView ();

      }

    }

    自定义skin教程:http://forum.unity3d.com/threads/creating-custom-gui-skins-part-one.113055/

  • 相关阅读:
    云时代架构读后感
    余额宝技术架构读后感
    shiyan
    11111
    编写hdfs文件遇到的问题
    123
    啦啦啦
    Hadoop安装
    js根据银行卡号进行判断属于哪个银行并返回银行卡类型
    git 使用
  • 原文地址:https://www.cnblogs.com/wantnon/p/5101370.html
Copyright © 2020-2023  润新知