/// <summary> /// On inspector enable, load serialized objects /// </summary> public void OnEnable() { clipCurve = new SerializedObject(this.target); CinemaMultiActorCurveClip curveclipGO = target as CinemaMultiActorCurveClip; actorCount = curveclipGO.Actors.Count; componentSelection = new int[actorCount]; propertySelection = new int[actorCount]; SerializedProperty curveData = clipCurve.FindProperty("curveData"); if (curveData.arraySize > 0) { SerializedProperty member = curveData.GetArrayElementAtIndex(0); propertyType = member.FindPropertyRelative("PropertyType"); } componentsProperty = clipCurve.FindProperty("Components"); propertiesProperty = clipCurve.FindProperty("Properties"); this.editorRevert = clipCurve.FindProperty("editorRevertMode"); this.runtimeRevert = clipCurve.FindProperty("runtimeRevertMode"); componentsProperty.arraySize = actorCount; propertiesProperty.arraySize = actorCount; for (int i = 0; i < actorCount; i++) { Transform actor = curveclipGO.Actors[i]; Component currentComponent = componentsProperty.GetArrayElementAtIndex(i).objectReferenceValue as Component; string currentProperty = propertiesProperty.GetArrayElementAtIndex(i).stringValue; Component[] components = getValidComponents(actor.gameObject); for (int j = 0; j < components.Length; j++) { if (components[j] == currentComponent) { componentSelection[i] = j; } } PropertyInfo[] properties = getValidProperties(components[componentSelection[i]], (PropertyTypeInfo)propertyType.enumValueIndex); for (int j = 0; j < properties.Length; j++) { if (properties[j].Name == currentProperty) { propertySelection[i] = j; } } } }
/// <summary> /// Update and Draw the inspector /// </summary> public override void OnInspectorGUI() { curveTrack.Update(); TimelineItem[] items = (target as MultiCurveTrack).TimelineItems; for (int i = 0; i < items.Length; i++) { CinemaMultiActorCurveClip clip = items[i] as CinemaMultiActorCurveClip; EditorGUILayout.ObjectField(clip.name, clip, typeof(CinemaMultiActorCurveClip), true); } if (GUILayout.Button(addClip)) { Undo.RegisterCreatedObjectUndo(CutsceneItemFactory.CreateMultiActorClipCurve((target as MultiCurveTrack)).gameObject, "Create Curve Clip"); } curveTrack.ApplyModifiedProperties(); }
internal static CinemaMultiActorCurveClip CreateMultiActorClipCurve(MultiCurveTrack multiCurveTrack) { string name = DirectorHelper.getCutsceneItemName(multiCurveTrack.gameObject, CURVE_CLIP_NAME_DEFAULT, typeof(CinemaMultiActorCurveClip)); GameObject item = new GameObject(name); item.transform.parent = multiCurveTrack.transform; CinemaMultiActorCurveClip clip = item.AddComponent <CinemaMultiActorCurveClip>(); SortedDictionary <float, CinemaMultiActorCurveClip> sortedItems = new SortedDictionary <float, CinemaMultiActorCurveClip>(); foreach (CinemaMultiActorCurveClip c in multiCurveTrack.TimelineItems) { sortedItems.Add(c.Firetime, c); } float latestTime = 0; float length = DEFAULT_CURVE_LENGTH; foreach (CinemaMultiActorCurveClip c in sortedItems.Values) { if (latestTime >= c.Firetime) { latestTime = Mathf.Max(latestTime, c.Firetime + c.Duration); } else { length = c.Firetime - latestTime; break; } } clip.Firetime = latestTime; clip.Duration = length; return(clip); }
public override void UpdateCurveWrappers(CinemaClipCurveWrapper clipWrapper) { CinemaMultiActorCurveClip clipCurve = clipWrapper.Behaviour as CinemaMultiActorCurveClip; if (clipCurve == null) { return; } for (int i = 0; i < clipCurve.CurveData.Count; i++) { MemberClipCurveData member = clipCurve.CurveData[i]; CinemaMemberCurveWrapper memberWrapper = null; if (!clipWrapper.TryGetValue(member.PropertyType.ToString(), member.PropertyName, out memberWrapper)) { memberWrapper = new CinemaMemberCurveWrapper(); memberWrapper.Type = member.PropertyType.ToString(); memberWrapper.PropertyName = member.PropertyName; memberWrapper.Texture = EditorGUIUtility.ObjectContent(null, UnityPropertyTypeInfo.GetUnityType(member.Type)).image; ArrayUtility.Add <CinemaMemberCurveWrapper>(ref clipWrapper.MemberCurves, memberWrapper); int showingCurves = UnityPropertyTypeInfo.GetCurveCount(member.PropertyType); memberWrapper.AnimationCurves = new CinemaAnimationCurveWrapper[showingCurves]; for (int j = 0; j < showingCurves; j++) { memberWrapper.AnimationCurves[j] = new CinemaAnimationCurveWrapper(); memberWrapper.AnimationCurves[j].Id = j; memberWrapper.AnimationCurves[j].Curve = member.GetCurve(j); memberWrapper.AnimationCurves[j].Color = UnityPropertyTypeInfo.GetCurveColor(j); memberWrapper.AnimationCurves[j].Label = UnityPropertyTypeInfo.GetCurveName(member.PropertyType, j); } } } // Remove missing track items List <CinemaMemberCurveWrapper> itemRemovals = new List <CinemaMemberCurveWrapper>(); { // foreach(var cw in clipWrapper.MemberCurves) var __enumerator1 = (clipWrapper.MemberCurves).GetEnumerator(); while (__enumerator1.MoveNext()) { var cw = (CinemaMemberCurveWrapper)__enumerator1.Current; { bool found = false; { // foreach(var member in clipCurve.CurveData) var __enumerator3 = (clipCurve.CurveData).GetEnumerator(); while (__enumerator3.MoveNext()) { var member = (MemberClipCurveData)__enumerator3.Current; { if (member.PropertyType.ToString() == cw.Type && member.PropertyName == cw.PropertyName) { found = true; break; } } } } if (!found) { itemRemovals.Add(cw); } } } } { var __list2 = itemRemovals; var __listCount2 = __list2.Count; for (int __i2 = 0; __i2 < __listCount2; ++__i2) { var item = (CinemaMemberCurveWrapper)__list2[__i2]; { ArrayUtility.Remove <CinemaMemberCurveWrapper>(ref clipWrapper.MemberCurves, item); } } } }
/// <summary> /// Update and Draw the inspector /// </summary> public override void OnInspectorGUI() { clipCurve.Update(); EditorGUILayout.PropertyField(editorRevert); EditorGUILayout.PropertyField(runtimeRevert); SerializedProperty curveData = clipCurve.FindProperty("curveData"); if (curveData.arraySize > 0) { CinemaMultiActorCurveClip curveclip = target as CinemaMultiActorCurveClip; SerializedProperty member = curveData.GetArrayElementAtIndex(0); propertyType = member.FindPropertyRelative("PropertyType"); PropertyTypeInfo current = (PropertyTypeInfo)propertyType.enumValueIndex; PropertyTypeInfo newProperty = (PropertyTypeInfo)EditorGUILayout.EnumPopup(new GUIContent("Property Type"), current); if (current != newProperty) { propertyType.enumValueIndex = (int)newProperty; SerializedProperty curve1 = member.FindPropertyRelative("Curve1"); SerializedProperty curve2 = member.FindPropertyRelative("Curve2"); SerializedProperty curve3 = member.FindPropertyRelative("Curve3"); SerializedProperty curve4 = member.FindPropertyRelative("Curve4"); //SerializedProperty firetime = clipCurve.FindProperty("Firetime"); //SerializedProperty duration = clipCurve.FindProperty("Duration"); curve1.animationCurveValue = AnimationCurve.Linear(curveclip.Firetime, 0, curveclip.Duration, 0); curve2.animationCurveValue = AnimationCurve.Linear(curveclip.Firetime, 0, curveclip.Duration, 0); curve3.animationCurveValue = AnimationCurve.Linear(curveclip.Firetime, 0, curveclip.Duration, 0); curve4.animationCurveValue = AnimationCurve.Linear(curveclip.Firetime, 0, curveclip.Duration, 0); } componentsProperty.arraySize = actorCount; propertiesProperty.arraySize = actorCount; for (int i = 0; i < actorCount; i++) { Transform actor = curveclip.Actors[i]; EditorGUILayout.LabelField(actor.name); EditorGUI.indentLevel++; List <GUIContent> componentSelectionList = new List <GUIContent>(); List <GUIContent> propertySelectionList = new List <GUIContent>(); // Display component selection Component[] components = getValidComponents(actor.gameObject); foreach (Component component in components) { componentSelectionList.Add(new GUIContent(component.GetType().Name)); } componentSelection[i] = EditorGUILayout.Popup(new GUIContent("Component"), componentSelection[i], componentSelectionList.ToArray()); componentsProperty.GetArrayElementAtIndex(i).objectReferenceValue = components[componentSelection[i]]; // Display property selection PropertyInfo[] properties = getValidProperties(components[componentSelection[i]], (PropertyTypeInfo)propertyType.enumValueIndex); foreach (PropertyInfo propertyInfo in properties) { propertySelectionList.Add(new GUIContent(propertyInfo.Name)); } Color temp = GUI.color; if (propertySelectionList.Count < 1) { propertySelectionList.Add(new GUIContent("None")); GUI.color = Color.red; } propertySelection[i] = EditorGUILayout.Popup(new GUIContent("Property"), propertySelection[i], propertySelectionList.ToArray()); if (propertySelection[i] > propertySelectionList.Count - 1) { propertySelection[i] = 0; } string selectedProperty = propertySelectionList[propertySelection[i]].text; propertiesProperty.GetArrayElementAtIndex(i).stringValue = selectedProperty; GUI.color = temp; EditorGUI.indentLevel--; } } clipCurve.ApplyModifiedProperties(); }
public override void UpdateCurveWrappers(CinemaClipCurveWrapper clipWrapper) { CinemaMultiActorCurveClip clipCurve = clipWrapper.Behaviour as CinemaMultiActorCurveClip; if (clipCurve == null) { return; } for (int i = 0; i < clipCurve.CurveData.Count; i++) { MemberClipCurveData member = clipCurve.CurveData[i]; CinemaMemberCurveWrapper memberWrapper = null; if (!clipWrapper.TryGetValue(member.PropertyType.ToString(), member.PropertyName, out memberWrapper)) { memberWrapper = new CinemaMemberCurveWrapper(); memberWrapper.Type = member.PropertyType.ToString(); memberWrapper.PropertyName = member.PropertyName; memberWrapper.Texture = EditorGUIUtility.ObjectContent(null, UnityPropertyTypeInfo.GetUnityType(member.Type)).image; ArrayUtility.Add <CinemaMemberCurveWrapper>(ref clipWrapper.MemberCurves, memberWrapper); int showingCurves = UnityPropertyTypeInfo.GetCurveCount(member.PropertyType); memberWrapper.AnimationCurves = new CinemaAnimationCurveWrapper[showingCurves]; for (int j = 0; j < showingCurves; j++) { memberWrapper.AnimationCurves[j] = new CinemaAnimationCurveWrapper(); memberWrapper.AnimationCurves[j].Id = j; memberWrapper.AnimationCurves[j].Curve = new AnimationCurve(member.GetCurve(j).keys); memberWrapper.AnimationCurves[j].Color = UnityPropertyTypeInfo.GetCurveColor(j); memberWrapper.AnimationCurves[j].Label = UnityPropertyTypeInfo.GetCurveName(member.PropertyType, j); } } else { int showingCurves = UnityPropertyTypeInfo.GetCurveCount(member.PropertyType); for (int j = 0; j < showingCurves; j++) { memberWrapper.AnimationCurves[j].Curve = new AnimationCurve(member.GetCurve(j).keys); } } } // Remove missing track items List <CinemaMemberCurveWrapper> itemRemovals = new List <CinemaMemberCurveWrapper>(); for (int i = 0; i < clipWrapper.MemberCurves.Length; i++) { CinemaMemberCurveWrapper cw = clipWrapper.MemberCurves[i]; bool found = false; for (int j = 0; j < clipCurve.CurveData.Count; j++) { MemberClipCurveData member = clipCurve.CurveData[j]; if (member.PropertyType.ToString() == cw.Type && member.PropertyName == cw.PropertyName) { found = true; break; } } if (!found) { itemRemovals.Add(cw); } } for (int i = 0; i < itemRemovals.Count; i++) { ArrayUtility.Remove <CinemaMemberCurveWrapper>(ref clipWrapper.MemberCurves, itemRemovals[i]); } }