阶段性完成
This commit is contained in:
24
Assets/OtherPlugins/Le Tai's Asset/Common/Editor/Assets.cs
Normal file
24
Assets/OtherPlugins/Le Tai's Asset/Common/Editor/Assets.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
// Copyright (c) Le Loc Tai <leloctai.com> . All rights reserved. Do not redistribute.
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace LeTai.Common.Editor
|
||||
{
|
||||
public static class Assets
|
||||
{
|
||||
public static T Find<T>(string assetName, string label = "TranslucentImageEditorResources") where T : Object
|
||||
{
|
||||
var guids = AssetDatabase.FindAssets($"l:{label} {assetName}");
|
||||
if (guids.Length == 0)
|
||||
{
|
||||
Debug.LogError($"Asset \"{assetName}\" not found. " +
|
||||
$"Make sure it have the label \"TranslucentImageEditorResources\"");
|
||||
return null;
|
||||
}
|
||||
|
||||
var path = AssetDatabase.GUIDToAssetPath(guids[0]);
|
||||
return AssetDatabase.LoadAssetAtPath<T>(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 62f3490712e742dbafd854da4b66319c
|
||||
timeCreated: 1751092491
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 78464
|
||||
packageName: Translucent Image - Fast UI Background Blur
|
||||
packageVersion: 6.5.0
|
||||
assetPath: Assets/Le Tai's Asset/Common/Editor/Assets.cs
|
||||
uploadId: 824068
|
||||
@@ -0,0 +1,73 @@
|
||||
// Copyright (c) Le Loc Tai <leloctai.com> . All rights reserved. Do not redistribute.
|
||||
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace LeTai.Common.Editor
|
||||
{
|
||||
public static class EditorCustom
|
||||
{
|
||||
static readonly GUIContent LABEL = new GUIContent();
|
||||
|
||||
public class LabelWidthScope : GUI.Scope
|
||||
{
|
||||
readonly float oldLabelWidth;
|
||||
|
||||
public LabelWidthScope(float labelWidth)
|
||||
{
|
||||
oldLabelWidth = EditorGUIUtility.labelWidth;
|
||||
EditorGUIUtility.labelWidth = labelWidth;
|
||||
}
|
||||
|
||||
protected override void CloseScope()
|
||||
{
|
||||
EditorGUIUtility.labelWidth = oldLabelWidth;
|
||||
}
|
||||
}
|
||||
|
||||
public static (Rect labelRect, Rect fieldRect) PrefixLabel(Rect rect, int id, GUIContent label)
|
||||
{
|
||||
var fieldRect = EditorGUI.PrefixLabel(rect, id, label);
|
||||
var labelRect = new Rect(rect.x, rect.y, rect.width - fieldRect.width, rect.height);
|
||||
|
||||
return (labelRect, fieldRect);
|
||||
}
|
||||
|
||||
public static float LabelFloatField(Rect rectControl, Rect rectLabel, GUIContent label, float value, GUIStyle styleLabel = null, GUIStyle styleField = null)
|
||||
{
|
||||
var controlId = GUIUtility.GetControlID(FocusType.Keyboard, rectControl);
|
||||
EditorGUI.HandlePrefixLabel(rectControl, rectLabel, label, controlId, styleLabel);
|
||||
return EditorInternal.DoFloatFieldInternal(rectControl, rectLabel, controlId, value, style: styleField);
|
||||
}
|
||||
|
||||
public static void ComputedPropertyField(SerializedProperty property, Func<SerializedProperty, string> compute)
|
||||
{
|
||||
using var _ = new EditorGUILayout.HorizontalScope();
|
||||
EditorGUILayout.PropertyField(property);
|
||||
EditorGUILayout.LabelField(compute(property), GUILayout.ExpandWidth(false));
|
||||
}
|
||||
|
||||
public static bool LinkButton(string label, params GUILayoutOption[] options)
|
||||
{
|
||||
LABEL.text = label;
|
||||
return LinkButton(LABEL, options);
|
||||
}
|
||||
|
||||
public static bool LinkButton(GUIContent label, params GUILayoutOption[] options)
|
||||
{
|
||||
var rect = GUILayoutUtility.GetRect(label, EditorStyles.linkLabel, options);
|
||||
rect = EditorGUI.IndentedRect(rect);
|
||||
|
||||
// var prevHandleColor = Handles.color;
|
||||
// Handles.color = EditorStyles.linkLabel.normal.textColor;
|
||||
// Handles.DrawLine(new Vector3(position.xMin + EditorStyles.linkLabel.padding.left, position.yMax),
|
||||
// new Vector3(position.xMax - EditorStyles.linkLabel.padding.right, position.yMax));
|
||||
// Handles.color = prevHandleColor;
|
||||
|
||||
EditorGUIUtility.AddCursorRect(rect, MouseCursor.Link);
|
||||
|
||||
return GUI.Button(rect, label, EditorStyles.linkLabel);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a42329183e3c49b9a43603047c1a7e92
|
||||
timeCreated: 1751092578
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 78464
|
||||
packageName: Translucent Image - Fast UI Background Blur
|
||||
packageVersion: 6.5.0
|
||||
assetPath: Assets/Le Tai's Asset/Common/Editor/EditorCustom.cs
|
||||
uploadId: 824068
|
||||
@@ -0,0 +1,69 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace LeTai.Common.Editor
|
||||
{
|
||||
static class EditorInternal
|
||||
{
|
||||
static readonly MethodInfo DO_FLOAT_FIELD_METHOD;
|
||||
#if UNITY_6000_0_OR_NEWER
|
||||
static readonly PropertyInfo RECYCLED_EDITOR_PROPERTY;
|
||||
#else
|
||||
static readonly FieldInfo RECYCLED_EDITOR_PROPERTY;
|
||||
#endif
|
||||
static readonly FieldInfo FLOAT_FIELD_FORMAT_STRING_CONST;
|
||||
|
||||
static EditorInternal()
|
||||
{
|
||||
var editorGUIType = typeof(EditorGUI);
|
||||
const BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Static;
|
||||
|
||||
Type[] argumentTypes = {
|
||||
Assembly.GetAssembly(editorGUIType).GetType("UnityEditor.EditorGUI+RecycledTextEditor"),
|
||||
typeof(Rect),
|
||||
typeof(Rect),
|
||||
typeof(int),
|
||||
typeof(float),
|
||||
typeof(string),
|
||||
typeof(GUIStyle),
|
||||
typeof(bool)
|
||||
};
|
||||
DO_FLOAT_FIELD_METHOD = editorGUIType.GetMethod("DoFloatField", flags, null, argumentTypes, null);
|
||||
#if UNITY_6000_0_OR_NEWER
|
||||
RECYCLED_EDITOR_PROPERTY = editorGUIType.GetProperty("s_RecycledEditor", flags);
|
||||
#else
|
||||
RECYCLED_EDITOR_PROPERTY = editorGUIType.GetField("s_RecycledEditor", flags);
|
||||
#endif
|
||||
FLOAT_FIELD_FORMAT_STRING_CONST = editorGUIType.GetField("kFloatFieldFormatString", flags);
|
||||
}
|
||||
|
||||
internal static float DoFloatFieldInternal(
|
||||
Rect position,
|
||||
Rect dragHotZone,
|
||||
int id,
|
||||
float value,
|
||||
string formatString = null,
|
||||
GUIStyle style = null,
|
||||
bool draggable = true
|
||||
)
|
||||
{
|
||||
style = style ?? EditorStyles.numberField;
|
||||
formatString = formatString ?? (string)FLOAT_FIELD_FORMAT_STRING_CONST.GetValue(null);
|
||||
|
||||
var editor = RECYCLED_EDITOR_PROPERTY.GetValue(null);
|
||||
|
||||
return (float)DO_FLOAT_FIELD_METHOD.Invoke(null, new[] {
|
||||
editor,
|
||||
position,
|
||||
dragHotZone,
|
||||
id,
|
||||
value,
|
||||
formatString,
|
||||
style,
|
||||
draggable
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c8c94534f87244218d95b02d343eabf2
|
||||
timeCreated: 1695375609
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 78464
|
||||
packageName: Translucent Image - Fast UI Background Blur
|
||||
packageVersion: 6.5.0
|
||||
assetPath: Assets/Le Tai's Asset/Common/Editor/EditorInternal.cs
|
||||
uploadId: 824068
|
||||
@@ -0,0 +1,57 @@
|
||||
// Copyright (c) Le Loc Tai <leloctai.com> . All rights reserved. Do not redistribute.
|
||||
|
||||
using System;
|
||||
using UnityEditor;
|
||||
|
||||
namespace LeTai.Common.Editor
|
||||
{
|
||||
public class EditorPrefValue<T>
|
||||
{
|
||||
readonly string key;
|
||||
readonly T initialValue;
|
||||
|
||||
public T Value
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!EditorPrefs.HasKey(key))
|
||||
{
|
||||
Value = initialValue;
|
||||
return initialValue;
|
||||
}
|
||||
|
||||
return typeof(T) switch {
|
||||
{ } t when t == typeof(bool) => (T)(object)EditorPrefs.GetBool(key),
|
||||
{ } t when t == typeof(float) => (T)(object)EditorPrefs.GetFloat(key),
|
||||
|
||||
_ => throw new ArgumentException("Type " + typeof(T) + " is not supported.")
|
||||
};
|
||||
}
|
||||
set
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case bool v:
|
||||
EditorPrefs.SetBool(key, v);
|
||||
break;
|
||||
case float v:
|
||||
EditorPrefs.SetFloat(key, v);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException("Type " + typeof(T) + " is not supported.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public EditorPrefValue(string key, T initialValue = default)
|
||||
{
|
||||
this.key = key;
|
||||
this.initialValue = initialValue;
|
||||
}
|
||||
|
||||
public static implicit operator T(EditorPrefValue<T> value)
|
||||
{
|
||||
return value.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6654bb5e80e849c999172d15fba0797d
|
||||
timeCreated: 1751272512
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 78464
|
||||
packageName: Translucent Image - Fast UI Background Blur
|
||||
packageVersion: 6.5.0
|
||||
assetPath: Assets/Le Tai's Asset/Common/Editor/EditorPrefValue.cs
|
||||
uploadId: 824068
|
||||
@@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace LeTai.Common.Editor
|
||||
{
|
||||
public class EditorProperty
|
||||
{
|
||||
public readonly SerializedProperty serializedProperty;
|
||||
|
||||
readonly SerializedObject serializedObject;
|
||||
readonly MethodInfo propertySetter;
|
||||
readonly SerializedProperty dirtyFlag;
|
||||
|
||||
public EditorProperty(SerializedObject obj, string name, string serializedName = null)
|
||||
{
|
||||
serializedObject = obj;
|
||||
serializedProperty = FindPropertyByName(serializedObject, name);
|
||||
propertySetter = serializedObject.targetObject.GetType().GetProperty(name).SetMethod;
|
||||
dirtyFlag = serializedObject.FindProperty("modifiedFromInspector");
|
||||
}
|
||||
|
||||
static SerializedProperty FindPropertyByName(SerializedObject obj, string name)
|
||||
{
|
||||
var sb = new StringBuilder(name.Length + 1);
|
||||
var lower = sb.Append(char.ToLowerInvariant(name[0])).Append(name[1..]).ToString();
|
||||
var property = obj.FindProperty(lower);
|
||||
if (property != null)
|
||||
return property;
|
||||
|
||||
sb.Clear();
|
||||
property = obj.FindProperty(sb.Append('_').Append(lower).ToString());
|
||||
if (property != null)
|
||||
return property;
|
||||
|
||||
throw new ArgumentException($"Can't automatically find serialized name for property {name} in {obj.targetObject.GetType()}");
|
||||
}
|
||||
|
||||
public void Draw(params GUILayoutOption[] options)
|
||||
{
|
||||
using (var scope = new EditorGUI.ChangeCheckScope())
|
||||
{
|
||||
EditorGUILayout.PropertyField(serializedProperty, options);
|
||||
|
||||
if (!scope.changed)
|
||||
return;
|
||||
|
||||
if (dirtyFlag != null)
|
||||
dirtyFlag.boolValue = true;
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
if (serializedProperty.propertyType != SerializedPropertyType.Generic) // Not needed for now
|
||||
{
|
||||
var propertyValue = GetPropertyValue();
|
||||
CallSetters(propertyValue);
|
||||
}
|
||||
|
||||
// In case the setter changes any serialized data
|
||||
serializedObject.Update();
|
||||
}
|
||||
}
|
||||
|
||||
public void CallSetters(object value)
|
||||
{
|
||||
foreach (var target in serializedObject.targetObjects)
|
||||
propertySetter.Invoke(target, new[] { value });
|
||||
}
|
||||
|
||||
object GetPropertyValue()
|
||||
{
|
||||
switch (serializedProperty.propertyType)
|
||||
{
|
||||
case SerializedPropertyType.ObjectReference:
|
||||
return serializedProperty.objectReferenceValue;
|
||||
case SerializedPropertyType.Float:
|
||||
return serializedProperty.floatValue;
|
||||
case SerializedPropertyType.Integer:
|
||||
return serializedProperty.intValue;
|
||||
case SerializedPropertyType.Rect:
|
||||
return serializedProperty.rectValue;
|
||||
case SerializedPropertyType.Enum:
|
||||
return serializedProperty.enumValueIndex;
|
||||
case SerializedPropertyType.Boolean:
|
||||
return serializedProperty.boolValue;
|
||||
case SerializedPropertyType.Color:
|
||||
return serializedProperty.colorValue;
|
||||
case SerializedPropertyType.Vector2:
|
||||
return serializedProperty.vector2Value;
|
||||
default: throw new NotImplementedException($"Type {serializedProperty.propertyType} is not implemented");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a6efd34a11308a746bf9a43556eb283b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 78464
|
||||
packageName: Translucent Image - Fast UI Background Blur
|
||||
packageVersion: 6.5.0
|
||||
assetPath: Assets/Le Tai's Asset/Common/Editor/EditorProperty.cs
|
||||
uploadId: 824068
|
||||
@@ -0,0 +1,67 @@
|
||||
// Copyright (c) Le Loc Tai <leloctai.com> . All rights reserved. Do not redistribute.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Build;
|
||||
|
||||
namespace LeTai.Common.Editor
|
||||
{
|
||||
public static class EditorUtils
|
||||
{
|
||||
public static List<string> GetDefines(BuildTarget buildTarget = BuildTarget.NoTarget)
|
||||
{
|
||||
if (buildTarget == BuildTarget.NoTarget)
|
||||
buildTarget = EditorUserBuildSettings.activeBuildTarget;
|
||||
|
||||
var currentGroup = BuildPipeline.GetBuildTargetGroup(buildTarget);
|
||||
string definesStr;
|
||||
#if UNITY_2021_2_OR_NEWER
|
||||
var namedBuildTarget = NamedBuildTarget.FromBuildTargetGroup(currentGroup);
|
||||
definesStr = PlayerSettings.GetScriptingDefineSymbols(namedBuildTarget);
|
||||
#else
|
||||
definesStr = PlayerSettings.GetScriptingDefineSymbolsForGroup(currentGroup);
|
||||
#endif
|
||||
return definesStr.Split(';').ToList();
|
||||
}
|
||||
|
||||
public static void SetDefines(IEnumerable<string> defines, BuildTarget buildTarget = BuildTarget.NoTarget)
|
||||
{
|
||||
if (buildTarget == BuildTarget.NoTarget)
|
||||
buildTarget = EditorUserBuildSettings.activeBuildTarget;
|
||||
|
||||
var newDefinesStr = string.Join(";", defines);
|
||||
|
||||
var currentGroup = BuildPipeline.GetBuildTargetGroup(buildTarget);
|
||||
#if UNITY_2021_2_OR_NEWER
|
||||
var namedBuildTarget = NamedBuildTarget.FromBuildTargetGroup(currentGroup);
|
||||
PlayerSettings.SetScriptingDefineSymbols(namedBuildTarget, newDefinesStr);
|
||||
#else
|
||||
PlayerSettings.SetScriptingDefineSymbolsForGroup(currentGroup, newDefinesStr);
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void AddDefines(HashSet<string> toAdd, BuildTarget buildTarget = BuildTarget.NoTarget)
|
||||
{
|
||||
if (buildTarget == BuildTarget.NoTarget)
|
||||
buildTarget = EditorUserBuildSettings.activeBuildTarget;
|
||||
|
||||
var defines = GetDefines(buildTarget);
|
||||
var missing = toAdd.Except(defines).ToList();
|
||||
defines.AddRange(missing);
|
||||
if (missing.Count > 0)
|
||||
SetDefines(defines, buildTarget);
|
||||
}
|
||||
|
||||
public static void RemoveDefines(HashSet<string> toRemove, BuildTarget buildTarget = BuildTarget.NoTarget)
|
||||
{
|
||||
if (buildTarget == BuildTarget.NoTarget)
|
||||
buildTarget = EditorUserBuildSettings.activeBuildTarget;
|
||||
|
||||
var defines = GetDefines(buildTarget);
|
||||
var removed = defines.Except(toRemove).ToList();
|
||||
if (removed.Count < defines.Count)
|
||||
SetDefines(removed, buildTarget);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cead91eb2ca046498697087e0c426513
|
||||
timeCreated: 1751099123
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 78464
|
||||
packageName: Translucent Image - Fast UI Background Blur
|
||||
packageVersion: 6.5.0
|
||||
assetPath: Assets/Le Tai's Asset/Common/Editor/EditorUtils.cs
|
||||
uploadId: 824068
|
||||
114
Assets/OtherPlugins/Le Tai's Asset/Common/Editor/Knob.cs
Normal file
114
Assets/OtherPlugins/Le Tai's Asset/Common/Editor/Knob.cs
Normal file
@@ -0,0 +1,114 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using EGU = UnityEditor.EditorGUIUtility;
|
||||
|
||||
namespace LeTai.Common.Editor
|
||||
{
|
||||
public static class EditorGUICustom
|
||||
{
|
||||
static readonly Texture2D KNOB_BG_TEXTURE = Assets.Find<Texture2D>("Knob_BG");
|
||||
static readonly Texture2D KNOB_FG_TEXTURE = Assets.Find<Texture2D>("Knob_FG");
|
||||
|
||||
static readonly Color KNOB_BG_COLOR;
|
||||
static readonly Color KNOB_FG_COLOR;
|
||||
static readonly Color KNOB_FG_COLOR_ACTIVE;
|
||||
|
||||
static EditorGUICustom()
|
||||
{
|
||||
if (EGU.isProSkin)
|
||||
{
|
||||
KNOB_BG_COLOR = new Color(.164f, .164f, .164f);
|
||||
KNOB_FG_COLOR = new Color(.701f, .701f, .701f);
|
||||
KNOB_FG_COLOR_ACTIVE = new Color(.49f, .67f, .94f);
|
||||
}
|
||||
else
|
||||
{
|
||||
KNOB_BG_COLOR = new Color(.941f, .941f, .941f);
|
||||
KNOB_FG_COLOR = new Color(.239f, .239f, .239f);
|
||||
KNOB_FG_COLOR_ACTIVE = new Color(.054f, .274f, .549f);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static float KnobField(GUIContent label, float angle, Vector2 zeroVector, float height = 0)
|
||||
{
|
||||
if (height <= 0)
|
||||
height = EGU.singleLineHeight * 1.3f;
|
||||
float knobSize = height + EGU.standardVerticalSpacing * (4 - 1);
|
||||
float knobYOffset = (height - knobSize) / 2;
|
||||
|
||||
Rect rect = EditorGUILayout.GetControlRect(true, height);
|
||||
|
||||
var labelRect = new Rect(rect) {
|
||||
y = rect.y + (height - EGU.singleLineHeight) / 2,
|
||||
height = EGU.singleLineHeight
|
||||
};
|
||||
|
||||
var oldLabelWidth = EGU.labelWidth;
|
||||
EGU.labelWidth -= height;
|
||||
|
||||
int fieldId = GUIUtility.GetControlID(FocusType.Keyboard, labelRect);
|
||||
var fieldRect = EditorGUI.PrefixLabel(labelRect, fieldId, label);
|
||||
labelRect.xMax = fieldRect.x;
|
||||
fieldRect.x += height;
|
||||
fieldRect.width -= height;
|
||||
|
||||
Rect knobRect = new Rect(rect.x + EGU.labelWidth + knobYOffset,
|
||||
rect.y + knobYOffset,
|
||||
knobSize, knobSize);
|
||||
|
||||
angle = Knob(knobRect, angle, zeroVector);
|
||||
angle = EditorInternal.DoFloatFieldInternal(fieldRect, labelRect, fieldId, angle);
|
||||
|
||||
EGU.labelWidth = oldLabelWidth;
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
||||
public static float Knob(Rect position, float angle, Vector2 zeroVector)
|
||||
{
|
||||
int controlID = GUIUtility.GetControlID(FocusType.Passive, position);
|
||||
|
||||
if (Event.current != null)
|
||||
{
|
||||
if (Event.current.type == EventType.MouseDown && position.Contains(Event.current.mousePosition))
|
||||
{
|
||||
GUIUtility.hotControl = controlID;
|
||||
|
||||
var dir = (Event.current.mousePosition - position.center).normalized;
|
||||
angle = MathCustom.VecToAngle360(zeroVector, dir);
|
||||
|
||||
GUI.changed = true;
|
||||
}
|
||||
else if (Event.current.type == EventType.MouseUp && GUIUtility.hotControl == controlID)
|
||||
{
|
||||
GUIUtility.hotControl = 0;
|
||||
}
|
||||
else if (Event.current.type == EventType.MouseDrag && GUIUtility.hotControl == controlID)
|
||||
{
|
||||
var dir = (Event.current.mousePosition - position.center).normalized;
|
||||
angle = MathCustom.VecToAngle360(zeroVector, dir);
|
||||
|
||||
GUI.changed = true;
|
||||
}
|
||||
else if (Event.current.type == EventType.Repaint)
|
||||
{
|
||||
var notRotated = GUI.matrix;
|
||||
var oldColor = GUI.color;
|
||||
var highlighted = GUIUtility.hotControl == controlID;
|
||||
|
||||
GUIUtility.RotateAroundPivot(angle, position.center);
|
||||
GUI.color = KNOB_BG_COLOR;
|
||||
GUI.DrawTexture(position, KNOB_BG_TEXTURE, ScaleMode.ScaleToFit, true, 1);
|
||||
GUI.color = highlighted ? KNOB_FG_COLOR_ACTIVE : KNOB_FG_COLOR;
|
||||
GUI.DrawTexture(position, KNOB_FG_TEXTURE, ScaleMode.ScaleToFit, true, 1);
|
||||
|
||||
GUI.matrix = notRotated;
|
||||
GUI.color = oldColor;
|
||||
}
|
||||
}
|
||||
|
||||
return angle;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8785778a8d728904589c40f715ae793d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 78464
|
||||
packageName: Translucent Image - Fast UI Background Blur
|
||||
packageVersion: 6.5.0
|
||||
assetPath: Assets/Le Tai's Asset/Common/Editor/Knob.cs
|
||||
uploadId: 824068
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "LeTai.Common.Editor",
|
||||
"rootNamespace": "LeTai.Common.Editor",
|
||||
"references": ["GUID:07cd4d3e8f0583542ab74e7b8b032f7e"],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6329229812871a6488deb623f659955b
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 78464
|
||||
packageName: Translucent Image - Fast UI Background Blur
|
||||
packageVersion: 6.5.0
|
||||
assetPath: Assets/Le Tai's Asset/Common/Editor/LeTai.Common.Editor.asmdef
|
||||
uploadId: 824068
|
||||
@@ -0,0 +1,24 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace LeTai.Common.Editor
|
||||
{
|
||||
public static class MathCustom
|
||||
{
|
||||
public static float VecToAngle360(Vector2 from, Vector2 to)
|
||||
{
|
||||
float angle = Vector2.SignedAngle(from, to);
|
||||
return angle < 0 ? 360 + angle : angle;
|
||||
}
|
||||
|
||||
public static Vector2 Angle360ToVec(float angle, Vector2 zeroVector)
|
||||
{
|
||||
float sin = Mathf.Sin(angle * Mathf.Deg2Rad);
|
||||
float cos = Mathf.Cos(angle * Mathf.Deg2Rad);
|
||||
|
||||
return new Vector2(
|
||||
zeroVector.x * cos - zeroVector.y * sin,
|
||||
zeroVector.x * sin + zeroVector.y * cos
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cd2f496da54e4254ac9c1b0ca2e76fb1
|
||||
timeCreated: 1695714616
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 78464
|
||||
packageName: Translucent Image - Fast UI Background Blur
|
||||
packageVersion: 6.5.0
|
||||
assetPath: Assets/Le Tai's Asset/Common/Editor/MathCustom.cs
|
||||
uploadId: 824068
|
||||
@@ -0,0 +1,52 @@
|
||||
// Copyright (c) Le Loc Tai <leloctai.com> . All rights reserved. Do not redistribute.
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace LeTai.Common.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(TinyTween.Spring))]
|
||||
public class SpringDrawer : PropertyDrawer
|
||||
{
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
return EditorGUIUtility.singleLineHeight * 2 + EditorGUIUtility.standardVerticalSpacing;
|
||||
}
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
|
||||
SerializedProperty approxDurationProp = property.FindPropertyRelative(nameof(TinyTween.Spring.approxDuration));
|
||||
SerializedProperty overshootProp = property.FindPropertyRelative(nameof(TinyTween.Spring.overshoot));
|
||||
SerializedProperty stiffnessProp = property.FindPropertyRelative(nameof(TinyTween.Spring.stiffness));
|
||||
SerializedProperty dampingProp = property.FindPropertyRelative(nameof(TinyTween.Spring.damping));
|
||||
|
||||
position = EditorGUI.PrefixLabel(position, label);
|
||||
|
||||
using var _ = new EditorCustom.LabelWidthScope(64f);
|
||||
using var changes = new EditorGUI.ChangeCheckScope();
|
||||
|
||||
float lineHeight = EditorGUIUtility.singleLineHeight;
|
||||
Rect durationRect = new Rect(position.x, position.y,
|
||||
position.width, lineHeight);
|
||||
Rect overshootRect = new Rect(position.x, position.y + lineHeight + EditorGUIUtility.standardVerticalSpacing,
|
||||
position.width, lineHeight);
|
||||
|
||||
float approxDuration = EditorGUI.FloatField(durationRect, "Duration", approxDurationProp.floatValue);
|
||||
float overshoot = EditorGUI.Slider(overshootRect, "Overshoot", overshootProp.floatValue, 0, .5f);
|
||||
|
||||
if (changes.changed)
|
||||
{
|
||||
TinyTween.Spring s = TinyTween.Spring.DurationOvershoot(approxDuration, overshoot);
|
||||
|
||||
approxDurationProp.floatValue = s.approxDuration;
|
||||
overshootProp.floatValue = s.overshoot;
|
||||
stiffnessProp.floatValue = s.stiffness;
|
||||
dampingProp.floatValue = s.damping;
|
||||
}
|
||||
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 03b5046c644a48e8a2078a44033e85d0
|
||||
timeCreated: 1754471011
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 78464
|
||||
packageName: Translucent Image - Fast UI Background Blur
|
||||
packageVersion: 6.5.0
|
||||
assetPath: Assets/Le Tai's Asset/Common/Editor/SpringPropertyDrawer.cs
|
||||
uploadId: 824068
|
||||
Reference in New Issue
Block a user