Prefix
Unity に関するメモ書き。
HumanoidAvatar
Inspector
CustomEditor
using UnityEngine;
using UnityEditor;
[CustomEditor (typeof(Character))]
public class CharacterInspector : Editor
{
Character character = null;
void OnEnable ()
{
//Character コンポーネントを取得
character = (Character) target;
}
public override void OnInspectorGUI ()
{
base.OnInspectorGUI ();
//攻撃力の数値をラベルとして表示する
EditorGUILayout.LabelField ("攻撃力", character.攻撃力.ToString ());
}
}
text
public override bool HasPreviewGUI()
{
return true;
//return Application.isPlaying;
}
public override GUIContent GetPreviewTitle()
{
return new GUIContent("Title");
}
public override string GetInfoString()
{
return "Status";
}
sample
public override bool HasPreviewGUI()
{
return Application.isPlaying; // Editor時だと表示が乱れる?
}
public override GUIContent GetPreviewTitle ()
{
return new GUIContent ("プレビュー名");
}
public override void OnPreviewSettings ()
{
GUIStyle preLabel = new GUIStyle ("preLabel");
GUIStyle preButton = new GUIStyle ("preButton");
GUILayout.Label ("ラベル", preLabel);
GUILayout.Button ("ボタン", preButton);
}
public override void OnPreviewGUI (Rect r, GUIStyle background)
{
GUI.Box (r, "Preview");
}
Layout
var r = GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none, GUILayout.Height(EditorGUIUtility.singleLineHeight * 3 + 20));
Rect r = EditorGUILayout.GetControlRect ();
begin/end
using (new GUILayout.VerticalScope(GUI.skin.box))
{
GUILayout.Button("Click me");
GUILayout.Button("Or me");
}
GUILayout.BeginArea(new Rect(16,16,300,300));
GUILayout.Label(title, guiSkin.label);
GUILayout.Label ("Time : "+lapseTime.ToString("0.0"), guiSkin.label);
GUILayout.HorizontalSlider(70,0,100);
GUILayout.Button ("Click!", guiSkin.button);
GUILayout.EndArea();
EditorGUILayout.BeginHorizontal();
chara.hp = EditorGUILayout.IntField( chara.hp, GUILayout.Width(48) );
chara.maxHp = EditorGUILayout.IntField( chara.maxHp, GUILayout.Width(48) );
EditorGUILayout.EndHorizontal();
SerializedObject
using UnityEngine;
using UnityEditor;
[CustomEditor (typeof(Character))]
public class CharacterInspector : Editor
{
SerializedProperty hpProperty;
void OnEnable ()
{
hpProperty = serializedObject.FindProperty ("hp");
}
public override void OnInspectorGUI ()
{
serializedObject.Update ();
EditorGUILayout.IntSlider (hpProperty, 0, 100);
serializedObject.ApplyModifiedProperties ();
}
}
ReorderableList
Asset
AssetDatabase.StartAssetEditing ();
foreach (var sound in sounds) {
var path = AssetDatabase.GetAssetPath (sound);
var audioImporter = AudioImporter.GetAtPath (path) as AudioImporter;
if (audioImporter){
audioImporter.threeD = false;
//AssetDatabase.ImportAsset(path);
EditorUtility.SetDirty(sound);
}
}
AssetDatabase.StopAssetEditing ();
// import dirty objects
AssetDatabase.Refresh();