// Cinema Suite 2014 using System; using System.Collections.Generic; using System.Reflection; using UnityEngine; namespace CinemaDirector { /// /// A helper class for getting useful data from Director Runtime objects. /// public static class DirectorRuntimeHelper { /// /// Returns a list of Track types that are associated with the given Track Group. /// /// The track group to be inspected /// A list of track types that meet the genre criteria of the given track group. public static List GetAllowedTrackTypes(TrackGroup trackGroup) { // Get all the allowed Genres for this track group TimelineTrackGenre[] genres = new TimelineTrackGenre[0]; MemberInfo info = trackGroup.GetType(); foreach (TrackGroupAttribute attribute in info.GetCustomAttributes(typeof(TrackGroupAttribute), true)) { if (attribute != null) { genres = attribute.AllowedTrackGenres; break; } } List allowedTrackTypes = new List(); foreach (Type type in DirectorRuntimeHelper.GetAllSubTypes(typeof(TimelineTrack))) { foreach (TimelineTrackAttribute attribute in type.GetCustomAttributes(typeof(TimelineTrackAttribute), true)) { if (attribute != null) { foreach (TimelineTrackGenre genre in attribute.TrackGenres) { foreach (TimelineTrackGenre genre2 in genres) { if (genre == genre2) { allowedTrackTypes.Add(type); break; } } } break; } } } return allowedTrackTypes; } /// /// Returns a list of Cutscene Item types that are associated with the given Track. /// /// The track to look up. /// A list of valid cutscene item types. public static List GetAllowedItemTypes(TimelineTrack timelineTrack) { // Get all the allowed Genres for this track CutsceneItemGenre[] genres = new CutsceneItemGenre[0]; MemberInfo info = timelineTrack.GetType(); foreach (TimelineTrackAttribute attribute in info.GetCustomAttributes(typeof(TimelineTrackAttribute), true)) { if (attribute != null) { genres = attribute.AllowedItemGenres; break; } } List allowedItemTypes = new List(); foreach (Type type in DirectorRuntimeHelper.GetAllSubTypes(typeof(TimelineItem))) { foreach (CutsceneItemAttribute attribute in type.GetCustomAttributes(typeof(CutsceneItemAttribute), true)) { if (attribute != null) { foreach (CutsceneItemGenre genre in attribute.Genres) { foreach (CutsceneItemGenre genre2 in genres) { if (genre == genre2) { allowedItemTypes.Add(type); break; } } } break; } } } return allowedItemTypes; } /// /// Get all Sub types from the given parent type. /// /// The parent type /// all children types of the parent. private static Type[] GetAllSubTypes(System.Type ParentType) { List list = new List(); foreach (Assembly a in System.AppDomain.CurrentDomain.GetAssemblies()) { foreach (System.Type type in a.GetTypes()) { if (type.IsSubclassOf(ParentType)) { list.Add(type); } } } return list.ToArray(); } /// /// Retrieve all children of a parent Transform recursively. /// /// The parent transform /// All children of that parent. public static List GetAllTransformsInHierarchy(Transform parent) { List children = new List(); foreach (Transform child in parent) { children.AddRange(GetAllTransformsInHierarchy(child)); children.Add(child); } return children; } } }