init
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e7fc7377b1d5469abc7437b0ae10b63e
|
||||
timeCreated: 1761485555
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 11f768f38d9c4fb18dc357fde085548a
|
||||
timeCreated: 1761774372
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 67aaf260711d4718a2d97c29246a5ec7
|
||||
timeCreated: 1761919244
|
||||
@@ -0,0 +1,106 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using RPGCore.ObjectModules.EventObjectModule;
|
||||
using RPGCoreCommon.Helpers;
|
||||
using UnityEditor;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace RPGCore.Editor.Drawers.SceneModules.Event
|
||||
{
|
||||
[CustomEditor(typeof(EventModule))]
|
||||
public class EventModuleDrawer : UnityEditor.Editor
|
||||
{
|
||||
private class DrawerContext
|
||||
{
|
||||
public SerializedObject obj;
|
||||
public List<Type> events = new();
|
||||
public List<Type> preventableEvents = new();
|
||||
}
|
||||
|
||||
public override VisualElement CreateInspectorGUI()
|
||||
{
|
||||
var root = new VisualElement();
|
||||
|
||||
var property = serializedObject.GetIterator();
|
||||
|
||||
var enterChildren = true;
|
||||
while (property.NextVisible(enterChildren))
|
||||
{
|
||||
root.Add(new PropertyField(property) { enabledSelf = property.name != "m_Script" });
|
||||
enterChildren = false;
|
||||
}
|
||||
|
||||
root.Add(CreateEventList());
|
||||
return root;
|
||||
}
|
||||
|
||||
private VisualElement CreateEventList()
|
||||
{
|
||||
if (!EditorApplication.isPlaying)
|
||||
return new HelpBox("Subscribed events preview available only in play mode.", HelpBoxMessageType.Info);
|
||||
|
||||
var wrapper = new VisualElement();
|
||||
|
||||
var list1 = new Foldout();
|
||||
list1.text = "<b>Events</b> registered:";
|
||||
list1.style.marginLeft = 12;
|
||||
list1.Add(new Label("List empty."));
|
||||
wrapper.Add(list1);
|
||||
|
||||
var list2 = new Foldout();
|
||||
list2.text = "<b>Preventable Events (before)</b> registered:";
|
||||
list2.style.marginLeft = 12;
|
||||
list2.Add(new Label("List empty."));
|
||||
wrapper.Add(list2);
|
||||
|
||||
var list3 = new Foldout();
|
||||
list3.text = "<b>Preventable Events (after)</b> registered:";
|
||||
list3.style.marginLeft = 12;
|
||||
list3.Add(new Label("List empty."));
|
||||
wrapper.Add(list3);
|
||||
|
||||
var context = new DrawerContext{obj = serializedObject};
|
||||
wrapper.schedule.Execute(() => Refresh(context, list1, list2, list3)).Every(1000);
|
||||
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
private void Refresh(DrawerContext context, VisualElement list, VisualElement beforeList, VisualElement afterList)
|
||||
{
|
||||
var eventModule = context.obj.targetObject as EventModule;
|
||||
RefreshList(context.events, eventModule.events, list);
|
||||
RefreshList(context.preventableEvents, eventModule.preventableEvents.ToDictionary(pair => pair.Key, pair => pair.Value[0]), beforeList);
|
||||
RefreshList(context.preventableEvents, eventModule.preventableEvents.ToDictionary(pair => pair.Key, pair => pair.Value[1]), afterList);
|
||||
|
||||
context.events = eventModule.events.Keys.ToList();
|
||||
context.preventableEvents = eventModule.preventableEvents.Keys.ToList();
|
||||
}
|
||||
|
||||
private void RefreshList(List<Type> before, Dictionary<Type, Delegate> after, VisualElement list)
|
||||
{
|
||||
var toRemove = before.Except(after.Keys).ToList();
|
||||
var toAdd = after.Keys.Except(before).ToList();
|
||||
|
||||
if (!toRemove.Any() && !toAdd.Any()) return;
|
||||
|
||||
list.Clear();
|
||||
after.DictSelect((type, action) =>
|
||||
{
|
||||
var row = new VisualElement();
|
||||
row.style.flexDirection = FlexDirection.Row;
|
||||
row.Add(new HelpBox { text = type.Name });
|
||||
|
||||
var callers = action?.GetInvocationList().Select(a => $"{a.Target.GetType().Name} : {a.Method.Name}").StringJoin("\n");
|
||||
if (string.IsNullOrEmpty(callers)) callers = "<u>No registered callers</u>";
|
||||
row.Add(string.IsNullOrEmpty(callers) ? new Label() : new HelpBox { text = callers });
|
||||
|
||||
return row;
|
||||
|
||||
}).ForEach(list.Add);
|
||||
|
||||
if (!after.Any()) list.Add(new Label("List empty."));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3379740cce21445b882d2175c6f699ce
|
||||
timeCreated: 1761919852
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3d95afed367c4251b29cc8c3137f99dd
|
||||
timeCreated: 1761774365
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fa8e75168dd14631a1776e9eb6f4b0fd
|
||||
timeCreated: 1761839848
|
||||
@@ -0,0 +1,78 @@
|
||||
using System.Linq;
|
||||
using RPGCore.SceneModules.PathVisualizerSceneModule;
|
||||
using UnityEditor;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace RPGCore.Editor.Drawers.SceneModules.PathVisualizer
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(PathVisualizerModule))]
|
||||
public class PathVisualizerModuleDrawer : PropertyDrawer
|
||||
{
|
||||
public override VisualElement CreatePropertyGUI(SerializedProperty property)
|
||||
{
|
||||
var root = new VisualElement();
|
||||
|
||||
root.Add(new PropertyField(property));
|
||||
|
||||
if (EditorApplication.isPlaying)
|
||||
{
|
||||
root.Add(CreateList(property));
|
||||
}
|
||||
else
|
||||
{
|
||||
root.Add(new HelpBox("Subscribed events preview available only in play mode.", HelpBoxMessageType.Info));
|
||||
}
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
private VisualElement CreateList(SerializedProperty property)
|
||||
{
|
||||
var wrapper = new VisualElement();
|
||||
|
||||
var helpBox = new HelpBox();
|
||||
helpBox.text = "Usable only runtime via script.<br>Below is list of currently managed paths.";
|
||||
helpBox.messageType = HelpBoxMessageType.Info;
|
||||
helpBox.style.marginTop = 15;
|
||||
wrapper.Add(helpBox);
|
||||
|
||||
var list = new VisualElement();
|
||||
list.schedule.Execute(() => RefreshList(property, list)).Every(2500);
|
||||
list.Add(new Label("List empty."));
|
||||
wrapper.Add(list);
|
||||
|
||||
RefreshList(property, list);
|
||||
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
private void RefreshList(SerializedProperty property, VisualElement list)
|
||||
{
|
||||
var pathVisualizers = (property.boxedValue as PathVisualizerModule).pathVisualizers;
|
||||
|
||||
// No elements, only label with info
|
||||
if (pathVisualizers.Count == 0 && list.Children().FirstOrDefault() is Label) return;
|
||||
|
||||
// Nothing changed
|
||||
if (pathVisualizers.Count == list.childCount && list.Children().FirstOrDefault() is not Label) return;
|
||||
|
||||
list.Clear();
|
||||
|
||||
if (!pathVisualizers.Any())
|
||||
{
|
||||
list.Add(new Label("List empty."));
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var pathVisualizer in pathVisualizers)
|
||||
{
|
||||
if (!pathVisualizer) continue;
|
||||
var objectField = new ObjectField();
|
||||
objectField.value = pathVisualizer;
|
||||
objectField.SetEnabled(false);
|
||||
list.Add(objectField);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 774f2a8b09b7472c982b804adde32e41
|
||||
timeCreated: 1761839859
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "RPGCore.Editor",
|
||||
"rootNamespace": "RPGCore.Editor",
|
||||
"references": [
|
||||
"RPGCore",
|
||||
"RPGCoreCommon.Helpers"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 06fa85d8d22f490491ae2a4a024e353a
|
||||
timeCreated: 1759057737
|
||||
Reference in New Issue
Block a user