Beispiel #1
0
 public bool hasSamePropertyAs(AMITarget target, AMMaterialTrack _track)
 {
     if (_track.GetTarget(target) == GetTarget(target) && _track.GetMaterial(target) == GetMaterial(target) && _track.getTrackType() == getTrackType())
     {
         return(true);
     }
     return(false);
 }
Beispiel #2
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 (!mTrack)
            {
                return;
            }

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

            if (!render)
            {
                AMTimeline.MessageBox("Assign a Renderer to the track first.", AMTimeline.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;
            AMMaterialTrack.ValueType[] shaderPropertyTypes;
            int[] shaderPropertyInds;
            GetPropertyInfos(mat, out shaderPropertyNames, out shaderPropertyDetails, out shaderPropertyTypes, out shaderPropertyInds);

            int shaderPropertyInd = -1;

            AMMaterialTrack.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] == AMMaterialTrack.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)
            {
                Undo.RecordObject(mTrack, "Material Track Property Change");

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