added: lock on target graphic
This commit is contained in:
@@ -5,16 +5,44 @@ using UnityEngine.UIElements;
|
||||
public class LockOnManager : MonoBehaviour{
|
||||
[ShowInInspector]
|
||||
public UIDocument lockOnDocument;
|
||||
[ShowInInspector, SerializeField]
|
||||
public ILockOnTarget lockOnTarget;
|
||||
public GameObject lockOnTarget;
|
||||
|
||||
private Label elementLabelName;
|
||||
private VisualElement elementRoot;
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
if (lockOnTarget.GetComponent<ILockOnTarget>() == null) {
|
||||
Debug.LogError($"Game Object {lockOnTarget.name} does not implement the ILockOnTarget interface. Not processing lock-on actions!");
|
||||
}
|
||||
|
||||
elementRoot = lockOnDocument.rootVisualElement.Query<VisualElement>("LockOnGroup");
|
||||
elementLabelName = lockOnDocument.rootVisualElement.Query<Label>("LockOnName").First();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
Debug.Log(RuntimePanelUtils.CameraTransformWorldToPanel(lockOnDocument.rootVisualElement.panel, lockOnTarget.GetReticlePosition(), Camera.main.GetComponent<Camera>()));
|
||||
void LateUpdate(){
|
||||
if (lockOnTarget.GetComponent<ILockOnTarget>() != null) {
|
||||
// This is just test logic to get an image above a lock on.
|
||||
// TODO: Replace with something less silly
|
||||
Vector2 screenPos = RuntimePanelUtils.CameraTransformWorldToPanel(
|
||||
lockOnDocument.rootVisualElement.panel,
|
||||
lockOnTarget.GetComponent<ILockOnTarget>().GetReticlePosition(),
|
||||
Camera.main.GetComponent<Camera>()
|
||||
);
|
||||
|
||||
// Set name
|
||||
elementLabelName.name = lockOnTarget.name;
|
||||
|
||||
// Set position (add the width/height of the element)
|
||||
elementRoot.style.top = new StyleLength(screenPos.y - elementRoot.resolvedStyle.height * .7f );
|
||||
elementRoot.style.left = new StyleLength(screenPos.x - elementRoot.resolvedStyle.width / 2f);
|
||||
|
||||
// Set enabled
|
||||
elementRoot.SetEnabled(true);
|
||||
} else {
|
||||
elementRoot.SetEnabled(false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,2 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 092c74123418b7a4482fc45aa5870077
|
||||
guid: 092c74123418b7a4482fc45aa5870077
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 5000
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
||||
Reference in New Issue
Block a user