ControlPlayableAssetEditor.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using UnityEngine.Timeline;
  4. using UnityEngine.Playables;
  5. namespace UnityEditor.Timeline
  6. {
  7. [CustomTimelineEditor(typeof(ControlPlayableAsset))]
  8. class ControlPlayableAssetEditor : ClipEditor
  9. {
  10. static readonly Texture2D[] s_ParticleSystemIcon = {AssetPreview.GetMiniTypeThumbnail(typeof(ParticleSystem))};
  11. public override ClipDrawOptions GetClipOptions(TimelineClip clip)
  12. {
  13. var asset = (ControlPlayableAsset)clip.asset;
  14. var options = base.GetClipOptions(clip);
  15. if (asset.updateParticle && TimelineEditor.inspectedDirector != null && asset.controllingParticles)
  16. options.icons = s_ParticleSystemIcon;
  17. return options;
  18. }
  19. public override void OnCreate(TimelineClip clip, TrackAsset track, TimelineClip clonedFrom)
  20. {
  21. var asset = (ControlPlayableAsset)clip.asset;
  22. GameObject sourceObject = null;
  23. // go by sourceObject first, then by prefab
  24. if (TimelineEditor.inspectedDirector != null)
  25. sourceObject = asset.sourceGameObject.Resolve(TimelineEditor.inspectedDirector);
  26. if (sourceObject == null && asset.prefabGameObject != null)
  27. sourceObject = asset.prefabGameObject;
  28. if (sourceObject)
  29. {
  30. var directors = asset.GetComponent<PlayableDirector>(sourceObject);
  31. var particleSystems = asset.GetComponent<ParticleSystem>(sourceObject);
  32. // update the duration and loop values (used for UI purposes) here
  33. // so they are tied to the latest gameObject bound
  34. asset.UpdateDurationAndLoopFlag(directors, particleSystems);
  35. clip.displayName = sourceObject.name;
  36. }
  37. }
  38. public override void GetSubTimelines(TimelineClip clip, PlayableDirector director, List<PlayableDirector> subTimelines)
  39. {
  40. var asset = (ControlPlayableAsset)clip.asset;
  41. // If there is a prefab, it will override the source GameObject
  42. if (!asset.updateDirector || asset.prefabGameObject != null || director == null)
  43. return;
  44. var go = asset.sourceGameObject.Resolve(director);
  45. if (go == null)
  46. return;
  47. foreach (var subTimeline in asset.GetComponent<PlayableDirector>(go))
  48. {
  49. if (subTimeline == director || subTimeline == TimelineEditor.masterDirector || subTimeline == TimelineEditor.inspectedDirector)
  50. continue;
  51. if (subTimeline.playableAsset is TimelineAsset)
  52. subTimelines.Add(subTimeline);
  53. }
  54. }
  55. }
  56. }