120 lines
4.1 KiB
C#
120 lines
4.1 KiB
C#
using System;
|
|
using Fusion;
|
|
using UnityEngine;
|
|
|
|
public class ApplicationManager : NetworkBehaviour
|
|
{
|
|
public GameObject loadingIndicator;
|
|
public GameObject placeholderMarkerGuide;
|
|
public OVRSpatialAnchor hostPlaceholderMarker;
|
|
public OVRSpatialAnchor PlacedAnchor { private set; get; }
|
|
public NetworkObject networkPlantPrefab;
|
|
public NetworkObject networkStatsPrefab;
|
|
public NetworkObject networkCommentsPrefab;
|
|
public NetworkObject networkActionsPrefab;
|
|
|
|
public bool InProgress { private set; get; }
|
|
public bool IsAnchorSubmitted { private set; get; }
|
|
public bool? IsHost { private set; get; }
|
|
|
|
// We keep track of the object we just spawned
|
|
private NetworkObject _spawnedInstance1;
|
|
private NetworkObject _spawnedInstance2;
|
|
private NetworkObject _spawnedInstance3;
|
|
private NetworkObject _spawnedInstance4;
|
|
private GameObject _plant;
|
|
|
|
public override void Spawned()
|
|
{
|
|
IsHost = Object.HasStateAuthority;
|
|
Debug.Log("[DCDC] IsHost: " + IsHost);
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
// loadingIndicator.SetActive(true);
|
|
placeholderMarkerGuide.SetActive(false);
|
|
}
|
|
|
|
private void FixedUpdate()
|
|
{
|
|
if (IsHost == true && placeholderMarkerGuide.activeSelf != (PlacedAnchor == null))
|
|
{
|
|
placeholderMarkerGuide.SetActive(PlacedAnchor == null);
|
|
}
|
|
|
|
if (_plant == null)
|
|
{
|
|
var p = GameObject.FindGameObjectWithTag("Plant");
|
|
if (p != null)
|
|
{
|
|
_plant = p;
|
|
Debug.Log("[DCDC] Plant found and assigned: " + _plant);
|
|
}
|
|
}
|
|
else if (_plant.activeSelf && IsHost == true)
|
|
{
|
|
_plant.SetActive(false);
|
|
Debug.Log("[DCDC] Plant hidden for host.");
|
|
}
|
|
}
|
|
|
|
public void SetInProgress(bool flag)
|
|
{
|
|
InProgress = flag;
|
|
loadingIndicator.SetActive(flag);
|
|
Debug.Log("[DCDC] inProgress: " + InProgress);
|
|
}
|
|
|
|
public void SetAnchor(OVRSpatialAnchor anchor)
|
|
{
|
|
PlacedAnchor = anchor;
|
|
placeholderMarkerGuide.SetActive(anchor == null);
|
|
Debug.Log("[DCDC] anchor: " + PlacedAnchor);
|
|
}
|
|
|
|
public void AnchorSubmitted()
|
|
{
|
|
Debug.Log("[DCDC] Anchor submitted: " + PlacedAnchor);
|
|
|
|
HandleButtonPress();
|
|
}
|
|
|
|
private void HandleButtonPress()
|
|
{
|
|
// Object doesn't exist yet? SPAWN IT
|
|
if (IsHost != null && _spawnedInstance1 == null && _spawnedInstance2 == null && _spawnedInstance3 == null &&
|
|
_spawnedInstance4 == null)
|
|
{
|
|
// show virtual plant for the supervisor only (client)
|
|
// if (!IsHost.Value)
|
|
// {
|
|
// Spawn relative to the Anchor
|
|
_spawnedInstance1 = Runner.Spawn(networkPlantPrefab, PlacedAnchor.transform.position,
|
|
PlacedAnchor.transform.rotation);
|
|
// }
|
|
|
|
// 1m to the right of the anchor and 1m backwards and .5m up
|
|
_spawnedInstance2 = Runner.Spawn(networkStatsPrefab,
|
|
PlacedAnchor.transform.position + PlacedAnchor.transform.right * .7f +
|
|
PlacedAnchor.transform.forward * -.3f + PlacedAnchor.transform.up * 0.5f);
|
|
|
|
// 1.5m to the right of the anchor and 1m backwards and .5m up
|
|
_spawnedInstance3 = Runner.Spawn(networkActionsPrefab,
|
|
PlacedAnchor.transform.position + PlacedAnchor.transform.right * .3f +
|
|
PlacedAnchor.transform.forward * -.2f + PlacedAnchor.transform.up * 0.1f);
|
|
// PlacedAnchor.transform.position + PlacedAnchor.transform.right * 1f +
|
|
// PlacedAnchor.transform.forward * -.8f + PlacedAnchor.transform.up * 0.5f);
|
|
|
|
// 1m to the left of the anchor and 1m backwards and .5m up
|
|
_spawnedInstance4 = Runner.Spawn(networkCommentsPrefab,
|
|
PlacedAnchor.transform.position + PlacedAnchor.transform.right * -1f +
|
|
PlacedAnchor.transform.forward * -.3f + PlacedAnchor.transform.up * 0.5f);
|
|
|
|
Debug.Log("[DCDC] Object Spawned at Anchor!");
|
|
}
|
|
|
|
|
|
IsAnchorSubmitted = true;
|
|
}
|
|
} |