public IEnumerator MultiRotationConstraint_FollowSourceObjects() { var data = SetupConstraintRig(); var constraint = data.constraint; var constrainedObject = constraint.data.constrainedObject; var sources = constraint.data.sourceObjects; // src0.w = 0, src1.w = 0 Assert.Zero(sources[0].weight); Assert.Zero(sources[1].weight); yield return(RuntimeRiggingTestFixture.YieldTwoFrames()); Assert.AreEqual(constrainedObject.rotation, data.constrainedObjectRestRotation); // Add rotation to source objects sources[0].transform.rotation *= Quaternion.AngleAxis(90, Vector3.up); sources[1].transform.rotation *= Quaternion.AngleAxis(-90, Vector3.up); // src0.w = 1, src1.w = 0 sources[0] = new WeightedTransform(sources[0].transform, 1f); constraint.data.sourceObjects = sources; yield return(RuntimeRiggingTestFixture.YieldTwoFrames()); Assert.AreEqual(constrainedObject.rotation, sources[0].transform.rotation); // src0.w = 0, src1.w = 1 sources[0] = new WeightedTransform(sources[0].transform, 0f); sources[1] = new WeightedTransform(sources[1].transform, 1f); constraint.data.sourceObjects = sources; yield return(RuntimeRiggingTestFixture.YieldTwoFrames()); Assert.AreEqual(constrainedObject.rotation, sources[1].transform.rotation); }
public IEnumerator MultiRotationConstraint_ApplyWeight() { var data = SetupConstraintRig(); var constraint = data.constraint; var constrainedObject = constraint.data.constrainedObject; var sources = constraint.data.sourceObjects; sources[0].transform.rotation *= Quaternion.AngleAxis(90, Vector3.up); sources[0] = new WeightedTransform(sources[0].transform, 1f); constraint.data.sourceObjects = sources; for (int i = 0; i <= 5; ++i) { float w = i / 5.0f; data.constraint.weight = w; yield return(null); Quaternion weightedRot = Quaternion.Lerp(data.constrainedObjectRestRotation, sources[0].transform.rotation, w); Assert.AreEqual( constrainedObject.rotation, weightedRot, String.Format("Expected constrainedObject rotation to be {0} for a weight of {1}, but was {2}", weightedRot, w, constrainedObject.rotation) ); } }
void OnEnable() { m_Weight = serializedObject.FindProperty("m_Weight"); m_SourceObjectsToggle = serializedObject.FindProperty("m_SourceObjectsGUIToggle"); m_SettingsToggle = serializedObject.FindProperty("m_SettingsGUIToggle"); var data = serializedObject.FindProperty("m_Data"); m_ConstrainedObject = data.FindPropertyRelative("m_ConstrainedObject"); m_ConstrainedPositionAxes = data.FindPropertyRelative("m_ConstrainedPositionAxes"); m_ConstrainedRotationAxes = data.FindPropertyRelative("m_ConstrainedRotationAxes"); m_SourceObjects = data.FindPropertyRelative("m_SourceObjects"); m_MaintainPositionOffset = data.FindPropertyRelative("m_MaintainPositionOffset"); m_MaintainRotationOffset = data.FindPropertyRelative("m_MaintainRotationOffset"); m_Constraint = (MultiParentConstraint)serializedObject.targetObject; m_SourceObjectsArray = m_Constraint.data.sourceObjects; var dataType = m_Constraint.data.GetType(); var fieldInfo = dataType.GetField("m_SourceObjects", BindingFlags.NonPublic | BindingFlags.Instance); var range = fieldInfo.GetCustomAttribute <RangeAttribute>(); if (m_SourceObjectsArray.Count == 0) { m_SourceObjectsArray.Add(WeightedTransform.Default(1f)); m_Constraint.data.sourceObjects = m_SourceObjectsArray; } m_ReorderableList = WeightedTransformHelper.CreateReorderableList(m_SourceObjects, ref m_SourceObjectsArray, range); m_ReorderableList.onChangedCallback = (ReorderableList reorderableList) => { m_Constraint.data.sourceObjects = (WeightedTransformArray)reorderableList.list; }; }
void OnEnable() { m_Weight = serializedObject.FindProperty("m_Weight"); m_TwistNodesToggle = serializedObject.FindProperty("m_TwistNodesGUIToggle"); var data = serializedObject.FindProperty("m_Data"); m_Source = data.FindPropertyRelative("m_Source"); m_TwistAxis = data.FindPropertyRelative("m_TwistAxis"); m_TwistNodes = data.FindPropertyRelative("m_TwistNodes"); m_Constraint = (TwistCorrection)serializedObject.targetObject; m_TwistNodesArray = m_Constraint.data.twistNodes; var dataType = m_Constraint.data.GetType(); var fieldInfo = dataType.GetField("m_TwistNodes", BindingFlags.NonPublic | BindingFlags.Instance); var range = fieldInfo.GetCustomAttribute <RangeAttribute>(); if (m_TwistNodesArray.Count == 0) { m_TwistNodesArray.Add(WeightedTransform.Default(0f)); m_Constraint.data.twistNodes = m_TwistNodesArray; } m_ReorderableList = WeightedTransformHelper.CreateReorderableList(m_TwistNodes, ref m_TwistNodesArray, range); m_ReorderableList.onChangedCallback = (ReorderableList reorderableList) => { m_Constraint.data.twistNodes = (WeightedTransformArray)reorderableList.list; }; }
public static ReorderableList CreateReorderableList(SerializedProperty property, ref WeightedTransformArray array, RangeAttribute range = null, bool draggable = true, bool displayHeader = false) { var reorderableList = new ReorderableList(array, typeof(WeightedTransform), draggable, displayHeader, true, true); var serializedObject = property.serializedObject; reorderableList.drawElementBackgroundCallback = (Rect rect, int index, bool isActive, bool isFocused) => { // Didn't find a way to register a callback before we repaint the reorderable list to toggle draggable flag. // Ideally, we'd need a callback canReorderElementCallback that would enable/disable draggable handle. reorderableList.draggable = !AnimationMode.InAnimationMode() && !Application.isPlaying; ReorderableList.defaultBehaviours.DrawElementBackground(rect, index, isActive, isFocused, reorderableList.draggable); }; reorderableList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { var element = property.FindPropertyRelative("m_Item" + index); var offset = k_ElementHeightPadding * 0.5f; rect.y += offset; rect.height = EditorGUIUtility.singleLineHeight; EditorGUI.BeginChangeCheck(); WeightedTransformOnGUI(rect, element, GUIContent.none, range); if (EditorGUI.EndChangeCheck()) { var transformProperty = element.FindPropertyRelative("transform"); var weightProperty = element.FindPropertyRelative("weight"); reorderableList.list[index] = new WeightedTransform(transformProperty.objectReferenceValue as Transform, weightProperty.floatValue);; } }; reorderableList.onCanAddCallback = (ReorderableList list) => { return(list.list.Count < WeightedTransformArray.k_MaxLength && !AnimationMode.InAnimationMode() && !Application.isPlaying); }; reorderableList.onCanRemoveCallback = (ReorderableList list) => { return(!AnimationMode.InAnimationMode() && !Application.isPlaying); }; reorderableList.onAddCallback = (ReorderableList list) => { list.list.Add(WeightedTransform.Default(1f)); }; reorderableList.elementHeight = EditorGUIUtility.singleLineHeight + k_ElementHeightPadding; if (!displayHeader) { reorderableList.headerHeight = k_NoHeaderHeight; } return(reorderableList); }
void OnEnable() { m_Weight = serializedObject.FindProperty("m_Weight"); m_SourceObjectsToggle = serializedObject.FindProperty("m_SourceObjectsGUIToggle"); m_SettingsToggle = serializedObject.FindProperty("m_SettingsGUIToggle"); var data = serializedObject.FindProperty("m_Data"); m_ConstrainedObject = data.FindPropertyRelative("m_ConstrainedObject"); m_AimAxis = data.FindPropertyRelative("m_AimAxis"); m_UpAxis = data.FindPropertyRelative("m_UpAxis"); m_WorldUpType = data.FindPropertyRelative("m_WorldUpType"); m_WorldUpAxis = data.FindPropertyRelative("m_WorldUpAxis"); m_WorldUpObject = data.FindPropertyRelative("m_WorldUpObject"); m_SourceObjects = data.FindPropertyRelative("m_SourceObjects"); m_MaintainOffset = data.FindPropertyRelative("m_MaintainOffset"); m_Offset = data.FindPropertyRelative("m_Offset"); m_ConstrainedAxes = data.FindPropertyRelative("m_ConstrainedAxes"); m_MinLimit = data.FindPropertyRelative("m_MinLimit"); m_MaxLimit = data.FindPropertyRelative("m_MaxLimit"); m_Constraint = (MultiAimConstraint)serializedObject.targetObject; m_SourceObjectsArray = m_Constraint.data.sourceObjects; var dataType = m_Constraint.data.GetType(); var fieldInfo = dataType.GetField("m_SourceObjects", BindingFlags.NonPublic | BindingFlags.Instance); var range = fieldInfo.GetCustomAttribute <RangeAttribute>(); if (m_SourceObjectsArray.Count == 0) { m_SourceObjectsArray.Add(WeightedTransform.Default(1f)); m_Constraint.data.sourceObjects = m_SourceObjectsArray; } m_ReorderableList = WeightedTransformHelper.CreateReorderableList(m_SourceObjects, ref m_SourceObjectsArray, range); m_ReorderableList.onChangedCallback = (ReorderableList reorderableList) => { Undo.RegisterCompleteObjectUndo(m_Constraint, "Edit MultiAim"); m_Constraint.data.sourceObjects = (WeightedTransformArray)reorderableList.list; if (PrefabUtility.IsPartOfPrefabInstance(m_Constraint)) { EditorUtility.SetDirty(m_Constraint); } }; Undo.undoRedoPerformed += () => { m_ReorderableList.list = m_Constraint.data.sourceObjects; }; }
void OnEnable() { m_Weight = serializedObject.FindProperty("m_Weight"); m_TwistNodesToggle = serializedObject.FindProperty("m_TwistNodesGUIToggle"); var data = serializedObject.FindProperty("m_Data"); m_Source = data.FindPropertyRelative("m_Source"); m_TwistAxis = data.FindPropertyRelative("m_TwistAxis"); m_TwistNodes = data.FindPropertyRelative("m_TwistNodes"); m_Constraint = (TwistCorrection)serializedObject.targetObject; m_TwistNodesArray = m_Constraint.data.twistNodes; var dataType = m_Constraint.data.GetType(); var fieldInfo = dataType.GetField("m_TwistNodes", BindingFlags.NonPublic | BindingFlags.Instance); var range = fieldInfo.GetCustomAttribute <RangeAttribute>(); if (m_TwistNodesArray.Count == 0) { m_TwistNodesArray.Add(WeightedTransform.Default(0f)); m_Constraint.data.twistNodes = m_TwistNodesArray; } m_ReorderableList = WeightedTransformHelper.CreateReorderableList(m_TwistNodes, ref m_TwistNodesArray, range); m_ReorderableList.onChangedCallback = (ReorderableList reorderableList) => { Undo.RegisterCompleteObjectUndo(m_Constraint, "Edit TwistCorrection"); m_Constraint.data.twistNodes = (WeightedTransformArray)reorderableList.list; if (PrefabUtility.IsPartOfPrefabInstance(m_Constraint)) { EditorUtility.SetDirty(m_Constraint); } }; Undo.undoRedoPerformed += () => { m_ReorderableList.list = m_Constraint.data.twistNodes; }; }