示例#1
0
文件: SdkSys.cs 项目: MF-JIN/test
        public void NativeMessageHandler(string jsonstr)
        {
            if (luaJsonDecoder == null)
            {
                luaJsonDecoder = LuaSys.Instance.GetGLuaFunc("json.decode");
            }
            Debug.Assert(luaJsonDecoder != null, $"luaJsonDecoder not found");

            LuaTable lt = luaJsonDecoder(jsonstr, null) as LuaTable;

            Debug.Assert(lt != null, $"json to lua decode err:[{jsonstr}]");

            var type     = lt.Get <string>("type") ?? "";
            var gluafunc = "OnNativeMessage" + type;
            var luaf     = LuaSys.Instance.GetGLuaFunc(gluafunc);

            if (luaf != null)
            {
                luaf(null, lt);
            }
            else
            {
                Debug.LogError($"global lua function [{gluafunc}] not found");
            }
        }
示例#2
0
    public static void Draw(this XLua.LuaTable self, string ltname = "luat", int indent = 0, GUILayoutOption[] guiOpts = null, string grep = null)
    {
        if (mLuaFuncDelegate == null)
        {
            mLuaFuncDelegate = LuaSys.Instance.GetGLuaFunc("BridgingClass.Draw");
        }
        LuaTable opt = LuaSys.Instance.luaEnv.NewTable();

        opt.Set("ltname", "lt");
        opt.Set("indent", 0);
        if (!string.IsNullOrWhiteSpace(grep))
        {
            opt.Set("grep", grep);
        }
        if (mLuaFuncDelegate != null)
        {
            mLuaFuncDelegate(self, opt);
        }
        else
        {
            Debug.LogError($"place call require \"BridgingClass\" first");
        }

        /*
         * if(EditorGUI.indentLevel > 5)
         *  return;
         * EditorGUI.indentLevel += indent;
         * var name = (self.ContainsKey("Name") ? self.Get<string>("Name"):ltname);
         * var Foldout = self.ContainsKey("Foldout") ? self.Get<bool>("Foldout"):false;
         * Foldout = EditorGUILayout.Foldout(Foldout, name + " " + self.ToStringLua(), true);
         * self.RawSet("Foldout", Foldout);
         * if (Foldout)
         * {
         *  self.RawSet("Drawed", true);
         *  ValueDelegate drawv = (k, v)=>{
         *      if (v is bool)
         *      {
         *          var tmp = EditorGUILayout.Toggle((bool)v);
         *          self.Set(k, tmp);
         *      }
         *      else if (v is Enum)
         *      {
         *          {
         *              var tmp = EditorGUILayout.EnumPopup((Enum)v);
         *              self.Set(k, tmp);
         *          }
         *      }
         *      else if (v is long)
         *      {
         *          {
         *              var tmp = EditorGUILayout.LongField((long)v);
         *              self.Set(k, tmp);
         *          }
         *      }
         *      else if (v is double)
         *      {
         *          var tmp = EditorGUILayout.DoubleField((double)v);
         *          self.Set(k, tmp);
         *      }
         *      else if (v is string)
         *      {
         *          var tmp = EditorGUILayout.TextField((string)v);
         *          self.Set(k, tmp);
         *      }
         *      else if (v is Component)
         *      {
         *          EditorGUILayout.ObjectField((v as Component).gameObject, typeof(UnityEngine.Object), true);
         *      }
         *      else if (v is LuaFunction)
         *      {
         *          var fun = v as LuaFunction;
         *          EditorGUILayout.TextField(fun.GetFuncId());
         *      }
         *      else if (v != null)
         *      {
         *          EditorGUILayout.LabelField(v.ToString());
         *      }
         *      return v;
         *  };
         *  using (var verticalScope = new EditorGUILayout.VerticalScope("box"))
         *  {
         *      self.ForEach<object, object>((k, v) =>
         *      {
         *          var kk = k.ToString();
         *          // if (kk == "_G")
         *          //     return;
         *          if(k is Int64)
         *              kk =  "[" + kk + "]";
         *          if (v is XLua.LuaTable)
         *          {
         *              var t = (v as XLua.LuaTable);
         *              t.RawSet("Name", kk);
         *              var Drawed = t.ContainsKey("Drawed") ? t.Get<bool>("Drawed"):false;
         *              if(!Drawed)
         *              {
         *                  // t.RawSet("Drawed", true);
         *                  t.Draw(kk, 1);
         *              }
         *              else
         *              {
         *                  EditorGUILayout.LabelField(kk + "->" + t.ToStringLua());
         *              }
         *          }
         *          else
         *          {
         *              if(kk == "Foldout" || kk == "Name")
         *              {
         *                  return;
         *              }
         *
         *              var tname = (v != null ? v.GetType().ToString() : "nil");
         *              var dotidx = tname.LastIndexOf('.');
         *              if(dotidx > 0)tname = tname.Substring(dotidx+1);
         *              if (!string.IsNullOrWhiteSpace(grep) && !tname.Contains(grep))
         *                  return;
         *
         *              EditorGUILayout.BeginHorizontal();
         *              {
         *                  EditorGUILayout.LabelField(kk + ":" + tname);
         *                  drawv(k,v);
         *              }
         *              EditorGUILayout.EndHorizontal();
         *              if (v is LuaMonoBehaviour)
         *              {
         *                  var t = (v as LuaMonoBehaviour).Lua;
         *                  t.Draw("LuaMono", 1);
         *              }
         *          }
         *      });//ForEach
         *
         *      // metatable
         *      var meta = self.GetMetaTable();
         *      if(meta != null)
         *      {
         *          meta.Draw("__meta", 1);
         *      }
         *  }
         *  self.RawSet("Drawed", false);
         * }//if
         *
         * EditorGUI.indentLevel -= indent;
         */
    }