Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
12
Help us understand the problem. What is going on with this article?
@miyumiyu

Inspectorの配列のElementに固定の名前つける

More than 3 years have passed since last update.

Inspectorの配列のElementのところをわかりやすくしたい

ことの発端はOculus OVRLipSyncを使って製作を行っているのですが、15種類の口形素(sil, PP, FF, TH, DD, kk, CH, SS, nn, RR, aa, E, ih, oh, ou)を配列のElementに入れていかないといけないが途中でわけがわからず、よく間違えるのでなんとかならないかなぁと
74280c28d21d371e7a191ae0ca145461.png
※この15個のElementです

EditorフォルダにPropertyDrawerの拡張を書く

Editorフォルダの中に以下のソースを入れる

NamedArrayDrawer.cs
using UnityEngine;
using UnityEditor;

[CustomPropertyDrawer(typeof(NamedArrayAttribute))]
public class NamedArrayDrawer : PropertyDrawer
{
    public override void OnGUI(Rect rect, SerializedProperty property, GUIContent label)
    {
        try
        {
            int pos = int.Parse(property.propertyPath.Split('[', ']')[1]);
            EditorGUI.PropertyField(rect, property, new GUIContent(((NamedArrayAttribute)attribute).names[pos]));

        }
        catch
        {
            EditorGUI.PropertyField(rect, property, label);
        }
    }
}

※Unity 5.4だとこの書き方
5.3だと【EditorGUI.PropertyField】→【EditorGUI.ObjecField】な気がします(未検証)

NamedArrayAttributeクラスの作成

適当なところにNamedArrayAttributeクラスを作成

NamedArrayAttribute.cs
using UnityEngine;

public class NamedArrayAttribute : PropertyAttribute
{
    public readonly string[] names;
    public NamedArrayAttribute(string[] names) { this.names = names; }
}

実際に使う

OVRLipSyncContextMorphTarget.cs内で該当する配列の上に拡張したAttributeを置く

OVRLipSyncContextMorphTarget.cs
    // Set the blendshape index to go to (-1 means there is not one assigned)
    [NamedArrayAttribute(new string[] { "sil", "PP", "FF", "TH", "DD", "kk", "CH", "SS", "nn", "RR", "aa", "E", "ih", "oh", "ou" })]  // ←追加
    public int[] VisemeToBlendTargets = new int[(int)OVRLipSync.ovrLipSyncViseme.Count];

できたもの

1af33868c190de938e7e9e350e749d2e.png

うん、これで間違えなくなりそう!

12
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
miyumiyu
virtualcast
VRシステム(バーチャルキャスト)の開発、運営、企画

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
12
Help us understand the problem. What is going on with this article?