Skip to content

Commit b4c9e36

Browse files
Merge pull request #13 from MystikalPooka/UpdateUniRX
Update uni rx
2 parents 0a15db1 + 6fbca30 commit b4c9e36

File tree

254 files changed

+17339
-1837
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

254 files changed

+17339
-1837
lines changed

Assets/Editor/BehaviorLogDrawer.cs

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
using Assets.Scripts.AI.Behavior_Logger;
2+
using UniRx;
3+
using UnityEngine;
4+
using System;
5+
using UnityEditor;
6+
using Assets.Editor.BehaviorTreeViewEditor;
7+
using System.Collections.Generic;
8+
9+
namespace Assets.Editor
10+
{
11+
public class BehaviorLogDrawer
12+
{
13+
private int BehaviorID;
14+
private string ManagerName = "Wolf Pancakes Taste Like Fur";
15+
public Rect DrawHere;
16+
17+
public Vector2 BoxSize;
18+
public RectOffset TotalOffset;
19+
20+
protected BehaviorLogDrawer Parent = null;
21+
22+
/// <summary>
23+
/// Depth of this drawer (taken from entry) Default: 0
24+
/// </summary>
25+
private int DrawDepth = 0;
26+
27+
private Dictionary<int, BehaviorLogDrawer> ChildrenDrawers = new Dictionary<int, BehaviorLogDrawer>();
28+
29+
/// <summary>
30+
/// Custom Styling options for this behavior log drawer
31+
/// </summary>
32+
public GUIStyle Style = new GUIStyle();
33+
34+
public BehaviorLogEntry Entry { get; set; }
35+
private IObservable<BehaviorLogEntry> LogStream;
36+
37+
public BehaviorLogDrawer(string loggerName, int ID, Vector2 boxSize, GUIStyle subStyle = null)
38+
{
39+
BehaviorID = ID;
40+
ManagerName = loggerName;
41+
BoxSize = boxSize;
42+
if (subStyle != null)
43+
Style = subStyle;
44+
else
45+
{
46+
Style = new GUIStyle();
47+
Style.margin = new RectOffset(15, 15, 30, 30);
48+
}
49+
50+
TotalOffset = Style.margin;
51+
Initialize();
52+
}
53+
54+
private bool Initialized = false;
55+
public void Initialize()
56+
{
57+
ChildrenDrawers = new Dictionary<int, BehaviorLogDrawer>();
58+
LogStream = ObservableBehaviorLogger.Listener
59+
.Where(x =>
60+
x.BehaviorID == BehaviorID &&
61+
x.LoggerName == ManagerName)
62+
.Do(x =>
63+
{
64+
Entry = x;
65+
if(Entry.State.HasChildren)
66+
{
67+
foreach (var child in Entry.State.Children)
68+
{
69+
if (!ChildrenDrawers.ContainsKey(child.ID))
70+
{
71+
float y = (child.Depth+1) * (BoxSize.y + Style.margin.top);
72+
ChildrenDrawers.Add(child.ID, new BehaviorLogDrawer(ManagerName, child.ID, BoxSize, Style)
73+
{
74+
Parent = this,
75+
DrawHere = new Rect(Style.margin.left, y, BoxSize.x, BoxSize.y)
76+
});
77+
}
78+
}
79+
}
80+
});
81+
82+
Initialized = true;
83+
}
84+
85+
public void DrawBehaviorWithAllChildren()
86+
{
87+
if (!Initialized)
88+
{
89+
Initialize();
90+
}
91+
//Draw Breadth First, Offset parent second
92+
LogStream.Subscribe();
93+
94+
int offset = Style.margin.left;
95+
96+
if(Entry == null)
97+
{
98+
return;
99+
}
100+
else if(Entry.State.HasChildren)
101+
{
102+
offset = DrawChildrenAndGetOffset() / 2;
103+
}
104+
var parent = Entry.State.Parent;
105+
if (parent != null)
106+
{
107+
if (parent.HasChildren)
108+
{
109+
if (parent.Children.Count == 1)
110+
{
111+
offset = (int)BoxSize.x / 2;
112+
}
113+
}
114+
}
115+
this.TotalOffset.left = offset;
116+
this.TotalOffset.right = offset;
117+
DrawBehaviorLogEntry();
118+
}
119+
120+
private int DrawChildrenAndGetOffset()
121+
{
122+
var newOffset = 0;
123+
BehaviorLogDrawer prevChildDrawer = null;
124+
foreach (var child in ChildrenDrawers.Values)
125+
{
126+
if (prevChildDrawer == null)
127+
{
128+
child.DrawHere.x = this.DrawHere.x;
129+
}
130+
else
131+
{
132+
child.DrawHere.x = prevChildDrawer.DrawHere.x +
133+
BoxSize.x +
134+
prevChildDrawer.TotalOffset.right;
135+
136+
newOffset += prevChildDrawer.TotalOffset.right;
137+
}
138+
139+
newOffset += (int)BoxSize.x;
140+
prevChildDrawer = child;
141+
child.DrawBehaviorWithAllChildren();
142+
}
143+
return newOffset;
144+
}
145+
146+
protected void DrawBehaviorLogEntry()
147+
{
148+
if(Entry != null)
149+
{
150+
var totalX = DrawHere.x + TotalOffset.left;
151+
var totalPosition = new Rect(totalX, DrawHere.y,
152+
BoxSize.x, BoxSize.y);
153+
154+
if(Parent != null)
155+
{
156+
var startVector = new Vector3(totalX + BoxSize.x / 2, DrawHere.y);
157+
var endVector = new Vector3(Parent.DrawHere.x + BoxSize.x / 2 + Parent.TotalOffset.left,
158+
Parent.DrawHere.y + BoxSize.y);
159+
using (new Handles.DrawingScope(Color.black))
160+
{
161+
Handles.DrawLine(startVector, endVector);
162+
}
163+
}
164+
165+
CustomGUI.DrawQuad(totalPosition, Entry.State.CurrentState.GetBehaviorStateColor());
166+
167+
GUI.BeginGroup(totalPosition);
168+
169+
if (Entry.State.Parent != null)
170+
{
171+
GUI.Label(new Rect(0, 20, 120, 30), new GUIContent(Entry.State.Parent.Name));
172+
}
173+
GUI.Label(new Rect(0,35,120,30), new GUIContent(Entry.State.Name));
174+
GUI.EndGroup();
175+
}
176+
}
177+
}
178+
}

Assets/Editor/BehaviorLogDrawer.cs.meta

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Editor/BehaviorManagerEditor.cs

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,15 @@ protected override void OnEnable()
2020
public override void OnInspectorGUI()
2121
{
2222
base.OnInspectorGUI();
23-
if(name == "")
24-
{
25-
if(GUILayout.Button("Create New Tree"))
26-
{
27-
CustomAssetUtility.CreateAsset<BehaviorTreeManagerAsset>();
28-
_BTreeAsset = (BehaviorTreeManagerAsset)Selection.activeObject;
29-
}
30-
}
3123

32-
if (GUILayout.Button("Save"))
24+
if (GUILayout.Button("Reload"))
3325
{
34-
string name = serializedObject.FindProperty("FileName").stringValue;
35-
if (name == "")
36-
{
37-
Debug.LogError("Name Field is required to save a behavior tree manager asset");
38-
}
39-
else
40-
{
41-
BTreeManager.SaveBehaviorAsset("Assets/Behaviors/" + name + ".asset", _BTreeAsset);
42-
}
43-
Debug.Log("Attempted save.");
26+
BTreeManager.Reinitialize();
4427
}
4528

46-
47-
if (GUILayout.Button("Reload"))
29+
if(GUILayout.Button("Debug"))
4830
{
49-
BTreeManager.Reinitialize();
31+
TreeDebuggerWindow.ShowWindow();
5032
}
5133
}
5234
}

Assets/Editor/BehaviorTreeViewEditor/BackendData/BehaviorTreeAsset.asset

Lines changed: 0 additions & 38 deletions
This file was deleted.

Assets/Editor/BehaviorTreeViewEditor/BackendData/BehaviorTreeAsset.asset.meta

Lines changed: 0 additions & 10 deletions
This file was deleted.

Assets/Editor/BehaviorTreeViewEditor/BackendData/MultiColumnBTreeWindow.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,9 @@ void CreateNewTree()
133133
{
134134
CustomAssetUtility.CreateAsset<BehaviorTreeManagerAsset>();
135135
_BehaviorTreeManagerAsset = (BehaviorTreeManagerAsset)Selection.activeObject;
136+
var root =new ParallelRunner("root",-1,-1);
136137
BehaviorExtensions.SaveBehaviorAsset(null, AssetDatabase.GetAssetPath(_BehaviorTreeManagerAsset),
137-
_BehaviorTreeManagerAsset,(ParallelRunner)_TreeView.treeModel.Root);
138+
_BehaviorTreeManagerAsset,(ParallelRunner)root);
138139
}
139140

140141
void OnSelectionChange()
@@ -180,12 +181,7 @@ void TopToolbar(Rect rect)
180181
GenericMenu menu = new GenericMenu();
181182
if (EditorGUILayout.DropdownButton(new GUIContent("Add Behavior"),FocusType.Passive))
182183
{
183-
foreach (var elType in BehaviorExtensions.GetListOfTypes<BehaviorTreeElement>())
184-
{
185-
var menuStrings = elType.ToString().Split('.');
186-
menu.AddItem(new GUIContent(menuStrings[menuStrings.Length-2] +
187-
"/" + menuStrings.Last()), false, OnTypeSelected, elType.ToString());
188-
}
184+
menu.CreateTypeMenu<BehaviorTreeElement>(OnTypeSelected);
189185
menu.ShowAsContext();
190186
}
191187

@@ -228,7 +224,7 @@ void BottomToolBar(Rect rect)
228224
{
229225
GUILayout.BeginArea(rect);
230226

231-
using (new EditorGUILayout.HorizontalScope())
227+
using(new EditorGUILayout.HorizontalScope())
232228
{
233229
var style = "miniButton";
234230
if (GUILayout.Button("Expand All", style))
@@ -246,7 +242,6 @@ void BottomToolBar(Rect rect)
246242
_TreeView.ShowParams = (MultiColumnBehaviorTreeView.ShowParameters)
247243
EditorGUILayout.EnumPopup("Show Parameter Lists", _TreeView.ShowParams, "miniButton");
248244
}
249-
250245
GUILayout.EndArea();
251246
}
252247
}

Assets/Editor/BehaviorTreeViewEditor/BackendData/MultiColumnBehaviorTreeView.cs

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,6 @@ internal class MultiColumnBehaviorTreeView : TreeViewWithTreeModel<BehaviorTreeE
1717
const float kTypeButtonWidth = 70f;
1818
public ShowParameters ShowParams;
1919

20-
private static Color GetBehaviorStateColor(int state)
21-
{
22-
switch (state)
23-
{
24-
case (int)BehaviorState.Fail:
25-
return Color.red;
26-
case (int)BehaviorState.Running:
27-
return Color.blue;
28-
case (int)BehaviorState.Success:
29-
return new Color(0.1f, 0.9f, 0.2f);
30-
case (int)BehaviorState.Null:
31-
return Color.grey;
32-
default:
33-
return Color.black;
34-
}
35-
}
36-
3720
// All columns
3821
enum BTreeColumns
3922
{
@@ -187,16 +170,9 @@ IOrderedEnumerable<TreeViewItem<BehaviorTreeElement>> InitialOrder(IEnumerable<T
187170

188171
protected override void ContextClickedItem(int id)
189172
{
190-
var item = treeModel.Find(id);
173+
//var item = treeModel.Find(id);
191174
GenericMenu menu = new GenericMenu();
192-
foreach (var elType in BehaviorExtensions.GetListOfTypes<BehaviorTreeElement>())
193-
{
194-
object[] obj = new object[2] { item, elType };
195-
var menuStrings = elType.ToString().Split('.');
196-
menu.AddItem(new GUIContent(menuStrings[menuStrings.Length - 2] + "/" + menuStrings.Last()),
197-
item.ElementType == elType.ToString(),
198-
OnMenuTypeSelected, obj);
199-
}
175+
menu.CreateTypeMenu<BehaviorTreeElement>(OnMenuTypeSelected);
200176
menu.ShowAsContext();
201177
}
202178

@@ -222,13 +198,11 @@ protected override void RowGUI(RowGUIArgs args)
222198
void CellGUI(Rect cellRect, TreeViewItem<BehaviorTreeElement> item, BTreeColumns column, ref RowGUIArgs args)
223199
{
224200
// Center cell rect vertically (makes it easier to place controls, icons etc in the cells)
225-
226-
227201
switch (column)
228202
{
229203
case BTreeColumns.State:
230204
CenterRectUsingSingleLineHeight(ref cellRect);
231-
EditorGUI.DrawRect(cellRect, GetBehaviorStateColor((int)item.data.CurrentState));
205+
//EditorGUI.DrawRect(cellRect, GetBehaviorStateColor((int)item.data.CurrentState));
232206
break;
233207
case BTreeColumns.Name:
234208
// Do toggle

0 commit comments

Comments
 (0)