Exemplo n.º 1
0
        public void Start()
        {
            if (assembly == null)
            {
                return;
            }

            var allTypes = Compiler.GetLoadableTypes(assembly);

            foreach (var type in allTypes)
            {
                if (type.ToString() == "ScriptMain")
                {
                    IModScript entry = (IModScript)assembly.CreateInstance(type.ToString(), true);

                    if (entry == null)
                    {
                        break;
                    }

                    entry.Start(this);

                    break;
                }
            }
        }
Exemplo n.º 2
0
        public void Init()
        {
            GameManager.instance.fileSystem.AddOptionalPath(modPath);

            var scriptsPath = Path.Combine(modPath, "Scripts");

            if (Directory.Exists(scriptsPath))
            {
                var fileNames = Directory.GetFiles(scriptsPath);
                var sources   = new List <string>();

                foreach (var fileName in fileNames)
                {
                    if (File.Exists(fileName))
                    {
                        sources.Add(File.ReadAllText(fileName));
                    }
                }

                assembly = Compiler.CompileSource(sources.Where(x => Path.GetExtension(x) == "cs").ToArray(), true);

                if (assembly == null)
                {
                    Debug.LogError("Assembly for " + modName + " couldn't be compiled!");
                    return;
                }

                var allTypes = Compiler.GetLoadableTypes(assembly);

                foreach (var type in allTypes)
                {
                    if (type.ToString() == "ScriptMain")
                    {
                        IModScript entry = (IModScript)assembly.CreateInstance(type.ToString(), true);

                        if (entry == null)
                        {
                            break;
                        }

                        entry.Start(this);

                        break;
                    }
                }
            }
        }