Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- File Classes.cs
- ----------------------------------------
- using UnityEngine;
- using System;
- [Serializable]
- public class BaseClass
- {
- public float SomeValue;
- public virtual void SendMessage()
- {
- Debug.Log("There's nothing here!");
- }
- }
- [Serializable]
- public class ChildClass : BaseClass
- {
- public string SpecialMessage;
- public override void SendMessage()
- {
- Debug.Log("Message for you Sir! " + SpecialMessage);
- }
- }
- ----------------------------------------
- File: Beda.cs
- using UnityEngine;
- using UnityEditor;
- using System.Collections.Generic;
- public class Beda : MonoBehaviour
- {
- public List<BaseClass> myValues = new List<BaseClass>();
- public void Start()
- {
- for(int i = 0; i< myValues.Count; i++)
- {
- Debug.Log(myValues[i].GetType().Name);
- }
- }
- }
- #if UNITY_EDITOR
- [CustomEditor(typeof(Beda))]
- public class BedaEditor: Editor
- {
- public override void OnInspectorGUI()
- {
- base.OnInspectorGUI();
- if(GUILayout.Button("Create 2 BaseClass and 2 ChildClass"))
- {
- var bedaScript = (Beda)target;
- bedaScript.myValues.Clear();
- bedaScript.myValues.Add(new BaseClass());
- bedaScript.myValues.Add(new BaseClass());
- bedaScript.myValues.Add(new ChildClass());
- bedaScript.myValues.Add(new ChildClass());
- for(int i = 0; i < 4; i++)
- {
- Debug.Log($"Item #{i} Type {bedaScript.myValues[i].GetType().Name}");
- }
- }
- }
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement