Example #1
0
        private void BuildTab()
        {
            if (!_buildingMod && !_builtMod)
            {
                _buildingMod = true;
                ModLab.ClearDebug();
                var mod = new Mod(_modName, _modVersion, _modAuthor, _modDescription);
                foreach (var s in _givenFiles)
                {
                    ModLab.AddDebug("Adding asset: " + s.name);
                    var type = s.GetType();
                    if (type == typeof(MonoScript))
                    {
                        mod.AddScript(s);
                    }
                    else
                    {
                        ModLab.AddDebug("Unable to add asset: " + s.name + " (" + s.GetType() + ")");
                    }
                }
                ModLab.SerializeMod(mod);
                _builtMod    = true;
                _buildingMod = false;
            }

            var logRect = new Rect(8f, 24f, position.size.x - 16f, position.size.y - 24f - 8f);

            GUI.enabled = false;
            EditorGUI.TextArea(logRect, ModLab.DebugText);
            GUI.enabled = true;
        }
Example #2
0
        private void AddModComponent(ModClass modClass)
        {
            var obj = ModLab.GetObject(modClass.Type);

            _objectCache.Add(obj);
            Debug.Log("Added ModComponent to the cache: " + modClass.Type.Name);
        }
Example #3
0
 public ModClass(string code)
 {
     Type    = ModLab.CompileCode(code);
     Object  = ModLab.GetObject(Type);
     Methods = ModLab.GetMethods(Type);
     Fields  = ModLab.GetFields(Type);
 }
Example #4
0
        public Type EditClass(string className, string code)
        {
            if (!Scripts.ContainsKey(className))
            {
                return(null);
            }
            Scripts[className] = code;
            // reload script
            var t = ModLab.CompileCode(code);

            Debug.Log(t.Name);
            return(t);
        }
Example #5
0
        public void RecompileScript(string modName, string scriptName, string newCode)
        {
            // save script change
            var loadedMod = _loadedMods.FirstOrDefault(mod => mod.Name == modName);
            var t         = loadedMod?.EditClass(scriptName, newCode);

            ModLab.SerializeMod(loadedMod);
            #if UNITY_EDITOR
            var logEntries  = Type.GetType("UnityEditor.LogEntries,UnityEditor.dll");
            var clearMethod = logEntries.GetMethod("Clear", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
            clearMethod.Invoke(null, null);
            #endif
            SceneManager.LoadScene(0);
        }
Example #6
0
        private void LoadMods()
        {
            var modsLoc = Application.dataPath + "/Mods";

            if (!Directory.Exists(modsLoc))
            {
                Directory.CreateDirectory(modsLoc);
            }
            var files = Directory.GetFiles(modsLoc, "*.mod");

            foreach (var file in files)
            {
                Debug.Log(file);
                var mod = ModLab.DeserializeModAtFile(file);
                _loadedMods.Add(mod);
            }
        }