2 // EngineComponentStateCaptor.cs
5 // Created by Benjamin Sherratt on 04/05/2021.
6 // Copyright © 2021 SKFX Ltd. All rights reserved.
9 using System.Collections.Generic;
12 namespace JurassicTween.Internal {
13 public class TransformComponentStateCaptor : IComponentStateCaptor {
14 static string[] animationKeys = {
27 public ComponentState GetComponentState(Component component) {
28 Transform transform = (Transform)component;
30 float[] stateValues = new float[10];
31 stateValues[0] = transform.localPosition.x;
32 stateValues[1] = transform.localPosition.y;
33 stateValues[2] = transform.localPosition.z;
34 stateValues[3] = transform.localRotation.x;
35 stateValues[4] = transform.localRotation.y;
36 stateValues[5] = transform.localRotation.z;
37 stateValues[6] = transform.localRotation.w;
38 stateValues[7] = transform.localScale.x;
39 stateValues[8] = transform.localScale.y;
40 stateValues[9] = transform.localScale.z;
42 ComponentState state = new ComponentState(stateValues);
46 public ComponentStateDelta GenerateComponentStateDelta(ComponentState startState, ComponentState endState) {
47 Dictionary<string, ComponentStateDelta.Range> rangeByAnimationKey = new Dictionary<string, ComponentStateDelta.Range>();
49 for (uint i = 0; i < animationKeys.Length; ++i) {
50 if (startState.values[i] != endState.values[i]) {
51 rangeByAnimationKey[animationKeys[i]] = new ComponentStateDelta.Range(startState.values[i], endState.values[i]);
55 ComponentStateDelta delta = new ComponentStateDelta(rangeByAnimationKey);