Beispiel #1
0
 ///Bind the BBParameter to target. Null unbinds.
 protected abstract void Bind(Variable data);
Beispiel #2
0
 ///Handle what happens when blackboard variable is drag&droped in graph
 protected virtual void OnVariableDropInGraph(Variable variable, Event e, Vector2 canvasMousePos)
 {
 }
        static void ShowDataGUI(Variable data, IBlackboard bb, UnityEngine.Object contextParent, GUILayoutOption[] layoutOptions)
        {
            //Bind info or value GUI control
            if (data.hasBinding){
                var arr = data.propertyPath.Split('.');
                GUI.color = new Color(0.8f,0.8f,1);
                GUILayout.Label(string.Format(".{0} ({1})", arr[1], arr[0]), layoutOptions);
                GUI.color = Color.white;
            } else {
                var isPersistent = contextParent == null || EditorUtility.IsPersistent(contextParent);
                GUI.enabled = !data.nonEditable;
                data.value = EditorField(data.value, data.varType, isPersistent, layoutOptions);
                GUI.enabled = true;
                GUI.backgroundColor = Color.white;
            }

            //'B' to bind variable data to property
            if ( bb.propertiesBindTarget != null && GUILayout.Button("B", GUILayout.Width(8), GUILayout.Height(16))){
                System.Action<System.Reflection.PropertyInfo> Selected = (prop) => {
                    data.BindProperty(prop);
                };

                var menu = new GenericMenu();
                foreach (var comp in bb.propertiesBindTarget.GetComponents(typeof(Component)).Where(c => c.hideFlags == 0) )
                    menu = EditorUtils.GetPropertySelectionMenu(comp.GetType(), data.varType, Selected, false, false, menu, "Bind Property");

                menu.AddItem(new GUIContent("Non Editable"), data.nonEditable, ()=>{ data.nonEditable = !data.nonEditable; });

                menu.AddSeparator("/");
                if (data.hasBinding){
                    menu.AddItem(new GUIContent("UnBind Property"), false, ()=> {data.UnBindProperty();});
                } else {
                    menu.AddDisabledItem(new GUIContent("UnBind Property"));
                }

                menu.ShowAsContext();
                Event.current.Use();
            }
        }
Beispiel #4
0
        //While there is a similar method in EditorUtils, due to layouting and especialy no prefix name, this has to be redone a bit differently
        static object VariableField(Variable data, UnityEngine.Object context, GUILayoutOption[] layoutOptions)
        {
            var o = data.value;
            var t = data.varType;

            //Check scene object type for UnityObjects. Consider Interfaces as scene object type. Assumpt that user uses interfaces with UnityObjects
            var isSceneObjectType = (typeof(Component).IsAssignableFrom(t) || typeof(IScriptableComponent).IsAssignableFrom(t) || t == typeof(GameObject) || t.IsInterface);
            if (typeof(UnityEngine.Object).IsAssignableFrom(t) || t.IsInterface){
                return UnityEditor.EditorGUILayout.ObjectField((UnityEngine.Object)o, t, isSceneObjectType, layoutOptions);
            }

            //Check Type second
            if (t == typeof(System.Type)){
                return EditorUtils.Popup<System.Type>(null, (System.Type)o, UserTypePrefs.GetPreferedTypesList(typeof(object), false), layoutOptions );
            }

            t = o != null? o.GetType() : t;
            if (t.IsAbstract){
                GUILayout.Label( string.Format("({0})", t.FriendlyName()), layoutOptions );
                return o;
            }

            if (o == null && !t.IsAbstract && !t.IsInterface && (t.GetConstructor(System.Type.EmptyTypes) != null || t.IsArray ) ){
                if (GUILayout.Button("(null) Create", layoutOptions)){
                    if (t.IsArray)
                        return System.Array.CreateInstance(t.GetElementType(), 0);
                    return System.Activator.CreateInstance(t);
                }
                return o;
            }

            if (t == typeof(bool))
                return UnityEditor.EditorGUILayout.Toggle((bool)o, layoutOptions);
            if (t == typeof(Color))
                return UnityEditor.EditorGUILayout.ColorField((Color)o, layoutOptions);
            if (t == typeof(AnimationCurve))
                return UnityEditor.EditorGUILayout.CurveField((AnimationCurve)o, layoutOptions);
            if (t.IsSubclassOf(typeof(System.Enum) ))
                return UnityEditor.EditorGUILayout.EnumPopup((System.Enum)o, layoutOptions);
            if (t == typeof(float)){
                GUI.backgroundColor = UserTypePrefs.GetTypeColor(t);
                return UnityEditor.EditorGUILayout.FloatField((float)o, layoutOptions);
            }
            if (t == typeof(int)){
                GUI.backgroundColor = UserTypePrefs.GetTypeColor(t);
                return UnityEditor.EditorGUILayout.IntField((int)o, layoutOptions);
            }
            if (t == typeof(string)){
                GUI.backgroundColor = UserTypePrefs.GetTypeColor(t);
                return UnityEditor.EditorGUILayout.TextField((string)o, layoutOptions);
            }

            if (t == typeof(Vector2))
                return UnityEditor.EditorGUILayout.Vector2Field("", (Vector2)o, layoutOptions);
            if (t == typeof(Vector3))
                return UnityEditor.EditorGUILayout.Vector3Field("", (Vector3)o, layoutOptions);
            if (t == typeof(Vector4))
                return UnityEditor.EditorGUILayout.Vector4Field("", (Vector4)o, layoutOptions);

            if (t == typeof(Quaternion)){
                var q = (Quaternion)o;
                var v = new Vector4(q.x, q.y, q.z, q.w);
                v = UnityEditor.EditorGUILayout.Vector4Field("", v, layoutOptions);
                return new Quaternion(v.x, v.y, v.z, v.w);
            }

            if (t == typeof(LayerMask))
                return EditorUtils.LayerMaskField(null, (LayerMask)o, layoutOptions);

            //If some other type, show it in the generic object editor window
            if (GUILayout.Button( string.Format("{0} {1}", t.FriendlyName(), (o is IList)? ((IList)o).Count.ToString() : "" ), layoutOptions)){
                GenericInspectorWindow.Show(data.name, o, t, context);
            }

            //if we are externaly inspecting value and it's this one, get value from the external editor. This is basicaly done for structs
            if (GenericInspectorWindow.current != null && GenericInspectorWindow.current.inspectedID == data.name){
                return GenericInspectorWindow.current.value;
            }

            return o;
        }
Beispiel #5
0
        static void ShowDataGUI(Variable data, IBlackboard bb, UnityEngine.Object contextParent, GUILayoutOption[] layoutOptions)
        {
            //Bind info or value GUI control
            if (data.hasBinding){
                var arr = data.propertyPath.Split('.');
                GUI.color = new Color(0.8f,0.8f,1);
                GUILayout.Label(string.Format(".{0} ({1})", arr[1], arr[0]), layoutOptions);
                GUI.color = Color.white;
            } else {
                GUI.enabled = !data.isProtected;
                data.value = VariableField(data, contextParent, layoutOptions);
                GUI.enabled = true;
                GUI.backgroundColor = Color.white;
            }

            //Variable options menu
            if ( !Application.isPlaying && GUILayout.Button(" ", GUILayout.Width(8), GUILayout.Height(16))){

                System.Action<PropertyInfo> SelectProp = (p) => {
                    data.BindProperty(p);
                };

                System.Action<FieldInfo> SelectField = (f) => {
                    data.BindProperty(f);
                };

                var menu = new GenericMenu();

                if (bb.propertiesBindTarget != null){
                    foreach (var comp in bb.propertiesBindTarget.GetComponents(typeof(Component)).Where(c => c.hideFlags == 0) ){
                        menu = EditorUtils.GetPropertySelectionMenu(comp.GetType(), data.varType, SelectProp, false, false, menu, "Bind Property");
                        menu = EditorUtils.GetFieldSelectionMenu(comp.GetType(), data.varType, SelectField, menu, "Bind Field");
                    }
                }

                menu.AddItem(new GUIContent("Protected"), data.isProtected, ()=>{ data.isProtected = !data.isProtected; });

                if (bb.propertiesBindTarget != null){
                    menu.AddSeparator("/");
                    if (data.hasBinding){
                        menu.AddItem(new GUIContent("UnBind"), false, ()=> {data.UnBindProperty();});
                    } else {
                        menu.AddDisabledItem(new GUIContent("UnBind"));
                    }
                }

                menu.ShowAsContext();
                Event.current.Use();
            }
        }
Beispiel #6
0
 ///Editor. Handle what happens when blackboard variable is drag&droped in graph
 virtual protected void OnVariableDropInGraph(Variable variable, Vector2 canvasMousePos)
 {
 }
Beispiel #7
0
 public void CallbackOnVariableDropInGraph(Variable variable, Vector2 canvasMousePos)
 {
     OnVariableDropInGraph(variable, canvasMousePos);
 }