53 lines
1.4 KiB
C#
53 lines
1.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
|
|
public class AxialMoveBehavior : ToggleBehaviour
|
|
{
|
|
|
|
private SelectionManager selectionManager;
|
|
private GameObject currentGizmosMove;
|
|
[SerializeField] private GameObject gizmosMovePrefab;
|
|
private IInteractable CurrentSelection;
|
|
|
|
protected void Start()
|
|
{
|
|
selectionManager = SelectionManager.getInstance();
|
|
selectionManager.SelectionEvent.AddListener(interactable => CurrentSelection = interactable);
|
|
base.Start();
|
|
}
|
|
|
|
public override void Activate()
|
|
{
|
|
GizmoInit();
|
|
}
|
|
|
|
public override void Deactivate()
|
|
{
|
|
GizmoDeselect();
|
|
}
|
|
|
|
private void GizmoInit()
|
|
{
|
|
if (selectionManager.HasOneSelection())
|
|
{
|
|
if (currentGizmosMove == null)
|
|
{
|
|
currentGizmosMove = Instantiate(gizmosMovePrefab, CurrentSelection.transform);
|
|
currentGizmosMove.transform.parent = CurrentSelection.transform;
|
|
currentGizmosMove.transform.localPosition = Vector3.zero;
|
|
currentGizmosMove.transform.localRotation = Quaternion.identity;
|
|
}
|
|
}
|
|
}
|
|
private void GizmoDeselect()
|
|
{
|
|
if (currentGizmosMove != null)
|
|
{
|
|
Destroy(currentGizmosMove);
|
|
currentGizmosMove = null;
|
|
}
|
|
}
|
|
}
|