public override void Initialize(BlackBoardAsset blackboard, GameObject target) { BlackBoard = blackboard; Target = target; #if UNITY_EDITOR RefreshInternalValue(); #endif Variable = blackboard.GetVariable<T, TAsset, TVariable>(target, Alpha); }
public override void RefreshInternalValue() { if(BlackBoard == null || Target == null) { FiniteStateMachine fsm = GetComponentInParent<FiniteStateMachine>(); BlackBoard = fsm.Blackboard; Target = fsm.BlackboardTarget; } var values = BlackBoard.GetAllBlackboardValueOfTarget(Target); if(values.ContainsKey(typeof(T))) { BlackboardEntries = values[typeof(T)]; SelectedEntry = Mathf.Clamp(SelectedEntry, 0, BlackboardEntries.Count - 1); Alpha = BlackboardEntries[SelectedEntry]; } else { BlackboardEntries = null; } }
public virtual void Initialize(BlackBoardAsset blackboard, GameObject target) { }
private void OnEnable() { if (target == null) { return; } Target = target as BlackBoardAsset; Target.OnAssetDeletion += ClearBeforeDeletion; // Step 1: Get properties. SerializedProperty BlackboardParameters = serializedObject.FindProperty("BlackboardParameters"); // Step 1.1: Security check. if (BlackboardParameters == null) { return; } // Step 2: Setup Reoderable lists. ExecuteList = new ReorderableList(serializedObject, BlackboardParameters, true, true, true, true); // Step 2.1: CallBacks setup. // Draw Header ExecuteList.drawHeaderCallback = (Rect rect) => { EditorGUI.LabelField(rect, new GUIContent("Blackboard parameters")); }; // Draw Element ExecuteList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocus) => { serializedObject.Update(); BlackboardParameterDrawerUtility.DrawElementCallback(ExecuteList, rect, index); Target.NeedRefresh = true; }; // On Add ExecuteList.onAddDropdownCallback = (Rect rect, ReorderableList rlist) => { GenericMenu dropdownMenu = new GenericMenu(); string[] assetGUIDS = AssetDatabase.FindAssets("l:BlackboardParameter"); for (int i = 0; i < assetGUIDS.Length; i++) { string path = AssetDatabase.GUIDToAssetPath(assetGUIDS[i]); path = System.IO.Path.GetFileNameWithoutExtension(path); dropdownMenu.AddItem(new GUIContent(path.Replace("InternalBlackboardParameter_", "")), false, AddItem, new AssetInfo <ReorderableList> { AssetPath = path, ComplementaryData = ExecuteList }); } dropdownMenu.ShowAsContext(); }; ExecuteList.onRemoveCallback = (ReorderableList rlist) => { int i = ExecuteList.index; if (i >= Target.BlackboardParameters.Count) { return; } RemoveItem(i); Target.NeedRefresh = true; }; ExecuteList.elementHeightCallback = (int index) => { return(BlackboardParameterDrawerUtility.ElementHeightCallback(ExecuteList, index)); }; }