Exemplo n.º 1
0
        private static void OnWillCreateAsset(string metaPath)
        {
            string filePath = metaPath.Replace(".meta", "");
            EZScriptTemplateObject ezScriptTemplate = EZScriptableObject.Load <EZScriptTemplateObject>(EZScriptTemplateObject.AssetName, false);

            if (ezScriptTemplate != null)
            {
                Replace(filePath, ezScriptTemplate);
            }
        }
 protected override void OnFocus()
 {
     base.OnFocus();
     ezScriptTemplate                = EZScriptableObject.Load <EZScriptTemplateObject>(EZScriptTemplateObject.AssetName);
     so_EZScriptTemplate             = new SerializedObject(ezScriptTemplate);
     extensionList                   = so_EZScriptTemplate.FindProperty("extensionList");
     patternList                     = new ReorderableList(so_EZScriptTemplate, so_EZScriptTemplate.FindProperty("patternList"), true, true, true, true);
     patternList.drawHeaderCallback  = DrawPatternListHeader;
     patternList.drawElementCallback = DrawPatternListElement;
 }
Exemplo n.º 3
0
        public static void Replace(string filePath, EZScriptTemplateObject ezScriptTemplate)
        {
            if (!IsEZScriptAsset(filePath, ezScriptTemplate))
            {
                return;
            }
            string content = File.ReadAllText(filePath);

            content = content.Replace("#SCRIPTNAME", Path.GetFileNameWithoutExtension(filePath));
            content = content.Replace("#CREATETIME#", System.DateTime.Now.ToString());
            foreach (EZScriptTemplateObject.Pattern pattern in ezScriptTemplate.patternList)
            {
                content = content.Replace(pattern.Key, pattern.Value);
            }
            File.WriteAllText(filePath, content);
        }
 public static void Replace(string filePath, EZScriptTemplateObject ezScriptTemplate)
 {
     if (CheckTemplate(filePath, ezScriptTemplate) == CheckResult.Script)
     {
         string content = File.ReadAllText(filePath);
         content = content.Replace("#SCRIPTNAME", Path.GetFileNameWithoutExtension(filePath));
         content = content.Replace("#CREATETIME#", System.DateTime.Now.ToString(ezScriptTemplate.timeFormat));
         foreach (EZScriptTemplateObject.Pattern pattern in ezScriptTemplate.patternList)
         {
             if (!string.IsNullOrEmpty(pattern.Value))
             {
                 content = content.Replace(pattern.Key, pattern.Value);
             }
         }
         File.WriteAllText(filePath, content);
     }
 }
Exemplo n.º 5
0
        private static bool IsEZScriptAsset(string filePath, EZScriptTemplateObject ezScriptTemplate)
        {
            string lowerName = filePath.ToLower();

            foreach (string ext in ezScriptTemplate.extensionList)
            {
                if (lowerName.EndsWith(ext + ".txt"))
                {
                    return(false);
                }
            }
            foreach (string ext in ezScriptTemplate.extensionList)
            {
                if (lowerName.EndsWith(ext))
                {
                    return(true);
                }
            }
            return(false);
        }
        public static CheckResult CheckTemplate(string filePath, EZScriptTemplateObject ezScriptTemplate)
        {
            string fileName = Path.GetFileName(filePath.ToLower());

            string[] info = fileName.Split('-');
            if (info.Length == 3 && Regex.IsMatch(info[0], @"^[0-9]{1,2}$"))
            {
                foreach (string ext in ezScriptTemplate.extensionList)
                {
                    if (info[2].EndsWith(ext + ".txt"))
                    {
                        return(CheckResult.Template);
                    }
                }
            }
            foreach (string ext in ezScriptTemplate.extensionList)
            {
                if (fileName.EndsWith(ext))
                {
                    return(CheckResult.Script);
                }
            }
            return(CheckResult.Unknow);
        }