You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.0 KiB
81 lines
2.0 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Unity.Netcode;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
public class Interactable : NetworkBehaviour
|
|
{
|
|
[SerializeField] protected NetworkObject networkObject;
|
|
[SerializeField] protected Collider _collider;
|
|
[SerializeField] protected bool isOccupied;
|
|
[SerializeField] protected List<Interaction> interactions;
|
|
|
|
public bool IsOccupied => isOccupied;
|
|
|
|
public List<Interaction> Interactions => interactions;
|
|
public Vector3 Rotation => interactions[0].Rotation;
|
|
public GameObject GoToPoint => interactions[0].GoToPoint;
|
|
public GameObject FinishPoint => interactions[0].FinishPoint;
|
|
|
|
public int ActiveInteractionsCount
|
|
{
|
|
get
|
|
{
|
|
int count = 0;
|
|
|
|
foreach (Interaction interaction in interactions)
|
|
{
|
|
if (interaction.Active) count++;
|
|
}
|
|
|
|
return count;
|
|
}
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
if (IsServer)
|
|
{
|
|
networkObject.Spawn();
|
|
}
|
|
}
|
|
public void CreateInteractions()
|
|
{
|
|
int count = ActiveInteractionsCount;
|
|
Bounds obj = _collider.bounds;
|
|
|
|
float sizeobj = 1f;
|
|
float sizebtw = 0.2f;
|
|
|
|
float width = count * sizeobj + (count - 1) * sizebtw;
|
|
Vector3 point = new Vector3(obj.center.x - width / 2f + sizeobj / 2f, obj.center.y + obj.extents.y);
|
|
|
|
foreach (Interaction interaction in interactions)
|
|
{
|
|
if (!interaction.Active) continue;
|
|
|
|
interaction.InitializeButton(point);
|
|
point.x += sizeobj + sizebtw;
|
|
}
|
|
}
|
|
|
|
public void Interact()
|
|
{
|
|
if (Interactions.Count == 0) return;
|
|
|
|
//SetOccupiedEveryoneRpc(true);
|
|
Interactions[0].Action();
|
|
}
|
|
|
|
public void Uninteract()
|
|
{
|
|
//SetOccupiedEveryoneRpc(false);
|
|
}
|
|
|
|
[Rpc(SendTo.Everyone)]
|
|
public void SetOccupiedEveryoneRpc(bool occupied)
|
|
{
|
|
isOccupied = occupied;
|
|
}
|
|
}
|
|
|