summaryrefslogtreecommitdiff
path: root/Assets/ThirdParty/AdvancedInspector/Examples/CSharp/AIExample38_Constructor.cs
blob: 27cadeb31fa9899417435f580436d0463d8b835d (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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using UnityEngine;
using AdvancedInspector;

public class AIExample38_Constructor : MonoBehaviour
{
    // In some case, you may want a class to have a custom constructor.
    // Usually, Unity is unable to invoke that constructor.
    [Serializable]
    public class CustomConstructor
    {
        [Inspect]
        public string value;

        public CustomConstructor(string text)
        {
            value = text;
        }
    }

    // Advanced Inspector allows you to create your own instance using the constructor attribute.
    // You may setup your object as you wish before returning it.
    [Inspect, Constructor("InvokeConstructor")]
    public CustomConstructor[] constructors;

    public CustomConstructor InvokeConstructor()
    {
        return new CustomConstructor("This was added in a constructor");
    }
}