6 using System.Collections.Generic;
9 namespace HKI.Core.Variables.Editor
18 const string containerSPName =
"container";
24 public static T AddHKIVarToContainer<T>(
Container container,
string variableName, params
object[] parameters) where T :
HKIVar 28 Debug.LogError(
"Container null");
32 HKIVar variable = (
HKIVar)ScriptableObject.CreateInstance<T>();
33 variable.name = variableName;
35 AssetDatabase.AddObjectToAsset(variable, container);
36 AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(variable));
38 SerializedObject containerSO =
new SerializedObject(container);
41 SerializedProperty containerSP = containerSO.FindProperty(containerSPName);
43 containerSP.InsertArrayElementAtIndex(containerSP.arraySize);
44 SerializedProperty elementSP = containerSP.GetArrayElementAtIndex(containerSP.arraySize - 1);
46 elementSP.objectReferenceValue = variable;
48 containerSO.ApplyModifiedProperties();
50 if(parameters != null && parameters.Length != 0)
52 MethodInfo setWithParametersMethode = typeof(T).GetMethod(
"SetWithParameters", BindingFlags.NonPublic | BindingFlags.Instance);
53 if(setWithParametersMethode != null)
54 setWithParametersMethode.Invoke(variable,
new object[] { parameters });
72 serializedObject.Update();
76 EditorGUILayout.Space();
80 serializedObject.ApplyModifiedProperties();
86 static float lineCount = 1;
96 EditorGUI.LabelField(guiRect, ((
Container)sp.objectReferenceValue).ToString());
This class extends the Unity ReorderableList with features so it can be used by HKIVar. HKIVars are longer than one line so the height of each ReorderableList element must be adjusted accordingly.
override void OnInspectorGUI()
This abstract class of a ScriptableObject is provides child classes with on value changed callback ca...
Custom inspector for the Container class. The code is split into two subclasses for better readabilit...
This container is itself a HKIVar but it purpose is to hold other HKIVars together at one place...
static void DrawContainerDrawer(Rect guiRect, SerializedProperty sp)
static float GetContainerDrawerLineCount()