Exemple #1
0
                private Material GetClipBoundMaterial()
                {
                    PlayableDirector   selectedDirector = TimelineEditor.inspectedDirector;
                    MaterialParamTrack track            = base.target as MaterialParamTrack;

                    if (selectedDirector != null && track != null)
                    {
                        ParentBindingTrack parentTrack = track.parent as ParentBindingTrack;

                        if (parentTrack != null)
                        {
                            Object binding = parentTrack.GetEditorBinding(selectedDirector);

                            if (binding is Material material)
                            {
                                return(material);
                            }
                        }
                        else
                        {
                            return(selectedDirector.GetGenericBinding(track) as Material);
                        }
                    }

                    return(null);
                }
Exemple #2
0
                private bool MatchesTrack(MaterialParamTrack track, MaterialProperty property)
                {
                    if (track is MaterialColorParamTrack)
                    {
                        return(property.type == MaterialProperty.PropType.Color || property.type == MaterialProperty.PropType.Vector);
                    }

                    if (track is MaterialFloatParamTrack)
                    {
                        return(property.type == MaterialProperty.PropType.Float || property.type == MaterialProperty.PropType.Range);
                    }

                    return(false);
                }
Exemple #3
0
            public override void ProcessFrame(Playable playable, FrameData info, object playerData)
            {
                if (!_parentBinding)
                {
                    _trackBinding = playerData as Material;
                }

                if (_trackBinding == null)
                {
                    return;
                }

                MaterialParamTrack track = (MaterialParamTrack)_trackAsset;

                if (_firstFrame)
                {
                    _parameterHash = GetHash(track._parameterId);
                    _defaultValue  = GetValue();
                    _firstFrame    = false;
                }

#if UNITY_EDITOR
                //Always update hash in editor
                if (Application.isEditor)
                {
                    _parameterHash = GetHash(track._parameterId);
                }
#endif

                if (_parameterHash == -1)
                {
                    return;
                }

                object value = _defaultValue;

                int numInputs = playable.GetInputCount();

                for (int i = 0; i < numInputs; i++)
                {
                    float inputWeight = playable.GetInputWeight(i);

                    if (inputWeight > 0.0f)
                    {
                        value = ApplyPlayableValue(value, playable.GetInput(i), inputWeight);
                    }
                }

                SetValue(value);
            }
Exemple #4
0
                public override void OnInspectorGUI()
                {
                    MaterialParamTrack track    = base.target as MaterialParamTrack;
                    Material           material = GetClipBoundMaterial();

                    if (material != null)
                    {
                        MaterialProperty[] properties = MaterialEditor.GetMaterialProperties(new Object[] { material });
                        List <string>      parameters = new List <string>();

                        int index = 0;

                        for (int i = 0; i < properties.Length; i++)
                        {
                            if (MatchesTrack(track, properties[i]))
                            {
                                if (properties[i].name == track._parameterId)
                                {
                                    index = parameters.Count;
                                }

                                parameters.Add(properties[i].name);
                            }
                        }

                        if (properties.Length > 0)
                        {
                            index = EditorGUILayout.Popup(kParameterLabel, index, parameters.ToArray());
                            track._parameterId = parameters[index];
                        }
                        else
                        {
                            GUI.enabled = false;
                            EditorGUILayout.TextField(kNoParametersLabel);
                            GUI.enabled = true;
                        }
                    }
                    else
                    {
                        GUI.enabled = false;
                        EditorGUILayout.TextField(kParameterLabel, track._parameterId);
                        GUI.enabled = true;
                    }
                }