SkyGUITimelineMenu.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor;
  5. namespace Funly.SkyStudio
  6. {
  7. // Show a popup menu that lets the user add an item to the timeline. This is typically triggered from a button.
  8. public abstract class SkyGUITimelineMenu : System.Object
  9. {
  10. private static SkyProfile s_Profile;
  11. public static void ShowAddTimelinePropertyMenu(SkyProfile profile)
  12. {
  13. List<ProfileGroupDefinition> offTimeline = profile.GetGroupDefinitionsNotManagedByTimeline();
  14. ShowAddTimelinePropertyMenu(profile, offTimeline);
  15. }
  16. public static void ShowAddTimelinePropertyMenu(SkyProfile profile, List<ProfileGroupDefinition> groups)
  17. {
  18. s_Profile = profile;
  19. GenericMenu menu = new GenericMenu();
  20. foreach (ProfileGroupSection sectionInfo in s_Profile.GetProfileDefinitions()) {
  21. foreach (ProfileGroupDefinition groupInfo in sectionInfo.groups) {
  22. if (s_Profile.IsManagedByTimeline(groupInfo.propertyKey) == false && s_Profile.CanGroupBeOnTimeline(groupInfo)) {
  23. string itemName = sectionInfo.sectionTitle + "/" + groupInfo.groupName;
  24. menu.AddItem(new GUIContent(itemName), false, DidSelectAddTimelineProperty, groupInfo.propertyKey);
  25. }
  26. }
  27. }
  28. menu.ShowAsContext();
  29. }
  30. // Menu callback for adding new timeline keys into profile.
  31. private static void DidSelectAddTimelineProperty(object propertyKey)
  32. {
  33. // Prevent duplicates when you add.
  34. s_Profile.timelineManagedKeys.Remove((string)propertyKey);
  35. s_Profile.timelineManagedKeys.Add((string)propertyKey);
  36. }
  37. }
  38. }