Unity 적용 설정 파일 생성
프로젝트 디렉토리 구조에는 다음과 같은 구조가 있습니다.
ProjectDirectory
ProjectName
|
|-- Assets
|-- Editor
|-- SettingsEditor.cs
|-- Sctipts
|-- Settings.cs
Editor에는 pull downmenu(Local, Develop, Production)를 통해 APIHost를 선택하고 Create 버튼을 누르면 Settings가 표시됩니다.cs 파일이 생성되었습니다.다음은 Editor의 코드 및 설정 화면입니다.Editor/SettingsEditor.cs
using UnityEditor;
using UnityEngine;
public class SettingsEditor : EditorWindow
{
public enum APIHost
{
Local,
Develop,
Production
}
APIHost _host;
[MenuItem("Window/SettingsEditor")]
public static void ShowWindow()
{
EditorWindow.GetWindow(typeof(SettingsEditor));
}
void OnGUI()
{
GUILayout.Label ("Host", EditorStyles.boldLabel);
_host = (APIHost)EditorGUILayout.EnumPopup ("API Host", _host);
if (GUILayout.Button ("Create")) {
using (System.IO.StreamWriter file = new System.IO.StreamWriter(System.IO.Directory.GetCurrentDirectory() + "/Assets/Scripts/Settings.cs"))
{
var host = "";
switch (_host)
{
case APIHost.Local:
host = "http://127.0.0.1:8000";
break;
case APIHost.Develop:
host = "http://develop.com";
break;
case APIHost.Production:
host = "http://production.com";
break;
}
file.WriteLine ("using System;");
file.WriteLine ("using System.Collections;");
file.WriteLine ("using System.Collections.Generic;");
file.WriteLine ("using UnityEngine;");
file.WriteLine ("");
file.WriteLine ("public static class Settings");
file.WriteLine ("{");
file.WriteLine (string.Format(" public static string Host = \"{0}\";", host));
file.WriteLine ("}");
}
}
}
}

Create 버튼을 누르면 다음과 같은 코드가 생성되고 설정값이 변경됩니다.
Scripts/Settings.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public static class Settings
{
public static string Host = "http://develop.com";
}
이렇게 하면 코드를 일일이 다시 쓰지 않고 GUI 설정 화면에서 설정을 쉽게 다시 쓸 수 있다.
Reference
이 문제에 관하여(Unity 적용 설정 파일 생성), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/HirokazuMiyaji/items/a5ff6959c65fa9b7904c텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)