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--;
        }
Example #2
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--;
        }
Example #3
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--;
        }
Example #5
0
        void DrawSerializeFields(Type modelType)
        {
            var beforeSerializedValues = new Dictionary <string, ModelObjectBinder.SerializedBinder>();

            for (var i = 0; i < _bindersProperty.arraySize; i++)
            {
                var element = _bindersProperty.GetArrayElementAtIndex(i);
                var value   = new ModelObjectBinder.SerializedBinder()
                {
                    FieldName      = element.FindPropertyRelative("FieldName").stringValue,
                    ManualInput    = element.FindPropertyRelative("ManualInput").boolValue,
                    TokenType      = (MTokenType)element.FindPropertyRelative("TokenType").intValue,
                    BinderInstance = element.FindPropertyRelative("BinderInstance").objectReferenceValue
                };
                if (!string.IsNullOrEmpty(value.FieldName))
                {
                    beforeSerializedValues.Add(value.FieldName, value);
                }
            }

            var afterSerializedValues = new List <ModelObjectBinder.SerializedBinder>();
            //var afterSerializedValues = new Dictionary<string, UnityEngine.Object>();
            var toSerializeMembers = BinderUtil.GetRequireBinderInfoFromModelMembers(modelType);

            foreach (var member in toSerializeMembers)
            {
                var fieldName = member.Key;
                ModelObjectBinder.SerializedBinder binderInfo;
                if (!beforeSerializedValues.TryGetValue(fieldName, out binderInfo))
                {
                    binderInfo = new ModelObjectBinder.SerializedBinder()
                    {
                        FieldName   = fieldName,
                        ManualInput = false,
                        TokenType   = member.Value.BinderInfo.TokenType
                    };
                }

                if (member.Value.BinderInfo.TokenType == MTokenType.Dynamic)
                {
                    EditorGUILayout.LabelField(fieldName, member.Value.BinderInfo.ValueTypeName + "is not supported. Use float instead.");
                }
                else
                {
                    binderInfo.BinderInstance = EditorKit.DrawBinderField(
                        fieldName, member.Value.BinderInfo.ValueTypeName, binderInfo.BinderInstance, member.Value.BinderInfo.InterfaceType);
                }
                afterSerializedValues.Add(binderInfo);
            }

            for (var i = beforeSerializedValues.Count - 1; i >= afterSerializedValues.Count; i--)
            {
                _bindersProperty.DeleteArrayElementAtIndex(i);
            }

            for (var i = 0; i < afterSerializedValues.Count; i++)
            {
                if (i >= _bindersProperty.arraySize)
                {
                    _bindersProperty.InsertArrayElementAtIndex(i);
                }
                var data    = afterSerializedValues[i];
                var element = _bindersProperty.GetArrayElementAtIndex(i);
                element.FindPropertyRelative("FieldName").stringValue = data.FieldName;
                element.FindPropertyRelative("ManualInput").boolValue = data.ManualInput;
                element.FindPropertyRelative("TokenType").intValue    = (int)data.TokenType;
                element.FindPropertyRelative("BinderInstance").objectReferenceValue = data.BinderInstance;
            }
        }
        //int _selectedPageIndex;
        public override void OnInspectorGUI()
        {
            //_selectedPageIndex = GUILayout.Toolbar(_selectedPageIndex, new string[] { "Settings", "Events" }, EditorStyles.miniButton);
            //EditorGUILayout.Space();
            //Rect rect = EditorGUILayout.GetControlRect(false, 1f);
            //EditorGUI.DrawRect(rect, EditorStyles.label.normal.textColor * 0.5f);
            //EditorGUILayout.Space();

            //if (_selectedPageIndex == 1)
            //{
            //	EditorGUILayout.PropertyField(serializedObject.FindProperty("_beforeReceiveEvent"));
            //	EditorGUILayout.PropertyField(serializedObject.FindProperty("_afterReceiveEvent"));
            //}
            //else
            {
                var typeProperty = serializedObject.FindProperty("_dataType");
                EditorGUILayout.PropertyField(typeProperty);

                Type binderInterfaceType = null;
                var  arrayElementType    = (ArrayElementTypeEnum)typeProperty.enumValueIndex;

                switch (arrayElementType)
                {
                case ArrayElementTypeEnum.Bool:
                    binderInterfaceType = typeof(IMvpBoolBinder);
                    break;

                case ArrayElementTypeEnum.String:
                    binderInterfaceType = typeof(IMvpStringBinder);
                    break;

                case ArrayElementTypeEnum.Float:
                    binderInterfaceType = typeof(IMvpFloatBinder);
                    break;

                case ArrayElementTypeEnum.Object:
                    binderInterfaceType = typeof(IMvpObjectBinder);
                    break;

                case ArrayElementTypeEnum.Custom:
                {
                    var customElementTypeStringProp = serializedObject.FindProperty("_customElementTypeString");
                    if (_allBinderValueTypes.Count == 0)
                    {
                        EditorGUILayout.HelpBox("No custom type binder implemented.", MessageType.Warning);
                    }
                    else
                    {
                        var returnType = EditorKit.DrawTypeSelector("Custom Element Type", customElementTypeStringProp.stringValue, _allBinderValueTypes);
                        if (returnType != null)
                        {
                            customElementTypeStringProp.stringValue = returnType.Value.TypeString;
                            binderInterfaceType = typeof(IMvpCustomTypeBinder <>).MakeGenericType(returnType.Value.Type);
                        }
                    }
                }
                break;
                }
                if (binderInterfaceType != null)
                {
                    var mainBinderProperty    = serializedObject.FindProperty("_mainBinder");
                    var extendBindersProperty = serializedObject.FindProperty("_extendBinders");

                    //EditorGUILayout.BeginHorizontal();
                    //EditorGUILayout.PrefixLabel("Array Element Template");
                    mainBinderProperty.objectReferenceValue = EditorKit.DrawBinderField("Main Binder", mainBinderProperty.objectReferenceValue, binderInterfaceType);

                    if (EditorGUILayout.PropertyField(extendBindersProperty, false))
                    {
                        EditorGUI.indentLevel++;

                        var size = EditorGUILayout.DelayedIntField("Size", extendBindersProperty.arraySize);
                        while (extendBindersProperty.arraySize > size)
                        {
                            extendBindersProperty.DeleteArrayElementAtIndex(size);
                        }

                        for (var i = 0; i < size; i++)
                        {
                            if (i >= extendBindersProperty.arraySize)
                            {
                                extendBindersProperty.InsertArrayElementAtIndex(i);
                            }

                            var elementProp = extendBindersProperty.GetArrayElementAtIndex(i);
                            elementProp.objectReferenceValue = EditorKit.DrawBinderField("Element " + i, elementProp.objectReferenceValue, binderInterfaceType);
                        }

                        EditorGUI.indentLevel--;
                    }

                    //EditorGUILayout.PropertyField(extendBindersProperty, true);
                    //for(var i = 0; i < extendBindersProperty.arraySize; i++)
                    //{
                    //	var exbp = extendBindersProperty.GetArrayElementAtIndex(i);

                    //}

                    //EditorGUILayout.EndHorizontal();
                }
            }

            serializedObject.ApplyModifiedProperties();
        }
Example #7
0
        public override void OnInspectorGUI()
        {
            _selectedPageIndex = GUILayout.Toolbar(_selectedPageIndex, new string[] { "Settings", "Events" }, EditorStyles.miniButton);
            EditorGUILayout.Space();
            Rect rect = EditorGUILayout.GetControlRect(false, 1f);

            EditorGUI.DrawRect(rect, EditorStyles.label.normal.textColor * 0.5f);
            EditorGUILayout.Space();

            if (_selectedPageIndex == 1)
            {
                EditorGUILayout.PropertyField(serializedObject.FindProperty("_beforeReceiveEvent"));
                EditorGUILayout.PropertyField(serializedObject.FindProperty("_afterReceiveEvent"));
            }
            else
            {
                var typeProperty = serializedObject.FindProperty("_elementType");
                EditorGUILayout.PropertyField(typeProperty);

                var templateProperty = serializedObject.FindProperty("_elementBinder");

                Type templateInterfaceType = null;
                var  arrayElementType      = (ArrayElementTypeEnum)typeProperty.enumValueIndex;

                switch (arrayElementType)
                {
                case ArrayElementTypeEnum.Bool:
                    templateInterfaceType = typeof(IMvpBoolBinder);
                    break;

                case ArrayElementTypeEnum.String:
                    templateInterfaceType = typeof(IMvpStringBinder);
                    break;

                case ArrayElementTypeEnum.Float:
                    templateInterfaceType = typeof(IMvpFloatBinder);
                    break;

                case ArrayElementTypeEnum.Object:
                    templateInterfaceType = typeof(IMvpObjectBinder);
                    break;

                case ArrayElementTypeEnum.Custom:
                {
                    var customElementTypeStringProp = serializedObject.FindProperty("_customElementTypeString");
                    if (_allBinderValueTypes.Count == 0)
                    {
                        EditorGUILayout.HelpBox("No custom type binder implemented.", MessageType.Warning);
                    }
                    else
                    {
                        var returnType = EditorKit.DrawTypeSelector("Custom Element Type", customElementTypeStringProp.stringValue, _allBinderValueTypes);
                        if (returnType != null)
                        {
                            customElementTypeStringProp.stringValue = returnType.Value.TypeString;
                            templateInterfaceType = typeof(IMvpCustomTypeBinder <>).MakeGenericType(returnType.Value.Type);
                        }
                    }
                }
                break;
                }
                if (templateInterfaceType != null)
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.PrefixLabel("Element Binder");
                    templateProperty.objectReferenceValue = EditorKit.DrawBinderField("", templateProperty.objectReferenceValue, templateInterfaceType);
                    EditorGUILayout.EndHorizontal();
                }
            }

            serializedObject.ApplyModifiedProperties();
        }