using System;
class Program
{
static void Main(string[] args)
{
int a = 5;
int b = 10;
Console.WriteLine($"Before Swap: a = {a}, b = {b}");
Swap(ref a, ref b);
Console.WriteLine($"After Swap: a = {a}, b = {b}");
string x = "hello";
string y = "world";
Console.WriteLine($"Before Swap: x = {x}, y = {y}");
Swap(ref x, ref y);
Console.WriteLine($"After Swap: x = {x}, y = {y}");
}
static void Swap<T>(ref T lhs, ref T rhs)
{
T temp;
temp = lhs;
lhs = rhs;
rhs = temp;
}
}
https://docs.unity3d.com/ScriptReference/EditorWindow.html
Unity - Scripting API: EditorWindow
Create your own custom editor window that can float free or be docked as a tab, just like the native windows in the Unity interface. Editor windows are typically opened using a menu item.
docs.unity3d.com
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class BlockSwapWindow : EditorWindow
{
[MenuItem("Window/Block Swap Window")]
public static void ShowWindow()
{
GetWindow<BlockSwapWindow>("Block Swap Window");
}
private void OnGUI()
{
GUILayout.Label("Swap Blocks", EditorStyles.boldLabel);
}
}
https://docs.unity3d.com/ScriptReference/GUILayout.Label.html
Unity - Scripting API: GUILayout.Label
Labels have no user interaction, do not catch mouse clicks and are always rendered in normal style. If you want to make a control that responds visually to user input, use a Box control Label in the Game View.
docs.unity3d.com
https://docs.unity3d.com/ScriptReference/EditorGUILayout.IntField.html
Unity - Scripting API: EditorGUILayout.IntField
Success! Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable. Close
docs.unity3d.com
using Codice.Client.BaseCommands.Filters;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class BlockSwapWindow : EditorWindow
{
private int row1;
private int col1;
private int row2;
private int col2;
[MenuItem("Window/Block Swap Window")]
public static void ShowWindow()
{
GetWindow<BlockSwapWindow>("Block Swap Window");
}
private void OnGUI()
{
GUILayout.Label("Swap Blocks", EditorStyles.boldLabel);
row1 = EditorGUILayout.IntField("Row 1", row1);
col1 = EditorGUILayout.IntField("Column 1", col1);
row2 = EditorGUILayout.IntField("Row 2", row2);
col2 = EditorGUILayout.IntField("Column 2", col2);
}
}
using Codice.Client.BaseCommands.Filters;
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEditor;
using UnityEngine;
public class BlockSwapWindow : EditorWindow
{
private int row1;
private int col1;
private int row2;
private int col2;
[MenuItem("Window/Block Swap Window")]
public static void ShowWindow()
{
GetWindow<BlockSwapWindow>("Block Swap Window");
}
private void OnGUI()
{
GUILayout.Label("Swap Blocks", EditorStyles.boldLabel);
row1 = EditorGUILayout.IntField("Row 1", row1);
col1 = EditorGUILayout.IntField("Column 1", col1);
row2 = EditorGUILayout.IntField("Row 2", row2);
col2 = EditorGUILayout.IntField("Column 2", col2);
//버튼 UI추가
if (GUILayout.Button("Swap"))
{
//Board.instance.SwapBlocks(row1, col1, row2, col2);
Debug.Log($"Swapped blocks at [{row1}, {col1} ane [{row2}, {col2}]");
}
}
}
'Solo > Puzzle' 카테고리의 다른 글
[3Match Puzzle]스왑 -> 빈공간 찾기 -> 생성하기 -> 이동하기 (0) | 2024.06.24 |
---|---|
[3Match Puzzle] 스왑 메서드 만들기 (0) | 2024.06.20 |
[3Match Puzzle] 각 행에 있는 모든 블록 내려보내기 버튼 생성 (0) | 2024.06.19 |
[3Match Puzzle] 각 열에 빈공간 찾기 로직 수 (0) | 2024.06.19 |
[3Match Puzzle] 빈공간에 해당하는 위치에 블록 생성하기 (0) | 2024.06.18 |