Skip to content

Commit

Permalink
Add BlackBoard.SetObject
Browse files Browse the repository at this point in the history
Fix null reference exception in BehaviorTreeSetting.GetMask
  • Loading branch information
AkiKurisu committed Jul 7, 2024
1 parent a95f698 commit 39b9ca5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
9 changes: 3 additions & 6 deletions Editor/Core/Model/BehaviorTreeSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,9 @@ public static StyleSheet GetNodeStyle(string editorName)
public static (string[], string[]) GetMask(string editorName)
{
var setting = GetOrCreateSettings();
if (setting.settings.Any(x => x.EditorName.Equals(editorName)))
{
var editorSetting = setting.settings.First(x => x.EditorName.Equals(editorName));
return (editorSetting.ShowGroups, editorSetting.NotShowGroups.Concat(new string[1] { "Hidden" }).ToArray());
}
return (null, null);
if (setting.settings == null || setting.settings.Length == 0 || !setting.settings.Any(x => x.EditorName.Equals(editorName))) return (null, null);
var editorSetting = setting.settings.First(x => x.EditorName.Equals(editorName));
return (editorSetting.ShowGroups, editorSetting.NotShowGroups.Concat(new string[1] { "Hidden" }).ToArray());
}
public static BehaviorTreeSetting GetOrCreateSettings()
{
Expand Down
20 changes: 20 additions & 0 deletions Runtime/Core/Model/BlackBoard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,25 @@ public SharedVariable<string> SetString(string key, string value)
variable.Value = value;
return variable;
}
public SharedVariable<Object> SetObject(string key, Object value)
{
if (!this.TryGetSharedObject(key, out SharedVariable<Object> variable))
{
variable = new SharedObject() { Name = key };
SharedVariables.Add(variable);
}
variable.Value = value;
return variable;
}
public SharedVariable<Object> SetTObject<T>(string key, T value) where T : Object
{
if (!this.TryGetSharedObject(key, out SharedVariable<Object> variable))
{
variable = new SharedObject() { Name = key, ConstraintTypeAQN = typeof(T).AssemblyQualifiedName };
SharedVariables.Add(variable);
}
variable.Value = value;
return variable;
}
}
}

0 comments on commit 39b9ca5

Please sign in to comment.