// Please note this assumes only one component of type MouthShapeSetter on the same gameobject. public override void GatherProperties(PlayableDirector director, IPropertyCollector driver) { #if UNITY_EDITOR RhubarbSprite trackBinding = director.GetGenericBinding(this) as RhubarbSprite; if (trackBinding == null) { return; } // These field names are procedurally generated estimations based on the associated property names. // If any of the names are incorrect you will get a DrivenPropertyManager error saying it has failed to register the name. // In this case you will need to find the correct backing field name. // The suggested way of finding the field name is to: // 1. Make sure your scene is serialized to text. // 2. Search the text for the track binding component type. // 3. Look through the field names until you see one that looks correct. //driver.AddFromName<RhubarbSprite>(trackBinding.gameObject, "m_MouthShape"); #endif base.GatherProperties(director, driver); }
public override void ProcessFrame(Playable playable, FrameData info, object playerData) { m_TrackBinding = playerData as RhubarbSprite; if (m_TrackBinding == null) { return; } int inputCount = playable.GetInputCount(); float totalWeight = 0f; float greatestWeight = 0f; int currentInputs = 0; for (int i = 0; i < inputCount; i++) { float inputWeight = playable.GetInputWeight(i); ScriptPlayable <RhubarbPlayableBehaviour> inputPlayable = (ScriptPlayable <RhubarbPlayableBehaviour>)playable.GetInput(i); RhubarbPlayableBehaviour input = inputPlayable.GetBehaviour(); totalWeight += inputWeight; if (inputWeight > greatestWeight) { m_AssignedMouthShape = input.MouthShape; m_TrackBinding.MouthShape = m_AssignedMouthShape; greatestWeight = inputWeight; } if (!Mathf.Approximately(inputWeight, 0f)) { currentInputs++; } } if (currentInputs != 1 && 1f - totalWeight > greatestWeight) { m_TrackBinding.MouthShape = m_DefaultMouthShape; } }