Esempio n. 1
0
 public bool hasSamePropertyAs(AMITarget target, AMPropertyTrack _track)
 {
     if (_track.GetTarget(target) == GetTarget(target) && _track.GetTargetComp(target) == GetTargetComp(target) && _track.getTrackType() == getTrackType())
     {
         return(true);
     }
     return(false);
 }
Esempio n. 2
0
        protected override void DoCopy(AMTrack track)
        {
            AMPropertyTrack ntrack = track as AMPropertyTrack;

            ntrack.valueType     = valueType;
            ntrack.obj           = obj;
            ntrack.component     = component;
            ntrack.componentName = componentName;
            ntrack.fieldName     = fieldName;
            ntrack.propertyName  = propertyName;
        }
Esempio n. 3
0
        DG.Tweening.Core.DOSetter <T> GenerateSetter <T>(AMPropertyTrack propTrack, Component comp, T val)
        {
            PropertyInfo propInfo = propTrack.GetCachedPropertyInfo();

            if (propInfo != null)
            {
                return(delegate(T x) { propInfo.SetValue(comp, x, null); });
            }

            FieldInfo fieldInfo = propTrack.GetCachedFieldInfo();

            if (fieldInfo != null)
            {
                return(delegate(T x) { fieldInfo.SetValue(comp, x); });
            }

            return(null);
        }
Esempio n. 4
0
        public string getValueString(System.Type type, int valueType, AMPropertyKey nextKey, bool brief)
        {
            System.Text.StringBuilder s = new System.Text.StringBuilder();

            if (AMPropertyTrack.isValueTypeNumeric(valueType))
            {
                //s+= start_val.ToString();
                s.Append(formatNumeric(val));
                if (!brief && nextKey)
                {
                    s.Append(" -> "); s.Append(formatNumeric(nextKey.val));
                }
                //if(!brief && endFrame != -1) s += " -> "+end_val.ToString();
            }
            else if (valueType == (int)AMPropertyTrack.ValueType.Bool)
            {
                s.Append(val > 0.0 ? "(true)" : "(false)");
            }
            else if (valueType == (int)AMPropertyTrack.ValueType.String)
            {
                s.AppendFormat("\"{0}\"", valString);
            }
            else if (valueType == (int)AMPropertyTrack.ValueType.Vector2)
            {
                s.Append(vect2.ToString());
                if (!brief && nextKey)
                {
                    s.Append(" -> "); s.Append(nextKey.vect2.ToString());
                }
            }
            else if (valueType == (int)AMPropertyTrack.ValueType.Vector3)
            {
                s.Append(vect3.ToString());
                if (!brief && nextKey)
                {
                    s.Append(" -> "); s.Append(nextKey.vect3.ToString());
                }
            }
            else if (valueType == (int)AMPropertyTrack.ValueType.Color)
            {
                //return null;
                s.Append(color.ToString());
                if (!brief && nextKey)
                {
                    s.Append(" -> "); s.Append(nextKey.color.ToString());
                }
            }
            else if (valueType == (int)AMPropertyTrack.ValueType.Rect)
            {
                //return null;
                s.Append(rect.ToString());
                if (!brief && nextKey)
                {
                    s.Append(" -> "); s.Append(nextKey.rect.ToString());
                }
            }
            else if (valueType == (int)AMPropertyTrack.ValueType.Vector4)
            {
                s.Append(vect4.ToString());
                if (!brief && nextKey)
                {
                    s.Append(" -> "); s.Append(nextKey.vect4.ToString());
                }
            }
            else if (valueType == (int)AMPropertyTrack.ValueType.Quaternion)
            {
                s.Append(quat.ToString());
                if (!brief && nextKey)
                {
                    s.Append(" -> "); s.Append(nextKey.quat.ToString());
                }
            }
            else if (valueType == (int)AMPropertyTrack.ValueType.Sprite)
            {
                s.AppendFormat("\"{0}\"", valObj ? valObj.name : "none");
            }
            else if (valueType == (int)AMPropertyTrack.ValueType.Enum)
            {
                s.Append(System.Enum.ToObject(type, (int)val).ToString());
            }
            return(s.ToString());
        }
Esempio n. 5
0
        public override void build(AMSequence seq, AMTrack track, int index, UnityEngine.Object target)
        {
            AMPropertyTrack propTrack = track as AMPropertyTrack;

            if (endFrame == -1 && canTween && propTrack.canTween)
            {
                return;
            }

            int valueType = propTrack.valueType;

            //get component and fill the cached method info
            Component comp = propTrack.GetTargetComp(target as GameObject);

            if (comp == null)
            {
                return;
            }

            string varName = propTrack.getMemberName();

            int frameRate = seq.take.frameRate;

            //change to use setvalue track in AMSequence
            if (!string.IsNullOrEmpty(varName))
            {
                propTrack.RefreshData(comp);

                //allow tracks with just one key
                if (!propTrack.canTween || !canTween || track.keys.Count == 1)
                {
                    seq.Insert(this, GenerateTweener(seq, propTrack, frameRate, comp));
                }
                else
                {
                    //grab end frame
                    AMPropertyKey endKey = track.keys[index + 1] as AMPropertyKey;

                    if (targetsAreEqual(valueType, endKey))
                    {
                        return;
                    }

                    Tweener tween = null;

                    PropertyInfo propInfo = propTrack.GetCachedPropertyInfo();
                    if (propInfo != null)
                    {
                        switch ((AMPropertyTrack.ValueType)valueType)
                        {
                        case AMPropertyTrack.ValueType.Integer:
                            tween = DOTween.To(new IntPlugin(), () => System.Convert.ToInt32(propInfo.GetValue(comp, null)), (x) => propInfo.SetValue(comp, x, null), System.Convert.ToInt32(endKey.val), getTime(frameRate)); break;

                        case AMPropertyTrack.ValueType.Float:
                            tween = DOTween.To(new FloatPlugin(), () => System.Convert.ToSingle(propInfo.GetValue(comp, null)), (x) => propInfo.SetValue(comp, x, null), System.Convert.ToSingle(endKey.val), getTime(frameRate)); break;

                        case AMPropertyTrack.ValueType.Double:
                            tween = DOTween.To(new DoublePlugin(), () => System.Convert.ToDouble(propInfo.GetValue(comp, null)), (x) => propInfo.SetValue(comp, x, null), endKey.val, getTime(frameRate)); break;

                        case AMPropertyTrack.ValueType.Long:
                            tween = DOTween.To(new LongPlugin(), () => System.Convert.ToInt64(propInfo.GetValue(comp, null)), (x) => propInfo.SetValue(comp, x, null), System.Convert.ToInt64(endKey.val), getTime(frameRate)); break;

                        case AMPropertyTrack.ValueType.Vector2:
                            tween = DOTween.To(new Vector2Plugin(), () => (Vector2)propInfo.GetValue(comp, null), (x) => propInfo.SetValue(comp, x, null), endKey.vect2, getTime(frameRate)); break;

                        case AMPropertyTrack.ValueType.Vector3:
                            tween = DOTween.To(new Vector3Plugin(), () => (Vector3)propInfo.GetValue(comp, null), (x) => propInfo.SetValue(comp, x, null), endKey.vect3, getTime(frameRate)); break;

                        case AMPropertyTrack.ValueType.Color:
                            tween = DOTween.To(new ColorPlugin(), () => (Color)propInfo.GetValue(comp, null), (x) => propInfo.SetValue(comp, x, null), endKey.color, getTime(frameRate)); break;

                        case AMPropertyTrack.ValueType.Rect:
                            tween = DOTween.To(new RectPlugin(), () => (Rect)propInfo.GetValue(comp, null), (x) => propInfo.SetValue(comp, x, null), endKey.rect, getTime(frameRate)); break;

                        case AMPropertyTrack.ValueType.Vector4:
                            tween = DOTween.To(new Vector4Plugin(), () => (Vector4)propInfo.GetValue(comp, null), (x) => propInfo.SetValue(comp, x, null), endKey.vect4, getTime(frameRate)); break;

                        case AMPropertyTrack.ValueType.Quaternion:
                            tween = DOTween.To(new PureQuaternionPlugin(), () => (Quaternion)propInfo.GetValue(comp, null), (x) => propInfo.SetValue(comp, x, null), endKey.quat, getTime(frameRate)); break;
                        }
                    }
                    else
                    {
                        FieldInfo fieldInfo = propTrack.GetCachedFieldInfo();
                        if (fieldInfo != null)
                        {
                            switch ((AMPropertyTrack.ValueType)valueType)
                            {
                            case AMPropertyTrack.ValueType.Integer:
                                tween = DOTween.To(new IntPlugin(), () => System.Convert.ToInt32(fieldInfo.GetValue(comp)), (x) => fieldInfo.SetValue(comp, x), System.Convert.ToInt32(endKey.val), getTime(frameRate)); break;

                            case AMPropertyTrack.ValueType.Float:
                                tween = DOTween.To(new FloatPlugin(), () => System.Convert.ToSingle(fieldInfo.GetValue(comp)), (x) => fieldInfo.SetValue(comp, x), System.Convert.ToSingle(endKey.val), getTime(frameRate)); break;

                            case AMPropertyTrack.ValueType.Double:
                                tween = DOTween.To(new DoublePlugin(), () => System.Convert.ToDouble(fieldInfo.GetValue(comp)), (x) => fieldInfo.SetValue(comp, x), endKey.val, getTime(frameRate)); break;

                            case AMPropertyTrack.ValueType.Long:
                                tween = DOTween.To(new LongPlugin(), () => System.Convert.ToInt64(fieldInfo.GetValue(comp)), (x) => fieldInfo.SetValue(comp, x), System.Convert.ToInt64(endKey.val), getTime(frameRate)); break;

                            case AMPropertyTrack.ValueType.Vector2:
                                tween = DOTween.To(new Vector2Plugin(), () => (Vector2)fieldInfo.GetValue(comp), (x) => fieldInfo.SetValue(comp, x), endKey.vect2, getTime(frameRate)); break;

                            case AMPropertyTrack.ValueType.Vector3:
                                tween = DOTween.To(new Vector3Plugin(), () => (Vector3)fieldInfo.GetValue(comp), (x) => fieldInfo.SetValue(comp, x), endKey.vect3, getTime(frameRate)); break;

                            case AMPropertyTrack.ValueType.Color:
                                tween = DOTween.To(new ColorPlugin(), () => (Color)fieldInfo.GetValue(comp), (x) => fieldInfo.SetValue(comp, x), endKey.color, getTime(frameRate)); break;

                            case AMPropertyTrack.ValueType.Rect:
                                tween = DOTween.To(new RectPlugin(), () => (Rect)fieldInfo.GetValue(comp), (x) => fieldInfo.SetValue(comp, x), endKey.rect, getTime(frameRate)); break;

                            case AMPropertyTrack.ValueType.Vector4:
                                tween = DOTween.To(new Vector4Plugin(), () => (Vector4)fieldInfo.GetValue(comp), (x) => fieldInfo.SetValue(comp, x), endKey.vect4, getTime(frameRate)); break;

                            case AMPropertyTrack.ValueType.Quaternion:
                                tween = DOTween.To(new PureQuaternionPlugin(), () => (Quaternion)fieldInfo.GetValue(comp), (x) => fieldInfo.SetValue(comp, x), endKey.quat, getTime(frameRate)); break;
                            }
                        }
                    }

                    if (tween != null)
                    {
                        if (hasCustomEase())
                        {
                            tween.SetEase(easeCurve);
                        }
                        else
                        {
                            tween.SetEase((Ease)easeType, amplitude, period);
                        }

                        seq.Insert(this, tween);
                    }
                }
            }
            else
            {
                Debug.LogError("Animator: No FieldInfo or PropertyInfo set.");
            }

            return;
        }
Esempio n. 6
0
        Tweener GenerateTweener(AMSequence seq, AMPropertyTrack propTrack, float frameRate, Component comp)
        {
            float numFrames = endFrame == -1 ? 1f : (float)(endFrame - frame);
            float time      = numFrames / frameRate;

            switch ((AMPropertyTrack.ValueType)propTrack.valueType)
            {
            case AMPropertyTrack.ValueType.Integer: {
                int _val  = System.Convert.ToInt32(val);
                var tween = DOTween.To(new AMPlugValueSet <int>(), () => _val, GenerateSetter(propTrack, comp, _val), _val, time);
                tween.plugOptions = new AMPlugValueSetOptions(seq.sequence);
                return(tween);
            }

            case AMPropertyTrack.ValueType.Float: {
                float _val  = System.Convert.ToSingle(val);
                var   tween = DOTween.To(new AMPlugValueSet <float>(), () => _val, GenerateSetter(propTrack, comp, _val), _val, time);
                tween.plugOptions = new AMPlugValueSetOptions(seq.sequence);
                return(tween);
            }

            case AMPropertyTrack.ValueType.Double: {
                var tween = DOTween.To(new AMPlugValueSet <double>(), () => val, GenerateSetter(propTrack, comp, val), val, time);
                tween.plugOptions = new AMPlugValueSetOptions(seq.sequence);
                return(tween);
            }

            case AMPropertyTrack.ValueType.Long: {
                long _val  = System.Convert.ToInt64(val);
                var  tween = DOTween.To(new AMPlugValueSet <long>(), () => _val, GenerateSetter(propTrack, comp, _val), _val, time);
                tween.plugOptions = new AMPlugValueSetOptions(seq.sequence);
                return(tween);
            }

            case AMPropertyTrack.ValueType.Vector2: {
                Vector2 _val  = vect2;
                var     tween = DOTween.To(new AMPlugValueSet <Vector2>(), () => _val, GenerateSetter(propTrack, comp, _val), _val, time);
                tween.plugOptions = new AMPlugValueSetOptions(seq.sequence);
                return(tween);
            }

            case AMPropertyTrack.ValueType.Vector3: {
                Vector3 _val  = vect3;
                var     tween = DOTween.To(new AMPlugValueSet <Vector3>(), () => _val, GenerateSetter(propTrack, comp, _val), _val, time);
                tween.plugOptions = new AMPlugValueSetOptions(seq.sequence);
                return(tween);
            }

            case AMPropertyTrack.ValueType.Color: {
                Color _val  = color;
                var   tween = DOTween.To(new AMPlugValueSet <Color>(), () => _val, GenerateSetter(propTrack, comp, _val), _val, time);
                tween.plugOptions = new AMPlugValueSetOptions(seq.sequence);
                return(tween);
            }

            case AMPropertyTrack.ValueType.Rect: {
                Rect _val  = rect;
                var  tween = DOTween.To(new AMPlugValueSet <Rect>(), () => _val, GenerateSetter(propTrack, comp, _val), _val, time);
                tween.plugOptions = new AMPlugValueSetOptions(seq.sequence);
                return(tween);
            }

            case AMPropertyTrack.ValueType.Vector4: {
                var tween = DOTween.To(new AMPlugValueSet <Vector4>(), () => vect4, GenerateSetter(propTrack, comp, vect4), vect4, time);
                tween.plugOptions = new AMPlugValueSetOptions(seq.sequence);
                return(tween);
            }

            case AMPropertyTrack.ValueType.Quaternion: {
                Quaternion _val  = quat;
                var        tween = DOTween.To(new AMPlugValueSet <Quaternion>(), () => _val, GenerateSetter(propTrack, comp, _val), _val, time);
                tween.plugOptions = new AMPlugValueSetOptions(seq.sequence);
                return(tween);
            }

            case AMPropertyTrack.ValueType.Bool: {
                bool _val  = valb;
                var  tween = DOTween.To(new AMPlugValueSet <bool>(), () => _val, GenerateSetter(propTrack, comp, _val), _val, time);
                tween.plugOptions = new AMPlugValueSetOptions(seq.sequence);
                return(tween);
            }

            case AMPropertyTrack.ValueType.String: {
                var tween = DOTween.To(new AMPlugValueSet <string>(), () => valString, GenerateSetter(propTrack, comp, valString), valString, time);
                tween.plugOptions = new AMPlugValueSetOptions(seq.sequence);
                return(tween);
            }

            case AMPropertyTrack.ValueType.Sprite: {
                var spriteRenderer = comp as SpriteRenderer;
                var _val           = valObj as Sprite;
                var tween          = DOTween.To(new AMPlugValueSet <Sprite>(), () => _val, (x) => spriteRenderer.sprite = x, _val, time);
                tween.plugOptions = new AMPlugValueSetOptions(seq.sequence);
                return(tween);
            }

            case AMPropertyTrack.ValueType.Enum: {
                System.Type infType = propTrack.GetCachedInfoType(seq.target);
                object      enumVal = infType != null?System.Enum.ToObject(infType, (int)val) : null;

                if (enumVal != null)
                {
                    var tween = DOTween.To(new AMPlugValueSet <object>(), () => enumVal, GenerateSetter(propTrack, comp, enumVal), enumVal, time);
                    tween.plugOptions = new AMPlugValueSetOptions(seq.sequence);
                    return(tween);
                }
                else
                {
                    Debug.LogError("Invalid enum value.");
                    break;
                }
            }
            }
            return(null); //no type match
        }
Esempio n. 7
0
        void OnGUI()
        {
            AMTimeline.loadSkin(ref skin, ref cachedSkinName, position);
            if (aData == null)
            {
                AMTimeline.MessageBox("Animator requires an AnimatorData component in your scene. Launch Animator to add the component.", AMTimeline.MessageBoxType.Warning);
                return;
            }
            if (!track)
            {
                return;
            }
            if (!(track.GetTarget(aData.target) as GameObject))
            {
                AMTimeline.MessageBox("Assign a GameObject to the track first.", AMTimeline.MessageBoxType.Warning);
                return;
            }
            GUILayout.Label("Select a property to add to track '" + track.name + "'" /*, styleLabel*/);
            scrollView = GUILayout.BeginScrollView(scrollView);
            if (arrComponents != null && arrComponents.Length > 0)
            {
                for (int i = 0; i < arrComponents.Length; i++)
                {
                    // skip behaviours because they may repeat properties
                    // if script is missing (unlikely but it happens in error) then catch and skip
                    try {
                        if (arrComponents[i].GetType() == typeof(Behaviour))
                        {
                            continue;
                        }
                    }
                    catch {
                        continue;
                    }
                    Component myComponent = _go.GetComponent(arrComponents[i].GetType());
                    if (myComponent == null)
                    {
                        continue;
                    }

                    // component button
                    GUILayout.BeginHorizontal(GUILayout.Width(position.width - 5f));
                    string componentName = myComponent.GetType().Name;
                    if (GUILayout.Button(componentName /*,buttonStyle*/))
                    {
                        if (selectionIndex != i)
                        {
                            selectionIndex = i;
                        }
                        else
                        {
                            selectionIndex = -1;
                        }
                    }
                    string lblToggle;
                    if (selectionIndex != i)
                    {
                        lblToggle = "+";
                    }
                    else
                    {
                        lblToggle = "-";
                    }

                    GUILayout.Label(lblToggle, GUILayout.Width(15f));

                    GUILayout.EndHorizontal();

                    if (selectionIndex == i)
                    {
                        //scrollViewComponent = GUILayout.BeginScrollView(scrollViewComponent);
                        int         numberOfProperties = 0;
                        FieldInfo[] fields             = myComponent.GetType().GetFields();
                        // loop through all fields sfields
                        foreach (FieldInfo fieldInfo in fields)
                        {
                            if (!AMPropertyTrack.isValidType(fieldInfo.FieldType))
                            {
                                // invalid type
                                continue;
                            }
                            // fields
                            GUILayout.BeginHorizontal();
                            // field button
                            if (GUILayout.Button(fieldInfo.Name, GUILayout.Width(150f)))
                            {
                                // select the field
                                processSelectProperty(myComponent, fieldInfo, null);
                            }
                            object val = fieldInfo.GetValue(myComponent);
                            GUILayout.Label(val != null ? val.ToString() : "");
                            GUILayout.EndHorizontal();
                            numberOfProperties++;
                        }
                        PropertyInfo[] properties = myComponent.GetType().GetProperties();
                        // properties
                        foreach (PropertyInfo propertyInfo in properties)
                        {
                            if (propertyInfo.PropertyType == typeof(HideFlags))
                            {
                                continue;
                            }
                            if (shouldIgnoreProperty(propertyInfo.Name))
                            {
                                continue;
                            }
                            if (propertyInfo.CanWrite && AMPropertyTrack.isValidType(propertyInfo.PropertyType))
                            {
                                object propertyValue;
                                try {
                                    propertyValue = propertyInfo.GetValue(myComponent, null);
                                }
                                catch {
                                    continue;
                                }
                                GUILayout.BeginHorizontal();
                                if (GUILayout.Button(propertyInfo.Name, GUILayout.Width(150f)))
                                {
                                    // select the property
                                    processSelectProperty(myComponent, null, propertyInfo);
                                }

                                GUILayout.Label(propertyValue.ToString());
                                GUILayout.EndHorizontal();
                                numberOfProperties++;
                            }
                        }
                        if (numberOfProperties <= 0)
                        {
                            GUILayout.Label("No usable properties found");
                        }
                        //GUILayout.EndScrollView();
                    }
                }
            }
            GUILayout.EndScrollView();
        }
Esempio n. 8
0
 void OnDisable()
 {
     window = null;
     track  = null;
 }
Esempio n. 9
0
 public static void setValues(AMPropertyTrack _track)
 {
     track = _track;
 }