Skip to content

Commit

Permalink
Merge pull request #17 from AkiKurisu/dev/v0.1.6
Browse files Browse the repository at this point in the history
Merge dev v0.1.6
  • Loading branch information
AkiKurisu authored Jan 31, 2025
2 parents 4f9929e + 61c6b94 commit 0bd7f02
Show file tree
Hide file tree
Showing 44 changed files with 202 additions and 172 deletions.
1 change: 1 addition & 0 deletions Editor/Core/UIElements/Graph/CeresBlackboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ protected void CreateBuiltInSharedVariableMenu(GenericMenu menu)
{
menu.AddItem(new GUIContent("Int"), false, () => AddVariable(new SharedInt(), true));
menu.AddItem(new GUIContent("Float"), false, () => AddVariable(new SharedFloat(), true));
menu.AddItem(new GUIContent("Double"), false, () => AddVariable(new SharedDouble(), true));
menu.AddItem(new GUIContent("Bool"), false, () => AddVariable(new SharedBool(), true));
menu.AddItem(new GUIContent("Vector2Int"), false, () => AddVariable(new SharedVector2Int(), true));
menu.AddItem(new GUIContent("Vector2"), false, () => AddVariable(new SharedVector2(), true));
Expand Down
4 changes: 1 addition & 3 deletions Editor/Core/UIElements/Graph/CeresGraphView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ protected virtual void OnPasteSerializedGraph(string operationName, string seria
/// <param name="blackboard"></param>
public void AddBlackboard(CeresBlackboard blackboard)
{
Blackboard = blackboard;
Blackboard.SetPosition(new Rect(20, 70, 250, 400));
Add(blackboard);
AddBlackboard(blackboard, new Rect(20, 70, 250, 400));
}

/// <summary>
Expand Down
4 changes: 0 additions & 4 deletions Editor/Core/UIElements/Graph/Fields/EnumField.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
using System;
using System.Collections.Generic;
#if UNITY_2022_1_OR_NEWER
using UnityEngine.UIElements;
#else
using UnityEditor.UIElements;
#endif
namespace Ceres.Editor.Graph
{
public class EnumField : PopupField<Enum>
Expand Down
22 changes: 11 additions & 11 deletions Editor/Core/UIElements/Graph/Fields/ListField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ namespace Ceres.Editor.Graph
{
public class ListField<T> : BaseField<List<T>>
{
protected readonly ListView ListView;
private readonly ListView _listView;

protected readonly Func<VisualElement> ElementCreator;
protected readonly Func<object> ValueCreator;
protected const int DefaultListItemHeight = 20;

private readonly Func<object> _valueCreator;

private const int DefaultListItemHeight = 20;

private ListField(string label, Func<VisualElement> elementCreator, Func<object> valueCreator, VisualElement listContainer) : base(label, listContainer)
{
value ??= new List<T>();
ElementCreator = elementCreator;
ValueCreator = valueCreator;
listContainer.Add(ListView = CreateListView());
_valueCreator = valueCreator;
listContainer.Add(_listView = CreateListView());
}

public ListField(string label, Func<VisualElement> elementCreator, Func<object> valueCreator) : this(label, elementCreator, valueCreator, new VisualElement())
Expand Down Expand Up @@ -58,8 +58,8 @@ protected virtual VisualElement OnMakeListItem()

protected virtual void OnRequestAddListItem()
{
value.Add((T)ValueCreator.Invoke());
ListView.RefreshItems();
value.Add((T)_valueCreator.Invoke());
_listView.RefreshItems();
}

public sealed override List<T> value
Expand All @@ -74,8 +74,8 @@ public sealed override List<T> value

private void UpdateValue()
{
if (ListView == null) return;
ListView.itemsSource = value; ListView.RefreshItems();
if (_listView == null) return;
_listView.itemsSource = value; _listView.RefreshItems();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
using System;
using System.Reflection;
#if UNITY_2022_1_OR_NEWER
using UnityEngine.UIElements;
#else
using UnityEditor.UIElements;
#endif
using UnityEngine;
namespace Ceres.Editor.Graph
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
using System;
using System.Reflection;
#if UNITY_2022_1_OR_NEWER
using UnityEngine.UIElements;
#else
using UnityEditor.UIElements;
#endif
using UnityEngine;
namespace Ceres.Editor.Graph
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
using System;
using System.Reflection;
#if UNITY_2022_1_OR_NEWER
using UnityEngine.UIElements;
#else
using UnityEditor.UIElements;
#endif
namespace Ceres.Editor.Graph
{
public class DoubleResolver : FieldResolver<DoubleField, double>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
using System;
using System.Reflection;
#if UNITY_2022_1_OR_NEWER
using UnityEngine.UIElements;
#else
using UnityEditor.UIElements;
#endif
namespace Ceres.Editor.Graph
{
public class FloatResolver : FieldResolver<FloatField, float>
Expand Down
4 changes: 0 additions & 4 deletions Editor/Core/UIElements/Graph/Fields/Resolvers/IntResolver.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
using System;
using System.Reflection;
#if UNITY_2022_1_OR_NEWER
using UnityEngine.UIElements;
#else
using UnityEditor.UIElements;
#endif
namespace Ceres.Editor.Graph
{
public class IntResolver : FieldResolver<IntegerField, int>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ protected override ListField<T> CreateEditorField(FieldInfo fieldInfo)
public override bool IsAcceptable(Type fieldValueType, FieldInfo _)
{
if (fieldValueType.IsGenericType && fieldValueType.GetGenericTypeDefinition() == typeof(List<>) && fieldValueType.GenericTypeArguments[0].IsEnum) return true;
if (fieldValueType.IsArray && fieldValueType.GetElementType()!.IsEnum) return true;
return false;
return fieldValueType.IsArray && fieldValueType.GetElementType()!.IsEnum;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class ListResolver<T> : FieldResolver<ListField<T>, List<T>, IList<T>>
{
protected readonly IFieldResolver ChildResolver;

// ReSharper disable once MemberCanBeProtected.Global
public ListResolver(FieldInfo fieldInfo, IFieldResolver resolver) : base(fieldInfo)
{
ChildResolver = resolver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class ObjectListResolver<T> : ListResolver<T> where T : UnityEngine.Objec
{

}

protected override ListField<T> CreateEditorField(FieldInfo fieldInfo)
{
return new ObjectListField<T>(fieldInfo.Name, () => ChildResolver.CreateField(), () => null);
Expand Down
4 changes: 0 additions & 4 deletions Editor/Core/UIElements/Graph/Fields/Resolvers/LongResolver.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
using System;
using System.Reflection;
#if UNITY_2022_1_OR_NEWER
using UnityEngine.UIElements;
#else
using UnityEditor.UIElements;
#endif
namespace Ceres.Editor.Graph
{
public class LongResolver : FieldResolver<LongField, long>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
using System;
using System.Reflection;
#if UNITY_2022_1_OR_NEWER
using UnityEngine.UIElements;
#else
using UnityEditor.UIElements;
#endif
using UnityEngine;
namespace Ceres.Editor.Graph
{
Expand Down
4 changes: 0 additions & 4 deletions Editor/Core/UIElements/Graph/Fields/Resolvers/RectResolver.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
using System;
using System.Reflection;
#if UNITY_2022_1_OR_NEWER
using UnityEngine.UIElements;
#else
using UnityEditor.UIElements;
#endif
using UnityEngine;
namespace Ceres.Editor.Graph
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
using UnityEditor.UIElements;
using System;
using UnityEngine.UIElements;
using UObject = UnityEngine.Object;
namespace Ceres.Editor.Graph
{
public class SharedObjectResolver : FieldResolver<SharedObjectField, SharedUObject>
public sealed class SharedObjectResolver : FieldResolver<SharedObjectField, SharedUObject>
{
public SharedObjectResolver(FieldInfo fieldInfo) : base(fieldInfo)
{
Expand All @@ -20,21 +21,22 @@ public override bool IsAcceptable(Type fieldValueType, FieldInfo _)
return fieldValueType == typeof(SharedUObject);
}
}
public class SharedObjectField : SharedVariableField<SharedUObject, UnityEngine.Object>

public sealed class SharedObjectField : SharedVariableField<SharedUObject, UObject>
{
public SharedObjectField(string label, Type objectType, FieldInfo fieldInfo) : base(label, objectType, fieldInfo)
{
}

protected override BaseField<UnityEngine.Object> CreateValueField()
protected override BaseField<UObject> CreateValueField()
{
return new ObjectField
{
objectType = value.GetValueType()
};
}

protected sealed override void OnRepaint()
protected override void OnRepaint()
{
((ObjectField)ValueField).objectType = value.GetValueType();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using UnityEngine.UIElements;
namespace Ceres.Editor.Graph
{
public class SharedStringResolver : SharedVariableResolver<SharedString, string, TextField>
public sealed class SharedStringResolver : SharedVariableResolver<SharedString, string, TextField>
{
public SharedStringResolver(FieldInfo fieldInfo) : base(fieldInfo)
{
Expand All @@ -15,7 +15,7 @@ protected override Field CreateEditorField(FieldInfo fieldInfo)
return new SharedStringField(fieldInfo.Name, fieldInfo.FieldType, fieldInfo);
}

public class SharedStringField : Field
public sealed class SharedStringField : Field
{
private readonly bool _multiline;
public SharedStringField(string label, Type objectType, FieldInfo fieldInfo) : base(label, objectType, fieldInfo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
using Ceres.Annotations;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
using UObject = UnityEngine.Object;
namespace Ceres.Editor.Graph
{
public class SharedTObjectResolver<T> : FieldResolver<SharedTObjectField<T>, SharedUObject<T>> where T : UnityEngine.Object
public sealed class SharedTObjectResolver<T> : FieldResolver<SharedTObjectField<T>, SharedUObject<T>> where T : UObject
{
public SharedTObjectResolver(FieldInfo fieldInfo) : base(fieldInfo)
{
Expand All @@ -25,7 +26,8 @@ public override bool IsAcceptable(Type fieldValueType, FieldInfo _)
return fieldValueType.IsSharedTObject() && fieldValueType.GenericTypeArguments.Length == 1 && fieldValueType.GenericTypeArguments[0] == typeof(T);
}
}
public class SharedTObjectField<T> : BaseField<SharedUObject<T>>, IBindableField where T : UnityEngine.Object

public class SharedTObjectField<T> : BaseField<SharedUObject<T>>, IBindableField where T : UObject
{
private readonly bool _forceShared;

Expand All @@ -38,6 +40,7 @@ public class SharedTObjectField<T> : BaseField<SharedUObject<T>>, IBindableField
private DropdownField _nameDropdown;

private SharedVariable _bindExposedProperty;

public SharedTObjectField(string label, FieldInfo fieldInfo) : base(label, null)
{
_forceShared = fieldInfo.GetCustomAttribute<ForceSharedAttribute>() != null;
Expand All @@ -59,6 +62,7 @@ public SharedTObjectField(string label, FieldInfo fieldInfo) : base(label, null)
}
_foldout.Add(_toggle);
}

public void BindGraph(CeresGraphView graph)
{
_graphView = graph;
Expand All @@ -70,6 +74,7 @@ public void BindGraph(CeresGraphView graph)
});
OnToggle(_toggle.value);
}

private static List<string> GetList(CeresGraphView graphView)
{
return graphView.SharedVariables
Expand All @@ -78,6 +83,7 @@ private static List<string> GetList(CeresGraphView graphView)
.Select(v => v.Name)
.ToList();
}

private void BindProperty()
{
if (_graphView == null) return;
Expand All @@ -86,6 +92,7 @@ private void BindProperty()
&& sharedObject.GetValueType().IsAssignableTo(typeof(T))
&& x.Name.Equals(value.Name));
}

private void OnToggle(bool isShared)
{
if (isShared)
Expand All @@ -101,26 +108,30 @@ private void OnToggle(bool isShared)
AddValueField();
}
}

private void AddNameDropDown()
{
var list = GetList(_graphView);
value.Name = value.Name ?? string.Empty;
value.Name ??= string.Empty;
int index = list.IndexOf(value.Name);
_nameDropdown = new DropdownField($"Shared {typeof(T).Name}", list, index);
_nameDropdown.RegisterCallback<MouseEnterEvent>((evt) => { _nameDropdown.choices = GetList(_graphView); });
_nameDropdown.RegisterValueChangedCallback(evt => { value.Name = evt.newValue; BindProperty(); NotifyValueChange(); });
_foldout.Insert(0, _nameDropdown);
}

private void RemoveNameDropDown()
{
if (_nameDropdown != null) _foldout.Remove(_nameDropdown);
_nameDropdown = null;
}

private void RemoveValueField()
{
if (ValueField != null) _foldout.Remove(ValueField);
ValueField = null;
}

private void AddValueField()
{
ValueField = new ObjectField()
Expand All @@ -131,6 +142,7 @@ private void AddValueField()
if (value != null) ValueField.value = value.Value;
_foldout.Insert(0, ValueField);
}

public sealed override SharedUObject<T> value
{
get => base.value; set
Expand All @@ -147,7 +159,9 @@ public sealed override SharedUObject<T> value
Repaint();
}
}

private ObjectField ValueField { get; set; }

public void Repaint()
{
_toggle.value = value.IsShared;
Expand All @@ -156,9 +170,10 @@ public void Repaint()
OnToggle(value.IsShared);
NotifyValueChange();
}
protected void NotifyValueChange()

private void NotifyValueChange()
{
using ChangeEvent<SharedUObject<T>> changeEvent = ChangeEvent<SharedUObject<T>>.GetPooled(value, value);
using var changeEvent = ChangeEvent<SharedUObject<T>>.GetPooled(value, value);
changeEvent.target = this;
SendEvent(changeEvent);
}
Expand Down
Loading

0 comments on commit 0bd7f02

Please sign in to comment.