Instantly share code, notes, and snippets.

Embed
What would you like to do?
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
public enum StateID
{
None, Idle, Run, Boost, JumpStart, Jumping, JumpEnd, Down, DownRecover,
Step_Forward, Step_Back, Step_Left, Step_Right,
Run_F, Run_B, Run_L, Run_R
}
public class LayoutTest : MonoBehaviour
{  
  [System.Serializable]
public class Content
{
public AnimationClip clip;
public Transform trans;
}
public List<Content> contents = new List<Content>();
#if UNITY_EDITOR
[CustomEditor(typeof(LayoutTest))]
public class MyEditor : Editor
{
public override void OnInspectorGUI()
{
LayoutTest a = target as LayoutTest;
EditorGUIUtility.labelWidth = 80;
GUIStyle back0 = new GUIStyle();
back0.normal.background = MakeTex(600, 1, new Color(0.4f, 0.4f, 0.4f, 0.1f));
GUIStyle back1 = new GUIStyle();
back1.normal.background = MakeTex(600, 1, new Color(1.0f, 1.0f, 1.0f, 0.1f));
bool isEven = true;
foreach (StateID stateID in Enum.GetValues(typeof(StateID)))
{
int i = (int)stateID;
a.contents.Add(new Content());
//色変更
if (isEven)
EditorGUILayout.BeginHorizontal(back0);
else
EditorGUILayout.BeginHorizontal(back1);
isEven = !isEven;
//入力欄生成
EditorGUILayout.LabelField(stateID.ToString(), EditorStyles.boldLabel, GUILayout.Width(150));
GUI.backgroundColor = (manager.contents[i].clip != null) ? Color.yellow : Color.white;
a.contents[i].clip = EditorGUILayout.ObjectField("AnimClip", a.contents[i].clip, typeof(AnimationClip), false) as AnimationClip;
GUI.backgroundColor = (manager.contents[i].clip != null) ? Color.yellow : Color.white;
a.contents[i].trans = EditorGUILayout.ObjectField("Transform", a.contents[i].trans, typeof(Transform), true) as Transform;
EditorGUILayout.EndHorizontal();
GUI.backgroundColor = Color.white;
}
}
private Texture2D MakeTex(int width, int height, Color col)
{
Color[] pix = new Color[width * height];
for (int i = 0; i < pix.Length; i++)
pix[i] = col;
Texture2D result = new Texture2D(width, height);
result.SetPixels(pix);
result.Apply();
return result;
}
}
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment