void DrawRemovedObjectListElement(Rect rect, int index, bool isActive, bool isFocused)
        {
            var actionParameters = (target as ActionDefinition).Parameters.ToList();

            var list          = m_ObjectRemovedList.serializedProperty;
            var removedObject = list.GetArrayElementAtIndex(index);

            TraitGUIUtility.DrawParameterSelectorField(rect, removedObject, actionParameters);
        }
        public override void OnClose()
        {
            string oldUnknownType = default;
            var    oldType        = TraitGUIUtility.GetOperandValuePropertyType(m_Property, null, ref oldUnknownType);

            m_Property.FindPropertyRelative("m_Parameter").stringValue      = m_EditingOperand.Parameter;
            m_Property.FindPropertyRelative("m_Trait").objectReferenceValue = m_EditingOperand.Trait;
            m_Property.FindPropertyRelative("m_TraitPropertyId").intValue   = m_EditingOperand.TraitProperty.PropertyId;
            m_Property.FindPropertyRelative("m_Enum").objectReferenceValue  = m_EditingOperand.Enum;
            m_Property.FindPropertyRelative("m_Value").stringValue          = m_EditingOperand.Value;
            m_Property.serializedObject.ApplyModifiedProperties();

            string newUnknownType = default;
            var    newType        = TraitGUIUtility.GetOperandValuePropertyType(m_Property, null, ref newUnknownType);

            if (newType != oldType || newUnknownType != oldUnknownType)
            {
                m_OnExpectedTypeChanged?.Invoke(m_Property);
            }
        }
Пример #3
0
        internal static void PropertyField(Rect rect, IList <ParameterDefinition> parameters, SerializedProperty precondition, Type[] types)
        {
            const int operatorSize = 65;
            const int spacer       = 5;

            var w          = rect.width;
            var buttonSize = (w - operatorSize - 3 * spacer) / 2;

            rect.x    += spacer;
            rect.y    += EditorGUIUtility.standardVerticalSpacing;
            rect.width = buttonSize;

            var @operator = precondition.FindPropertyRelative("m_Operator");

            switch (@operator.stringValue)
            {
            case nameof(Operation.SpecialOperators.Custom):
                rect.width = w - spacer;
                var customType = precondition.FindPropertyRelative("m_CustomOperatorType").stringValue;
                EditorStyleHelper.CustomMethodField(rect, customType, types);
                break;

            default:
            {
                var operandA = precondition.FindPropertyRelative("m_OperandA");
                var operandB = precondition.FindPropertyRelative("m_OperandB");

                TraitGUIUtility.DrawOperandSelectorField(rect, operandA, @operator, parameters, true, false, property =>
                    {
                        TraitGUIUtility.ClearOperandProperty(operandB);
                    });

                var validLeftOperand = !string.IsNullOrEmpty(operandA.FindPropertyRelative("m_Parameter").stringValue);

                rect.x    += buttonSize + spacer;
                rect.width = operatorSize;

                if (validLeftOperand)
                {
                    var operators = GetComparisonOperators(operandA);
                    var opIndex   = EditorGUI.Popup(rect, Array.IndexOf(operators, @operator.stringValue),
                                                    operators, EditorStyleHelper.listPopupStyleBold);

                    @operator.stringValue = operators[Math.Max(0, opIndex)];
                }
                else
                {
                    // No operand available
                    GUI.enabled = false;
                    GUI.Button(rect, string.Empty, EditorStyleHelper.listPopupStyle);
                    GUI.enabled = true;
                }

                rect.x    += operatorSize + spacer;
                rect.width = buttonSize;

                if (validLeftOperand)
                {
                    string unknownType = default;
                    TraitGUIUtility.DrawOperandSelectorField(rect, operandB, @operator, parameters,
                                                             TraitGUIUtility.GetOperandValuePropertyType(operandA, @operator, ref unknownType), unknownType);
                }
                else
                {
                    // No operand available
                    GUI.enabled = false;
                    GUI.Button(rect, string.Empty, EditorStyleHelper.listPopupStyle);
                    GUI.enabled = true;
                }
            }
            break;
            }
        }
Пример #4
0
 static string[] GetComparisonOperators(SerializedProperty operand)
 {
     return(TraitGUIUtility.IsNumberOperand(operand)? k_NumberComparison :
            TraitGUIUtility.IsListOperand(operand) ?
            k_ListComparison : k_DefaultComparison);
 }
 protected static string[] GetAssignmentOperators(SerializedProperty operand)
 {
     return(TraitGUIUtility.IsNumberOperand(operand)? k_NumberOperators :
            TraitGUIUtility.IsListOperand(operand) ? k_ListOperators :
            k_DefaultOperators);
 }
        void DrawObjectModifierListElement(Rect rect, int index, bool isActive, bool isFocused)
        {
            var actionDefinition = (target as ActionDefinition);

            if (actionDefinition == null)
            {
                return;
            }

            const int operatorSize = 50;
            const int spacer       = 5;

            var parameters        = actionDefinition.Parameters.ToList();
            var effectsParameters = actionDefinition.CreatedObjects.ToList();

            parameters.AddRange(effectsParameters);

            var w          = rect.width;
            var buttonSize = (w - operatorSize - 3 * spacer) / 2;

            rect.x    += spacer;
            rect.y    += EditorGUIUtility.standardVerticalSpacing;
            rect.width = buttonSize;

            var list   = m_ObjectModifierList.serializedProperty;
            var effect = list.GetArrayElementAtIndex(index);

            var @operator = effect.FindPropertyRelative("m_Operator");
            var operandA  = effect.FindPropertyRelative("m_OperandA");
            var operandB  = effect.FindPropertyRelative("m_OperandB");

            switch (@operator.stringValue)
            {
            case nameof(Operation.SpecialOperators.Add):
            case nameof(Operation.SpecialOperators.Remove):
            {
                TraitGUIUtility.DrawParameterSelectorField(rect, operandA.FindPropertyRelative("m_Parameter"), parameters);

                rect.x    += buttonSize + spacer;
                rect.width = operatorSize;

                EditorGUI.LabelField(rect, (@operator.stringValue == nameof(Operation.SpecialOperators.Add))?"Add":"Remove", EditorStyleHelper.listValueStyle);

                rect.x    += operatorSize + spacer;
                rect.width = buttonSize;

                var traitDefinitions = PlannerAssetDatabase.TraitDefinitions.ToArray();
                var traitNames       = traitDefinitions.Select(t => t?.name).ToArray();

                var traitIndex = Array.IndexOf(traitDefinitions, operandB.FindPropertyRelative("m_Trait").objectReferenceValue as TraitDefinition);
                EditorGUI.BeginChangeCheck();
                traitIndex = EditorGUI.Popup(rect, traitIndex, traitNames, EditorStyleHelper.listPopupStyle);

                if (EditorGUI.EndChangeCheck())
                {
                    TraitGUIUtility.ClearOperandProperty(operandB);
                    operandB.FindPropertyRelative("m_Trait").objectReferenceValue = traitDefinitions[traitIndex];
                }
            }
            break;

            case nameof(Operation.SpecialOperators.Custom):
                rect.width = w - spacer;
                var customType = effect.FindPropertyRelative("m_CustomOperatorType").stringValue;
                EditorStyleHelper.CustomMethodField(rect, customType, PlannerCustomTypeCache.ActionEffectTypes);
                break;

            default:
            {
                TraitGUIUtility.DrawOperandSelectorField(rect, operandA, null, parameters, modified =>
                    {
                        TraitGUIUtility.ClearOperandProperty(operandB);
                    });

                var validLeftOperand = !string.IsNullOrEmpty(operandA.FindPropertyRelative("m_Parameter").stringValue);

                rect.x    += buttonSize + spacer;
                rect.width = operatorSize;

                if (validLeftOperand)
                {
                    var operators = GetAssignmentOperators(operandA);
                    var opIndex   = EditorGUI.Popup(rect, Array.IndexOf(operators, @operator.stringValue),
                                                    operators, EditorStyleHelper.listPopupStyleBold);
                    var operatorSelected = operators[Math.Max(0, opIndex)];
                    if (@operator.stringValue != operatorSelected)
                    {
                        if (TraitGUIUtility.IsListOperand(operandA) && TraitGUIUtility.IsListUnaryOperator(@operator))
                        {
                            TraitGUIUtility.ClearOperandProperty(operandB);
                        }

                        @operator.stringValue = operatorSelected;
                    }
                }
                else
                {
                    // No operand available
                    GUI.enabled = false;
                    GUI.Button(rect, string.Empty, EditorStyleHelper.listPopupStyle);
                    GUI.enabled = true;
                }

                var showRightOperand = !TraitGUIUtility.IsListOperand(operandA) || !TraitGUIUtility.IsListUnaryOperator(@operator);

                rect.x    += operatorSize + spacer;
                rect.width = buttonSize;

                if (validLeftOperand && showRightOperand)
                {
                    string unknownType = default;
                    TraitGUIUtility.DrawOperandSelectorField(rect, operandB, @operator, parameters,
                                                             TraitGUIUtility.GetOperandValuePropertyType(operandA, @operator, ref unknownType), unknownType);
                }
                else
                {
                    // No operand available
                    GUI.enabled = false;
                    GUI.Button(rect, string.Empty, EditorStyleHelper.listPopupStyle);
                    GUI.enabled = true;
                }
            }
            break;
            }
        }
        internal static void PropertyField(Rect rect, IList<ParameterDefinition> target, SerializedProperty rewardElement, Type[] rewardTypes)
        {
            const int operatorSize = 60;
            const int spacer = 5;

            var w = rect.width;
            rect.width = operatorSize;
            rect.y += EditorGUIUtility.standardVerticalSpacing;

            var @operator = rewardElement.FindPropertyRelative("m_Operator");
            var opIndex = EditorGUI.Popup(rect, Array.IndexOf(k_RewardOperators, @operator.stringValue),
                k_RewardOperators, EditorStyleHelper.listPopupStyle);

            if (k_RewardOperators.Length > 0)
                @operator.stringValue = k_RewardOperators[Math.Max(0, opIndex)];

            rect.x += operatorSize;
            rect.width = w - operatorSize;
            rect.height = EditorGUIUtility.singleLineHeight;
            var methodName = rewardElement.FindPropertyRelative("m_Typename");
            var customRewardFullNames = rewardTypes.Select(t => t.FullName).ToArray();

            rect.x += spacer;
            EditorStyleHelper.CustomMethodField(rect, methodName.stringValue, rewardTypes);

            var customRewardIndex = Array.IndexOf(customRewardFullNames, methodName.stringValue);
            if (customRewardIndex >= 0)
            {
                rect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;

                var rewardType = rewardTypes[customRewardIndex];

                var rewardParametersInfo = rewardType.GetMethod(k_RewardModifierMethodName)?.GetParameters();
                if (rewardParametersInfo != null)
                {
                    if (rewardParametersInfo[0].ParameterType.GetInterfaces().Contains(typeof(IStateData)))
                    {
                        GUI.Label(rect, "No parameters", EditorStyleHelper.italicGrayLabel);
                    }
                    else
                    {
                        var parameterProperties = rewardElement.FindPropertyRelative("m_Parameters");

                        var customParamCount = rewardParametersInfo.Length;
                        if (parameterProperties.arraySize != customParamCount)
                        {
                            parameterProperties.arraySize = customParamCount;
                        }

                        if (customParamCount >= 0)
                        {
                            float paramWidth = rect.width / customParamCount;
                            rect.width = paramWidth;

                            for (var i = 0; i < customParamCount; i++)
                            {
                                var parameterType = rewardParametersInfo[i].ParameterType;

                                TraitGUIUtility.DrawParameterSelectorField(rect, parameterProperties.GetArrayElementAtIndex(i), target, parameterType);
                                rect.x += paramWidth;
                            }
                        }
                    }
                }
                else
                {
                    GUI.Label(rect, "Invalid reward type", EditorStyleHelper.errorTextField);
                }
            }
        }