Пример #1
0
        public void OnEvent(params MToken[] data)
        {
            try
            {
                if (_beforeReceiveData != null)
                {
                    _beforeReceiveData.Invoke();
                }

                if (data.Length != _eventParameterBinders.Count)
                {
                    Debug.LogErrorFormat(this, "parameter count {0} is not equal with binders coutn {1}", _eventParameterBinders.Count);
                    return;
                }

                for (var i = 0; i < _eventParameterBinders.Count; i++)
                {
                    BinderUtil.SetValueToBinder(data[i], _eventParameterBinders[i]);
                }

                if (_afterReceiveData != null)
                {
                    _afterReceiveData.Invoke();
                }
            }
            catch (Exception e)
            {
                Debug.LogErrorFormat(this, e.Message);
                Debug.LogException(e);
            }
        }
Пример #2
0
        void OnResponse(IPresenterResponse res)
        {
            try
            {
                _beforeReceiveData.Invoke();
                if (res.StatusCode == 200)
                {
                    if (res.Data != null)
                    {
                        for (var i = 0; i < _responseDataBinder.Count; i++)
                        {
                            BinderUtil.SetValueToBinder(res.Data[i], _responseDataBinder[i]);
                        }
                    }
                }
                else
                {
                    Debug.LogWarningFormat(this, "Local request {0} returned with error. code {1} : {2}", _url, res.StatusCode, res.ErrorMessage);
                }

                _afterReceiveData.Invoke();
            }
            catch (Exception e)
            {
                Debug.LogErrorFormat(this, e.Message);
                Debug.LogException(e);
            }
        }
Пример #3
0
        public void SendRequest()
        {
            var toSendData = _toSendDataBinders.Select(b => BinderUtil.GetValueFromBinder(b));

            if (!_async)
            {
                var res = PresenterDispatcher.GetInstance().RequestWithMTokens(_url, toSendData.ToArray());
                OnResponse(res);
            }
            else
            {
                PresenterDispatcher.GetInstance().RequestWithMTokensAsync(this, OnResponse, _url, toSendData.ToArray());
            }
        }
Пример #4
0
        public bool HasEditorError()
        {
            var eventsMapping = PresenterUtil.GetAllPresetnerEvents();

            if (!eventsMapping.ContainsKey(_url))
            {
                return(true);
            }

            if (_eventParameterBinders.Any(b => b == null))
            {
                return(true);
            }

            return(BinderUtil.IsUnityEventHasError(_beforeReceiveData) ||
                   BinderUtil.IsUnityEventHasError(_afterReceiveData));
        }
Пример #5
0
        public bool HasEditorError()
        {
            var actionMapping = PresenterUtil.GetAllPresenterAction();

            if (!actionMapping.ContainsKey(_url))
            {
                return(true);
            }

            if (_toSendDataBinders.Any(b => b == null) ||
                _responseDataBinder.Any(b => b == null))
            {
                return(true);
            }

            return(BinderUtil.IsUnityEventHasError(_beforeReceiveData) ||
                   BinderUtil.IsUnityEventHasError(_afterReceiveData));
        }
        void DrawParameters(PresenterActionInfo action)
        {
            EditorGUILayout.LabelField("Parameters");
            EditorGUI.indentLevel++;

            var binderProperties = serializedObject.FindProperty("_toSendDataBinders");
            var parameters       = action.Method.GetParameters();

            var parameterLength = parameters.Length;

            if (action.IsAsync)
            {
                parameterLength--;
            }

            if (parameterLength == 0)
            {
                EditorGUILayout.HelpBox("No parameter to send", MessageType.Info);
            }
            else
            {
                for (var i = 0; i < parameterLength; i++)
                {
                    if (binderProperties.arraySize <= i)
                    {
                        binderProperties.InsertArrayElementAtIndex(i);
                    }

                    var binderProperty = binderProperties.GetArrayElementAtIndex(i);
                    var parameter      = parameters[i];

                    var paraType          = parameter.ParameterType;
                    var requireBinderInfo = BinderUtil.GetRequireBinderInfoByValueType(paraType);
                    binderProperty.objectReferenceValue = EditorKit.DrawBinderField(
                        parameter.Name, requireBinderInfo.ValueTypeName, binderProperty.objectReferenceValue, requireBinderInfo.InterfaceType);
                }
            }
            while (binderProperties.arraySize > parameters.Length)
            {
                binderProperties.DeleteArrayElementAtIndex(parameters.Length);
            }

            EditorGUI.indentLevel--;
        }
Пример #7
0
        void DrawParameters(Dictionary <string, Type> parameterTypes)
        {
            if (parameterTypes == null)
            {
                parameterTypes = new Dictionary <string, Type>();
            }

            EditorGUILayout.LabelField("Parameters");
            EditorGUI.indentLevel++;

            var binderProperties = serializedObject.FindProperty("_eventParameterBinders");

            while (binderProperties.arraySize > parameterTypes.Count)
            {
                binderProperties.DeleteArrayElementAtIndex(parameterTypes.Count);
            }

            if (parameterTypes.Count == 0)
            {
                EditorGUILayout.HelpBox("No parameter data", MessageType.Info);
            }
            else
            {
                var keys = parameterTypes.Keys.ToArray();
                for (var i = 0; i < keys.Length; i++)
                {
                    if (binderProperties.arraySize <= i)
                    {
                        binderProperties.InsertArrayElementAtIndex(i);
                    }

                    var binderProperty = binderProperties.GetArrayElementAtIndex(i);
                    var label          = keys[i];
                    var parameterType  = parameterTypes[label];

                    var requireBinderInfo = BinderUtil.GetRequireBinderInfoByValueType(parameterType);
                    binderProperty.objectReferenceValue = EditorKit.DrawBinderField(
                        label, requireBinderInfo.ValueTypeName, binderProperty.objectReferenceValue, requireBinderInfo.InterfaceType);
                }
            }
            EditorGUI.indentLevel--;
        }
Пример #8
0
        void DrawConditions(Dictionary <string, Type> conditionTypes)
        {
            if (conditionTypes == null)
            {
                conditionTypes = new Dictionary <string, Type>();
            }

            var binderProperties = serializedObject.FindProperty("_registConditionBinders");

            while (binderProperties.arraySize > conditionTypes.Count)
            {
                binderProperties.DeleteArrayElementAtIndex(conditionTypes.Count);
            }

            if (conditionTypes.Count != 0)
            {
                EditorGUILayout.LabelField("Conditions");
                EditorGUI.indentLevel++;

                var keys = conditionTypes.Keys.ToArray();
                for (var i = 0; i < keys.Length; i++)
                {
                    if (binderProperties.arraySize <= i)
                    {
                        binderProperties.InsertArrayElementAtIndex(i);
                    }

                    var binderProperty = binderProperties.GetArrayElementAtIndex(i);
                    var label          = keys[i];
                    var parameterType  = conditionTypes[label];

                    var requireBinderInfo = BinderUtil.GetRequireBinderInfoByValueType(parameterType);
                    binderProperty.objectReferenceValue = EditorKit.DrawBinderField(
                        label, requireBinderInfo.ValueTypeName, binderProperty.objectReferenceValue, requireBinderInfo.InterfaceType);
                }

                EditorGUI.indentLevel--;
            }
        }
        void DrawResponse(PresenterActionInfo action)
        {
            EditorGUILayout.LabelField("Responese");
            EditorGUI.indentLevel++;

            List <Type> retTypeList = new List <Type>();

            if (action.IsAsync)
            {
                var parameters = action.Method.GetParameters();
                var lastParam  = parameters[parameters.Length - 1];
                if (lastParam.ParameterType == typeof(AsyncReturn) || lastParam.ParameterType.IsSubclassOf(typeof(AsyncReturn)))
                {
                    var genericTypes = lastParam.ParameterType.GetGenericArguments();
                    foreach (var gt in genericTypes)
                    {
                        retTypeList.Add(gt);
                    }
                }
                else
                {
                    EditorGUILayout.HelpBox("it is an async action but the last parameter is not AysncReturn", MessageType.Error);
                    return;
                }
            }
            else if (action.Method.ReturnType != typeof(void))
            {
                retTypeList.Add(action.Method.ReturnType);
            }

            var binderListProperty = serializedObject.FindProperty("_responseDataBinder");

            while (binderListProperty.arraySize > retTypeList.Count)
            {
                binderListProperty.DeleteArrayElementAtIndex(retTypeList.Count);
            }

            if (retTypeList.Count == 0)
            {
                EditorGUILayout.HelpBox("No response data", MessageType.Info);
            }
            else
            {
                for (var i = 0; i < retTypeList.Count; i++)
                {
                    if (binderListProperty.arraySize <= i)
                    {
                        binderListProperty.InsertArrayElementAtIndex(i);
                    }

                    var binderProperty = binderListProperty.GetArrayElementAtIndex(i);
                    var retType        = retTypeList[i];

                    var requireBinderInfo = BinderUtil.GetRequireBinderInfoByValueType(retType);

                    binderProperty.objectReferenceValue = EditorKit.DrawBinderField(
                        "return " + i, requireBinderInfo.ValueTypeName, binderProperty.objectReferenceValue, requireBinderInfo.InterfaceType);
                }
            }

            EditorGUI.indentLevel--;
        }
Пример #10
0
 public MToken[] GetRegistConditionData()
 {
     return(_registConditionBinders.Select(r => BinderUtil.GetValueFromBinder(r)).ToArray());
 }