Example #1
0
        private WebTemplate Load(string path)
        {
            if (!Directory.Exists(path))
            {
                return(null);
            }

            WebTemplate template = new WebTemplate();

            string[] splitPath = path.Split(new char[] { '/', '\\' });
            template.m_Name = splitPath[splitPath.Length - 1];
            if (splitPath.Length > 3 && splitPath[splitPath.Length - 3].Equals("Assets"))
            {
                template.m_Path = "PROJECT:" + template.m_Name;
            }
            else
            {
                template.m_Path = "APPLICATION:" + template.m_Name;
            }

            string thumbnailPath = Path.Combine(path, "thumbnail.png");

            if (File.Exists(thumbnailPath))
            {
                template.m_Thumbnail = new Texture2D(2, 2);
                template.m_Thumbnail.LoadImage(File.ReadAllBytes(thumbnailPath));
            }

            Regex         preprocessedFilenameRegex = new Regex("\\.(html|php|css|js|json)$");
            Regex         preprocessedBlockRegex    = new Regex("((^|\\n)#if [^\\n]+(\\n|$))|({{{([^}]|}(?!}))+}}})");
            Regex         customKeyRegex            = new Regex("(?<=[^0-9a-zA-Z_$]UNITY_CUSTOM_)[A-Z_]+(?=[^0-9a-zA-Z_$])");
            List <string> customKeys = new List <string>();

            foreach (var file in FileUtil.GetAllFilesRecursive(path))
            {
                if (preprocessedFilenameRegex.IsMatch(FileUtil.UnityGetFileName(file)))
                {
                    MatchCollection preprocessedBlockMatches = preprocessedBlockRegex.Matches(File.ReadAllText(file));
                    foreach (Match preprocessedBlockMatch in preprocessedBlockMatches)
                    {
                        MatchCollection customKeysMatches = customKeyRegex.Matches(preprocessedBlockMatch.Value);
                        foreach (Match customKeysMatch in customKeysMatches)
                        {
                            if (!customKeys.Contains(customKeysMatch.Value))
                            {
                                customKeys.Add(customKeysMatch.Value);
                            }
                        }
                    }
                }
            }
            template.m_CustomKeys = customKeys.ToArray();

            return(template);
        }