using ExitGames.Client.Photon;
using Photon.Realtime;
using UnityEngine;
using UnityEngine.UI;
namespace Photon.Pun.Demo.Procedural
{
///
/// The Ingame Control Panel basically controls the WorldGenerator.
/// It is only interactable for the current MasterClient in the room.
///
public class IngameControlPanel : MonoBehaviourPunCallbacks
{
private bool isSeedValid;
private InputField seedInputField;
private Dropdown worldSizeDropdown;
private Dropdown clusterSizeDropdown;
private Dropdown worldTypeDropdown;
private Button generateWorldButton;
#region UNITY
///
/// When the object gets created, all necessary references are set up.
/// Also the UI elements get set up properly in order to control the WorldGenerator.
///
public void Awake()
{
isSeedValid = false;
seedInputField = GetComponentInChildren();
seedInputField.characterLimit = 10;
seedInputField.characterValidation = InputField.CharacterValidation.Integer;
seedInputField.interactable = PhotonNetwork.PhotonServerSettings.StartInOfflineMode;
seedInputField.onValueChanged.AddListener((string value) =>
{
int seed;
if (int.TryParse(value, out seed))
{
isSeedValid = true;
WorldGenerator.Instance.Seed = seed;
}
else
{
isSeedValid = false;
Debug.LogError("Invalid Seed entered. Only numeric Seeds are allowed.");
}
});
worldSizeDropdown = GetComponentsInChildren()[0];
worldSizeDropdown.interactable = PhotonNetwork.PhotonServerSettings.StartInOfflineMode;
worldSizeDropdown.onValueChanged.AddListener((int value) =>
{
switch (value)
{
case 0:
{
WorldGenerator.Instance.WorldSize = WorldSize.Tiny;
break;
}
case 1:
{
WorldGenerator.Instance.WorldSize = WorldSize.Small;
break;
}
case 2:
{
WorldGenerator.Instance.WorldSize = WorldSize.Medium;
break;
}
case 3:
{
WorldGenerator.Instance.WorldSize = WorldSize.Large;
break;
}
}
});
clusterSizeDropdown = GetComponentsInChildren()[1];
clusterSizeDropdown.interactable = PhotonNetwork.PhotonServerSettings.StartInOfflineMode;
clusterSizeDropdown.onValueChanged.AddListener((int value) =>
{
switch (value)
{
case 0:
{
WorldGenerator.Instance.ClusterSize = ClusterSize.Small;
break;
}
case 1:
{
WorldGenerator.Instance.ClusterSize = ClusterSize.Medium;
break;
}
case 2:
{
WorldGenerator.Instance.ClusterSize = ClusterSize.Large;
break;
}
}
});
worldTypeDropdown = GetComponentsInChildren()[2];
worldTypeDropdown.interactable = PhotonNetwork.PhotonServerSettings.StartInOfflineMode;
worldTypeDropdown.onValueChanged.AddListener((int value) =>
{
switch (value)
{
case 0:
{
WorldGenerator.Instance.WorldType = WorldType.Flat;
break;
}
case 1:
{
WorldGenerator.Instance.WorldType = WorldType.Standard;
break;
}
case 2:
{
WorldGenerator.Instance.WorldType = WorldType.Mountain;
break;
}
}
});
generateWorldButton = GetComponentInChildren