This commit is contained in:
MuHua-123
2025-02-28 15:32:19 +08:00
parent 34d02c4015
commit 5bc834bfcd
10 changed files with 153 additions and 253 deletions
@@ -9,9 +9,6 @@ GameObject:
serializedVersion: 6 serializedVersion: 6
m_Component: m_Component:
- component: {fileID: 2000843579383799871} - component: {fileID: 2000843579383799871}
- component: {fileID: 632317377290173438}
- component: {fileID: 5347523686693499412}
- component: {fileID: 6209684243745889243}
- component: {fileID: 2332360223713012105} - component: {fileID: 2332360223713012105}
m_Layer: 5 m_Layer: 5
m_Name: LabelController m_Name: LabelController
@@ -20,33 +17,81 @@ GameObject:
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 1 m_IsActive: 1
--- !u!224 &2000843579383799871 --- !u!4 &2000843579383799871
RectTransform: Transform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2282457566440489139} m_GameObject: {fileID: 2282457566440489139}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 4366520896438658900}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &2332360223713012105
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2282457566440489139}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f7eb8180a2e59e44f94464ec35f42b5f, type: 3}
m_Name:
m_EditorClassIdentifier:
parent: {fileID: 4366520896438658900}
labelPrefab: {fileID: 2682401737700228647, guid: 10d433e31ddc82941b7939b1f41d6121, type: 3}
--- !u!1 &5990839265172870881
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 4366520896438658900}
- component: {fileID: 1585856385847655300}
- component: {fileID: 8368974480207407461}
- component: {fileID: 8442284695854397385}
m_Layer: 5
m_Name: Canvas
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &4366520896438658900
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5990839265172870881}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0.01, y: 0.01, z: 0.01} m_LocalScale: {x: 0.01, y: 0.01, z: 0.01}
m_ConstrainProportionsScale: 1 m_ConstrainProportionsScale: 1
m_Children: m_Children: []
- {fileID: 124208415017971562} m_Father: {fileID: 2000843579383799871}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0} m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0} m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0} m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5} m_Pivot: {x: 0.5, y: 0.5}
--- !u!223 &632317377290173438 --- !u!223 &1585856385847655300
Canvas: Canvas:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2282457566440489139} m_GameObject: {fileID: 5990839265172870881}
m_Enabled: 1 m_Enabled: 1
serializedVersion: 3 serializedVersion: 3
m_RenderMode: 2 m_RenderMode: 2
@@ -63,13 +108,13 @@ Canvas:
m_SortingLayerID: 0 m_SortingLayerID: 0
m_SortingOrder: 0 m_SortingOrder: 0
m_TargetDisplay: 0 m_TargetDisplay: 0
--- !u!114 &5347523686693499412 --- !u!114 &8368974480207407461
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2282457566440489139} m_GameObject: {fileID: 5990839265172870881}
m_Enabled: 1 m_Enabled: 1
m_EditorHideFlags: 0 m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3} m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3}
@@ -85,14 +130,14 @@ MonoBehaviour:
m_FallbackScreenDPI: 96 m_FallbackScreenDPI: 96
m_DefaultSpriteDPI: 96 m_DefaultSpriteDPI: 96
m_DynamicPixelsPerUnit: 1 m_DynamicPixelsPerUnit: 1
m_PresetInfoIsWorld: 0 m_PresetInfoIsWorld: 1
--- !u!114 &6209684243745889243 --- !u!114 &8442284695854397385
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2282457566440489139} m_GameObject: {fileID: 5990839265172870881}
m_Enabled: 1 m_Enabled: 1
m_EditorHideFlags: 0 m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: dc42784cf147c0c48a680349fa168899, type: 3} m_Script: {fileID: 11500000, guid: dc42784cf147c0c48a680349fa168899, type: 3}
@@ -103,128 +148,3 @@ MonoBehaviour:
m_BlockingMask: m_BlockingMask:
serializedVersion: 2 serializedVersion: 2
m_Bits: 4294967295 m_Bits: 4294967295
--- !u!114 &2332360223713012105
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2282457566440489139}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f7eb8180a2e59e44f94464ec35f42b5f, type: 3}
m_Name:
m_EditorClassIdentifier:
canvas: {fileID: 632317377290173438}
labelPrefab: {fileID: 9154778333717445799}
--- !u!1001 &6500242687431049856
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 2000843579383799871}
m_Modifications:
- target: {fileID: 2682401737700228647, guid: 10d433e31ddc82941b7939b1f41d6121, type: 3}
propertyPath: m_Name
value: LabelFollower
objectReference: {fileID: 0}
- target: {fileID: 2682401737700228647, guid: 10d433e31ddc82941b7939b1f41d6121, type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6596866004371516906, guid: 10d433e31ddc82941b7939b1f41d6121, type: 3}
propertyPath: m_Pivot.x
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 6596866004371516906, guid: 10d433e31ddc82941b7939b1f41d6121, type: 3}
propertyPath: m_Pivot.y
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 6596866004371516906, guid: 10d433e31ddc82941b7939b1f41d6121, type: 3}
propertyPath: m_AnchorMax.x
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 6596866004371516906, guid: 10d433e31ddc82941b7939b1f41d6121, type: 3}
propertyPath: m_AnchorMax.y
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 6596866004371516906, guid: 10d433e31ddc82941b7939b1f41d6121, type: 3}
propertyPath: m_AnchorMin.x
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 6596866004371516906, guid: 10d433e31ddc82941b7939b1f41d6121, type: 3}
propertyPath: m_AnchorMin.y
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 6596866004371516906, guid: 10d433e31ddc82941b7939b1f41d6121, type: 3}
propertyPath: m_SizeDelta.x
value: 100
objectReference: {fileID: 0}
- target: {fileID: 6596866004371516906, guid: 10d433e31ddc82941b7939b1f41d6121, type: 3}
propertyPath: m_SizeDelta.y
value: 100
objectReference: {fileID: 0}
- target: {fileID: 6596866004371516906, guid: 10d433e31ddc82941b7939b1f41d6121, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6596866004371516906, guid: 10d433e31ddc82941b7939b1f41d6121, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6596866004371516906, guid: 10d433e31ddc82941b7939b1f41d6121, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6596866004371516906, guid: 10d433e31ddc82941b7939b1f41d6121, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 6596866004371516906, guid: 10d433e31ddc82941b7939b1f41d6121, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6596866004371516906, guid: 10d433e31ddc82941b7939b1f41d6121, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6596866004371516906, guid: 10d433e31ddc82941b7939b1f41d6121, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6596866004371516906, guid: 10d433e31ddc82941b7939b1f41d6121, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6596866004371516906, guid: 10d433e31ddc82941b7939b1f41d6121, type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6596866004371516906, guid: 10d433e31ddc82941b7939b1f41d6121, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6596866004371516906, guid: 10d433e31ddc82941b7939b1f41d6121, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6596866004371516906, guid: 10d433e31ddc82941b7939b1f41d6121, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 10d433e31ddc82941b7939b1f41d6121, type: 3}
--- !u!224 &124208415017971562 stripped
RectTransform:
m_CorrespondingSourceObject: {fileID: 6596866004371516906, guid: 10d433e31ddc82941b7939b1f41d6121, type: 3}
m_PrefabInstance: {fileID: 6500242687431049856}
m_PrefabAsset: {fileID: 0}
--- !u!1 &9154778333717445799 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 2682401737700228647, guid: 10d433e31ddc82941b7939b1f41d6121, type: 3}
m_PrefabInstance: {fileID: 6500242687431049856}
m_PrefabAsset: {fileID: 0}
-60
View File
@@ -762,50 +762,6 @@ PrefabInstance:
serializedVersion: 3 serializedVersion: 3
m_TransformParent: {fileID: 0} m_TransformParent: {fileID: 0}
m_Modifications: m_Modifications:
- target: {fileID: 2000843579383799871, guid: 0d8274e243a195247b4a0af03313fe9e, type: 3}
propertyPath: m_Pivot.x
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 2000843579383799871, guid: 0d8274e243a195247b4a0af03313fe9e, type: 3}
propertyPath: m_Pivot.y
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 2000843579383799871, guid: 0d8274e243a195247b4a0af03313fe9e, type: 3}
propertyPath: m_AnchorMax.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2000843579383799871, guid: 0d8274e243a195247b4a0af03313fe9e, type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2000843579383799871, guid: 0d8274e243a195247b4a0af03313fe9e, type: 3}
propertyPath: m_AnchorMin.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2000843579383799871, guid: 0d8274e243a195247b4a0af03313fe9e, type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2000843579383799871, guid: 0d8274e243a195247b4a0af03313fe9e, type: 3}
propertyPath: m_SizeDelta.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2000843579383799871, guid: 0d8274e243a195247b4a0af03313fe9e, type: 3}
propertyPath: m_SizeDelta.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2000843579383799871, guid: 0d8274e243a195247b4a0af03313fe9e, type: 3}
propertyPath: m_LocalScale.x
value: 0.01
objectReference: {fileID: 0}
- target: {fileID: 2000843579383799871, guid: 0d8274e243a195247b4a0af03313fe9e, type: 3}
propertyPath: m_LocalScale.y
value: 0.01
objectReference: {fileID: 0}
- target: {fileID: 2000843579383799871, guid: 0d8274e243a195247b4a0af03313fe9e, type: 3}
propertyPath: m_LocalScale.z
value: 0.01
objectReference: {fileID: 0}
- target: {fileID: 2000843579383799871, guid: 0d8274e243a195247b4a0af03313fe9e, type: 3} - target: {fileID: 2000843579383799871, guid: 0d8274e243a195247b4a0af03313fe9e, type: 3}
propertyPath: m_LocalPosition.x propertyPath: m_LocalPosition.x
value: 0 value: 0
@@ -834,14 +790,6 @@ PrefabInstance:
propertyPath: m_LocalRotation.z propertyPath: m_LocalRotation.z
value: 0 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2000843579383799871, guid: 0d8274e243a195247b4a0af03313fe9e, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2000843579383799871, guid: 0d8274e243a195247b4a0af03313fe9e, type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2000843579383799871, guid: 0d8274e243a195247b4a0af03313fe9e, type: 3} - target: {fileID: 2000843579383799871, guid: 0d8274e243a195247b4a0af03313fe9e, type: 3}
propertyPath: m_LocalEulerAnglesHint.x propertyPath: m_LocalEulerAnglesHint.x
value: 0 value: 0
@@ -858,14 +806,6 @@ PrefabInstance:
propertyPath: m_Name propertyPath: m_Name
value: "----\u6D6E\u52A8\u6807\u7B7E----" value: "----\u6D6E\u52A8\u6807\u7B7E----"
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2282457566440489139, guid: 0d8274e243a195247b4a0af03313fe9e, type: 3}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
- target: {fileID: 9154778333717445799, guid: 0d8274e243a195247b4a0af03313fe9e, type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: [] m_RemovedComponents: []
m_RemovedGameObjects: [] m_RemovedGameObjects: []
m_AddedGameObjects: [] m_AddedGameObjects: []
+2 -2
View File
@@ -1,8 +1,8 @@
{ {
"name": "muhua-finite-state-machine", "name": "muhua-fsm",
"version": "1.0.0", "version": "1.0.0",
"displayName": "MuHua FSM", "displayName": "MuHua FSM",
"description": "\u6709\u9650\u72b6\u6001\u673a\u6846\u67b6", "description": "FiniteStateMachine\u6709\u9650\u72b6\u6001\u673a\u6846\u67b6",
"author": { "author": {
"name": "MuHua", "name": "MuHua",
"email": "2960208585@qq.com" "email": "2960208585@qq.com"
+10 -14
View File
@@ -6,28 +6,24 @@ namespace MuHua
{ {
public static LabelController Instance { get; private set; } public static LabelController Instance { get; private set; }
public Canvas canvas; // 包含标签的Canvas public Transform parent; // 标签父物体
public GameObject labelPrefab; // 标签预制体 public GameObject labelPrefab; // 标签预制体
void Awake() void Awake()
{ {
if (Instance == null) if (Instance == null) { Instance = this; }
{ else { Destroy(gameObject); }
Instance = this;
}
else
{
Destroy(gameObject);
}
} }
public static GameObject CreateLabel(Transform target, Vector3 offset) // 启用标签
{ public static void Enable(bool enable) => Instance.parent.gameObject.SetActive(enable);
return CreateLabel(target, Instance.labelPrefab, offset);
} // 创建标签
public static GameObject CreateLabel(Transform target) => CreateLabel(target, Vector3.zero);
public static GameObject CreateLabel(Transform target, Vector3 offset) => CreateLabel(target, Instance.labelPrefab, offset);
public static GameObject CreateLabel(Transform target, GameObject labelPrefab, Vector3 offset) public static GameObject CreateLabel(Transform target, GameObject labelPrefab, Vector3 offset)
{ {
GameObject labelObject = Instantiate(labelPrefab, Instance.canvas.transform); GameObject labelObject = Instantiate(labelPrefab, Instance.parent);
LabelFollower followObjectLabel = labelObject.GetComponent<LabelFollower>(); LabelFollower followObjectLabel = labelObject.GetComponent<LabelFollower>();
followObjectLabel.target = target; followObjectLabel.target = target;
followObjectLabel.offset = offset; followObjectLabel.offset = offset;
@@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: d9d7dc56eb286ef44869e5c4a543a365 guid: e94d558a7fcc0af4a83b561abcdb6e67
folderAsset: yes folderAsset: yes
DefaultImporter: DefaultImporter:
externalObjects: {} externalObjects: {}
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 004a039923c4e3845b77cdbaae4fae09
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+1 -1
View File
@@ -12,7 +12,7 @@
{ {
"displayName": "Label Follow Example", "displayName": "Label Follow Example",
"description": "An example showing how to use the Label Follow system.", "description": "An example showing how to use the Label Follow system.",
"path": "Samples~" "path": "Samples"
} }
] ]
} }
@@ -4,34 +4,45 @@ using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.UIElements; using UnityEngine.UIElements;
namespace MuHua { namespace MuHua
public class MUSliderHorizontal : VisualElement { {
public enum RoundDataType { public class MUSliderHorizontal : VisualElement
{
public enum RoundDataType
{
= 0, = 0,
= 1, = 1,
= 2, = 2,
} }
public new class UxmlFactory : UxmlFactory<MUSliderHorizontal, UxmlTraits> { } public new class UxmlFactory : UxmlFactory<MUSliderHorizontal, UxmlTraits> { }
public new class UxmlTraits : VisualElement.UxmlTraits { public new class UxmlTraits : VisualElement.UxmlTraits
private UxmlStringAttributeDescription Text = new UxmlStringAttributeDescription { {
private UxmlStringAttributeDescription Text = new UxmlStringAttributeDescription
{
name = "text" name = "text"
}; };
private UxmlFloatAttributeDescription MinValue = new UxmlFloatAttributeDescription { private UxmlFloatAttributeDescription MinValue = new UxmlFloatAttributeDescription
{
name = "min-value" name = "min-value"
}; };
private UxmlFloatAttributeDescription MaxValue = new UxmlFloatAttributeDescription { private UxmlFloatAttributeDescription MaxValue = new UxmlFloatAttributeDescription
{
name = "max-value" name = "max-value"
}; };
private UxmlFloatAttributeDescription SlidingValue = new UxmlFloatAttributeDescription { private UxmlFloatAttributeDescription SlidingValue = new UxmlFloatAttributeDescription
{
name = "sliding-value" name = "sliding-value"
}; };
private UxmlBoolAttributeDescription DisplayInput = new UxmlBoolAttributeDescription { private UxmlBoolAttributeDescription DisplayInput = new UxmlBoolAttributeDescription
{
name = "display-input" name = "display-input"
}; };
private UxmlEnumAttributeDescription<RoundDataType> DataType = new UxmlEnumAttributeDescription<RoundDataType> { private UxmlEnumAttributeDescription<RoundDataType> DataType = new UxmlEnumAttributeDescription<RoundDataType>
{
name = "data-type" name = "data-type"
}; };
public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc) { public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
{
base.Init(ve, bag, cc); base.Init(ve, bag, cc);
MUSliderHorizontal slider = (MUSliderHorizontal)ve; MUSliderHorizontal slider = (MUSliderHorizontal)ve;
slider.Text = Text.GetValueFromBag(bag, cc); slider.Text = Text.GetValueFromBag(bag, cc);
@@ -50,31 +61,38 @@ namespace MuHua {
public VisualElement tracker = new VisualElement(); public VisualElement tracker = new VisualElement();
public VisualElement dragger = new VisualElement(); public VisualElement dragger = new VisualElement();
public string Text { public string Text
{
get => labelElement.text; get => labelElement.text;
set => UpdateLabelElement(value); set => UpdateLabelElement(value);
} }
public float MinValue { public float MinValue
{
get => minValue; get => minValue;
set { minValue = value; UpdateFloatField(); } set { minValue = value; UpdateFloatField(); }
} }
public float MaxValue { public float MaxValue
{
get => maxValue; get => maxValue;
set { maxValue = value; UpdateFloatField(); } set { maxValue = value; UpdateFloatField(); }
} }
public float SlidingValue { public float SlidingValue
{
get => slidingValue; get => slidingValue;
set => UpdateSlidingValue(value); set => UpdateSlidingValue(value);
} }
public bool DisplayInput { public bool DisplayInput
{
get => isDisplayInput; get => isDisplayInput;
set => UpdateFloatField(value); set => UpdateFloatField(value);
} }
public RoundDataType DataType { public RoundDataType DataType
{
get => dataType; get => dataType;
set { dataType = value; UpdateFloatField(); } set { dataType = value; UpdateFloatField(); }
} }
public float Value { public float Value
{
get => UpdateValue(); get => UpdateValue();
set => UpdateValue(value); set => UpdateValue(value);
} }
@@ -91,42 +109,56 @@ namespace MuHua {
internal float MaxPosition { get => container.resolvedStyle.width; } internal float MaxPosition { get => container.resolvedStyle.width; }
internal float CurrentPosition { get => slidingValue * container.resolvedStyle.width; } internal float CurrentPosition { get => slidingValue * container.resolvedStyle.width; }
internal void UpdateLabelElement(string value) { internal void UpdateLabelElement(string value)
{
bool display = value != "" && value != null; bool display = value != "" && value != null;
labelElement.text = value; labelElement.text = value;
labelElement.style.display = display ? DisplayStyle.Flex : DisplayStyle.None; labelElement.style.display = display ? DisplayStyle.Flex : DisplayStyle.None;
} }
internal void UpdateSlidingValue(float value) { internal void UpdateSlidingValue(float value)
{
UpdateDragger(value); UpdateDragger(value);
SlidingValueChanged?.Invoke(Value); SlidingValueChanged?.Invoke(Value);
} }
internal void UpdateDragger(float value) { internal void UpdateDragger(float value)
{
slidingValue = value; slidingValue = value;
slidingValue = Mathf.Clamp(slidingValue, 0, 1); slidingValue = Mathf.Clamp(slidingValue, 0, 1);
tracker.style.width = CurrentPosition; tracker.style.width = Length.Percent(slidingValue * 100);
UpdateFloatField(); UpdateFloatField();
} }
internal void UpdateFloatField(bool value) { internal void UpdateFloatField(ChangeEvent<float> evt)
{
float value = Mathf.Clamp(evt.newValue, MinValue, MaxValue);
slidingValue = Mathf.InverseLerp(MinValue, MaxValue, value);
tracker.style.width = Length.Percent(slidingValue * 100);
SlidingValueChanged?.Invoke(Value);
}
internal void UpdateFloatField(bool value)
{
isDisplayInput = value; isDisplayInput = value;
floatField.style.display = isDisplayInput ? DisplayStyle.Flex : DisplayStyle.None; floatField.style.display = isDisplayInput ? DisplayStyle.Flex : DisplayStyle.None;
} }
internal void UpdateFloatField() { internal void UpdateFloatField()
{
floatField.value = Value; floatField.value = Value;
} }
internal float UpdateValue() { internal float UpdateValue()
float value = (MaxValue - MinValue) * SlidingValue; {
float value = Mathf.Lerp(MinValue, MaxValue, SlidingValue);
if (dataType == RoundDataType.) { value = (float)Math.Round(value, 2); } if (dataType == RoundDataType.) { value = (float)Math.Round(value, 2); }
if (dataType == RoundDataType.) { value = Mathf.FloorToInt(value); } if (dataType == RoundDataType.) { value = Mathf.FloorToInt(value); }
return Mathf.Clamp(value, MinValue, MaxValue); return Mathf.Clamp(value, MinValue, MaxValue);
} }
internal void UpdateValue(float value) { internal void UpdateValue(float value)
slidingValue = value / (MaxValue - MinValue); {
slidingValue = Mathf.Clamp(slidingValue, 0, 1); slidingValue = Mathf.InverseLerp(MinValue, MaxValue, value);
tracker.style.width = CurrentPosition; tracker.style.width = Length.Percent(slidingValue * 100);
UpdateFloatField(); UpdateFloatField();
} }
public MUSliderHorizontal() { public MUSliderHorizontal()
{
//设置名称 //设置名称
labelElement.name = "Label"; labelElement.name = "Label";
floatField.name = "FloatField"; floatField.name = "FloatField";
@@ -165,20 +197,25 @@ namespace MuHua {
dragger.RegisterCallback<PointerUpEvent>((evt) => isDragger = false); dragger.RegisterCallback<PointerUpEvent>((evt) => isDragger = false);
dragger.RegisterCallback<PointerLeaveEvent>((evt) => isDragger = false); dragger.RegisterCallback<PointerLeaveEvent>((evt) => isDragger = false);
floatField.RegisterCallback<ChangeEvent<float>>(UpdateFloatField);
container.RegisterCallback<PointerDownEvent>(ContainerDown); container.RegisterCallback<PointerDownEvent>(ContainerDown);
} }
private void DraggerDown(PointerDownEvent evt) { private void DraggerDown(PointerDownEvent evt)
{
isDragger = true; isDragger = true;
mousePosition = evt.position.x; mousePosition = evt.position.x;
originalPosition = CurrentPosition; originalPosition = CurrentPosition;
} }
private void DraggerDrag(PointerMoveEvent evt) { private void DraggerDrag(PointerMoveEvent evt)
{
if (!isDragger) { return; } if (!isDragger) { return; }
float offset = evt.position.x - mousePosition; float offset = evt.position.x - mousePosition;
float value = (originalPosition + offset) / MaxPosition; float value = (originalPosition + offset) / MaxPosition;
UpdateSlidingValue(value); UpdateSlidingValue(value);
} }
private void ContainerDown(PointerDownEvent evt) { private void ContainerDown(PointerDownEvent evt)
{
float value = evt.localPosition.x / MaxPosition; float value = evt.localPosition.x / MaxPosition;
UpdateSlidingValue(value); UpdateSlidingValue(value);
} }
+1 -1
View File
@@ -215,7 +215,7 @@
}, },
"url": "https://packages.unity.cn" "url": "https://packages.unity.cn"
}, },
"muhua-finite-state-machine": { "muhua-fsm": {
"version": "file:FSM", "version": "file:FSM",
"depth": 0, "depth": 0,
"source": "embedded", "source": "embedded",