Initial commit
This commit is contained in:
@@ -0,0 +1,217 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
|
||||
public class CanvasPlatformUI : MonoBehaviour
|
||||
{
|
||||
private CanvasVirtualPlatformManager platformManager;
|
||||
|
||||
[Header("Plane Selection")]
|
||||
[SerializeField] private TMP_Dropdown planeDropdown;
|
||||
|
||||
[Header("Canvas Size Controls")]
|
||||
[SerializeField] private Slider canvasSizeSlider;
|
||||
[SerializeField] private float minCanvasSize = 1000f;
|
||||
[SerializeField] private float maxCanvasSize = 10000f;
|
||||
|
||||
[Header("Visibility Toggles")]
|
||||
[SerializeField] private Toggle platformToggle;
|
||||
[SerializeField] private Toggle gridToggle;
|
||||
|
||||
[Header("Display Info (Optional)")]
|
||||
[SerializeField] private TextMeshProUGUI infoText;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
platformManager = CanvasVirtualPlatformManager.getInstance();
|
||||
|
||||
if (platformManager == null)
|
||||
{
|
||||
Debug.LogError("CanvasVirtualPlatformManager not found in scene!");
|
||||
return;
|
||||
}
|
||||
|
||||
SetupUI();
|
||||
UpdateInfoDisplay();
|
||||
}
|
||||
|
||||
private void SetupUI()
|
||||
{
|
||||
// Setup Plane Dropdown
|
||||
if (planeDropdown != null)
|
||||
{
|
||||
planeDropdown.ClearOptions();
|
||||
planeDropdown.AddOptions(new System.Collections.Generic.List<string>
|
||||
{
|
||||
"XZ",
|
||||
"XY",
|
||||
"YZ"
|
||||
});
|
||||
planeDropdown.value = (int)platformManager.GetCurrentPlane();
|
||||
planeDropdown.onValueChanged.AddListener(OnPlaneChanged);
|
||||
}
|
||||
|
||||
// Setup Canvas Size Slider (for uniform sizing)
|
||||
if (canvasSizeSlider != null)
|
||||
{
|
||||
canvasSizeSlider.minValue = minCanvasSize;
|
||||
canvasSizeSlider.maxValue = maxCanvasSize;
|
||||
Vector2 currentSize = platformManager.GetCurrentCanvasSize();
|
||||
canvasSizeSlider.value = currentSize.x; // Use width as default
|
||||
canvasSizeSlider.onValueChanged.AddListener(OnCanvasSizeSliderChanged);
|
||||
}
|
||||
|
||||
|
||||
// Setup Platform Toggle
|
||||
if (platformToggle != null)
|
||||
{
|
||||
platformToggle.isOn = platformManager.IsPlatformVisible();
|
||||
platformToggle.onValueChanged.AddListener(OnPlatformToggleChanged);
|
||||
}
|
||||
|
||||
// Setup Grid Toggle
|
||||
if (gridToggle != null)
|
||||
{
|
||||
gridToggle.isOn = true; // Grid visible by default
|
||||
gridToggle.onValueChanged.AddListener(OnGridToggleChanged);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPlaneChanged(int index)
|
||||
{
|
||||
platformManager.SwitchToPlane((PlaneAxis)index);
|
||||
UpdateCanvasSizeFields();
|
||||
UpdateInfoDisplay();
|
||||
}
|
||||
|
||||
private void OnCanvasSizeSliderChanged(float value)
|
||||
{
|
||||
// Set both width and height to the same value (square canvas)
|
||||
platformManager.SetCurrentCanvasSize(value, value);
|
||||
|
||||
UpdateInfoDisplay();
|
||||
}
|
||||
|
||||
private void OnCanvasWidthChanged(string value)
|
||||
{
|
||||
if (float.TryParse(value, out float width))
|
||||
{
|
||||
width = Mathf.Clamp(width, minCanvasSize, maxCanvasSize);
|
||||
Vector2 currentSize = platformManager.GetCurrentCanvasSize();
|
||||
platformManager.SetCurrentCanvasSize(width, currentSize.y);
|
||||
|
||||
UpdateInfoDisplay();
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateCanvasSizeFields();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnCanvasHeightChanged(string value)
|
||||
{
|
||||
if (float.TryParse(value, out float height))
|
||||
{
|
||||
height = Mathf.Clamp(height, minCanvasSize, maxCanvasSize);
|
||||
Vector2 currentSize = platformManager.GetCurrentCanvasSize();
|
||||
platformManager.SetCurrentCanvasSize(currentSize.x, height);
|
||||
|
||||
UpdateInfoDisplay();
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateCanvasSizeFields();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateCanvasSizeFields()
|
||||
{
|
||||
Vector2 currentSize = platformManager.GetCurrentCanvasSize();
|
||||
|
||||
if (canvasSizeSlider != null)
|
||||
canvasSizeSlider.value = currentSize.x;
|
||||
}
|
||||
|
||||
private void OnPlatformToggleChanged(bool isOn)
|
||||
{
|
||||
platformManager.TogglePlatformVisibility(isOn);
|
||||
UpdateInfoDisplay();
|
||||
}
|
||||
|
||||
private void OnGridToggleChanged(bool isOn)
|
||||
{
|
||||
platformManager.ToggleGridVisibility(isOn);
|
||||
UpdateInfoDisplay();
|
||||
}
|
||||
|
||||
private void UpdateInfoDisplay()
|
||||
{
|
||||
if (infoText != null && platformManager != null)
|
||||
{
|
||||
string planeText = platformManager.GetCurrentPlane().ToString();
|
||||
string visibilityText = platformManager.IsPlatformVisible() ? "Visible" : "Hidden";
|
||||
Vector2 canvasSize = platformManager.GetCurrentCanvasSize();
|
||||
|
||||
infoText.text = $"Current Plane: {planeText}\n" +
|
||||
$"Platform: {visibilityText}\n" +
|
||||
$"Canvas Size: {canvasSize.x:F0} x {canvasSize.y:F0}";
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
// Keyboard shortcuts for plane selection
|
||||
if (Input.GetKeyDown(KeyCode.Alpha1))
|
||||
{
|
||||
if (planeDropdown != null)
|
||||
planeDropdown.value = 0;
|
||||
else
|
||||
platformManager.SwitchToPlane(PlaneAxis.XZ);
|
||||
UpdateInfoDisplay();
|
||||
}
|
||||
if (Input.GetKeyDown(KeyCode.Alpha2))
|
||||
{
|
||||
if (planeDropdown != null)
|
||||
planeDropdown.value = 1;
|
||||
else
|
||||
platformManager.SwitchToPlane(PlaneAxis.XY);
|
||||
UpdateInfoDisplay();
|
||||
}
|
||||
if (Input.GetKeyDown(KeyCode.Alpha3))
|
||||
{
|
||||
if (planeDropdown != null)
|
||||
planeDropdown.value = 2;
|
||||
else
|
||||
platformManager.SwitchToPlane(PlaneAxis.YZ);
|
||||
UpdateInfoDisplay();
|
||||
}
|
||||
|
||||
// Toggle platform visibility with V key
|
||||
if (Input.GetKeyDown(KeyCode.V))
|
||||
{
|
||||
bool newState = !platformManager.IsPlatformVisible();
|
||||
platformManager.TogglePlatformVisibility(newState);
|
||||
if (platformToggle != null)
|
||||
platformToggle.isOn = newState;
|
||||
UpdateInfoDisplay();
|
||||
}
|
||||
|
||||
// Adjust canvas size with bracket keys
|
||||
if (Input.GetKeyDown(KeyCode.LeftBracket))
|
||||
{
|
||||
Vector2 currentSize = platformManager.GetCurrentCanvasSize();
|
||||
float newSize = Mathf.Max(minCanvasSize, currentSize.x - 500f);
|
||||
platformManager.SetCurrentCanvasSize(newSize, newSize);
|
||||
UpdateCanvasSizeFields();
|
||||
UpdateInfoDisplay();
|
||||
}
|
||||
if (Input.GetKeyDown(KeyCode.RightBracket))
|
||||
{
|
||||
Vector2 currentSize = platformManager.GetCurrentCanvasSize();
|
||||
float newSize = Mathf.Min(maxCanvasSize, currentSize.x + 500f);
|
||||
platformManager.SetCurrentCanvasSize(newSize, newSize);
|
||||
UpdateCanvasSizeFields();
|
||||
UpdateInfoDisplay();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user