개발자용 멀티플레이 기능 추가

This commit is contained in:
2026-02-02 20:26:28 +09:00
parent b4c22edcbd
commit 9dea9daaa9
23 changed files with 1754 additions and 13 deletions

View File

@@ -0,0 +1,176 @@
using UnityEngine;
using UnityEngine.UI;
using UnityEditor;
namespace Northbound.Editor
{
public class NetworkUIBuilder
{
[MenuItem("GameObject/Network/Create Network Join UI")]
public static void CreateNetworkJoinUI()
{
Canvas canvas = FindOrCreateCanvas();
GameObject panel = CreatePanel(canvas.transform);
InputField ipInput = CreateInputField(panel.transform, "IP Input", "127.0.0.1", 150);
InputField portInput = CreateInputField(panel.transform, "Port Input", "7777", 100);
Button joinButton = CreateButton(panel.transform, "Join", new Vector2(0, -80));
Button hostButton = CreateButton(panel.transform, "Host", new Vector2(-60, -80));
Button disconnectButton = CreateButton(panel.transform, "Disconnect", new Vector2(60, -80));
Text statusText = CreateStatusText(panel.transform);
NetworkJoinUI networkJoinUI = panel.AddComponent<NetworkJoinUI>();
networkJoinUI.SetUIReferences(panel, ipInput, portInput, joinButton, hostButton, disconnectButton, statusText);
Selection.activeGameObject = panel;
Debug.Log("[NetworkUIBuilder] Network Join UI created!");
}
private static Canvas FindOrCreateCanvas()
{
Canvas[] canvases = Object.FindObjectsByType<Canvas>(FindObjectsSortMode.None);
if (canvases.Length > 0)
{
return canvases[0];
}
GameObject canvasObj = new GameObject("NetworkCanvas");
Canvas canvas = canvasObj.AddComponent<Canvas>();
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
canvasObj.AddComponent<CanvasScaler>();
canvasObj.AddComponent<GraphicRaycaster>();
return canvas;
}
private static GameObject CreatePanel(Transform parent)
{
GameObject panel = new GameObject("NetworkJoinPanel");
panel.transform.SetParent(parent, false);
RectTransform rect = panel.AddComponent<RectTransform>();
rect.anchorMin = new Vector2(0.5f, 0.5f);
rect.anchorMax = new Vector2(0.5f, 0.5f);
rect.pivot = new Vector2(0.5f, 0.5f);
rect.sizeDelta = new Vector2(300, 250);
rect.anchoredPosition = Vector2.zero;
Image image = panel.AddComponent<Image>();
image.color = new Color(0.1f, 0.1f, 0.1f, 0.95f);
return panel;
}
private static InputField CreateInputField(Transform parent, string name, string placeholder, float width)
{
GameObject fieldObj = new GameObject(name);
fieldObj.transform.SetParent(parent, false);
RectTransform rect = fieldObj.AddComponent<RectTransform>();
rect.anchorMin = new Vector2(0.5f, 0.5f);
rect.anchorMax = new Vector2(0.5f, 0.5f);
rect.pivot = new Vector2(0.5f, 0.5f);
rect.sizeDelta = new Vector2(width, 30);
int yPos = name.Contains("IP") ? 80 : 40;
rect.anchoredPosition = new Vector2(0, yPos);
Image bgImage = fieldObj.AddComponent<Image>();
bgImage.color = new Color(0.2f, 0.2f, 0.2f, 1f);
InputField inputField = fieldObj.AddComponent<InputField>();
inputField.textComponent = CreateTextComponent(fieldObj.transform, "");
inputField.text = placeholder;
inputField.contentType = InputField.ContentType.Standard;
Text placeholderText = CreateTextComponent(fieldObj.transform, placeholder);
placeholderText.color = new Color(0.5f, 0.5f, 0.5f, 0.5f);
inputField.placeholder = placeholderText;
Text label = CreateTextComponent(parent, name.ToUpper());
RectTransform labelRect = label.GetComponent<RectTransform>();
labelRect.anchoredPosition = new Vector2(-width / 2 - 30, yPos);
return inputField;
}
private static Button CreateButton(Transform parent, string text, Vector2 position)
{
GameObject buttonObj = new GameObject(text + "Button");
buttonObj.transform.SetParent(parent, false);
RectTransform rect = buttonObj.AddComponent<RectTransform>();
rect.anchorMin = new Vector2(0.5f, 0.5f);
rect.anchorMax = new Vector2(0.5f, 0.5f);
rect.pivot = new Vector2(0.5f, 0.5f);
rect.sizeDelta = new Vector2(80, 30);
rect.anchoredPosition = position;
Image bgImage = buttonObj.AddComponent<Image>();
bgImage.color = new Color(0.3f, 0.5f, 0.8f, 1f);
Button button = buttonObj.AddComponent<Button>();
Text buttonText = CreateTextComponent(buttonObj.transform, text);
buttonText.alignment = TextAnchor.MiddleCenter;
return button;
}
private static Text CreateTextComponent(Transform parent, string text)
{
GameObject textObj = new GameObject("Text");
textObj.transform.SetParent(parent, false);
RectTransform rect = textObj.AddComponent<RectTransform>();
rect.anchorMin = Vector2.zero;
rect.anchorMax = Vector2.one;
rect.offsetMin = Vector2.zero;
rect.offsetMax = Vector2.zero;
Text textComponent = textObj.AddComponent<Text>();
textComponent.text = text;
textComponent.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
textComponent.fontSize = 14;
textComponent.color = Color.white;
textComponent.alignment = TextAnchor.MiddleCenter;
return textComponent;
}
private static Text CreateStatusText(Transform parent)
{
GameObject textObj = new GameObject("StatusText");
textObj.transform.SetParent(parent, false);
RectTransform rect = textObj.AddComponent<RectTransform>();
rect.anchorMin = new Vector2(0.5f, 0.5f);
rect.anchorMax = new Vector2(0.5f, 0.5f);
rect.pivot = new Vector2(0.5f, 0.5f);
rect.sizeDelta = new Vector2(280, 30);
rect.anchoredPosition = new Vector2(0, -120);
Text textComponent = textObj.AddComponent<Text>();
textComponent.text = "Not connected";
textComponent.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
textComponent.fontSize = 12;
textComponent.color = Color.yellow;
textComponent.alignment = TextAnchor.MiddleCenter;
return textComponent;
}
[MenuItem("GameObject/Network/Create Network Helper")]
public static void CreateNetworkHelper()
{
GameObject helperObj = new GameObject("NetworkConnectionHelper");
helperObj.AddComponent<NetworkConnectionHelper>();
Selection.activeGameObject = helperObj;
Debug.Log("[NetworkUIBuilder] Network Connection Helper created!");
}
}
}