2024-05-31 18:39:23 +03:00
|
|
|
using System;
|
2023-07-24 16:38:13 +03:00
|
|
|
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;
|
|
|
|
|
2023-10-18 11:59:26 +03:00
|
|
|
public bool Active = false;
|
2023-07-24 16:38:13 +03:00
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
if (StartActive)
|
|
|
|
Activate();
|
|
|
|
else
|
|
|
|
Deactivate();
|
|
|
|
}
|
|
|
|
|
2024-05-31 18:39:23 +03:00
|
|
|
private void Update()
|
|
|
|
{
|
|
|
|
if(Input.GetKeyDown(KeyCode.S))
|
|
|
|
{
|
|
|
|
Debug.Log($"Activate", this);
|
|
|
|
Activate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-24 16:38:13 +03:00
|
|
|
private void Activate()
|
|
|
|
{
|
2023-10-18 11:59:26 +03:00
|
|
|
Active = true;
|
2023-07-24 16:38:13 +03:00
|
|
|
OnActivate?.Invoke();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Deactivate()
|
|
|
|
{
|
2023-10-18 11:59:26 +03:00
|
|
|
Active = false;
|
2023-07-24 16:38:13 +03:00
|
|
|
OnDeactivate?.Invoke();
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|