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
+10 -14
View File
@@ -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:
+1 -1
View File
@@ -12,7 +12,7 @@
{
"displayName": "Label Follow Example",
"description": "An example showing how to use the Label Follow system.",
"path": "Samples~"
"path": "Samples"
}
]
}