public static bool ConsoleToolStart()
        {
            if (isStart)
            {
                return(false);
            }

            RemoteDeviceInfo deviceInfo = RemoteDeviceInfo.GetLocalDeviceInfo();

            GameConsolePanelSettingConfig config = GameConsolePanelSettingConfig.GetCofig();

            try
            {
                string deviceInfoStr = SimpleJsonUtils.ToJson(deviceInfo);

                LitNetServer.SetNetworkServerManager(deviceInfoStr, config.netPort);
                LitNetServer.Start();
                LoginService loginService = LitNetServer.ServiceManager.Get <LoginService>();
                loginService.SetPlayerLoginHandler(new SimplePlayerLoginHandler());
            }
            catch (Exception e)
            {
                Debug.LogError(e);
                return(false);
            }


            Debug.Log("LitNetServer.port:" + config.netPort);
            isStart = true;
            return(true);
        }
        private void OnRemoteInvokingEvent(NetMessageHandler msgHandler)
        {
            UseMethod2Server msg = msgHandler.GetMessage <UseMethod2Server>();
            //Debug.Log("Server接收到UseMethod2Server:" + JsonUtils.ToJson(msg));
            int    code  = 0;
            string error = "";

            try
            {
                MethodInfo mInfo = null;
                foreach (var mData in invokeMothodsInfos)
                {
                    if (mData.Key.FullName == msg.classFullName)
                    {
                        List <MethodInfo> methods = mData.Value;

                        foreach (var m in methods)
                        {
                            if (m.Name == msg.methodName)
                            {
                                mInfo = m;
                                break;
                            }
                        }
                    }
                }

                if (mInfo != null)
                {
                    List <object>   pValues    = new List <object>();
                    ParameterInfo[] parameters = mInfo.GetParameters();
                    for (int i = 0; i < parameters.Length; i++)
                    {
                        ParameterInfo p = parameters[i];
                        object        v = SimpleJsonUtils.FromJson(p.ParameterType, msg.paramNameValues[p.Name]);
                        pValues.Add(v);
                    }
                    mInfo.Invoke(null, pValues.ToArray());
                }
                else
                {
                    code = -2;
                }
            }
            catch (Exception e)
            {
                code  = -1;
                error = e.ToString();
                Debug.LogError(e);
            }
            UseMethod2Client toMsg = new UseMethod2Client();

            toMsg.code  = code;
            toMsg.error = error;
            netManager.Send(msgHandler.player, toMsg);
            //Debug.Log("发送UseMethod2Client:" + JsonUtils.ToJson(toMsg));
        }
        public static void SaveConfig(GameConsolePanelSettingConfig config)
        {
            string json = SimpleJsonUtils.ToJson(config);

            byte[] keyBytes   = Convert.FromBase64String(KeyBase64);
            string _aesKeyStr = Encoding.UTF8.GetString(keyBytes);

            json = AESUtils.AESEncrypt(json, _aesKeyStr);
            CreateTextFile(SavePathDir + GameConsolePanelSettingConfig.FileName + ".txt", json);
        }
Beispiel #4
0
        public object GetDefaultValue()
        {
            Type type = GetParamValueType();

            if (type == null)
            {
                return(null);
            }
            if (string.IsNullOrEmpty(defaultValueStr))
            {
                return(ReflectionTool.CreateDefultInstance(type));
            }

            return(SimpleJsonUtils.FromJson(type, defaultValueStr));
        }
        public static GameConsolePanelSettingConfig GetCofig()
        {
            if (Application.isPlaying)
            {
                if (configData != null)
                {
                    return(configData);
                }
            }

            TextAsset textAsset = Resources.Load <TextAsset>(FileName);

            if (textAsset == null || string.IsNullOrEmpty(textAsset.text))
            {
                configData = new GameConsolePanelSettingConfig();
            }
            else
            {
                string json = textAsset.text;
                try
                {
                    byte[] keyBytes   = Convert.FromBase64String(KeyBase64);
                    string _aesKeyStr = Encoding.UTF8.GetString(keyBytes);
                    json = AESUtils.AESDecrypt(json, _aesKeyStr);
                }
                catch (Exception e)
                {
                    Debug.LogError(e);
                }
                configData = SimpleJsonUtils.FromJson <GameConsolePanelSettingConfig>(json);
                if (configData == null)
                {
                    configData = new GameConsolePanelSettingConfig();
                }
            }

            return(configData);
        }
        private string GetDefaultValueString(Type classType, Type parameterType, ParamsDescriptionAttribute paramsDescription)
        {
            object value = null;

            if (paramsDescription != null && !string.IsNullOrEmpty(paramsDescription.getDefaultValueMethodName))
            {
                MethodInfo info = classType.GetMethod(paramsDescription.getDefaultValueMethodName, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

                if (info != null)
                {
                    Type returnType = info.ReturnType;
                    if (returnType != parameterType)
                    {
                        Debug.LogError("GetDefaultValueString Method:" + classType.FullName + "." + paramsDescription.getDefaultValueMethodName + " ReturnType(" + returnType.FullName + ") is different from parameterType(" + parameterType + ")");
                    }
                    else
                    {
                        try
                        {
                            value = info.Invoke(null, new object[0]);
                        }
                        catch (Exception e)
                        {
                            Debug.LogError(e);
                        }
                    }
                }
            }
            if (value == null)
            {
                Debug.Log("CreateDefultInstance Type:" + parameterType);
                value = ReflectionTool.CreateDefultInstance(parameterType);
            }

            return(SimpleJsonUtils.ToJson(value));
        }
Beispiel #7
0
        public static void AddInfoValue(string typeName, string label, string key, object value, string description = null)
        {
            try
            {
                if (string.IsNullOrEmpty(typeName) ||
                    string.IsNullOrEmpty(label) ||
                    string.IsNullOrEmpty(key))
                {
                    Debug.LogError("typeName or label or key cant be null");
                    return;
                }
                if (value == null)
                {
                    Debug.LogError("value cant be null");
                    return;
                }

                ShowInfoData data         = GetShowInfoData(typeName, label, key);
                string       valueStr     = SimpleJsonUtils.ToJson(value);
                string       valueTypeStr = value.GetType().FullName;

                bool isSend = false;
                if (data == null)
                {
                    data              = new ShowInfoData();
                    data.typeName     = typeName;
                    data.label        = label;
                    data.key          = key;
                    data.value        = valueStr;
                    data.valueTypeStr = valueTypeStr;
                    data.discription  = description;
                    infoDatas.Add(data);

                    isSend = true;
                }
                else
                {
                    if (data.valueTypeStr != valueTypeStr)
                    {
                        Debug.LogError(" Path:" + data.GetPath() + " already have value Type:" + data.valueTypeStr + " can not set Value Type:" + valueStr);
                        return;
                    }
                    else
                    {
                        if (data.value != valueStr)
                        {
                            data.value = valueStr;
                            isSend     = true;
                        }
                        if (!string.IsNullOrEmpty(description) && data.discription != description)
                        {
                            data.discription = description;
                            isSend           = true;
                        }
                    }
                }
                if (isSend)
                {
                    Send2AllPlayer(data);
                }
            }
            catch (System.Exception e)
            {
                Debug.LogError(e);
            }
        }