63 lines
1.2 KiB
C#
63 lines
1.2 KiB
C#
|
using BNG;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.Events;
|
||
|
|
||
|
public class WheelActivator : MonoBehaviour
|
||
|
{
|
||
|
[SerializeField]
|
||
|
private List<Grabber> grabbers = new List<Grabber>();
|
||
|
|
||
|
public UnityEvent OnActivate;
|
||
|
public UnityEvent OnDeactivate;
|
||
|
|
||
|
public bool StartActive = false;
|
||
|
|
||
|
private bool _isActive = false;
|
||
|
|
||
|
private void Awake()
|
||
|
{
|
||
|
if (StartActive)
|
||
|
Activate();
|
||
|
else
|
||
|
Deactivate();
|
||
|
}
|
||
|
|
||
|
private void Activate()
|
||
|
{
|
||
|
_isActive = true;
|
||
|
OnActivate?.Invoke();
|
||
|
Debug.Log("Activate");
|
||
|
}
|
||
|
|
||
|
private void Deactivate()
|
||
|
{
|
||
|
_isActive = false;
|
||
|
OnDeactivate?.Invoke();
|
||
|
Debug.Log("Deactivate");
|
||
|
}
|
||
|
|
||
|
public void TryActivate(Grabber grabber)
|
||
|
{
|
||
|
if (!grabbers.Contains(grabber))
|
||
|
{
|
||
|
grabbers.Add(grabber);
|
||
|
|
||
|
if (grabbers.Count == 2)
|
||
|
{
|
||
|
Activate();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void TryDeactivate(Grabber grabber)
|
||
|
{
|
||
|
if (grabbers.Contains(grabber))
|
||
|
{
|
||
|
grabbers.Remove(grabber);
|
||
|
Deactivate();
|
||
|
}
|
||
|
}
|
||
|
}
|