Skip to content

Commit

Permalink
Optimize algorithm
Browse files Browse the repository at this point in the history
Optimize component
Normal version and Pro version are moved to different backend
Editor more friendly
Optimize memory
Update example
Simplify editor code
  • Loading branch information
AkiKurisu committed Dec 1, 2023
1 parent f96f78e commit 1f0895a
Show file tree
Hide file tree
Showing 91 changed files with 1,182 additions and 1,106 deletions.
27 changes: 0 additions & 27 deletions Editor/Core/GOAPActionSetEditor.cs

This file was deleted.

28 changes: 0 additions & 28 deletions Editor/Core/GOAPGoalSetEditor.cs

This file was deleted.

63 changes: 61 additions & 2 deletions Editor/Core/GOAPPlannerEditor.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;
using System.Linq;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine;
Expand All @@ -9,23 +11,80 @@ public class GOAPPlannerEditor : UnityEditor.Editor
{
private const string LabelText = "AkiGOAP <size=12>V1.1.1</size> Planner";
private const string GraphButtonText = "Open GOAP Editor";
private const string IsActiveTooltip = "Whether current planner is active, will be disbled automatically" +
" when skipSearchWhenActionRunning is on";
private const string SkilSearchTooltip = "Enabled to skip search plan when already have an action, enable this will need you to set correct precondition" +
" for each action to let it quit by itself";
private const string BackendTooltip = "Select planner path execution backend, " +
"recommand using Normal Backend for simple job and using JobSystem Backend for including distance caculation and complex job";
private VisualElement backendView;
public override VisualElement CreateInspectorGUI()
{
var myInspector = new VisualElement();
//Title
myInspector.Add(UIUtility.GetLabel(LabelText, 20));
//Backend
myInspector.AddSpace();
var backendType = serializedObject.FindProperty("backendType");
var enumValue = Enum.GetValues(typeof(PlannerBackend)).Cast<Enum>().Select(v => v).ToList();
var backend = new EnumField("Backend", enumValue, (PlannerBackend)backendType.enumValueIndex)
{
tooltip = BackendTooltip
};
backend.RegisterValueChangedCallback((e) => OnBackendChanged((PlannerBackend)e.newValue));
myInspector.Add(backend);
//Default
InspectorElement.FillDefaultInspector(myInspector, serializedObject, this);
myInspector.Remove(myInspector.Q<PropertyField>("PropertyField:m_Script"));
myInspector.Remove(myInspector.Q<PropertyField>("PropertyField:skipSearchWhenActionRunning"));
myInspector.Remove(myInspector.Q<PropertyField>("PropertyField:isActive"));
myInspector.Remove(myInspector.Q<PropertyField>("PropertyField:backendType"));
//Setting
myInspector.AddSpace();
UIUtility.GetLabel("Normal Setting", 14, color: UIUtility.AkiBlue, anchor: TextAnchor.MiddleLeft).AddTo(myInspector);
myInspector.Q<PropertyField>("PropertyField:logType").MoveToEnd(myInspector);
myInspector.Q<PropertyField>("PropertyField:tickType").MoveToEnd(myInspector);
//Editor
backendView = new VisualElement();
//Pro Setting
if ((PlannerBackend)backendType.enumValueIndex == PlannerBackend.JobSystem)
{
DrawJobSystemsBackend(backendView);
}
myInspector.Add(backendView);
//Editor Buttpm
UIUtility.GetButton(GraphButtonText, UIUtility.AkiBlue, ShowGOAPEditor, 100)
.Enabled(Application.isPlaying)
.AddTo(myInspector);
return myInspector;
}
private void DrawJobSystemsBackend(VisualElement myInspector)
{
var isActive = new Toggle("Is Active")
{
tooltip = IsActiveTooltip
};
isActive.BindProperty(serializedObject.FindProperty("isActive"));
isActive.AddTo(myInspector);
myInspector.AddSpace();
UIUtility.GetLabel("Pro Setting", 14, color: UIUtility.AkiBlue, anchor: TextAnchor.MiddleLeft).AddTo(myInspector);
var skipSearchProperty = serializedObject.FindProperty("skipSearchWhenActionRunning");
var skipSearchToggle = new Toggle("Skip Search When Action Running")
{
tooltip = SkilSearchTooltip
};
skipSearchToggle.BindProperty(skipSearchProperty);
skipSearchToggle.AddTo(myInspector);
}
private void OnBackendChanged(PlannerBackend newBackend)
{
serializedObject.FindProperty("backendType").enumValueIndex = (int)newBackend;
serializedObject.ApplyModifiedProperties();
//Repaint Editor
backendView.Clear();
if (newBackend == PlannerBackend.JobSystem)
{
DrawJobSystemsBackend(backendView);
}
}
private void ShowGOAPEditor()
{
GOAPEditorWindow.ShowEditorWindow(target as IGOAPSet);
Expand Down
2 changes: 1 addition & 1 deletion Editor/Core/GOAPPlannerEditor.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 0 additions & 56 deletions Editor/Core/GOAPPlannerProEditor.cs

This file was deleted.

27 changes: 0 additions & 27 deletions Editor/Core/GOAPSetEditor.cs

This file was deleted.

43 changes: 43 additions & 0 deletions Editor/Core/SetEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
namespace Kurisu.GOAP.Editor
{
public abstract class SetEditor : UnityEditor.Editor
{
protected abstract string LabelText { get; }
private const string ButtonText = "Open GOAP Editor";
public override VisualElement CreateInspectorGUI()
{
var myInspector = new VisualElement();
myInspector.styleSheets.Add(UIUtility.GetInspectorStyleSheet());
myInspector.Add(UIUtility.GetLabel(LabelText, 20));
var description = new TextField(string.Empty);
description.BindProperty(serializedObject.FindProperty("Description"));
description.multiline = true;
myInspector.Add(description);
//Draw Button
myInspector.Add(UIUtility.GetButton(ButtonText, UIUtility.AkiBlue, Open, 100));
return myInspector;
}
private void Open()
{
GOAPEditorWindow.ShowEditorWindow(target as IGOAPSet);
}
}
[CustomEditor(typeof(GOAPActionSet))]
public class GOAPActionSetEditor : SetEditor
{
protected override string LabelText => "AkiGOAP <size=12>V1.1.1</size> ActionSet";
}
[CustomEditor(typeof(GOAPGoalSet))]
public class GOAPGoalSetEditor : SetEditor
{
protected override string LabelText => "AkiGOAP <size=12>V1.1.1</size> GoalSet";
}
[CustomEditor(typeof(GOAPSet))]
public class GOAPSetEditor : SetEditor
{
protected override string LabelText => "AkiGOAP <size=12>V1.1.1</size> GOAPSet";
}
}
File renamed without changes.
2 changes: 1 addition & 1 deletion Editor/Core/WorldStateEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public override VisualElement CreateInspectorGUI()
myInspector.Add(stateLabel);
statesGroup = new VisualElement();
myInspector.Add(statesGroup);
if (StatesInfo.GetValue(localState) is not Dictionary<string, bool> states || states.Count == 0) return myInspector;
if (localState == null) return myInspector;
if (StatesInfo.GetValue(localState) is not Dictionary<string, bool> states || states.Count == 0) return myInspector;
RefreshStates();
}
return myInspector;
Expand Down
16 changes: 8 additions & 8 deletions Editor/Member/StringResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@
using UnityEngine.UIElements;
namespace Kurisu.GOAP.Editor
{
public class StringResolver : FieldResolver<TextField,string>
public class StringResolver : FieldResolver<TextField, string>
{
private bool multiline;
private readonly bool multiline;
public StringResolver(FieldInfo fieldInfo) : base(fieldInfo)
{
multiline=fieldInfo.GetCustomAttribute<MultilineAttribute>()!=null;
multiline = fieldInfo.GetCustomAttribute<MultilineAttribute>() != null;
}
protected override TextField CreateEditorField(FieldInfo fieldInfo)
{
var field = new TextField(fieldInfo.Name);
field.style.minWidth = 200;
if(multiline)
if (multiline)
{
field.multiline=true;
field.style.maxWidth=250;
field.style.whiteSpace=WhiteSpace.Normal;
field.multiline = true;
field.style.maxWidth = 250;
field.style.whiteSpace = WhiteSpace.Normal;
}
return field;
}
public static bool IsAcceptable(Type infoType,FieldInfo info)=>infoType == typeof(string);
public static bool IsAcceptable(Type infoType, FieldInfo _) => infoType == typeof(string);
}
}
Loading

0 comments on commit 1f0895a

Please sign in to comment.