Skip to content

Instantly share code, notes, and snippets.

@KorStrix
Created March 18, 2020 02:16
Show Gist options
  • Save KorStrix/2c31b79b9c6ec0ffa5bf0a41a5bdf9d8 to your computer and use it in GitHub Desktop.
Save KorStrix/2c31b79b9c6ec0ffa5bf0a41a5bdf9d8 to your computer and use it in GitHub Desktop.
// Tips from https://forum.unity3d.com/threads/c-script-template-how-to-make-custom-changes.273191/
using UnityEngine;
using System.Linq;
#if UNITY_EDITOR
using UnityEditor;
/// <summary>
/// 스크립트를 생성할 때 스크립트의 Keyword를 컨버팅합니다.
/// </summary>
internal sealed class ScriptKeywordProcessor : UnityEditor.AssetModificationProcessor
{
public static void OnWillCreateAsset(string strPath)
{
if (strPath.Contains(nameof(ScriptKeywordProcessor)))
return;
strPath = strPath.Replace(".meta", "");
int iIndex = strPath.LastIndexOf(".");
if (iIndex < 0)
return;
string strFile = strPath.Substring(iIndex);
if (strFile != ".cs")
return;
iIndex = Application.dataPath.LastIndexOf("Assets");
strPath = Application.dataPath.Substring(0, iIndex) + strPath;
if (System.IO.File.Exists(strPath) == false)
return;
string strFileContent = System.IO.File.ReadAllText(strPath);
strFileContent = strFileContent.Replace("#CREATIONDATE#", System.DateTime.Now.ToString("yyyy-MM-dd"));
strFileContent = Replace_Author(strFileContent);
System.IO.File.WriteAllText(strPath, strFileContent);
AssetDatabase.Refresh();
}
private static string Replace_Author(string strFileContent)
{
var listSaveData = PlayerPrefWindowEditor.GetPlayerPrefSaveDataList();
var pAurthorData = listSaveData.Where(p => p.strKey.ToLower().Contains("author")).
Where(p => p.eFieldType == PlayerPrefWindowEditor.EFieldType.String).
FirstOrDefault();
if (pAurthorData == null)
Debug.LogError("PlayerPref - AUTHOR(string) is Null Or Empty!!");
strFileContent = strFileContent.Replace("#AUTHOR#", pAurthorData.strValue);
return strFileContent;
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment