Skip to content

How to create your own variable Inspector

How to create your own variable Inspector

Postby Neodrop » 29 Jul 2011, 19:36

User avatar
Neodrop
Администратор
 
Posts: 1068
Joined: 15 Jan 2011, 13:18

Re: How to create your own variable Inspector

Postby Neodrop » 29 Jul 2011, 19:58

How to create (or override) Inspector for any variable type (Don't forget to put this code in "Editor" folder ) :

Syntax:
Using csharp Syntax Highlighting
using UnityEditor;
using UnityEngine;
using Antares.Vizio.Editor;
using Antares.Vizio.Runtime;

//You must inherit your class from CustomTypeInspector to create (or override existing one) type Inspector
public class MeOwnInspector : CustomTypeInspector
{
    // Here you define your type
    public override System.Type type
    {
        get { return typeof (MyClass); }
    }

    public override void DrawVariableField(Variable variable)
    {  
        //Cast variable value
        MyClass mc = (MyClass)variable.Value;
       
        if(mc == null)
           variable.Value = mc = new MyClass();
        // Call UnityEditor GUILayout method to show your bool. Here you can write any GUI code by your choice
        EditorGUILayout.Toggle(new GUIContent("My own bool", "My own inspector for my own class"),
                                   mc.MyBool);
    }
}
 
Parsed in 0.009 seconds, using GeSHi 1.0.8.4


Where MyClass is :

Syntax:
Using csharp Syntax Highlighting
public class MyClass
{
     public bool MyBool;
}
Parsed in 0.004 seconds, using GeSHi 1.0.8.4



Also, if you wish, you can override any existing Inspectors in Universe.
User avatar
Neodrop
Администратор
 
Posts: 1068
Joined: 15 Jan 2011, 13:18

Re: How to create your own variable Inspector

Postby Neodrop » 09 Nov 2011, 09:41

Inspector for type "double". But, unfortunately, Unity has no editing fields for double value and, this value will be rounded to float.

Syntax:
Using csharp Syntax Highlighting
using UnityEditor;
using UnityEngine;
using Antares.Vizio.Editor;
using Antares.Vizio.Runtime;

//You must inherit your class from CustomTypeInspector to create (or override existing one) type Inspector
public class MeOwnDoubleInspector : CustomTypeInspector
{
    // Here you define your type
    public override System.Type type
    {
        get { return typeof (double); }
    }

    public override void DrawVariableField(Variable variable)
    {  
        //Cast variable value
        double mc = (double)variable.Value;
       
        // Call UnityEditor GUILayout method to show your double value. Here you can write any GUI code by your choice

        //GUILayout.Label(new GUIContent("Double value : " + mc)); // uncomment if you want just see the value

        //variable.Value = (float)EditorGUILayout.FloatField(new GUIContent((float)mc, "Enter value here")); // uncomment here if you want edit your value
    }
}
 
Parsed in 0.008 seconds, using GeSHi 1.0.8.4
User avatar
Neodrop
Администратор
 
Posts: 1068
Joined: 15 Jan 2011, 13:18


Return to Documentation

Who is online

Registered users: No registered users