1
This commit is contained in:
17
Unity/Scripts/Selection/ColliderSelectable.cs
Normal file
17
Unity/Scripts/Selection/ColliderSelectable.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using RotaryHeart.Lib.SerializableDictionary;
|
||||
using UnityEngine.Events;
|
||||
namespace BITKit
|
||||
{
|
||||
public class SubSelectable : MonoBehaviour, ISelectable
|
||||
{
|
||||
Selectable root;
|
||||
public Transform GetTransform() => root.GetTransform();
|
||||
public void SetSelectionState(SelectionState state)
|
||||
{
|
||||
root.SetSelectionState(state);
|
||||
}
|
||||
}
|
||||
}
|
33
Unity/Scripts/Selection/ISelectable.cs
Normal file
33
Unity/Scripts/Selection/ISelectable.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
namespace BITKit
|
||||
{
|
||||
public enum SelectionState
|
||||
{
|
||||
None,
|
||||
Hover,
|
||||
Active,
|
||||
Inactive,
|
||||
Focus,
|
||||
Selected,
|
||||
Enabled,
|
||||
Checked,
|
||||
Root,
|
||||
}
|
||||
public interface ISelectable
|
||||
{
|
||||
Transform GetTransform();
|
||||
void SetSelectionState(SelectionState state);
|
||||
}
|
||||
public interface ISelectableCallback
|
||||
{
|
||||
void OnHover(ISelectable selectable);
|
||||
void OnActive(ISelectable selectable);
|
||||
void OnInactive(ISelectable selectable);
|
||||
}
|
||||
public interface ISelectableComponent
|
||||
{
|
||||
void SetSelectionState(SelectionState state);
|
||||
}
|
||||
}
|
26
Unity/Scripts/Selection/Selectable.cs
Normal file
26
Unity/Scripts/Selection/Selectable.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
namespace BITKit
|
||||
{
|
||||
public class Selectable : MonoBehaviour, ISelectable
|
||||
{
|
||||
public Transform GetTransform() => transform;
|
||||
ISelectableComponent[] components;
|
||||
void Start()
|
||||
{
|
||||
components = GetComponentsInChildren<ISelectableComponent>(true);
|
||||
foreach (var x in components)
|
||||
{
|
||||
x.SetSelectionState(0);
|
||||
}
|
||||
}
|
||||
public void SetSelectionState(SelectionState state)
|
||||
{
|
||||
foreach (var x in components)
|
||||
{
|
||||
x.SetSelectionState(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
59
Unity/Scripts/Selection/SelectableEvent.cs
Normal file
59
Unity/Scripts/Selection/SelectableEvent.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
namespace BITKit
|
||||
{
|
||||
public class SelectableEvent : MonoBehaviour, ISelectableComponent
|
||||
{
|
||||
[Header(nameof(SelectionState.None))]
|
||||
[SerializeField] UnityEvent OnNone;
|
||||
[Header(nameof(SelectionState.Hover))]
|
||||
[SerializeField] UnityEvent OnHover;
|
||||
[Header(nameof(SelectionState.Active))]
|
||||
[SerializeField] UnityEvent OnActive;
|
||||
[Header(nameof(SelectionState.Inactive))]
|
||||
[SerializeField] UnityEvent OnInactive;
|
||||
[Header(nameof(SelectionState.Focus))]
|
||||
[SerializeField] UnityEvent OnFocus;
|
||||
[Header(nameof(SelectionState.Selected))]
|
||||
[SerializeField] UnityEvent OnSelected;
|
||||
[Header(nameof(SelectionState.Enabled))]
|
||||
[SerializeField] UnityEvent OnEnabled;
|
||||
[Header(nameof(SelectionState.Checked))]
|
||||
[SerializeField] UnityEvent OnChecked;
|
||||
[Header(nameof(SelectionState.Root))]
|
||||
[SerializeField] UnityEvent OnRoot;
|
||||
public void SetSelectionState(SelectionState state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case SelectionState.None:
|
||||
OnNone.Invoke();
|
||||
break;
|
||||
case SelectionState.Hover:
|
||||
OnHover.Invoke();
|
||||
break;
|
||||
case SelectionState.Active:
|
||||
OnActive.Invoke();
|
||||
break;
|
||||
case SelectionState.Inactive:
|
||||
OnInactive.Invoke();
|
||||
break;
|
||||
case SelectionState.Focus:
|
||||
OnFocus.Invoke();
|
||||
break;
|
||||
case SelectionState.Selected:
|
||||
OnSelected.Invoke();
|
||||
break;
|
||||
case SelectionState.Enabled:
|
||||
OnEnabled.Invoke();
|
||||
break;
|
||||
case SelectionState.Checked:
|
||||
OnChecked.Invoke();
|
||||
break;
|
||||
case SelectionState.Root:
|
||||
OnRoot.Invoke();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user