void DoGUI(SerializedProperty property, GUIContent label)
        {
            SerializedProperty typeProperty = property.FindPropertyRelative("_Type");

            CalculatorCondition.Type type = EnumUtility.GetValueFromIndex <CalculatorCondition.Type>(typeProperty.enumValueIndex);

            switch (type)
            {
            case CalculatorCondition.Type.Int:
            {
                _LayoutArea.PropertyField(property.FindPropertyRelative("_CompareType"));
                _LayoutArea.PropertyField(property.FindPropertyRelative("_IntValue1"));
                _LayoutArea.PropertyField(property.FindPropertyRelative("_IntValue2"));
            }
            break;

            case CalculatorCondition.Type.Float:
            {
                _LayoutArea.PropertyField(property.FindPropertyRelative("_CompareType"));
                _LayoutArea.PropertyField(property.FindPropertyRelative("_FloatValue1"));
                _LayoutArea.PropertyField(property.FindPropertyRelative("_FloatValue2"));
            }
            break;

            case CalculatorCondition.Type.Bool:
            {
                _LayoutArea.PropertyField(property.FindPropertyRelative("_BoolValue1"));
                _LayoutArea.PropertyField(property.FindPropertyRelative("_BoolValue2"));
            }
            break;
            }
        }
        private void OnRemove(ReorderableList list)
        {
            SerializedProperty elementProperty = list.serializedProperty.GetArrayElementAtIndex(list.index);

            CalculatorCondition.Type type = GetType(elementProperty);

            DeleteParameter(elementProperty, type, true);

            ReorderableList.defaultBehaviours.DoRemoveButton(list);
        }
        void AddParameter(SerializedProperty elementProperty, CalculatorCondition.Type type)
        {
            SerializedProperty typeProperty = elementProperty.FindPropertyRelative(kTypePath);

            typeProperty.enumValueIndex = EnumUtility.GetIndexFromValue(type);

            SerializedProperty parametersProperty = GetParametersProperty(type);

            if (parametersProperty != null)
            {
                parametersProperty.arraySize++;
                int parameterIndex = parametersProperty.arraySize - 1;

                SerializedProperty parameterProperty = parametersProperty.GetArrayElementAtIndex(parameterIndex);

                SerializedProperty value1Property = parameterProperty.FindPropertyRelative("value1");
                SerializedProperty value2Property = parameterProperty.FindPropertyRelative("value2");

                FlexibleFieldProperty field1Property = null;
                FlexibleFieldProperty field2Property = null;
                switch (type)
                {
                case CalculatorCondition.Type.Int:
                case CalculatorCondition.Type.Float:
                    field1Property = new FlexibleNumericProperty(value1Property);
                    field2Property = new FlexibleNumericProperty(value2Property);
                    break;

                case CalculatorCondition.Type.Bool:
                    field1Property = new FlexibleBoolProperty(value1Property);
                    field2Property = new FlexibleBoolProperty(value2Property);
                    break;
                }

                if (field1Property != null)
                {
                    field1Property.Clear(true);
                }
                if (field2Property != null)
                {
                    bool clearBool = SerializedPropertyExtentions.clearBool;
                    if (type == CalculatorCondition.Type.Bool)
                    {
                        SerializedPropertyExtentions.clearBool = true;
                    }

                    field2Property.Clear(true);

                    SerializedPropertyExtentions.clearBool = clearBool;
                }

                SerializedProperty parameterIndexProperty = elementProperty.FindPropertyRelative(kParameterIndexPath);
                parameterIndexProperty.intValue = parameterIndex;
            }
        }
        SerializedProperty GetParametersProperty(CalculatorCondition.Type type)
        {
            switch (type)
            {
            case CalculatorCondition.Type.Int:
                return(_IntParameters);

            case CalculatorCondition.Type.Float:
                return(_FloatParameters);

            case CalculatorCondition.Type.Bool:
                return(_BoolParameters);
            }

            return(null);
        }
        void AddConditionMenu(object value)
        {
            SerializedObject serializedObject = _ConditionsList.serializedProperty.serializedObject;

            serializedObject.Update();

            CalculatorCondition.Type type = (CalculatorCondition.Type)value;

            ReorderableList.defaultBehaviours.DoAddButton(_ConditionsList);

            SerializedProperty elementProperty = _ConditionsList.serializedProperty.GetArrayElementAtIndex(_ConditionsList.index);

            AddParameter(elementProperty, type);

            serializedObject.ApplyModifiedProperties();
        }
        void DeleteParameter(SerializedProperty elementProperty, CalculatorCondition.Type type, bool deleteParameter)
        {
            SerializedProperty parametersProperty = GetParametersProperty(type);

            if (parametersProperty == null)
            {
                return;
            }

            SerializedProperty parameterIndexProperty = elementProperty.FindPropertyRelative(kParameterIndexPath);
            int parameterIndex = parameterIndexProperty.intValue;
            SerializedProperty parameterProperty = parametersProperty.GetArrayElementAtIndex(parameterIndex);

            if (parameterProperty == null)
            {
                return;
            }

            foreach (object valueObj in EditorGUITools.GetPropertyObjects(parameterProperty))
            {
                EachField <DataSlot> .Find(valueObj, valueObj.GetType(), (s) =>
                {
                    s.Disconnect();
                });
            }

            if (deleteParameter)
            {
                parametersProperty.DeleteArrayElementAtIndex(parameterIndex);

                for (int i = 0, count = _ConditionsList.serializedProperty.arraySize; i < count; i++)
                {
                    SerializedProperty       p = _ConditionsList.serializedProperty.GetArrayElementAtIndex(i);
                    CalculatorCondition.Type t = GetType(p);
                    if (t != type)
                    {
                        continue;
                    }
                    SerializedProperty indexProperty = p.FindPropertyRelative(kParameterIndexPath);
                    if (indexProperty.intValue > parameterIndex)
                    {
                        indexProperty.intValue--;
                    }
                }
            }
        }
Example #7
0
        internal bool Compare(CalculatorCondition.Type type, int parameterIndex, CompareType compareType)
        {
            switch (type)
            {
            case CalculatorCondition.Type.Int:
                IntParameter intParameter = _IntParameters[parameterIndex];
                return(intParameter.Compare(compareType));

            case CalculatorCondition.Type.Float:
                FloatParameter floatParameter = _FloatParameters[parameterIndex];
                return(floatParameter.Compare(compareType));

            case CalculatorCondition.Type.Bool:
                BoolParameter boolParameter = _BoolParameters[parameterIndex];
                return(boolParameter.Compare());
            }

            return(false);
        }
Example #8
0
        public void ImportLegacy(List <CalculatorConditionLegacy> legacyList)
        {
            foreach (var legacy in legacyList)
            {
                var condition = new CalculatorCondition(legacy._Type);
                condition._CompareType = legacy._CompareType;

                CalculatorCondition.Type type = condition._Type;

                switch (type)
                {
                case CalculatorCondition.Type.Int:
                    IntParameter intParameter = new IntParameter();
                    intParameter.value1 = legacy._IntValue1;
                    intParameter.value2 = legacy._IntValue2;
                    _IntParameters.Add(intParameter);
                    condition._ParameterIndex = _IntParameters.Count - 1;
                    break;

                case CalculatorCondition.Type.Float:
                    FloatParameter floatParameter = new FloatParameter();
                    floatParameter.value1 = legacy._FloatValue1;
                    floatParameter.value2 = legacy._FloatValue2;
                    _FloatParameters.Add(floatParameter);
                    condition._ParameterIndex = _FloatParameters.Count - 1;
                    break;

                case CalculatorCondition.Type.Bool:
                    BoolParameter boolParameter = new BoolParameter();
                    boolParameter.value1 = legacy._BoolValue1;
                    boolParameter.value2 = legacy._BoolValue2;
                    _BoolParameters.Add(boolParameter);
                    condition._ParameterIndex = _BoolParameters.Count - 1;
                    break;
                }

                condition.owner = this;

                _Conditions.Add(condition);
            }
        }
        void DoGUI(SerializedProperty elementProperty)
        {
            CalculatorCondition.Type type = GetType(elementProperty);

            SerializedProperty parametersProperty = GetParametersProperty(type);

            SerializedProperty parameterIndexProperty = elementProperty.FindPropertyRelative(kParameterIndexPath);

            SerializedProperty parameterProperty = parametersProperty.GetArrayElementAtIndex(parameterIndexProperty.intValue);

            SerializedProperty value1Property = parameterProperty.FindPropertyRelative("value1");
            SerializedProperty value2Property = parameterProperty.FindPropertyRelative("value2");

            switch (type)
            {
            case CalculatorCondition.Type.Int:
            {
                _LayoutArea.PropertyField(elementProperty.FindPropertyRelative("_CompareType"));
                _LayoutArea.PropertyField(value1Property, EditorGUITools.GetTextContent("Int Value 1"));
                _LayoutArea.PropertyField(value2Property, EditorGUITools.GetTextContent("Int Value 2"));
            }
            break;

            case CalculatorCondition.Type.Float:
            {
                _LayoutArea.PropertyField(elementProperty.FindPropertyRelative("_CompareType"));
                _LayoutArea.PropertyField(value1Property, EditorGUITools.GetTextContent("Float Value 1"));
                _LayoutArea.PropertyField(value2Property, EditorGUITools.GetTextContent("Float Value 2"));
            }
            break;

            case CalculatorCondition.Type.Bool:
            {
                _LayoutArea.PropertyField(value1Property, EditorGUITools.GetTextContent("Bool Value 1"));
                _LayoutArea.PropertyField(value2Property, EditorGUITools.GetTextContent("Bool Value 2"));
            }
            break;
            }
        }
 void OnChangeParameterType(SerializedProperty elementProperty, CalculatorCondition.Type oldType, CalculatorCondition.Type newType)
 {
     DeleteParameter(elementProperty, oldType, true);
     AddParameter(elementProperty, newType);
 }
        /// <summary>
        /// CalculatorConditionコンストラクタ
        /// </summary>
        /// <param name="type">値の型</param>
#else
        /// <summary>
        /// CalculatorCondition constructor
        /// </summary>
        /// <param name="type">Value type</param>
#endif
        public CalculatorConditionLegacy(CalculatorCondition.Type type)
        {
            _SerializeVersion = 1;
            _Type             = type;
        }