1
This commit is contained in:
@@ -9,9 +9,6 @@ GameObject:
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 2000843579383799871}
|
||||
- component: {fileID: 632317377290173438}
|
||||
- component: {fileID: 5347523686693499412}
|
||||
- component: {fileID: 6209684243745889243}
|
||||
- component: {fileID: 2332360223713012105}
|
||||
m_Layer: 5
|
||||
m_Name: LabelController
|
||||
@@ -20,33 +17,81 @@ GameObject:
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!224 &2000843579383799871
|
||||
RectTransform:
|
||||
--- !u!4 &2000843579383799871
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
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_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 0.01, y: 0.01, z: 0.01}
|
||||
m_ConstrainProportionsScale: 1
|
||||
m_Children:
|
||||
- {fileID: 124208415017971562}
|
||||
m_Father: {fileID: 0}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 2000843579383799871}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
m_AnchorMax: {x: 0, y: 0}
|
||||
m_AnchoredPosition: {x: 0, y: 0}
|
||||
m_SizeDelta: {x: 0, y: 0}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!223 &632317377290173438
|
||||
--- !u!223 &1585856385847655300
|
||||
Canvas:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2282457566440489139}
|
||||
m_GameObject: {fileID: 5990839265172870881}
|
||||
m_Enabled: 1
|
||||
serializedVersion: 3
|
||||
m_RenderMode: 2
|
||||
@@ -63,13 +108,13 @@ Canvas:
|
||||
m_SortingLayerID: 0
|
||||
m_SortingOrder: 0
|
||||
m_TargetDisplay: 0
|
||||
--- !u!114 &5347523686693499412
|
||||
--- !u!114 &8368974480207407461
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2282457566440489139}
|
||||
m_GameObject: {fileID: 5990839265172870881}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3}
|
||||
@@ -85,14 +130,14 @@ MonoBehaviour:
|
||||
m_FallbackScreenDPI: 96
|
||||
m_DefaultSpriteDPI: 96
|
||||
m_DynamicPixelsPerUnit: 1
|
||||
m_PresetInfoIsWorld: 0
|
||||
--- !u!114 &6209684243745889243
|
||||
m_PresetInfoIsWorld: 1
|
||||
--- !u!114 &8442284695854397385
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2282457566440489139}
|
||||
m_GameObject: {fileID: 5990839265172870881}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: dc42784cf147c0c48a680349fa168899, type: 3}
|
||||
@@ -103,128 +148,3 @@ MonoBehaviour:
|
||||
m_BlockingMask:
|
||||
serializedVersion: 2
|
||||
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}
|
||||
|
||||
@@ -762,50 +762,6 @@ PrefabInstance:
|
||||
serializedVersion: 3
|
||||
m_TransformParent: {fileID: 0}
|
||||
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}
|
||||
propertyPath: m_LocalPosition.x
|
||||
value: 0
|
||||
@@ -834,14 +790,6 @@ PrefabInstance:
|
||||
propertyPath: m_LocalRotation.z
|
||||
value: 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}
|
||||
propertyPath: m_LocalEulerAnglesHint.x
|
||||
value: 0
|
||||
@@ -858,14 +806,6 @@ PrefabInstance:
|
||||
propertyPath: m_Name
|
||||
value: "----\u6D6E\u52A8\u6807\u7B7E----"
|
||||
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_RemovedGameObjects: []
|
||||
m_AddedGameObjects: []
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"name": "muhua-finite-state-machine",
|
||||
"name": "muhua-fsm",
|
||||
"version": "1.0.0",
|
||||
"displayName": "MuHua FSM",
|
||||
"description": "\u6709\u9650\u72b6\u6001\u673a\u6846\u67b6",
|
||||
"description": "FiniteStateMachine\u6709\u9650\u72b6\u6001\u673a\u6846\u67b6",
|
||||
"author": {
|
||||
"name": "MuHua",
|
||||
"email": "2960208585@qq.com"
|
||||
|
||||
@@ -6,28 +6,24 @@ namespace MuHua
|
||||
{
|
||||
public static LabelController Instance { get; private set; }
|
||||
|
||||
public Canvas canvas; // 包含标签的Canvas
|
||||
public Transform parent; // 标签父物体
|
||||
public GameObject labelPrefab; // 标签预制体
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (Instance == null)
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
else
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
if (Instance == null) { Instance = this; }
|
||||
else { Destroy(gameObject); }
|
||||
}
|
||||
|
||||
public static GameObject CreateLabel(Transform target, Vector3 offset)
|
||||
{
|
||||
return CreateLabel(target, Instance.labelPrefab, offset);
|
||||
}
|
||||
// 启用标签
|
||||
public static void Enable(bool enable) => Instance.parent.gameObject.SetActive(enable);
|
||||
|
||||
// 创建标签
|
||||
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)
|
||||
{
|
||||
GameObject labelObject = Instantiate(labelPrefab, Instance.canvas.transform);
|
||||
GameObject labelObject = Instantiate(labelPrefab, Instance.parent);
|
||||
LabelFollower followObjectLabel = labelObject.GetComponent<LabelFollower>();
|
||||
followObjectLabel.target = target;
|
||||
followObjectLabel.offset = offset;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d9d7dc56eb286ef44869e5c4a543a365
|
||||
guid: e94d558a7fcc0af4a83b561abcdb6e67
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 004a039923c4e3845b77cdbaae4fae09
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -12,7 +12,7 @@
|
||||
{
|
||||
"displayName": "Label Follow Example",
|
||||
"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.UIElements;
|
||||
|
||||
namespace MuHua {
|
||||
public class MUSliderHorizontal : VisualElement {
|
||||
public enum RoundDataType {
|
||||
namespace MuHua
|
||||
{
|
||||
public class MUSliderHorizontal : VisualElement
|
||||
{
|
||||
public enum RoundDataType
|
||||
{
|
||||
保留两位小数 = 0,
|
||||
小数 = 1,
|
||||
整数 = 2,
|
||||
}
|
||||
public new class UxmlFactory : UxmlFactory<MUSliderHorizontal, UxmlTraits> { }
|
||||
public new class UxmlTraits : VisualElement.UxmlTraits {
|
||||
private UxmlStringAttributeDescription Text = new UxmlStringAttributeDescription {
|
||||
public new class UxmlTraits : VisualElement.UxmlTraits
|
||||
{
|
||||
private UxmlStringAttributeDescription Text = new UxmlStringAttributeDescription
|
||||
{
|
||||
name = "text"
|
||||
};
|
||||
private UxmlFloatAttributeDescription MinValue = new UxmlFloatAttributeDescription {
|
||||
private UxmlFloatAttributeDescription MinValue = new UxmlFloatAttributeDescription
|
||||
{
|
||||
name = "min-value"
|
||||
};
|
||||
private UxmlFloatAttributeDescription MaxValue = new UxmlFloatAttributeDescription {
|
||||
private UxmlFloatAttributeDescription MaxValue = new UxmlFloatAttributeDescription
|
||||
{
|
||||
name = "max-value"
|
||||
};
|
||||
private UxmlFloatAttributeDescription SlidingValue = new UxmlFloatAttributeDescription {
|
||||
private UxmlFloatAttributeDescription SlidingValue = new UxmlFloatAttributeDescription
|
||||
{
|
||||
name = "sliding-value"
|
||||
};
|
||||
private UxmlBoolAttributeDescription DisplayInput = new UxmlBoolAttributeDescription {
|
||||
private UxmlBoolAttributeDescription DisplayInput = new UxmlBoolAttributeDescription
|
||||
{
|
||||
name = "display-input"
|
||||
};
|
||||
private UxmlEnumAttributeDescription<RoundDataType> DataType = new UxmlEnumAttributeDescription<RoundDataType> {
|
||||
private UxmlEnumAttributeDescription<RoundDataType> DataType = new UxmlEnumAttributeDescription<RoundDataType>
|
||||
{
|
||||
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);
|
||||
MUSliderHorizontal slider = (MUSliderHorizontal)ve;
|
||||
slider.Text = Text.GetValueFromBag(bag, cc);
|
||||
@@ -50,31 +61,38 @@ namespace MuHua {
|
||||
public VisualElement tracker = new VisualElement();
|
||||
public VisualElement dragger = new VisualElement();
|
||||
|
||||
public string Text {
|
||||
public string Text
|
||||
{
|
||||
get => labelElement.text;
|
||||
set => UpdateLabelElement(value);
|
||||
}
|
||||
public float MinValue {
|
||||
public float MinValue
|
||||
{
|
||||
get => minValue;
|
||||
set { minValue = value; UpdateFloatField(); }
|
||||
}
|
||||
public float MaxValue {
|
||||
public float MaxValue
|
||||
{
|
||||
get => maxValue;
|
||||
set { maxValue = value; UpdateFloatField(); }
|
||||
}
|
||||
public float SlidingValue {
|
||||
public float SlidingValue
|
||||
{
|
||||
get => slidingValue;
|
||||
set => UpdateSlidingValue(value);
|
||||
}
|
||||
public bool DisplayInput {
|
||||
public bool DisplayInput
|
||||
{
|
||||
get => isDisplayInput;
|
||||
set => UpdateFloatField(value);
|
||||
}
|
||||
public RoundDataType DataType {
|
||||
public RoundDataType DataType
|
||||
{
|
||||
get => dataType;
|
||||
set { dataType = value; UpdateFloatField(); }
|
||||
}
|
||||
public float Value {
|
||||
public float Value
|
||||
{
|
||||
get => UpdateValue();
|
||||
set => UpdateValue(value);
|
||||
}
|
||||
@@ -91,42 +109,56 @@ namespace MuHua {
|
||||
internal float MaxPosition { get => 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;
|
||||
labelElement.text = value;
|
||||
labelElement.style.display = display ? DisplayStyle.Flex : DisplayStyle.None;
|
||||
}
|
||||
internal void UpdateSlidingValue(float value) {
|
||||
internal void UpdateSlidingValue(float value)
|
||||
{
|
||||
UpdateDragger(value);
|
||||
SlidingValueChanged?.Invoke(Value);
|
||||
}
|
||||
internal void UpdateDragger(float value) {
|
||||
internal void UpdateDragger(float value)
|
||||
{
|
||||
slidingValue = value;
|
||||
slidingValue = Mathf.Clamp(slidingValue, 0, 1);
|
||||
tracker.style.width = CurrentPosition;
|
||||
tracker.style.width = Length.Percent(slidingValue * 100);
|
||||
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;
|
||||
floatField.style.display = isDisplayInput ? DisplayStyle.Flex : DisplayStyle.None;
|
||||
}
|
||||
internal void UpdateFloatField() {
|
||||
internal void UpdateFloatField()
|
||||
{
|
||||
floatField.value = Value;
|
||||
}
|
||||
internal float UpdateValue() {
|
||||
float value = (MaxValue - MinValue) * SlidingValue;
|
||||
internal float UpdateValue()
|
||||
{
|
||||
float value = Mathf.Lerp(MinValue, MaxValue, SlidingValue);
|
||||
if (dataType == RoundDataType.保留两位小数) { value = (float)Math.Round(value, 2); }
|
||||
if (dataType == RoundDataType.整数) { value = Mathf.FloorToInt(value); }
|
||||
return Mathf.Clamp(value, MinValue, MaxValue);
|
||||
}
|
||||
internal void UpdateValue(float value) {
|
||||
slidingValue = value / (MaxValue - MinValue);
|
||||
slidingValue = Mathf.Clamp(slidingValue, 0, 1);
|
||||
tracker.style.width = CurrentPosition;
|
||||
internal void UpdateValue(float value)
|
||||
{
|
||||
slidingValue = Mathf.InverseLerp(MinValue, MaxValue, value);
|
||||
tracker.style.width = Length.Percent(slidingValue * 100);
|
||||
UpdateFloatField();
|
||||
}
|
||||
|
||||
public MUSliderHorizontal() {
|
||||
public MUSliderHorizontal()
|
||||
{
|
||||
//设置名称
|
||||
labelElement.name = "Label";
|
||||
floatField.name = "FloatField";
|
||||
@@ -165,20 +197,25 @@ namespace MuHua {
|
||||
dragger.RegisterCallback<PointerUpEvent>((evt) => isDragger = false);
|
||||
dragger.RegisterCallback<PointerLeaveEvent>((evt) => isDragger = false);
|
||||
|
||||
floatField.RegisterCallback<ChangeEvent<float>>(UpdateFloatField);
|
||||
|
||||
container.RegisterCallback<PointerDownEvent>(ContainerDown);
|
||||
}
|
||||
private void DraggerDown(PointerDownEvent evt) {
|
||||
private void DraggerDown(PointerDownEvent evt)
|
||||
{
|
||||
isDragger = true;
|
||||
mousePosition = evt.position.x;
|
||||
originalPosition = CurrentPosition;
|
||||
}
|
||||
private void DraggerDrag(PointerMoveEvent evt) {
|
||||
private void DraggerDrag(PointerMoveEvent evt)
|
||||
{
|
||||
if (!isDragger) { return; }
|
||||
float offset = evt.position.x - mousePosition;
|
||||
float value = (originalPosition + offset) / MaxPosition;
|
||||
UpdateSlidingValue(value);
|
||||
}
|
||||
private void ContainerDown(PointerDownEvent evt) {
|
||||
private void ContainerDown(PointerDownEvent evt)
|
||||
{
|
||||
float value = evt.localPosition.x / MaxPosition;
|
||||
UpdateSlidingValue(value);
|
||||
}
|
||||
|
||||
@@ -215,7 +215,7 @@
|
||||
},
|
||||
"url": "https://packages.unity.cn"
|
||||
},
|
||||
"muhua-finite-state-machine": {
|
||||
"muhua-fsm": {
|
||||
"version": "file:FSM",
|
||||
"depth": 0,
|
||||
"source": "embedded",
|
||||
|
||||
Reference in New Issue
Block a user