提交 9763540f 编写于 作者: 魔术师Dix's avatar 魔术师Dix

调整配置路径,修改本地设置;

上级 bc010228
......@@ -20,9 +20,8 @@ namespace Lycianthes
public class CreateScriptByTemplate
{
public static string Version = "0.0.1";
public static string Author = "Chief";
public static string Company = "RedPanda";
public static string NameSpace = "RedPanda";
public static string MoudleInfo = "模块说明";
public static void CreateSript(string resourceFile, string fileName = "/Scripts/", string className = "New_CS_Script")
{
......@@ -111,11 +110,12 @@ namespace Lycianthes
{
StringBuilder summary = new StringBuilder();
summary.Append("/*\n");
summary.Append($" *Copyright(C) 2023 by {Company} All rights reserved.\n");
summary.Append($" *Copyright(C) 2023 by {LycianthesConfig.GetInstance().CompanyName} All rights reserved.\n");
summary.Append($" *Unity版本:{Application.unityVersion} \n");
summary.Append($" *作者:{Author } \n");
summary.Append($" *作者:{LycianthesConfig.GetInstance().AuthorName} \n");
summary.Append($" *创建日期: {System.DateTime.Now.ToString("yyyy-MM-dd")} \n");
summary.Append(" *模块说明:\n");
if (LycianthesConfig.GetInstance().UseModuleInfo)
summary.Append($" *模块说明:{MoudleInfo}\n");
summary.Append($" *版本: {Version}\n");
summary.Append("*/");
text = Regex.Replace(text, "#SUMMARY#", summary.ToString());
......@@ -123,4 +123,4 @@ namespace Lycianthes
}
}
}
}
\ No newline at end of file
......@@ -24,6 +24,28 @@ namespace Lycianthes
public static LycianthesConfig FromJson(string json) { return JsonUtility.FromJson<LycianthesConfig>(json); }
/// <summary>
/// 本地配置;
/// </summary>
public const string KEY_LYCIANTHES_CONFIG = "KEY_LYCIANTHES_CONFIG";
private static LycianthesConfig instance;
public static LycianthesConfig GetInstance()
{
if (instance != null) return instance;
if (!PlayerPrefs.HasKey(KEY_LYCIANTHES_CONFIG))
{
instance = new LycianthesConfig(); ;
return instance;
}
var jsonStr = PlayerPrefs.GetString(KEY_LYCIANTHES_CONFIG);
instance = FromJson(jsonStr);
return instance;
}
[LabelText("作者"), LabelWidth(60)]
public string AuthorName;
......
......@@ -21,12 +21,6 @@ namespace Lycianthes
/// </summary>
public class LycianthesConfigWindow : OdinEditorWindow
{
/// <summary>
/// 本地配置;
/// </summary>
public const string KEY_LYCIANTHES_CONFIG = "KEY_LYCIANTHES_CONFIG";
/// <summary>
/// 上次选择的默认脚本模板文件夹
/// </summary>
......@@ -39,13 +33,7 @@ namespace Lycianthes
window.position = GUIHelper.GetEditorWindowRect().AlignCenter(500, 375);
window.titleContent = new GUIContent("本地配置");
if (PlayerPrefs.HasKey(KEY_LYCIANTHES_CONFIG))
{
var jsonStr = PlayerPrefs.GetString(KEY_LYCIANTHES_CONFIG);
window.LocalConfig = LycianthesConfig.FromJson(jsonStr);
}
else
window.LocalConfig = new LycianthesConfig();
window.LocalConfig = LycianthesConfig.GetInstance();
if (PlayerPrefs.HasKey(KEY_LYCIANTHES_LAST_TEMPLATE_FOLDER))
window.ScriptTemplateFolder = PlayerPrefs.GetString(KEY_LYCIANTHES_LAST_TEMPLATE_FOLDER);
......@@ -62,7 +50,7 @@ namespace Lycianthes
public void Save()
{
if (LocalConfig == null) return;
PlayerPrefs.SetString(KEY_LYCIANTHES_CONFIG, LocalConfig.GetJsonString());
PlayerPrefs.SetString(LycianthesConfig.KEY_LYCIANTHES_CONFIG, LocalConfig.GetJsonString());
}
[Title("脚本模板创建")]
......@@ -75,7 +63,7 @@ namespace Lycianthes
/// <summary>
/// 是否有合法的脚本模板文件夹
/// </summary>
private bool HasScriptTemplateFolder { get { return !string.IsNullOrEmpty(ScriptTemplateFolder); } }
private bool HasScriptTemplateFolder { get { return !string.IsNullOrEmpty(ScriptTemplateFolder); } }
[LabelText("脚本模板文件名")]
[PropertyOrder(30)]
......@@ -98,8 +86,20 @@ namespace Lycianthes
return;
}
PlayerPrefs.SetString(KEY_LYCIANTHES_LAST_TEMPLATE_FOLDER, ScriptTemplateFolder);
string path = $"{ScriptTemplateFolder}/{ScriptTemplateAssetName}.asset";
//先加载一下是否有当前文件;
var template = AssetDatabase.LoadAssetAtPath<LycianthesTemplateGroup>(path);
if (template != null)
{
EditorUtility.DisplayDialog("Lycianthes配置", $"已经有此模板:{ScriptTemplateAssetName}\n不能重复创建!", "确定");
return;
}
template = CreateInstance<LycianthesTemplateGroup>();
AssetDatabase.CreateAsset(template, path);
Debug.Log($"已生成模板:{path} : {template.name}");
//缓存本次保存的文件夹
PlayerPrefs.SetString(KEY_LYCIANTHES_LAST_TEMPLATE_FOLDER, ScriptTemplateFolder);
}
}
......
......@@ -61,15 +61,14 @@ namespace Lycianthes
#endregion
[LabelText("公司名")]
public string Company = "RedPanda";
[LabelText("版本")]
public string Version = "1.0.0";
[LabelText("用户名")]
public string AuthorName = "Chief";
[ShowIf("ShowMoudleInfo")]
public string MoudleInfo = "模块说明";
private bool ShowMoudleInfo => LycianthesConfig.GetInstance().UseModuleInfo;
[LabelText("命名空间")]
public string NameSpace = "RedPanda";
......@@ -98,8 +97,7 @@ namespace Lycianthes
string path = AssetDatabase.GetAssetPath(temp.Template);
//创建脚本
CreateScriptByTemplate.Version = Version;
CreateScriptByTemplate.Author = AuthorName;
CreateScriptByTemplate.Company = Company;
CreateScriptByTemplate.MoudleInfo = MoudleInfo;
CreateScriptByTemplate.NameSpace = NameSpace;
//删除前面的/Asset
string curPath = temp.DefaultFolder.Substring(6);
......@@ -130,8 +128,7 @@ namespace Lycianthes
string path = AssetDatabase.GetAssetPath(temp.Template);
//创建脚本
CreateScriptByTemplate.Version = Version;
CreateScriptByTemplate.Author = AuthorName;
CreateScriptByTemplate.Company = Company;
CreateScriptByTemplate.MoudleInfo = MoudleInfo;
CreateScriptByTemplate.NameSpace = NameSpace;
//删除前面的/Asset
CreateScriptByTemplate.CreateScriptNoChosse(path, curPath, name);
......
......@@ -23,8 +23,8 @@ namespace Lycianthes
/// </summary>
public class LycianthesScriptWindow : OdinEditorWindow
{
public const string KEY_USER_NAME = "KEY_SCRIPTCREATOR_USER_NAME";
public const string KEY_USER_NAMESPACE = "KEY_SCRIPTCREATOR_USER_NAMESPACE";
public const string KEY_USER_MOUDLE_INFO = "KEY_SCRIPTCREATOR_USER_MOUDLE_INFO";
public const float LABEL_WIDTH = 60;
[MenuItem("Assets/Create/创建.CS脚本", false, 81)]
......@@ -36,22 +36,17 @@ namespace Lycianthes
//缓存的配置文件位置
window.creator = AssetDatabase.LoadAssetAtPath<LycianthesScriptCreator>(window.assetPath);
//缓存的作者名;
if (PlayerPrefs.HasKey(KEY_USER_NAME))
window.UserName = PlayerPrefs.GetString(KEY_USER_NAME);
if (PlayerPrefs.HasKey(KEY_USER_NAMESPACE))
window.NameSpace = PlayerPrefs.GetString(KEY_USER_NAMESPACE);
//当前的文件夹;
window.TargetPath = GetCurrentSelectFolderPath();
window.Version = PlayerSettings.bundleVersion;
window.CompanyName = PlayerSettings.companyName;
window.creator.ResetOtherTemplate();
AutoLoadTemplateGroup();
}
private static void AutoLoadTemplateGroup()
{
var guids = AssetDatabase.FindAssets("t:LycianthesTemplateGroup");
foreach (var guid in guids)
{
......@@ -91,27 +86,29 @@ namespace Lycianthes
[LabelWidth(LABEL_WIDTH)]
[Title("配置信息")]
[ShowInInspector]
private string assetPath => AssetPath;
[PropertyOrder(0)]
private string assetPath
{
get { return AssetPath; }
set { }
}
/// <summary>
/// 资源位置
/// </summary>
[LabelText("配置目录"), ReadOnly]
[LabelWidth(LABEL_WIDTH)]
[PropertyOrder(1)]
[HideReferenceObjectPicker]
public LycianthesScriptCreator creator;
/// <summary>
/// 公司名,读取的PlayerSetting;
/// </summary>
[LabelText("公司名")]
[LabelWidth(LABEL_WIDTH)]
public string CompanyName = "RedPanda";
/// <summary>
/// 命名空间;
/// </summary>
[Title("脚本说明配置", "本地配置菜单: Tools/Lycianthes/本地设置", TitleAlignment = TitleAlignments.Split)]
[LabelText("命名空间"), OnValueChanged("OnChangeUserSetting")]
[LabelWidth(LABEL_WIDTH)]
[PropertyOrder(10)]
public string NameSpace = "RedPanda";
/// <summary>
......@@ -119,44 +116,80 @@ namespace Lycianthes
/// </summary>
[LabelText("版本号")]
[LabelWidth(LABEL_WIDTH)]
[PropertyOrder(10)]
public string Version = "1.0.0";
[LabelText("用户名"), OnValueChanged("OnChangeUserSetting")]
/// <summary>
/// 公司名,读取的PlayerSetting;
/// </summary>
[LabelText("模板信息")]
[LabelWidth(LABEL_WIDTH)]
[ShowIf("ShowMoudleInfo")]
[PropertyOrder(10)]
[OnValueChanged("OnChangeUserSetting")]
public string MoudelInfo = "模板信息";
private bool ShowMoudleInfo => LycianthesConfig.GetInstance().UseModuleInfo;
[LabelText("公司名")]
[LabelWidth(LABEL_WIDTH)]
public string UserName = "";
[PropertyOrder(10)]
[ShowInInspector, DisplayAsString]
public string CompanyName
{
get { return LycianthesConfig.GetInstance().CompanyName; }
set { }
}
[LabelText("用户名")]
[LabelWidth(LABEL_WIDTH)]
[ShowInInspector, DisplayAsString]
[PropertyOrder(10)]
public string AuthorName
{
get { return LycianthesConfig.GetInstance().AuthorName; }
set { }
}
private void OnChangeUserSetting()
{
PlayerPrefs.SetString(KEY_USER_NAME, UserName);
PlayerPrefs.SetString(KEY_USER_NAMESPACE, NameSpace);
if (ShowMoudleInfo)
PlayerPrefs.SetString(KEY_USER_MOUDLE_INFO, MoudelInfo);
}
[HideLabel, Title("脚本类型"), OnValueChanged("OnScriptTypeChanged")]
[ValueDropdown("GetScriptKey")]
[PropertyOrder(20)]
public string scriptType = "CSharpCommon";
private List<string> GetScriptKey() { return creator.GetScriptTemplateKey(); }
[Title("保存位置"), Space(15)]
[PropertyOrder(20)]
[LabelWidth(LABEL_WIDTH), LabelText("批量创建")]
public bool IsList = false;
[LabelText("脚本名"), OnValueChanged("OnScriptNameChagned")]
[PropertyOrder(20)]
[LabelWidth(LABEL_WIDTH)]
[HideIf("IsList")]
public string ScriptName = "";
[LabelText("脚本列表"), LabelWidth(LABEL_WIDTH), ShowIf("IsList")]
[PropertyOrder(20)]
public List<string> ListScriptName = new List<string>();
[TabGroup("在当前文件夹创建")]
[LabelWidth(LABEL_WIDTH)]
[LabelText("创建位置"), FolderPath]
[PropertyOrder(20)]
public string TargetPath = "";
[TabGroup("在默认文件夹创建")]
[LabelWidth(LABEL_WIDTH)]
[LabelText("默认位置"), FolderPath]
[PropertyOrder(20)]
public string DefaultPath = "";
/// <summary>
......@@ -188,11 +221,13 @@ namespace Lycianthes
[Button("开始创建"), HideIf("IsList")]
[TabGroup("在当前文件夹创建")]
[PropertyOrder(20)]
public void CreateAtTargetPath()
{ CreateScript(ScriptName, TargetPath); }
[Button("开始创建"), HideIf("IsList")]
[TabGroup("在默认文件夹创建")]
[PropertyOrder(20)]
public void CreateAtDefaultPath()
{ CreateScript(ScriptName, DefaultPath); }
......@@ -204,15 +239,8 @@ namespace Lycianthes
return;
}
if (string.IsNullOrEmpty(UserName))
{
EditorUtility.DisplayDialog("警告", $"创建脚本 {scriptType}时出错:\n没有输入用户名!", "确定");
return;
}
creator.Version = Version;
creator.AuthorName = UserName;
creator.Company = CompanyName;
creator.MoudleInfo = MoudelInfo;
creator.NameSpace = NameSpace;
//删除掉前面的Asset
creator.CreateNewScript(scriptType, path.Substring(6), scriptName);
......@@ -223,6 +251,7 @@ namespace Lycianthes
/// </summary>
[Button("开始创建"), ShowIf("IsList")]
[TabGroup("在当前文件夹创建")]
[PropertyOrder(20)]
public void CreateListScriptAtTarget()
{
int length = ListScriptName.Count;
......@@ -235,6 +264,7 @@ namespace Lycianthes
/// </summary>
[Button("开始创建"), ShowIf("IsList")]
[TabGroup("在默认文件夹创建")]
[PropertyOrder(20)]
public void CreateListAtDefault()
{
int length = ListScriptName.Count;
......@@ -246,6 +276,7 @@ namespace Lycianthes
/// 刷新编辑器;
/// </summary>
[PropertySpace(15), Button("刷新")]
[PropertyOrder(30)]
public void Refresh() { AssetDatabase.Refresh(); }
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册