更改文件架构

This commit is contained in:
CortexCore
2023-06-07 18:38:07 +08:00
parent 93292b1a59
commit ed84166723
720 changed files with 297 additions and 65 deletions

View File

@@ -0,0 +1,21 @@
{
"name": "Editor.BITKit.Debuger",
"rootNamespace": "",
"references": [
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
"GUID:38cb48f0835da4e4eb93d878b2eceb9f",
"GUID:2bafac87e7f4b9b418d9448d219b01ab",
"GUID:9400d40641bab5b4a9702f65bf5c6eb5"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [
"UNITY_EDITOR"
],
"versionDefines": [],
"noEngineReferences": false
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 67f0e518066885046b662a8c8f117310
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,94 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
using UnityEditor;
using UnityEditor.UIElements;
using System.Reflection;
using System.Linq;
namespace BITKit
{
[CustomPropertyDrawer(typeof(TempValue<float>))]
public sealed class TempValueFloatPropertyDrawer : TempValuePropertyDrawer<float, Slider>
{
protected override void OnCreate(VisualElement root, TempValue<float> tempValue, MethodInfo actionMethod, Slider element)
{
element.showInputField = true;
element.lowValue = tempValue.lowValue;
element.highValue = tempValue.highValue;
}
}
[CustomPropertyDrawer(typeof(TempValue<Vector3>))]
public sealed class TempValueVector3PropertyDrawer : TempValuePropertyDrawer<Vector3, Vector3Field>
{
protected override void OnCreate(VisualElement root, TempValue<Vector3> tempValue, MethodInfo actionMethod, Vector3Field element)
{
}
}
[CustomPropertyDrawer(typeof(TempValue<string>))]
public sealed class TempValueStringPropertyDrawer : TempValuePropertyDrawer<string, TextField>
{
protected override void OnCreate(VisualElement root, TempValue<string> tempValue, MethodInfo actionMethod, TextField element)
{
base.OnCreate(root, tempValue, actionMethod, element);
if (tempValue.optionals.IsValid())
{
DropdownField dropdown = new();
var value = tempValue.Get();
dropdown.choices = tempValue.optionals.ToList();
if (value is not null)
dropdown.SetValueWithoutNotify(value);
dropdown.RegisterValueChangedCallback(x =>
{
if (EditorApplication.isPlaying && x.previousValue?.Equals(x.newValue) is false)
{
actionMethod.Invoke(tempValue, new object[] { x.newValue });
}
});
root.Add(dropdown);
}
}
}
public abstract class TempValuePropertyDrawer<T, V> : PropertyDrawer where V : BindableElement, INotifyValueChanged<T>, new()
{
public override VisualElement CreatePropertyGUI(SerializedProperty property)
{
VisualElement root = new();
V v = new();
var value = property.FindPropertyRelative("value");
var locked = property.FindPropertyRelative("locked");
var field = new V();
var monoBehaviour = property.serializedObject.targetObject as MonoBehaviour;
var type = monoBehaviour.GetType();
var tempValue = type.GetField(property.name).GetValue(monoBehaviour) as TempValue<T>;
var actionMethod = typeof(TempValue<T>).GetMethod("Set");
var toggle = new Toggle("Lock");
toggle.BindProperty(locked);
root.Add(field);
OnCreate(root, tempValue, actionMethod, field);
root.Add(toggle);
field.BindProperty(value);
field.RegisterValueChangedCallback(x =>
{
if (EditorApplication.isPlaying && x.previousValue.Equals(x.newValue) is false)
{
actionMethod.Invoke(tempValue, new object[] { x.newValue });
}
});
field.style.flexGrow = 1;
root.style.flexDirection = new(FlexDirection.Row);
return root;
}
protected virtual void OnCreate(VisualElement root, TempValue<T> tempValue, MethodInfo actionMethod, V element)
{
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f5309042421b31b438068b5a66f6f40d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,39 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEngine.UIElements;
namespace BITKit.Editors
{
[CustomEditor(typeof(UIDebuger))]
public class UIDebugerInspector : Editor
{
public override VisualElement CreateInspectorGUI()
{
var debuger = serializedObject.targetObject as UIDebuger;
VisualElement visualElement = new();
Slider slider = new("Scale");
Toggle toggle = new("Display");
slider.lowValue = 0;
slider.value = debuger.scale;
slider.highValue = 2;
toggle.value = debuger.display;
slider.RegisterValueChangedCallback(x =>
{
debuger.SetScale(x.newValue);
});
toggle.RegisterValueChangedCallback(x =>
{
debuger.SetDisplay(x.newValue);
});
visualElement.Add(slider);
visualElement.Add(toggle);
return visualElement;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 79a1bf639caee2648bb39da0a6ee7196
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: