Example #1
0
        protected override Type GetExpectedOutputTypeOfOperation(IEnumerable <Type> inputTypes)
        {
            var outputComponentCount = inputTypes.Select(o =>
            {
                var type = VFXValueType.None;
                if (o == typeof(Position) || o == typeof(DirectionType) || o == typeof(Vector))
                {
                    type = VFXValueType.Float3;
                }
                else
                {
                    type = VFXExpression.GetVFXValueTypeFromType(o);
                }
                if (type == VFXValueType.None)
                {
                    throw new InvalidOperationException("Unable to compute value type from " + o);
                }
                return(VFXExpression.TypeToSize(type));
            }).Sum();

            outputComponentCount = Mathf.Min(Mathf.Max(outputComponentCount, 1), 4);
            switch (outputComponentCount)
            {
            case 2: return(typeof(Vector2));

            case 3: return(typeof(Vector3));

            case 4: return(typeof(Vector4));

            default: return(typeof(float));
            }
        }
Example #2
0
        private static Dictionary <Type, Type[]> ComputeHeuristcalAffinity()
        {
            /* Heuristical function which is a bit expensive but expects the same result as kTypeAffinity */
            var inputType = new[]
            {
                typeof(Matrix4x4),
                typeof(Vector4),
                typeof(Color),
                typeof(Vector3),
                typeof(Position),
                typeof(DirectionType),
                typeof(Vector),
                typeof(Vector2),
                typeof(float),
                typeof(int),
                typeof(uint),
            };

            var inputTypeHeurisicalDict = inputType.Select(o =>
            {
                var baseValueType       = VFXSlot.Create(new VFXProperty(o, "temp1"), VFXSlot.Direction.kOutput).DefaultExpr.valueType;
                var baseChannelCount    = VFXExpression.TypeToSize(baseValueType);
                var baseIsKindOfInteger = o == typeof(uint) || o == typeof(int);

                var compatibleSlotMetaData = inputType
                                             .Where(s => s != o && IsSlotCompatible(o, s))
                                             .Select(s =>
                {
                    var otherValueType       = VFXSlot.Create(new VFXProperty(s, "temp2"), VFXSlot.Direction.kOutput).DefaultExpr.valueType;
                    var otherChannelCount    = VFXExpression.TypeToSize(otherValueType);
                    var otherIsKindOfInteger = s == typeof(uint) || s == typeof(int);

                    return(new
                    {
                        type = s,
                        diffType = otherValueType == baseValueType ? 0 : 1,
                        diffChannelCount = Mathf.Abs(baseChannelCount - otherChannelCount),
                        diffPreferInteger = baseIsKindOfInteger == otherIsKindOfInteger ? 0 : 1
                    });
                }).OrderBy(s => s.diffType)
                                             .ThenBy(s => s.diffChannelCount)
                                             .ThenBy(s => s.diffPreferInteger)
                                             .ToArray();

                return(new KeyValuePair <Type, Type[]>
                       (
                           o,
                           compatibleSlotMetaData.Select(s => s.type).ToArray()
                       ));
            }).ToDictionary(x => x.Key, x => x.Value);

            return(inputTypeHeurisicalDict);
        }
Example #3
0
        protected override Type GetExpectedOutputTypeOfOperation(IEnumerable <Type> inputTypes)
        {
            var outputComponentCount = inputTypes.Select(o => VFXExpression.TypeToSize(VFXExpression.GetVFXValueTypeFromType(o))).Sum();

            outputComponentCount = Mathf.Min(Mathf.Max(outputComponentCount, 1), 4);
            switch (outputComponentCount)
            {
            case 2: return(typeof(Vector2));

            case 3: return(typeof(Vector3));

            case 4: return(typeof(Vector4));

            default: return(typeof(float));
            }
        }
        private void OnEnable()
        {
            Action <ReorderableList, SerializedProperty> fnAssetDropDown = delegate(ReorderableList list, SerializedProperty property)
            {
                var existingAttribute = new List <string>();
                for (int i = 0; i < property.arraySize; ++i)
                {
                    existingAttribute.Add(property.GetArrayElementAtIndex(i).FindPropertyRelative("attribute.m_Name").stringValue);
                }

                var menu = new GenericMenu();
                foreach (var attributeName in VFXAttribute.AllIncludingVariadicReadWritable.Except(existingAttribute).OrderBy(o => o))
                {
                    var attribute = VFXAttribute.Find(attributeName);
                    menu.AddItem(new GUIContent(attribute.name), false, () =>
                    {
                        serializedObject.Update();
                        property.arraySize++;

                        var newElement = property.GetArrayElementAtIndex(property.arraySize - 1);
                        newElement.FindPropertyRelative("attribute.m_Name").stringValue = attribute.name;
                        newElement.FindPropertyRelative("type").intValue = (int)attribute.type;

                        var size         = VFXExpression.TypeToSize(attribute.type);
                        var values       = newElement.FindPropertyRelative("values");
                        values.arraySize = size;

                        var initialValues = new float[size];
                        if (attribute.type == VFXValueType.Float)
                        {
                            initialValues[0] = attribute.value.Get <float>();
                        }
                        else if (attribute.type == VFXValueType.Float2)
                        {
                            var v            = attribute.value.Get <Vector2>();
                            initialValues[0] = v.x;
                            initialValues[1] = v.y;
                        }
                        else if (attribute.type == VFXValueType.Float3)
                        {
                            var v            = attribute.value.Get <Vector3>();
                            initialValues[0] = v.x;
                            initialValues[1] = v.y;
                            initialValues[2] = v.z;
                        }
                        else if (attribute.type == VFXValueType.Float4)
                        {
                            var v            = attribute.value.Get <Vector4>();
                            initialValues[0] = v.x;
                            initialValues[1] = v.y;
                            initialValues[2] = v.z;
                            initialValues[3] = v.w;
                        }
                        else if (attribute.type == VFXValueType.Int32)
                        {
                            initialValues[0] = attribute.value.Get <int>();
                        }
                        else if (attribute.type == VFXValueType.Uint32)
                        {
                            initialValues[0] = attribute.value.Get <uint>();
                        }
                        else if (attribute.type == VFXValueType.Boolean)
                        {
                            initialValues[0] = attribute.value.Get <bool>() ? 1.0f : 0.0f;
                        }
                        for (int i = 0; i < size; ++i)
                        {
                            values.GetArrayElementAtIndex(i).floatValue = initialValues[i];
                        }
                        serializedObject.ApplyModifiedProperties();
                    });
                }
                menu.ShowAsContext();
            };

            Action <Rect, SerializedProperty, int> fnDrawElement = delegate(Rect r, SerializedProperty property, int index)
            {
                var element = property.GetArrayElementAtIndex(index);

                var label      = element.FindPropertyRelative("attribute.m_Name").stringValue;
                var labelWidth = 110;//GUI.skin.label.CalcSize(new GUIContent(label)); //Should be maximized among all existing property, for now, angularVelocity is considered as maximum

                EditorGUI.LabelField(new Rect(r.x, r.y, labelWidth, EditorGUIUtility.singleLineHeight), label);
                var valueType       = (VFXValueType)element.FindPropertyRelative("type").intValue;
                var valueSize       = VFXExpression.TypeToSize(valueType);
                var fieldWidth      = (r.width - labelWidth) / valueSize;
                var emptyGUIContent = new GUIContent(string.Empty);
                var valuesProperty  = element.FindPropertyRelative("values");
                if (valueType == VFXValueType.Float ||
                    valueType == VFXValueType.Float2 ||
                    valueType == VFXValueType.Float3 ||
                    valueType == VFXValueType.Float4)
                {
                    if (label.Contains("color") && valueType == VFXValueType.Float3)
                    {
                        var oldColor = new Color(valuesProperty.GetArrayElementAtIndex(0).floatValue,
                                                 valuesProperty.GetArrayElementAtIndex(1).floatValue,
                                                 valuesProperty.GetArrayElementAtIndex(2).floatValue);

                        EditorGUI.BeginChangeCheck();
                        var newColor = EditorGUI.ColorField(new Rect(r.x + labelWidth, r.y, fieldWidth * 3, EditorGUIUtility.singleLineHeight), oldColor);
                        if (EditorGUI.EndChangeCheck())
                        {
                            valuesProperty.GetArrayElementAtIndex(0).floatValue = newColor.r;
                            valuesProperty.GetArrayElementAtIndex(1).floatValue = newColor.g;
                            valuesProperty.GetArrayElementAtIndex(2).floatValue = newColor.b;
                        }
                    }
                    else
                    {
                        for (int i = 0; i < valueSize; ++i)
                        {
                            EditorGUI.PropertyField(new Rect(r.x + labelWidth + fieldWidth * i, r.y, fieldWidth, EditorGUIUtility.singleLineHeight), valuesProperty.GetArrayElementAtIndex(i), emptyGUIContent);
                        }
                    }
                }
                else if (valueType == VFXValueType.Int32 ||
                         valueType == VFXValueType.Uint32 ||
                         valueType == VFXValueType.Boolean)
                {
                    var   oldValue = valuesProperty.GetArrayElementAtIndex(0).floatValue;
                    float newValue;
                    var   currentRect = new Rect(r.x + labelWidth, r.y, fieldWidth, EditorGUIUtility.singleLineHeight);
                    EditorGUI.BeginChangeCheck();
                    if (valueType == VFXValueType.Boolean)
                    {
                        newValue = EditorGUI.Toggle(currentRect, emptyGUIContent, oldValue != 0.0f) ? 1.0f : 0.0f;
                    }
                    else
                    {
                        newValue = (float)EditorGUI.LongField(currentRect, emptyGUIContent, (long)oldValue);
                        newValue = newValue < 0.0f ? 0.0f : newValue;
                    }
                    if (EditorGUI.EndChangeCheck())
                    {
                        valuesProperty.GetArrayElementAtIndex(0).floatValue = newValue;
                        serializedObject.ApplyModifiedProperties();
                    }
                }
            };

            onClipEnterProperty = serializedObject.FindProperty("activationBehavior.onClipEnter.m_Name");
            onClipExitProperty  = serializedObject.FindProperty("activationBehavior.onClipExit.m_Name");

            var clipEnterAttributesProperty = serializedObject.FindProperty("activationBehavior.clipEnterEventAttributes");
            var clipExitAttributesProperty  = serializedObject.FindProperty("activationBehavior.clipExitEventAttributes");

            clipEnterAttributesPropertyList = new ReorderableList(serializedObject, clipEnterAttributesProperty, true, true, true, true);
            clipExitAttributesPropertyList  = new ReorderableList(serializedObject, clipExitAttributesProperty, true, true, true, true);

            clipEnterAttributesPropertyList.drawHeaderCallback = (Rect r) => { EditorGUI.LabelField(r, "Enter Event Attributes"); };
            clipExitAttributesPropertyList.drawHeaderCallback  = (Rect r) => { EditorGUI.LabelField(r, "Exit Event Attributes"); };

            clipEnterAttributesPropertyList.onAddDropdownCallback += (Rect buttonRect, ReorderableList list) => fnAssetDropDown(list, clipEnterAttributesProperty);
            clipExitAttributesPropertyList.onAddDropdownCallback  += (Rect buttonRect, ReorderableList list) => fnAssetDropDown(list, clipExitAttributesProperty);

            clipEnterAttributesPropertyList.drawElementCallback = (Rect r, int index, bool active, bool focused) => fnDrawElement(r, clipEnterAttributesProperty, index);
            clipExitAttributesPropertyList.drawElementCallback  = (Rect r, int index, bool active, bool focused) => fnDrawElement(r, clipExitAttributesProperty, index);
        }