public void ApplyValue(MaterialTrack.ValueType valueType, string prop, int propId, Material mat)
        {
            switch (valueType)
            {
            case MaterialTrack.ValueType.Float:
            case MaterialTrack.ValueType.Range:
                mat.SetFloat(propId, val);
                break;

            case MaterialTrack.ValueType.Vector:
                mat.SetVector(propId, vector);
                break;

            case MaterialTrack.ValueType.Color:
                mat.SetColor(propId, color);
                break;

            case MaterialTrack.ValueType.TexEnv:
                mat.SetTexture(propId, texture);
                break;

            case MaterialTrack.ValueType.TexOfs:
                mat.SetTextureOffset(prop, texOfs);
                break;

            case MaterialTrack.ValueType.TexScale:
                mat.SetTextureScale(prop, texScale);
                break;
            }
        }
        public bool targetsAreEqual(MaterialTrack.ValueType valueType, MaterialKey nextKey)
        {
            if (nextKey != null)
            {
                if (valueType == MaterialTrack.ValueType.Float || valueType == MaterialTrack.ValueType.Range)
                {
                    return(val == nextKey.val);
                }
                if (valueType == MaterialTrack.ValueType.Vector)
                {
                    return(vector == nextKey.vector);
                }
                if (valueType == MaterialTrack.ValueType.Color)
                {
                    return(color == nextKey.color);
                }
                if (valueType == MaterialTrack.ValueType.TexOfs)
                {
                    return(texOfs == nextKey.texOfs);
                }
                if (valueType == MaterialTrack.ValueType.TexScale)
                {
                    return(texScale == nextKey.texScale);
                }
            }

            return(true);
        }
        public static void ApplyValueLerp(MaterialTrack.ValueType valueType, string prop, int propId, Material mat, MaterialKey fromKey, MaterialKey toKey, float t)
        {
            switch (valueType)
            {
            case MaterialTrack.ValueType.Float:
            case MaterialTrack.ValueType.Range:
                mat.SetFloat(propId, Mathf.Lerp(fromKey.val, toKey.val, t));
                break;

            case MaterialTrack.ValueType.Vector:
                mat.SetVector(propId, Vector4.Lerp(fromKey.vector, toKey.vector, t));
                break;

            case MaterialTrack.ValueType.Color:
                mat.SetColor(propId, Color.Lerp(fromKey.color, toKey.color, t));
                break;

            case MaterialTrack.ValueType.TexOfs:
                mat.SetTextureOffset(prop, Vector2.Lerp(fromKey.texOfs, toKey.texOfs, t));
                break;

            case MaterialTrack.ValueType.TexScale:
                mat.SetTextureScale(prop, Vector2.Lerp(fromKey.texScale, toKey.texScale, t));
                break;
            }
        }
        public string getValueString(MaterialTrack.ValueType valueType, MaterialKey nextKey, bool brief)
        {
            System.Text.StringBuilder s = new System.Text.StringBuilder();

            switch (valueType)
            {
            case MaterialTrack.ValueType.Float:
            case MaterialTrack.ValueType.Range:
                s.Append(formatNumeric(val));
                if (!brief && nextKey != null)
                {
                    s.Append(" -> "); s.Append(formatNumeric(nextKey.val));
                }
                break;

            case MaterialTrack.ValueType.Vector:
                s.Append(_val4.ToString());
                if (!brief && nextKey != null)
                {
                    s.Append(" -> "); s.Append(nextKey._val4.ToString());
                }
                break;

            case MaterialTrack.ValueType.Color:
                s.Append(color.ToString());
                if (!brief && nextKey != null)
                {
                    s.Append(" -> "); s.Append(nextKey.color.ToString());
                }
                break;

            case MaterialTrack.ValueType.TexEnv:
                s.Append(texture ? texture.name : "None");
                break;

            case MaterialTrack.ValueType.TexOfs:
                s.Append(texOfs.ToString());
                if (!brief && nextKey != null)
                {
                    s.Append(" -> "); s.Append(nextKey.texOfs.ToString());
                }
                break;

            case MaterialTrack.ValueType.TexScale:
                s.Append(texScale.ToString());
                if (!brief && nextKey != null)
                {
                    s.Append(" -> "); s.Append(nextKey.texScale.ToString());
                }
                break;
            }

            return(s.ToString());
        }
Example #5
0
        void GetPropertyInfos(Material mat, out string[] names, out string[] details, out MaterialTrack.ValueType[] types, out int[] inds)
        {
            Shader shader = mat.shader;
            int    count  = ShaderUtil.GetPropertyCount(shader);

            List <string> _names = new List <string>();
            List <MaterialTrack.ValueType> _types = new List <MaterialTrack.ValueType>();

            for (int i = 0; i < count; i++)
            {
                var name = ShaderUtil.GetPropertyName(shader, i);
                var type = ShaderUtil.GetPropertyType(shader, i);

                _names.Add(name);
                _types.Add((MaterialTrack.ValueType)type);

                if (type == ShaderUtil.ShaderPropertyType.TexEnv)
                {
                    _names.Add(name); _types.Add(MaterialTrack.ValueType.TexOfs);
                    _names.Add(name); _types.Add(MaterialTrack.ValueType.TexScale);
                }
            }

            count = _names.Count;

            names   = new string[count];
            details = new string[count];
            types   = new MaterialTrack.ValueType[count];
            inds    = new int[count];

            for (int i = 0; i < count; i++)
            {
                names[i] = _names[i];
                types[i] = _types[i];

                switch (types[i])
                {
                case MaterialTrack.ValueType.TexOfs:
                    details[i] = string.Format("{0} Offset", names[i]);
                    break;

                case MaterialTrack.ValueType.TexScale:
                    details[i] = string.Format("{0} Scale", names[i]);
                    break;

                default:
                    details[i] = names[i];
                    break;
                }

                inds[i] = i;
            }
        }
Example #6
0
        public static void ApplyValuePath(MaterialTrack.ValueType valueType, string prop, int propId, Material mat, MaterialKey key, float t)
        {
            float finalT;

            if (key.hasCustomEase())
            {
                finalT = Utility.EaseCustom(0.0f, 1.0f, t, key.easeCurve);
            }
            else
            {
                var ease = Utility.GetEasingFunction(key.easeType);
                finalT = ease(t, 1f, key.amplitude, key.period);
                if (float.IsNaN(finalT))  //this really shouldn't happen...
                {
                    key.ApplyValue(valueType, prop, propId, mat);
                    return;
                }
            }

            var pt = key.path.GetPoint(finalT);

            var val = key.GetValueFromPathPoint(valueType, pt);

            if (val != null)
            {
                switch (valueType)
                {
                case MaterialTrack.ValueType.Float:
                case MaterialTrack.ValueType.Range:
                    mat.SetFloat(propId, (float)val);
                    break;

                case MaterialTrack.ValueType.Vector:
                    mat.SetVector(propId, (Vector4)val);
                    break;

                case MaterialTrack.ValueType.Color:
                    mat.SetColor(propId, (Color)val);
                    break;

                case MaterialTrack.ValueType.TexOfs:
                    mat.SetTextureOffset(prop, (Vector2)val);
                    break;

                case MaterialTrack.ValueType.TexScale:
                    mat.SetTextureScale(prop, (Vector2)val);
                    break;
                }
            }
        }
Example #7
0
        public object GetValueFromPathPoint(MaterialTrack.ValueType valueType, TweenPlugPathPoint pt)
        {
            switch (valueType)
            {
            case MaterialTrack.ValueType.Color:
                return(pt.valueColor);

            case MaterialTrack.ValueType.Vector:
                return(pt.valueVector4);

            case MaterialTrack.ValueType.Float:
            case MaterialTrack.ValueType.Range:
                return(pt.valueFloat);

            case MaterialTrack.ValueType.TexOfs:
            case MaterialTrack.ValueType.TexScale:
                return(pt.valueVector2);
            }

            return(null);
        }
 public object getValue(MaterialTrack.ValueType valueType)
 {
     if (valueType == MaterialTrack.ValueType.TexEnv)
     {
         return(texture ? texture : null);
     }
     if (valueType == MaterialTrack.ValueType.Vector)
     {
         return(vector);
     }
     if (valueType == MaterialTrack.ValueType.Color)
     {
         return(color);
     }
     if (valueType == MaterialTrack.ValueType.TexOfs)
     {
         return(texOfs);
     }
     if (valueType == MaterialTrack.ValueType.TexScale)
     {
         return(texScale);
     }
     return(val);
 }
Example #9
0
        void OnGUI()
        {
            TimelineWindow.loadSkin(ref skin, ref cachedSkinName, position);
            if (aData == null)
            {
                TimelineWindow.MessageBox("Animator requires an Animate component in your scene. Launch Animator to add the component.", TimelineWindow.MessageBoxType.Warning);
                return;
            }

            if (mTrack == null)
            {
                return;
            }

            Renderer render = mTrack.GetTarget(aData.target) as Renderer;

            if (!render)
            {
                TimelineWindow.MessageBox("Assign a Renderer to the track first.", TimelineWindow.MessageBoxType.Warning);
                return;
            }

            //select material
            Material[] mats = render.sharedMaterials;

            string[] matNames = new string[mats.Length];
            int[]    matInds  = new int[mats.Length];
            for (int i = 0; i < mats.Length; i++)
            {
                matNames[i] = mats[i].name;
                matInds[i]  = i;
            }

            //grab track info
            int      matInd         = Mathf.Clamp(mTrack.materialIndex, 0, mats.Length - 1);
            Material matOverride    = mTrack.materialOverride;
            string   shaderProperty = mTrack.property;

            //material select
            matInd = EditorGUILayout.IntPopup("Material", matInd, matNames, matInds);

            //material override select
            matOverride = EditorGUILayout.ObjectField("Material Override", matOverride, typeof(Material), false) as Material;

            Material mat = matOverride ? matOverride : mats[matInd];

            //grab material info
            string[] shaderPropertyNames, shaderPropertyDetails;
            MaterialTrack.ValueType[] shaderPropertyTypes;
            int[] shaderPropertyInds;
            GetPropertyInfos(mat, out shaderPropertyNames, out shaderPropertyDetails, out shaderPropertyTypes, out shaderPropertyInds);

            int shaderPropertyInd = -1;

            MaterialTrack.ValueType shaderPropertyType = mTrack.propertyType;

            for (int i = 0; i < shaderPropertyNames.Length; i++)
            {
                if (shaderProperty == shaderPropertyNames[i])
                {
                    shaderPropertyInd = i;

                    //special case for texture offset and scale
                    if (shaderPropertyTypes[i] == MaterialTrack.ValueType.TexEnv && i + 2 < shaderPropertyNames.Length)
                    {
                        if (shaderPropertyType == shaderPropertyTypes[i + 1])
                        {
                            shaderPropertyInd += 1;
                        }
                        else if (shaderPropertyType == shaderPropertyTypes[i + 2])
                        {
                            shaderPropertyInd += 2;
                        }
                    }
                    break;
                }
            }

            if (shaderPropertyInd == -1)
            {
                shaderPropertyInd = 0;
            }

            EditorUtility.DrawSeparator();

            //shader property select
            shaderPropertyInd = EditorGUILayout.IntPopup("Property", shaderPropertyInd, shaderPropertyDetails, shaderPropertyInds);

            shaderProperty     = shaderPropertyNames[shaderPropertyInd];
            shaderPropertyType = shaderPropertyTypes[shaderPropertyInd];

            //check for change
            if (mTrack.materialIndex != matInd || mTrack.materialOverride != matOverride || mTrack.property != shaderProperty || mTrack.propertyType != shaderPropertyType)
            {
                aData.RegisterTakesUndo("Material Track Property Change", false);

                mTrack.materialIndex    = matInd;
                mTrack.materialOverride = matOverride;
                mTrack.property         = shaderProperty;
                mTrack.propertyType     = shaderPropertyType;
            }
        }
Example #10
0
        void OnGUI()
        {
            TimelineWindow.loadSkin(ref skin, ref cachedSkinName, position);
            if (aData == null)
            {
                TimelineWindow.MessageBox("Animator requires an Animate component in your scene. Launch Animator to add the component.", TimelineWindow.MessageBoxType.Warning);
                return;
            }

            if (mTrack == null)
            {
                return;
            }

            Renderer render = mTrack.GetTarget(aData.target) as Renderer;

            if (!render)
            {
                TimelineWindow.MessageBox("Assign a Renderer to the track first.", TimelineWindow.MessageBoxType.Warning);
                return;
            }

            //select material
            Material[] mats = render.sharedMaterials;

            string[] matNames = new string[mats.Length];
            int[]    matInds  = new int[mats.Length];
            for (int i = 0; i < mats.Length; i++)
            {
                matNames[i] = mats[i].name;
                matInds[i]  = i;
            }

            //grab track info
            int      matInd         = Mathf.Clamp(mTrack.materialIndex, 0, mats.Length - 1);
            Material matOverride    = mTrack.materialOverride;
            string   shaderProperty = mTrack.property;

            //material select
            matInd = EditorGUILayout.IntPopup("Material", matInd, matNames, matInds);

            //material override select
            matOverride = EditorGUILayout.ObjectField("Material Override", matOverride, typeof(Material), false) as Material;

            Material mat = matOverride ? matOverride : mats[matInd];

            //grab material info
            string[] shaderPropertyNames, shaderPropertyDetails;
            MaterialTrack.ValueType[] shaderPropertyTypes;
            int[] shaderPropertyInds;
            GetPropertyInfos(mat, out shaderPropertyNames, out shaderPropertyDetails, out shaderPropertyTypes, out shaderPropertyInds);

            int shaderPropertyInd = -1;

            MaterialTrack.ValueType shaderPropertyType = mTrack.propertyType;

            for (int i = 0; i < shaderPropertyNames.Length; i++)
            {
                if (shaderProperty == shaderPropertyNames[i])
                {
                    shaderPropertyInd = i;

                    //special case for texture offset and scale
                    if (shaderPropertyTypes[i] == MaterialTrack.ValueType.TexEnv && i + 2 < shaderPropertyNames.Length)
                    {
                        if (shaderPropertyType == shaderPropertyTypes[i + 1])
                        {
                            shaderPropertyInd += 1;
                        }
                        else if (shaderPropertyType == shaderPropertyTypes[i + 2])
                        {
                            shaderPropertyInd += 2;
                        }
                    }
                    break;
                }
            }

            if (shaderPropertyInd == -1)
            {
                shaderPropertyInd = 0;
            }

            EditorUtility.DrawSeparator();

            //shader property select
            shaderPropertyInd = EditorGUILayout.IntPopup("Property", shaderPropertyInd, shaderPropertyDetails, shaderPropertyInds);

            shaderProperty     = shaderPropertyNames[shaderPropertyInd];
            shaderPropertyType = shaderPropertyTypes[shaderPropertyInd];

            //check for change
            if (mTrack.materialIndex != matInd || mTrack.materialOverride != matOverride || mTrack.property != shaderProperty || mTrack.propertyType != shaderPropertyType)
            {
                bool applyChanges = true;
                bool deleteKeys   = false;

                //delete if changing type
                if (mTrack.keys.Count > 0 && !MaterialTrack.IsValueTypeCompatible(mTrack.propertyType, shaderPropertyType))
                {
                    if (UnityEditor.EditorUtility.DisplayDialog("Data Will Be Lost", "You will lose all of the keyframes on track '" + mTrack.name + "' if you continue.", "Continue Anway", "Cancel"))
                    {
                        deleteKeys = true;
                    }
                    else
                    {
                        applyChanges = false;
                    }
                }

                if (applyChanges)
                {
                    aData.RegisterTakesUndo("Material Track Property Change");

                    mTrack.materialIndex    = matInd;
                    mTrack.materialOverride = matOverride;
                    mTrack.property         = shaderProperty;
                    mTrack.propertyType     = shaderPropertyType;

                    if (deleteKeys)
                    {
                        mTrack.keys = new List <Key>();
                    }

                    aData.RecordTakesChanged();
                }
            }
        }