Initial commit
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f7369a4817ce3df499fbd2826b839ebd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,10 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public interface IBehaviour
|
||||
{
|
||||
void Activate();
|
||||
|
||||
void Deactivate();
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d29b16d510e417f48b045fc3d1ab28f6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,29 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public abstract class ToggleBehaviour : MonoBehaviour, IBehaviour
|
||||
{
|
||||
[SerializeField] private Toggle toggle;
|
||||
private bool isActivated = false;
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
toggle.onValueChanged.AddListener(value => init());
|
||||
}
|
||||
|
||||
private void init()
|
||||
{
|
||||
if (isActivated)
|
||||
Deactivate();
|
||||
else
|
||||
Activate();
|
||||
|
||||
isActivated = !isActivated; // flip the flag
|
||||
}
|
||||
|
||||
public abstract void Activate();
|
||||
|
||||
public abstract void Deactivate();
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2ce060346105eeb44a18e1c3583bffeb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user