示例#1
0
    /// <summary>
    /// 受け取ったobjectの値をウィンドウへ表示
    /// </summary>
    /// <param name="name">Name.</param>
    /// <param name="type">Type.</param>
    /// <param name="_object">Object.</param>
    static void InspectObject(String name, Type type, object _object)
    {
        // Registered types in InspectActionDict.
        if (InspectActionDict.ContainsKey(type))
        {
            InspectActionDict[type].Invoke(name, _object);
            return;
        }

        // Unity object
        var unityObject = _object as UnityEngine.Object;

        if (unityObject != null)
        {
            EditorGUILayout.ObjectField(name, unityObject, type, false, emptyOptions);
            return;
        }

        // Enum
        if (type.IsEnum)
        {
            EditorGUILayout.EnumPopup(name, (Enum)_object, emptyOptions);
            return;
        }

        // null check
        if (_object == null)
        {
            EditorGUILayout.TextField(name, null, emptyOptions);
            return;
        }

        // object has Inspectable attribute
        if (_object.GetType().GetCustomAttributes(true).Any(attr => attr.GetType() == InspectableType))
        {
            EditorGUILayout.LabelField(name);
            EditorGUI.indentLevel += 1;
            Inspect(_object);
            EditorGUI.indentLevel -= 1;
            return;
        }

        // Unregistered Types
        EditorGUILayout.TextField(name, _object.ToString(), emptyOptions);
    }
示例#2
0
 /// <summary>
 /// Registers the inspect action.
 /// </summary>
 /// <param name="type">Type.</param>
 /// <param name="action">Action.</param>
 public static void RegisterInspectAction(Type type, Action <string, object> action)
 {
     InspectActionDict.Add(type, action);
 }