ObjectDrawer get task is null

cooloo

New member
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.

1358

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 ();
    }
}
 
Thanks for the repro scene, though next time please do not include the actual Behavior Designer asset as anybody can download attachments even if you don't have a license to BD :)

You are doing things correctly and this is a problem in BD. I have a fix for it and will send you it via PM.
 
Thanks for the repro scene, though next time please do not include the actual Behavior Designer asset as anybody can download attachments even if you don't have a license to BD :)

You are doing things correctly and this is a problem in BD. I have a fix for it and will send you it via PM.
I replace the dll and It works.
For your advice I will pay attention next time.Thanks a lot.:)
 
Top