-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from AkiKurisu/dev_blackboard_component
Dev blackboard component
- Loading branch information
Showing
22 changed files
with
481 additions
and
255 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using UnityEditor; | ||
using UnityEngine; | ||
using UnityEngine.UIElements; | ||
namespace Kurisu.AkiBT.Editor | ||
{ | ||
[CustomEditor(typeof(BlackBoardComponent))] | ||
public class BlackBoardComponentEditor : UnityEditor.Editor | ||
{ | ||
private AdvancedBlackBoardController controller; | ||
public override VisualElement CreateInspectorGUI() | ||
{ | ||
var source = target as BlackBoardComponent; | ||
var bb = source.GetBlackBoard(); | ||
var myInspector = new VisualElement(); | ||
myInspector.style.flexDirection = FlexDirection.Column; | ||
controller = new AdvancedBlackBoardController(bb, | ||
new AdvancedBlackBoard.BlackBoardSettings() | ||
{ | ||
showIsExposed = true, | ||
showIsGlobalToggle = true, | ||
}, | ||
() => | ||
{ | ||
// commit to component | ||
source.SetBlackBoardVariables(controller.SharedVariables); | ||
EditorUtility.SetDirty(source); | ||
AssetDatabase.SaveAssets(); | ||
}); | ||
myInspector.Add(controller.GetBlackBoard()); | ||
if (Application.isPlaying) return myInspector; | ||
myInspector.RegisterCallback<DetachFromPanelEvent>(_ => controller.UpdateIfDirty()); | ||
return myInspector; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using UnityEngine.UIElements; | ||
using UnityEditor.Experimental.GraphView; | ||
using UnityEngine; | ||
using System.Collections.Generic; | ||
namespace Kurisu.AkiBT.Editor | ||
{ | ||
internal class AdvancedBlackBoardController : IVariableSource | ||
{ | ||
private class VirtualGraphView : GraphView { } | ||
private readonly AdvancedBlackBoard blackBoard; | ||
public List<SharedVariable> SharedVariables { get; } = new(); | ||
private readonly IVariableSource source; | ||
private bool isDirty; | ||
private readonly System.Action onUpdate; | ||
public AdvancedBlackBoardController(IVariableSource source, AdvancedBlackBoard.BlackBoardSettings settings = default, System.Action onUpdate = null) | ||
{ | ||
this.source = source; | ||
this.onUpdate = onUpdate; | ||
//Need attached to a virtual graphView to send event | ||
//It's an interesting hack so that you can use blackBoard outside of graphView | ||
blackBoard = new AdvancedBlackBoard(this, new VirtualGraphView(), settings); | ||
blackBoard.style.position = Position.Relative; | ||
blackBoard.style.width = Length.Percent(100f); | ||
foreach (var variable in source.SharedVariables) | ||
{ | ||
if (Application.isPlaying) | ||
{ | ||
blackBoard.AddSharedVariable(variable); | ||
} | ||
else | ||
{ | ||
blackBoard.AddSharedVariable(variable.Clone()); | ||
} | ||
} | ||
blackBoard.RegisterCallback<VariableChangeEvent>(_ => isDirty = true); | ||
} | ||
public AdvancedBlackBoard GetBlackBoard() => blackBoard; | ||
public void Update() | ||
{ | ||
source.SharedVariables.Clear(); | ||
source.SharedVariables.AddRange(SharedVariables); | ||
onUpdate?.Invoke(); | ||
} | ||
public void UpdateIfDirty() | ||
{ | ||
if (isDirty) | ||
{ | ||
Update(); | ||
isDirty = false; | ||
} | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Editor/Core/GraphView/AdvancedBlackBoardController.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.