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(); } }
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(); } }