Пример #1
0
        public override void OnMlfInstanceInterpret(MlfInstance instance)
        {
            MlfFlag flag = instance.GetFlag("DefaultImport");

            if (flag != null)
            {
                foreach (MlfBlock block in instance.Blocks)
                {
                    if (block.format == "python")
                    {
                        block.AddPrefixText("import UnityEngine as u");
                    }
                }
            }
        }
Пример #2
0
        public static List <MlfFlag> FindFlags(string script)
        {
            List <MlfFlag> codeFlags = new List <MlfFlag>();

            string pattern = @"\#*\{\{.+\}\}";

            MatchCollection matches = Regex.Matches(script, pattern);

            string[] headers = new string[matches.Count];

            for (int i = 0; i < matches.Count; i++)
            {
                headers[i] = matches[i].Value;
            }

            //Build flags
            for (int i = 0; i < headers.Length; i++)
            {
                Match m = Regex.Match(headers[i], @"\#*\{\{(.+?)\s*(|"".+"")\s*(|\(.+\))\}\}");

                MlfFlag flag = new MlfFlag();

                //ID Required
                if (!m.Groups[1].Success)
                {
                    continue;
                }

                flag.id = m.Groups[1].Value;

                //Tags
                if (m.Groups[2].Success && m.Groups[2].Value.Length != 0)
                {
                    flag.tags = new List <string>(m.Groups[2].Value.Trim('"').Split(','));
                }
                else
                {
                    flag.tags = new List <string>();
                }

                //Arguments
                if (m.Groups[3].Success && m.Groups[3].Value.Length != 0)
                {
                    flag.arguments = new List <string>(m.Groups[3].Value.Trim('(', ')').Split(','));
                }
                else
                {
                    flag.arguments = new List <string>();
                }

                //Trim quotes from arguments
                for (int k = 0; k < flag.arguments.Count; k++)
                {
                    flag.arguments[k] = flag.arguments[k].Trim('"', '\'');
                }

                codeFlags.Add(flag);
            }

            return(codeFlags);
        }