Created
July 27, 2013 14:12
-
-
Save masa795/6094982 to your computer and use it in GitHub Desktop.
シーンをメニューから開く。メニューに表示するシーンは自動で作成される。
https://github.com/masa795/OpenSceneFromMenuCreator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEditor; | |
namespace Nlib.Editor.Util | |
{ | |
[InitializeOnLoad] | |
public class InitOnLoad | |
{ | |
static int couner = 0; | |
static InitOnLoad() | |
{ | |
++couner; | |
EditorApplication.playmodeStateChanged += ChangedPlaymodeState; | |
EditorApplication.update += Update; | |
//Log(couner + " InitOnLoad!"); | |
} | |
public static bool IsClickedPlayButton() | |
{ | |
return EditorPrefs.GetBool("editor_InitOnLoad", false); | |
} | |
static void ChangedPlaymodeState() | |
{ | |
++couner; | |
EditorPrefs.SetBool("editor_InitOnLoad", EditorApplication.isPlayingOrWillChangePlaymode); | |
//Log(couner + " State Changed!"); | |
} | |
static void Update() | |
{ | |
++couner; | |
//Log(couner + " Update!"); | |
EditorApplication.update -= Update; | |
} | |
static void Log(string called) | |
{ | |
Debug.Log(called | |
+ " \n Application.isPlaying=" + Application.isPlaying | |
+ " \n EditorApplication.isPlaying=" + EditorApplication.isPlaying | |
+ " \n Application.isCompiling=" + EditorApplication.isCompiling | |
+ " \n Application.isPaused=" + EditorApplication.isPaused | |
+ " \n EditorApplication.isPlayingOrWillChangePlaymode=" + EditorApplication.isPlayingOrWillChangePlaymode | |
+ " \n editor_InitOnLoad=" + EditorPrefs.GetBool("editor_InitOnLoad", false) | |
+ " \n Time.timeSinceLevelLoad=" + Time.timeSinceLevelLoad | |
+ " \n EditorApplication.timeSinceStartup=" + EditorApplication.timeSinceStartup | |
); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using System.Collections.Generic; | |
using System; | |
using System.IO; | |
using UnityEditor; | |
namespace Nlib.Editor.Util | |
{ | |
/// <summary> | |
/// スクリプト自動生成util | |
/// </summary> | |
public class ScriptCreatorUtil | |
{ | |
/// <summary> | |
/// ファイルを作成する | |
/// </summary> | |
/// <param name="assetPath"></param> | |
/// <param name="output"></param> | |
/// <param name="prefsHashKey"></param> | |
/// <param name="isRefresh"></param> | |
/// <returns></returns> | |
public static bool CreateFile(string assetPath, string output, string prefsHashKey, bool isRefresh) | |
{ | |
if (!isRefresh) | |
{ | |
if (File.Exists(assetPath) && EditorPrefs.GetInt(prefsHashKey) == output.GetHashCode()) | |
return false; | |
if (EditorPrefs.GetInt(prefsHashKey) == output.GetHashCode()) | |
return false; | |
} | |
if (string.IsNullOrEmpty(output)) | |
{ | |
return false; | |
} | |
else | |
{ | |
if (System.IO.File.ReadAllText(assetPath) == output) | |
{ | |
EditorPrefs.SetInt(prefsHashKey, output.GetHashCode()); | |
return false; | |
} | |
} | |
System.IO.File.WriteAllText(assetPath, output); | |
EditorPrefs.SetInt(prefsHashKey, output.GetHashCode()); | |
AssetDatabase.SaveAssets(); | |
AssetDatabase.Refresh(); | |
//AssetPostprocessUTF8Encode.ConvertUtf8WithBom(assetPath); | |
return true; | |
} | |
public static void WriteNormalMember<T>(System.Text.StringBuilder builder, T sourceClass, string[] ignoreMembers) | |
{ | |
System.Reflection.FieldInfo[] fields = sourceClass.GetType().GetFields(); | |
foreach (System.Reflection.FieldInfo field in fields) | |
{ | |
if (IsIgnoreMember(ignoreMembers, field.Name)) continue; | |
WriteMember(builder, sourceClass, field); | |
} | |
} | |
public static void WriteMember<T>(System.Text.StringBuilder builder, T sourceClass, System.Reflection.FieldInfo field) | |
{ | |
builder.AppendLine(""); | |
if (field.GetValue(sourceClass) is string) | |
{ | |
WriteStringMember(builder, field.Name, (string)field.GetValue(sourceClass)); | |
} | |
else if (field.GetValue(sourceClass) is Int32) | |
{ | |
WriteIntMember(builder, field.Name, (int)field.GetValue(sourceClass)); | |
} | |
else if (field.GetValue(sourceClass) is bool) | |
{ | |
WriteBoolMember(builder, field.Name, (bool)field.GetValue(sourceClass)); | |
} | |
} | |
static bool IsIgnoreMember(string[] ignoreMembers, string memberName) | |
{ | |
if (ignoreMembers.Length == 0) return false; | |
foreach (string name in ignoreMembers) | |
if (name == memberName) return true; | |
return false; | |
} | |
#region write string | |
public static void WriteStringMember(System.Text.StringBuilder builder, string memberName, string value) | |
{ | |
builder.AppendLine(""); | |
WriteMemberDocSummaryString(builder, value); | |
builder.Append("\t").AppendFormat(@"public const string {0} = ""{1}"";", memberName, value).AppendLine(); | |
} | |
static void WriteMemberDocSummaryString(System.Text.StringBuilder builder, string value) | |
{ | |
builder.Append("\t").AppendLine("/// <summary>"); | |
builder.Append("\t").AppendFormat("/// return \"{0}\"", value).AppendLine(); | |
builder.Append("\t").AppendLine("/// </summary>"); | |
} | |
#endregion write string | |
#region write int | |
public static void WriteIntMember(System.Text.StringBuilder builder, string memberName, int value) | |
{ | |
builder.AppendLine(""); | |
WriteMemberDocSummaryInt(builder, value.ToString()); | |
builder.Append("\t").AppendFormat(@"public const int {0} = {1};", memberName, value).AppendLine(); | |
} | |
static void WriteMemberDocSummaryInt(System.Text.StringBuilder builder, string value) | |
{ | |
builder.Append("\t").AppendLine("/// <summary>"); | |
builder.Append("\t").AppendFormat("/// return {0}", value).AppendLine(); | |
builder.Append("\t").AppendLine("/// </summary>"); | |
} | |
#endregion write int | |
#region write bool | |
public static void WriteBoolMember(System.Text.StringBuilder builder, string memberName, bool value) | |
{ | |
builder.AppendLine(""); | |
string strVal = (value) ? "true" : "false"; | |
WriteMemberDocSummaryInt(builder, strVal); | |
builder.Append("\t").AppendFormat(@"public const bool {0} = {1};", memberName, strVal).AppendLine(); | |
} | |
static void WriteMemberDocSummaryBool(System.Text.StringBuilder builder, string value) | |
{ | |
builder.Append("\t").AppendLine("/// <summary>"); | |
builder.Append("\t").AppendFormat("/// return {0}", value).AppendLine(); | |
builder.Append("\t").AppendLine("/// </summary>"); | |
} | |
#endregion write bool | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment