Example #1
0
        protected virtual void Awake()
        {
            if (!string.IsNullOrEmpty(luaPath))
            {
                var luna  = LunaClient.Luna;
                var L     = luna.State;
                int index = luaPath.LastIndexOf(".");
                if (index != -1)
                {
                    className = luaPath.Remove(index);
                }
                else
                {
                    className = luaPath;
                }

                index = className.LastIndexOf("/");
                if (index != -1)
                {
                    className = className.Substring(index + 1);
                }

                scriptClass = luna.GetGlobal(className) as LuaRef;
                if (!scriptClass)
                {
                    luna.DoFile(luaPath);
                    scriptClass = luna.GetGlobal(className) as LuaRef;
                    if (!scriptClass)
                    {
                        return;
                    }
                }

                var metaTable = scriptClass.GetMetaTable();
                if (metaTable)
                {
                    var ctor = metaTable.RawGet("__call") as LuaRef;
                    scriptInstance = ctor.Call <LuaRef>(metaTable);
                    metaTable.Dispose();
                }
                else
                {
                    Debug.Log("GetMetaTable failed : " + className);
                }

                scriptInstance["gameObject"] = gameObject;
                scriptInstance["transform"]  = gameObject.transform;
                scriptInstance["behaviour"]  = this;

                onEnableFn  = scriptClass.Get("onEnable") as LuaRef;
                onDisableFn = scriptClass.Get("onDisable") as LuaRef;
                updateFn    = scriptClass.Get("update") as LuaRef;

                CallFunc("awake");
            }
        }
Example #2
0
        void Refresh(LuaRef table, TreeNodeCollection node, int depth)
        {
            if (depth <= 0)
            {
                return;
            }

            var meta = table.GetMetaTable();

            if (meta)
            {
                var      k = "metatable";
                var      v = meta;
                TreeNode n;
                if (!node.ContainsKey(k))
                {
                    n     = node.Add(k, k);
                    n.Tag = v;
                }
                else
                {
                    n = node[k];
                }
                Refresh(v, n.Nodes, depth - 1);
            }


            foreach (var t in table)
            {
                var key = t.Key();
                var k   = key.ToString();
                if (k == "_G")
                {
                    continue;
                }

                var      v = t.Value();
                TreeNode n;
                if (!node.ContainsKey(k))
                {
                    n     = node.Add(k, k);
                    n.Tag = v;
                }
                else
                {
                    n = node[k];
                }

                if (v.IsTable)
                {
                    Refresh(v, n.Nodes, depth - 1);
                }
            }
        }