Last active
April 13, 2016 11:40
-
-
Save tm8r/bd23b2a109ee48c067d25b4b588347aa to your computer and use it in GitHub Desktop.
GUIContentWindow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEditor; | |
using System.Collections.Generic; | |
public class GUIContentWindow : EditorWindow | |
{ | |
List<string> prefabList; | |
Vector2 scrollPos; | |
static GUIContentWindow window; | |
const string baseDir = "Assets/Resources"; | |
const string fbxPath = baseDir + "/Fbx/hoge.fbx"; | |
const string prefabBaseDir = baseDir + "/Prefab"; | |
static readonly Texture prefabIcon = EditorGUIUtility.IconContent ("PrefabNormal Icon").image; | |
static readonly Texture modelIcon = EditorGUIUtility.IconContent ("PrefabModel Icon").image; | |
static readonly Vector2 iconSize = new Vector2 (16f, 16f); | |
static readonly Vector2 windowSize = new Vector2 (600f, 300f); | |
[MenuItem ("Window/GUIContentWindow")] | |
static void Open () | |
{ | |
window = GetWindow<GUIContentWindow> (); | |
window.minSize = windowSize; | |
} | |
void OnEnable () | |
{ | |
prefabList = new List<string> (); | |
for (var i = 0; i < 30; i++) { | |
prefabList.Add (prefabBaseDir + "/fuga_" + i + ".prefab"); | |
} | |
} | |
void OnDisable () | |
{ | |
prefabList = null; | |
scrollPos = Vector2.zero; | |
} | |
void OnGUI () | |
{ | |
EditorGUILayout.HelpBox ("アイコンサイズを変更するテストですよ。", MessageType.Info); | |
// アイコンサイズを変更 | |
EditorGUIUtility.SetIconSize (iconSize); | |
EditorGUILayout.BeginVertical (GUI.skin.box); | |
// スクロール位置を保持 | |
scrollPos = EditorGUILayout.BeginScrollView (scrollPos, GUI.skin.scrollView); | |
EditorGUILayout.BeginHorizontal (); | |
EditorGUILayout.Toggle (false, "StaticDropdown", GUILayout.Width (5f)); | |
GUILayout.Label (new GUIContent (fbxPath, modelIcon)); | |
EditorGUILayout.EndHorizontal (); | |
foreach (var prefab in prefabList) { | |
EditorGUILayout.BeginHorizontal (); | |
GUILayout.Space (28f); | |
GUILayout.Label (new GUIContent (prefab, prefabIcon)); | |
EditorGUILayout.EndHorizontal (); | |
} | |
EditorGUILayout.EndScrollView (); | |
EditorGUILayout.EndVertical (); | |
// アイコンサイズを元に戻す | |
EditorGUIUtility.SetIconSize (Vector2.zero); | |
GUILayout.FlexibleSpace (); | |
EditorGUILayout.BeginHorizontal (); | |
GUILayout.FlexibleSpace (); | |
if (GUILayout.Button ("閉じる", GUILayout.Width (120f))) { | |
window.Close (); | |
} | |
GUILayout.FlexibleSpace (); | |
EditorGUILayout.EndHorizontal (); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment