Hi,
I want to draw SharedString for popup.
But OnGUI Method i get the Task is null.
So,How can i get the task.
Thanks.
The files is the Sample.
I want to draw SharedString for popup.
But OnGUI Method i get the Task is null.
So,How can i get the task.
Thanks.
The files is the Sample.
C#:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using BehaviorDesigner.Runtime.Tasks;
using BehaviorDesigner.Runtime;
public class TestAction : Action {
public TestClass test;
[TestAttribute("test")]
public string animName="";//success
public SharedTestClass test2;
[TestAttribute("test2")]
public string animName2="";//success
[TestAttribute("test")]
public SharedString animName3="";//TestAttributeDrawer task is null
[TestAttribute("test2")]
public SharedString animName4="";//TestAttributeDrawer task is null
}
C#:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using BehaviorDesigner.Runtime;
using BehaviorDesigner.Runtime.ObjectDrawers;
using BehaviorDesigner.Editor;
using System.Reflection;
[CustomObjectDrawer(typeof(TestAttribute))]
public class TestAttributeDrawer : ObjectDrawer {
public override void OnGUI (GUIContent label)
{
EditorGUILayout.BeginVertical ();
var cacheTask = Task;
if (cacheTask != null) {
var targetAttribute = (TestAttribute)Attribute;
var taskType = cacheTask.GetType ();
FieldInfo field = taskType.GetField (targetAttribute.dataField);
if (field != null) {
var animValue = field.GetValue (cacheTask);
TestClass testClass = null;
if (animValue is SharedTestClass) {
testClass = ((SharedTestClass)animValue).Value;
} else if (animValue is TestClass) {
testClass = animValue as TestClass;
}
if (testClass != null) {
List<string> popUpList = testClass.Animations;
if (value is string) {
int selectIndex = popUpList.IndexOf ((string)value);
int newIndex = EditorGUILayout.Popup (label.text, selectIndex, popUpList.ToArray ());
if (newIndex != selectIndex && newIndex >= 0) {
value = popUpList [newIndex];
}
}
} else {
GUILayout.Label (label.text + " Error----" + animValue);
}
}
}
GUILayout.Label ("Task:" + (Task != null ? Task.Owner.name : "null"));
GUILayout.Space (10f);
EditorGUILayout.EndVertical ();
}
}