66 lines
1.9 KiB
C#
66 lines
1.9 KiB
C#
using Fusion;
|
|
using UnityEngine;
|
|
|
|
public class PlantNetworkedScript : NetworkBehaviour
|
|
{
|
|
[Networked] public bool PlantVisibility { get; set; }
|
|
|
|
private ChangeDetector _changeDetector;
|
|
|
|
public GameObject plantModel;
|
|
public GameObject plantMarker;
|
|
public GameObject plantStatsDialog;
|
|
public GameObject plantNotesDialog;
|
|
|
|
// public Material material;
|
|
|
|
// private void Awake()
|
|
// {
|
|
// material = GetComponentInChildren<MeshRenderer>().material;
|
|
// }
|
|
|
|
public override void Spawned()
|
|
{
|
|
_changeDetector = GetChangeDetector(ChangeDetector.Source.SimulationState);
|
|
}
|
|
|
|
public override void Render()
|
|
{
|
|
foreach (var change in _changeDetector.DetectChanges(this))
|
|
{
|
|
Debug.Log("[Prageeth] Change detected: " + change);
|
|
switch (change)
|
|
{
|
|
case nameof(PlantVisibility):
|
|
// show the plant model to the [supervisor]
|
|
if (!Object.HasStateAuthority) plantModel.SetActive(true);
|
|
// show the plant stats dialogs
|
|
plantStatsDialog.SetActive(true);
|
|
plantStatsDialog.GetComponentInChildren<Canvas>().gameObject.SetActive(true);
|
|
plantNotesDialog.SetActive(true);
|
|
plantNotesDialog.GetComponentInChildren<Canvas>().gameObject.SetActive(true);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
public override void FixedUpdateNetwork()
|
|
{
|
|
// only [plant owner] can see the plant marker
|
|
if (Object.HasStateAuthority)
|
|
{
|
|
plantMarker.SetActive(true);
|
|
}
|
|
}
|
|
|
|
public void ConfirmMarkerPlace()
|
|
{
|
|
// Planting the plant marker
|
|
// [supervisor] can only see once the marker is planted
|
|
if (Object.HasStateAuthority)
|
|
{
|
|
Debug.Log("[Prageeth] Plant visibility set to: " + PlantVisibility);
|
|
PlantVisibility = true;
|
|
}
|
|
}
|
|
} |