创建标签系统包
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace MuHua
|
||||
{
|
||||
public class LabelController : MonoBehaviour
|
||||
{
|
||||
public static LabelController Instance { get; private set; }
|
||||
|
||||
public Canvas canvas; // 包含标签的Canvas
|
||||
public GameObject labelPrefab; // 标签预制体
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (Instance == null)
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
else
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
public static GameObject CreateLabel(Transform target, Vector3 offset)
|
||||
{
|
||||
return CreateLabel(target, Instance.labelPrefab, offset);
|
||||
}
|
||||
public static GameObject CreateLabel(Transform target, GameObject labelPrefab, Vector3 offset)
|
||||
{
|
||||
GameObject labelObject = Instantiate(labelPrefab, Instance.canvas.transform);
|
||||
LabelFollower followObjectLabel = labelObject.GetComponent<LabelFollower>();
|
||||
followObjectLabel.target = target;
|
||||
followObjectLabel.offset = offset;
|
||||
|
||||
return labelObject;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f7eb8180a2e59e44f94464ec35f42b5f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,21 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace MuHua
|
||||
{
|
||||
public class LabelFollower : MonoBehaviour
|
||||
{
|
||||
public Transform target; // 要跟随的目标物体
|
||||
public Vector3 offset; // 标签的偏移量
|
||||
void Update()
|
||||
{
|
||||
if (target != null)
|
||||
{
|
||||
// 设置标签的位置
|
||||
transform.position = target.position + offset;
|
||||
|
||||
// 使标签面向相机
|
||||
transform.rotation = Camera.main.transform.rotation;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 485994f2ed6f1e448bea192023877815
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "MuHua"
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8ea4e4c7b125e9d4e953b91e32da550b
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user