Animation.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Runtime.InteropServices;
  6. using System.Text;
  7. namespace BansheeEngine
  8. {
  9. /** @addtogroup Animation
  10. * @{
  11. */
  12. /// <summary>
  13. /// Determines how an animation clip behaves when it reaches the end.
  14. /// </summary>
  15. public enum AnimWrapMode // Note: Must match C++ enum AnimWrapMode
  16. {
  17. /// <summary>
  18. /// Loop around to the beginning/end when the last/first frame is reached.
  19. /// </summary>
  20. Loop,
  21. /// <summary>
  22. /// Clamp to end/beginning, keeping the last/first frame active.
  23. /// </summary>
  24. Clamp
  25. }
  26. /// <summary>
  27. /// Represents an animation clip used in 1D blending. Each clip has a position on the number line.
  28. /// </summary>
  29. public class BlendClipInfo
  30. {
  31. public AnimationClip clip;
  32. public float position;
  33. }
  34. /// <summary>
  35. /// Defines a 1D blend where two animation clips are blended between each other using linear interpolation.
  36. /// </summary>
  37. public class Blend1DInfo
  38. {
  39. public BlendClipInfo[] clips;
  40. }
  41. /// <summary>
  42. /// Defines a 2D blend where two animation clips are blended between each other using bilinear interpolation.
  43. /// </summary>
  44. public class Blend2DInfo
  45. {
  46. public AnimationClip topLeftClip;
  47. public AnimationClip topRightClip;
  48. public AnimationClip botLeftClip;
  49. public AnimationClip botRightClip;
  50. }
  51. /// <summary>
  52. /// Contains information about a currently playing animation clip.
  53. /// </summary>
  54. [StructLayout(LayoutKind.Sequential), SerializeObject]
  55. public struct AnimationClipState // Note: Must match C++ struct AnimationClipState
  56. {
  57. /// <summary>
  58. /// Layer the clip is playing on. Multiple clips can be played simulatenously on different layers.
  59. /// </summary>
  60. public int layer;
  61. /// <summary>
  62. /// Current time the animation is playing from.
  63. /// </summary>
  64. public float time;
  65. /// <summary>
  66. /// Speed at which the animation is playing.
  67. /// </summary>
  68. public float speed;
  69. /// <summary>
  70. /// Determines how much of an influence does the clip have on the final pose.
  71. /// </summary>
  72. public float weight;
  73. /// <summary>
  74. /// Determines what happens to other animation clips when a new clip starts playing.
  75. /// </summary>
  76. public AnimWrapMode wrapMode;
  77. /// <summary>
  78. /// Initializes the state with default values.
  79. /// </summary>
  80. public void InitDefault()
  81. {
  82. speed = 1.0f;
  83. weight = 1.0f;
  84. wrapMode = AnimWrapMode.Loop;
  85. }
  86. }
  87. /// <summary>
  88. /// Handles animation playback. Takes one or multiple animation clips as input and evaluates them every animation update
  89. /// tick depending on set properties.The evaluated data is used by the core thread for skeletal animation, by the sim
  90. /// thread for updating attached scene objects and bones (if skeleton is attached), or the data is made available for
  91. /// manual queries in the case of generic animation.
  92. /// </summary>
  93. public class Animation : Component
  94. {
  95. private NativeAnimation _native;
  96. [SerializeField] private SerializableData serializableData = new SerializableData();
  97. private FloatCurvePropertyInfo[] floatProperties;
  98. private AnimationClip floatPropertyClip;
  99. /// <summary>
  100. /// Contains mapping for a suffix used by property paths used for curve identifiers, to their index and type.
  101. /// </summary>
  102. internal static readonly Dictionary<string, PropertySuffixInfo> PropertySuffixInfos = new Dictionary
  103. <string, PropertySuffixInfo>
  104. {
  105. {".x", new PropertySuffixInfo(0, true)},
  106. {".y", new PropertySuffixInfo(1, true)},
  107. {".z", new PropertySuffixInfo(2, true)},
  108. {".w", new PropertySuffixInfo(3, true)},
  109. {".r", new PropertySuffixInfo(0, false)},
  110. {".g", new PropertySuffixInfo(1, false)},
  111. {".b", new PropertySuffixInfo(2, false)},
  112. {".a", new PropertySuffixInfo(3, false)}
  113. };
  114. /// <summary>
  115. /// Returns the non-component version of Animation that is wrapped by this component.
  116. /// </summary>
  117. internal NativeAnimation Native
  118. {
  119. get { return _native; }
  120. }
  121. /// <summary>
  122. /// Determines the default clip to play as soon as the component is enabled. If more control over playing clips is
  123. /// needed use the <see cref="Play"/>, <see cref="Blend1D"/>, <see cref="Blend2D"/> and <see cref="CrossFade"/>
  124. /// methods to queue clips for playback manually, and <see cref="SetState"/> method for modify their states
  125. /// individually.
  126. /// </summary>
  127. public AnimationClip DefaultClip
  128. {
  129. get { return serializableData.defaultClip; }
  130. set
  131. {
  132. serializableData.defaultClip = value;
  133. if (value != null && _native != null)
  134. _native.Play(value);
  135. }
  136. }
  137. /// <summary>
  138. /// Determines the wrap mode for all active animations. Wrap mode determines what happens when animation reaches the
  139. /// first or last frame.
  140. /// <see cref="AnimWrapMode"/>
  141. /// </summary>
  142. public AnimWrapMode WrapMode
  143. {
  144. get { return serializableData.wrapMode; }
  145. set
  146. {
  147. serializableData.wrapMode = value;
  148. if (_native != null)
  149. _native.WrapMode = value;
  150. }
  151. }
  152. /// <summary>
  153. /// Determines the speed for all animations. The default value is 1.0f. Use negative values to play-back in reverse.
  154. /// </summary>
  155. public float Speed
  156. {
  157. get { return serializableData.speed; }
  158. set
  159. {
  160. serializableData.speed = value;
  161. if (_native != null)
  162. _native.Speed = value;
  163. }
  164. }
  165. /// <summary>
  166. /// Checks if any animation clips are currently playing.
  167. /// </summary>
  168. public bool IsPlaying
  169. {
  170. get
  171. {
  172. if (_native != null)
  173. return _native.IsPlaying();
  174. return false;
  175. }
  176. }
  177. /// <summary>
  178. /// Plays the specified animation clip.
  179. /// </summary>
  180. /// <param name="clip">Clip to play.</param>
  181. public void Play(AnimationClip clip)
  182. {
  183. if (_native != null)
  184. _native.Play(clip);
  185. }
  186. /// <summary>
  187. /// Plays the specified animation clip on top of the animation currently playing in the main layer. Multiple such
  188. /// clips can be playing at once, as long as you ensure each is given its own layer. Each animation can also have a
  189. /// weight that determines how much it influences the main animation.
  190. /// </summary>
  191. /// <param name="clip">Clip to additively blend. Must contain additive animation curves.</param>
  192. /// <param name="weight">Determines how much of an effect will the blended animation have on the final output.
  193. /// In range [0, 1].</param>
  194. /// <param name="fadeLength">Applies the blend over a specified time period, increasing the weight as the time
  195. /// passes. Set to zero to blend immediately. In seconds.</param>
  196. /// <param name="layer">Layer to play the clip in. Multiple additive clips can be playing at once in separate layers
  197. /// and each layer has its own weight.</param>
  198. public void BlendAdditive(AnimationClip clip, float weight, float fadeLength, int layer)
  199. {
  200. if (_native != null)
  201. _native.BlendAdditive(clip, weight, fadeLength, layer);
  202. }
  203. /// <summary>
  204. /// Blends multiple animation clips between each other using linear interpolation. Unlike normal animations these
  205. /// animations are not advanced with the progress of time, and is instead expected the user manually changes the
  206. /// <see cref="t"/> parameter.
  207. /// </summary>
  208. /// <param name="info">Information about the clips to blend. Clip positions must be sorted from lowest to highest.
  209. /// </param>
  210. /// <param name="t">Parameter that controls the blending, in range [0, 1]. t = 0 means left animation has full
  211. /// influence, t = 1 means right animation has full influence.</param>
  212. public void Blend1D(Blend1DInfo info, float t)
  213. {
  214. if (_native != null)
  215. _native.Blend1D(info, t);
  216. }
  217. /// <summary>
  218. /// Blend four animation clips between each other using bilinear interpolation. Unlike normal animations these
  219. /// animations are not advanced with the progress of time, and is instead expected the user manually changes the
  220. /// <see cref="t"/> parameter.
  221. /// </summary>
  222. /// <param name="info">Information about the clips to blend.</param>
  223. /// <param name="t">Parameter that controls the blending, in range [(0, 0), (1, 1)]. t = (0, 0) means top left
  224. /// animation has full influence, t = (0, 1) means top right animation has full influence,
  225. /// t = (1, 0) means bottom left animation has full influence, t = (1, 1) means bottom right
  226. /// animation has full influence.
  227. /// </param>
  228. public void Blend2D(Blend2DInfo info, Vector2 t)
  229. {
  230. if (_native != null)
  231. _native.Blend2D(info, t);
  232. }
  233. /// <summary>
  234. /// Fades the specified animation clip in, while fading other playing animation out, over the specified time period.
  235. /// </summary>
  236. /// <param name="clip">Clip to fade in.</param>
  237. /// <param name="fadeLength">Determines the time period over which the fade occurs. In seconds.</param>
  238. public void CrossFade(AnimationClip clip, float fadeLength)
  239. {
  240. if (_native != null)
  241. _native.CrossFade(clip, fadeLength);
  242. }
  243. /// <summary>
  244. /// Stops playing all animations on the provided layer.
  245. /// </summary>
  246. /// <param name="layer">Layer on which to stop animations on.</param>
  247. public void Stop(int layer)
  248. {
  249. if (_native != null)
  250. _native.Stop(layer);
  251. }
  252. /// <summary>
  253. /// Stops playing all animations.
  254. /// </summary>
  255. public void StopAll()
  256. {
  257. if (_native != null)
  258. _native.StopAll();
  259. }
  260. /// <summary>
  261. /// Retrieves detailed information about a currently playing animation clip.
  262. /// </summary>
  263. /// <param name="clip">Clip to retrieve the information for.</param>
  264. /// <param name="state">Animation clip state containing the requested information. Only valid if the method returns
  265. /// true.</param>
  266. /// <returns>True if the state was found (animation clip is playing), false otherwise.</returns>
  267. public bool GetState(AnimationClip clip, out AnimationClipState state)
  268. {
  269. if (_native != null)
  270. return _native.GetState(clip, out state);
  271. state = new AnimationClipState();
  272. return false;
  273. }
  274. /// <summary>
  275. /// Searches the scene object hierarchy to find a property at the given path.
  276. /// </summary>
  277. /// <param name="root">Root scene object to which the path is relative to.</param>
  278. /// <param name="path">Path to the property, where each element of the path is separated with "/".
  279. ///
  280. /// Path elements prefixed with "!" signify names of child scene objects (first one relative to
  281. /// <paramref name="root"/>. Name of the root element should not be included in the path.
  282. ///
  283. /// Path element prefixed with ":" signify names of components. If a path doesn't have a
  284. /// component element, it is assumed the field is relative to the scene object itself (only
  285. /// "Translation", "Rotation" and "Scale fields are supported in such case). Only one component
  286. /// path element per path is allowed.
  287. ///
  288. /// Path entries with no prefix are considered regular script object fields. Each path must have
  289. /// at least one such entry. Last field entry can optionally have a suffix separated from the
  290. /// path name with ".". This suffix is not parsed internally, but will be returned as
  291. /// <paramref name="suffix"/>.
  292. ///
  293. /// Path examples:
  294. /// :MyComponent/myInt (path to myInt variable on a component attached to this object)
  295. /// !childSO/:MyComponent/myInt (path to myInt variable on a child scene object)
  296. /// !childSO/Translation (path to the scene object translation)
  297. /// :MyComponent/myVector.z (path to the z component of myVector on this object)
  298. /// </param>
  299. /// <param name="suffix">Suffix of the last field entry, if it has any. Contains the suffix separator ".".</param>
  300. /// <returns>If found, property object you can use for setting and getting the value from the property, otherwise
  301. /// null.</returns>
  302. internal static SerializableProperty FindProperty(SceneObject root, string path, out string suffix)
  303. {
  304. suffix = null;
  305. if (string.IsNullOrEmpty(path) || root == null)
  306. return null;
  307. string trimmedPath = path.Trim('/');
  308. string[] entries = trimmedPath.Split('/');
  309. // Find scene object referenced by the path
  310. SceneObject so = root;
  311. int pathIdx = 0;
  312. for (; pathIdx < entries.Length; pathIdx++)
  313. {
  314. string entry = entries[pathIdx];
  315. if (string.IsNullOrEmpty(entry))
  316. continue;
  317. // Not a scene object, break
  318. if (entry[0] != '!')
  319. break;
  320. string childName = entry.Substring(1, entry.Length - 1);
  321. so = so.FindChild(childName);
  322. if (so == null)
  323. break;
  324. }
  325. // Child scene object couldn't be found
  326. if (so == null)
  327. return null;
  328. // Path too short, no field entry
  329. if (pathIdx >= entries.Length)
  330. return null;
  331. // Check if path is referencing a component, and if so find it
  332. Component component = null;
  333. {
  334. string entry = entries[pathIdx];
  335. if (entry[0] == ':')
  336. {
  337. string componentName = entry.Substring(1, entry.Length - 1);
  338. Component[] components = so.GetComponents();
  339. component = Array.Find(components, x => x.GetType().Name == componentName);
  340. // Cannot find component with specified type
  341. if (component == null)
  342. return null;
  343. }
  344. }
  345. // Look for a field within a component
  346. if (component != null)
  347. {
  348. pathIdx++;
  349. if (pathIdx >= entries.Length)
  350. return null;
  351. SerializableObject componentObj = new SerializableObject(component);
  352. StringBuilder pathBuilder = new StringBuilder();
  353. for (; pathIdx < entries.Length - 1; pathIdx++)
  354. pathBuilder.Append(entries[pathIdx] + "/");
  355. // Check last path entry for suffix and remove it
  356. int suffixIdx = entries[pathIdx].LastIndexOf(".");
  357. if (suffixIdx != -1)
  358. {
  359. string entryNoSuffix = entries[pathIdx].Substring(0, suffixIdx);
  360. suffix = entries[pathIdx].Substring(suffixIdx, entries[pathIdx].Length - suffixIdx);
  361. pathBuilder.Append(entryNoSuffix);
  362. }
  363. else
  364. pathBuilder.Append(entries[pathIdx]);
  365. return componentObj.FindProperty(pathBuilder.ToString());
  366. }
  367. else // Field is one of the builtin ones on the SceneObject itself
  368. {
  369. if ((pathIdx + 1) < entries.Length)
  370. return null;
  371. string entry = entries[pathIdx];
  372. if (entry == "Position")
  373. {
  374. SerializableProperty property = new SerializableProperty(
  375. SerializableProperty.FieldType.Vector3,
  376. typeof(Vector3),
  377. () => so.LocalPosition,
  378. (x) => so.LocalPosition = (Vector3) x);
  379. return property;
  380. }
  381. else if (entry == "Rotation")
  382. {
  383. SerializableProperty property = new SerializableProperty(
  384. SerializableProperty.FieldType.Vector3,
  385. typeof(Vector3),
  386. () => so.LocalRotation.ToEuler(),
  387. (x) => so.LocalRotation = Quaternion.FromEuler((Vector3) x));
  388. return property;
  389. }
  390. else if (entry == "Scale")
  391. {
  392. SerializableProperty property = new SerializableProperty(
  393. SerializableProperty.FieldType.Vector3,
  394. typeof(Vector3),
  395. () => so.LocalScale,
  396. (x) => so.LocalScale = (Vector3) x);
  397. return property;
  398. }
  399. return null;
  400. }
  401. }
  402. /// <summary>
  403. /// Changes the state of a playing animation clip. If animation clip is not currently playing the state change is
  404. /// ignored.
  405. /// </summary>
  406. /// <param name="clip">Clip to change the state for.</param>
  407. /// <param name="state">New state of the animation (e.g. changing the time for seeking).</param>
  408. public void SetState(AnimationClip clip, AnimationClipState state)
  409. {
  410. if (_native != null)
  411. _native.SetState(clip, state);
  412. }
  413. private void OnUpdate()
  414. {
  415. if (_native == null)
  416. return;
  417. AnimationClip primaryClip = _native.GetClip(0);
  418. if (primaryClip != floatPropertyClip)
  419. {
  420. RebuildFloatProperties(primaryClip);
  421. floatPropertyClip = primaryClip;
  422. }
  423. // Apply values from generic float curves
  424. foreach (var entry in floatProperties)
  425. {
  426. float curveValue;
  427. if (_native.GetGenericCurveValue(entry.curveIdx, out curveValue))
  428. entry.setter(curveValue);
  429. }
  430. }
  431. private void OnEnable()
  432. {
  433. RestoreNative();
  434. }
  435. private void OnDisable()
  436. {
  437. DestroyNative();
  438. }
  439. private void OnDestroy()
  440. {
  441. DestroyNative();
  442. }
  443. /// <summary>
  444. /// Creates the internal representation of the animation and restores the values saved by the component.
  445. /// </summary>
  446. private void RestoreNative()
  447. {
  448. if (_native != null)
  449. _native.Destroy();
  450. _native = new NativeAnimation();
  451. _native.OnEventTriggered += EventTriggered;
  452. // Restore saved values after reset
  453. _native.WrapMode = serializableData.wrapMode;
  454. _native.Speed = serializableData.speed;
  455. if (serializableData.defaultClip != null)
  456. _native.Play(serializableData.defaultClip);
  457. Renderable renderable = SceneObject.GetComponent<Renderable>();
  458. if (renderable == null)
  459. return;
  460. NativeRenderable nativeRenderable = renderable.Native;
  461. if (nativeRenderable != null)
  462. nativeRenderable.Animation = _native;
  463. }
  464. /// <summary>
  465. /// Destroys the internal animation representation.
  466. /// </summary>
  467. private void DestroyNative()
  468. {
  469. Renderable renderableComponent = SceneObject.GetComponent<Renderable>();
  470. if (renderableComponent != null)
  471. {
  472. NativeRenderable renderable = renderableComponent.Native;
  473. if (renderable != null)
  474. renderable.Animation = null;
  475. }
  476. if (_native != null)
  477. {
  478. _native.Destroy();
  479. _native = null;
  480. }
  481. }
  482. /// <summary>
  483. /// Builds a list of properties that will be animated using float animation curves.
  484. /// </summary>
  485. /// <param name="clip">Clip to retrieve the float animation curves from.</param>
  486. private void RebuildFloatProperties(AnimationClip clip)
  487. {
  488. if (clip == null)
  489. {
  490. floatProperties = null;
  491. return;
  492. }
  493. AnimationCurves curves = clip.Curves;
  494. List<FloatCurvePropertyInfo> newFloatProperties = new List<FloatCurvePropertyInfo>();
  495. for (int i = 0; i < curves.FloatCurves.Length; i++)
  496. {
  497. string suffix;
  498. SerializableProperty property = FindProperty(SceneObject, curves.FloatCurves[i].Name, out suffix);
  499. if (property == null)
  500. continue;
  501. int elementIdx = 0;
  502. if (!string.IsNullOrEmpty(suffix))
  503. {
  504. PropertySuffixInfo suffixInfo;
  505. if (PropertySuffixInfos.TryGetValue(suffix, out suffixInfo))
  506. elementIdx = suffixInfo.elementIdx;
  507. }
  508. Action<float> setter = null;
  509. Type internalType = property.InternalType;
  510. switch (property.Type)
  511. {
  512. case SerializableProperty.FieldType.Vector2:
  513. if (internalType == typeof(Vector2))
  514. {
  515. setter = f =>
  516. {
  517. Vector2 value = property.GetValue<Vector2>();
  518. value[elementIdx] = f;
  519. property.SetValue(value);
  520. };
  521. }
  522. break;
  523. case SerializableProperty.FieldType.Vector3:
  524. if (internalType == typeof(Vector3))
  525. {
  526. setter = f =>
  527. {
  528. Vector3 value = property.GetValue<Vector3>();
  529. value[elementIdx] = f;
  530. property.SetValue(value);
  531. };
  532. }
  533. break;
  534. case SerializableProperty.FieldType.Vector4:
  535. if (internalType == typeof(Vector4))
  536. {
  537. setter = f =>
  538. {
  539. Vector4 value = property.GetValue<Vector4>();
  540. value[elementIdx] = f;
  541. property.SetValue(value);
  542. };
  543. }
  544. else if (internalType == typeof(Quaternion))
  545. {
  546. setter = f =>
  547. {
  548. Quaternion value = property.GetValue<Quaternion>();
  549. value[elementIdx] = f;
  550. property.SetValue(value);
  551. };
  552. }
  553. break;
  554. case SerializableProperty.FieldType.Color:
  555. if (internalType == typeof(Color))
  556. {
  557. setter = f =>
  558. {
  559. Color value = property.GetValue<Color>();
  560. value[elementIdx] = f;
  561. property.SetValue(value);
  562. };
  563. }
  564. break;
  565. case SerializableProperty.FieldType.Bool:
  566. setter = f =>
  567. {
  568. bool value = f > 0.0f;
  569. property.SetValue(value);
  570. };
  571. break;
  572. case SerializableProperty.FieldType.Int:
  573. setter = f =>
  574. {
  575. int value = (int)f;
  576. property.SetValue(value);
  577. };
  578. break;
  579. case SerializableProperty.FieldType.Float:
  580. setter = f =>
  581. {
  582. property.SetValue(f);
  583. };
  584. break;
  585. }
  586. if (setter == null)
  587. continue;
  588. FloatCurvePropertyInfo propertyInfo = new FloatCurvePropertyInfo();
  589. propertyInfo.curveIdx = i;
  590. propertyInfo.setter = setter;
  591. newFloatProperties.Add(propertyInfo);
  592. }
  593. floatProperties = newFloatProperties.ToArray();
  594. }
  595. /// <summary>
  596. /// Called whenever an animation event triggers.
  597. /// </summary>
  598. /// <param name="clip">Clip that the event originated from.</param>
  599. /// <param name="name">Name of the event.</param>
  600. private void EventTriggered(AnimationClip clip, string name)
  601. {
  602. // Event should be in format "ComponentType/MethodName"
  603. if (string.IsNullOrEmpty(name))
  604. return;
  605. string[] nameEntries = name.Split('/');
  606. if (nameEntries.Length != 2)
  607. return;
  608. string typeName = nameEntries[0];
  609. string methodName = nameEntries[1];
  610. Component[] components = SceneObject.GetComponents();
  611. for (int i = 0; i < components.Length; i++)
  612. {
  613. if (components[i].GetType().Name == typeName)
  614. {
  615. components[i].Invoke(methodName);
  616. break;
  617. }
  618. }
  619. }
  620. /// <summary>
  621. /// Holds all data the animation component needs to persist through serialization.
  622. /// </summary>
  623. [SerializeObject]
  624. private class SerializableData
  625. {
  626. public AnimationClip defaultClip;
  627. public AnimWrapMode wrapMode = AnimWrapMode.Loop;
  628. public float speed = 1.0f;
  629. }
  630. /// <summary>
  631. /// Contains information about a property animated by a generic animation curve.
  632. /// </summary>
  633. private class FloatCurvePropertyInfo
  634. {
  635. public int curveIdx;
  636. public Action<float> setter;
  637. }
  638. /// <summary>
  639. /// Information about a suffix used in a property path.
  640. /// </summary>
  641. internal struct PropertySuffixInfo
  642. {
  643. public PropertySuffixInfo(int elementIdx, bool isVector)
  644. {
  645. this.elementIdx = elementIdx;
  646. this.isVector = isVector;
  647. }
  648. public int elementIdx;
  649. public bool isVector;
  650. }
  651. }
  652. /** @} */
  653. }