summaryrefslogtreecommitdiff
path: root/Assets/ThirdParty/AdvancedInspector/Examples/CSharp/AIExample29_RuntimeResolve.cs
blob: 7fe9fc0b47b339c0089e092f992e19c89ce222f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using UnityEngine;
using System.Collections;

using AdvancedInspector;

[AdvancedInspector]
public class AIExample29_RuntimeResolve : MonoBehaviour 
{
    public bool myBoolean;
    public float myFloat;
    public string myString;

    private int index = 0;

    // The RuntimeResolve attribute is an edge case tool where you want to display an object, but don't know it's proper type.
    // In this case, there is no editor for "object", but there's one for bool, float and string.
    // By default the Advanced Inspector uses the editor related to the declared type, not the current object type.
    // The RuntimeResolve forces it to seek the proper editor for the current type.
    [Inspect, RuntimeResolve]
    public object MyProperty
    {
        get 
        {
            if (index == 0)
                return myBoolean;
            else if (index == 1)
                return myFloat;
            else
                return myString;
        }
        set
        {
            if (index == 0)
                myBoolean = (bool)value;
            else if (index == 1)
                myFloat = (float)value;
            else
                myString = (string)value;
        }
    }

    [Inspect]
    public void PressMe()
    {
        index++;
        if (index > 2)
            index = 0;
    }
}