示例#1
0
    public void LoadScriptTemplateFileTest()
    {
        const string packageName = "io.github.idreamsofgame.resharp.core";
        var          content     = ScriptTemplate.LoadScriptTemplateFile("package", packageName);

        Assert.AreNotEqual(string.Empty, content);
    }
        private static bool GenerateMetadataEntityScript(MetadataAssetSettings settings, string entityScriptName, List <MetadataEntityRawInfo> rawInfoList)
        {
            try
            {
                entityScriptName = entityScriptName.ToTitleCase();
                var scriptTextContent = ScriptTemplate.LoadScriptTemplateFile("NewMetadataEntityScriptTemplate.txt", UnityPackageName);
                scriptTextContent = scriptTextContent.Replace(ScriptTemplate.Placeholders.Namespace, settings.EntityScriptNamespace);
                scriptTextContent = scriptTextContent.Replace(ScriptTemplate.Placeholders.ScriptName, entityScriptName);
                scriptTextContent = scriptTextContent.Replace(ScriptTemplate.Placeholders.EnumInsideOfClass, GenerateEntityScriptEnumString(rawInfoList));
                scriptTextContent = scriptTextContent.Replace(ScriptTemplate.Placeholders.Properties, GenerateEntityScriptPropertiesString(rawInfoList));

                var scriptStorePath = EditorPath.ConvertToAbsolutePath(settings.EntityScriptsStorePath, $"{entityScriptName}.cs");
                var assetPath       = EditorPath.ConvertToAssetPath(scriptStorePath);
                File.WriteAllText(scriptStorePath, scriptTextContent, new UTF8Encoding(true));
                AssetDatabase.ImportAsset(assetPath);
                return(true);
            }
            catch (Exception ex)
            {
                UnityDebug.LogError(ex.ToString());
                return(false);
            }
        }