public override void Action(int instanceId, string pathName, string resourceFile)
            {
                var instance = DoCreateScriptAsset.CreateScriptAssetFromTemplate(pathName, resourceFile);

                ProjectWindowUtil.ShowCreatedAsset(instance);
                if (this.onCreated != null)
                {
                    this.onCreated.Invoke(instance);
                }
            }
            private static UnityEngine.Object CreateScriptAssetWithContent(string pathName, string templateContent)
            {
                templateContent = DoCreateScriptAsset.SetLineEndings(templateContent, EditorSettings.lineEndingsForNewScripts);
                var fullPath     = System.IO.Path.GetFullPath(pathName);
                var utF8Encoding = new System.Text.UTF8Encoding(true);

                System.IO.File.WriteAllText(fullPath, templateContent, (System.Text.Encoding)utF8Encoding);
                AssetDatabase.ImportAsset(pathName);
                return(AssetDatabase.LoadAssetAtPath(pathName, typeof(UnityEngine.Object)));
            }
            private static UnityEngine.Object CreateScriptAssetFromTemplate(string pathName, string resourceFile)
            {
                var    str1             = resourceFile.Replace("#NOTRIM#", "");
                var    withoutExtension = System.IO.Path.GetFileNameWithoutExtension(pathName);
                var    str2             = str1.Replace("#NAME#", withoutExtension);
                var    str3             = withoutExtension.Replace(" ", "");
                var    str4             = str2.Replace("#SCRIPTNAME#", str3);
                string templateContent;

                if (char.IsUpper(str3, 0))
                {
                    var newValue = char.ToLower(str3[0]).ToString() + str3.Substring(1);
                    templateContent = str4.Replace("#SCRIPTNAME_LOWER#", newValue);
                }
                else
                {
                    var newValue = "my" + (object)char.ToUpper(str3[0]) + str3.Substring(1);
                    templateContent = str4.Replace("#SCRIPTNAME_LOWER#", newValue);
                }

                return(DoCreateScriptAsset.CreateScriptAssetWithContent(pathName, templateContent));
            }
Example #4
0
 public override void Action(int instanceId, string pathName, string resourceFile)
 {
     ProjectWindowUtil.ShowCreatedAsset(DoCreateScriptAsset.CreateScriptAssetFromTemplate(pathName, resourceFile));
 }