/// <summary>
        /// Reload all scripts, rebind objects, and force compilation
        /// </summary>
        public void Reload()
        {
            if (IsReloading != null)
            {
                IsReloading(this, null);
            }

            ScriptManager.getInstance().CompileAll();

            foreach (BoundScript bs in registeredScripts)
            {
                if (bs.scriptObject != null)
                {
                    object newscriptObject = ScriptManager.getInstance().MakeObject(bs.scriptObject.GetType().Name);

                    //do property copy
                    CopyObject(bs.scriptObject, newscriptObject);

                    bs.scriptObject = newscriptObject;
                }
            }

            if (HasReloaded != null)
            {
                HasReloaded(this, null);
            }

            Console.WriteLine("...Reloaded all scripts.");
        }
        private void RegisterCScript(IntPtr from)
        {
            //setup
            MochaInterface.CScript cs = new MochaInterface.CScript(from, false);
            BoundScript            bs = new BoundScript();

            bs.scriptComponent = cs;
            string sc = cs.scriptAsset.GetName();       //assumed valid at this point

            sc            = sc.Remove(sc.Length - 3);
            bs.scriptName = sc;

            //post-compilation
            bs.scriptObject = ScriptManager.getInstance().MakeObject(bs.scriptName);
            if (bs.scriptObject != null)
            {
                bs.scriptObject.GetType().GetProperty("gameObject").SetValue(bs.scriptObject, cs.gameObject, null);
                try {
                    bs.Func_OnUpdate = bs.scriptObject.GetType().GetMethod("OnUpdate");
                    if (bs.Func_OnUpdate == null)
                    {
                        throw new Exception("No public OnUpdate specified for class: " + bs.scriptName);
                    }
                }
                catch (Exception e)
                {
                    Logger.Log("ERROR compiling scripts: " + e.Message);
                }
            }
            bs.register_id = cs.register_id;

            RelinkScriptPropertiesFromStore(bs);

            bs.scriptEvents.Enqueue(new ScriptEvent()
            {
                methodname = "OnStart"
            });

            //indexing
            registeredScripts.Add(bs);
            cscriptToBoundScriptLookup.Add(cs, bs);
            if (!gameObjectToBoundScriptsLookup.ContainsKey(cs.gameObject))
            {
                gameObjectToBoundScriptsLookup.Add(cs.gameObject, new List <BoundScript>());
            }
            gameObjectToBoundScriptsLookup[cs.gameObject].Add(bs);
        }