protected override void showContextMenu(Behaviour behaviour) { CinemaActorClipCurve clipCurve = behaviour as CinemaActorClipCurve; if (clipCurve == null) { return; } List <KeyValuePair <string, string> > currentCurves = new List <KeyValuePair <string, string> >(); { var __list1 = clipCurve.CurveData; var __listCount1 = __list1.Count; for (int __i1 = 0; __i1 < __listCount1; ++__i1) { var data = (MemberClipCurveData)__list1[__i1]; { KeyValuePair <string, string> curveStrings = new KeyValuePair <string, string>(data.Type, data.PropertyName); currentCurves.Add(curveStrings); } } } GenericMenu createMenu = new GenericMenu(); if (clipCurve.Actor != null) { Component[] components = DirectorHelper.getValidComponents(clipCurve.Actor.gameObject); for (int i = 0; i < components.Length; i++) { Component component = components[i]; MemberInfo[] members = DirectorHelper.getValidMembers(component); for (int j = 0; j < members.Length; j++) { AddCurveContext context = new AddCurveContext(); context.clipCurve = clipCurve; context.component = component; context.memberInfo = members[j]; if (!currentCurves.Contains(new KeyValuePair <string, string>(component.GetType().Name, members[j].Name))) { createMenu.AddItem(new GUIContent(string.Format("Add Curve/{0}/{1}", component.GetType().Name, DirectorHelper.GetUserFriendlyName(component, members[j]))), false, addCurve, context); } } } createMenu.AddSeparator(string.Empty); } createMenu.AddItem(new GUIContent("Copy"), false, copyItem, behaviour); createMenu.AddSeparator(string.Empty); createMenu.AddItem(new GUIContent("Clear"), false, deleteItem, clipCurve); createMenu.ShowAsContext(); }
public override void OnInspectorGUI() { actorClipCurve.Update(); CinemaActorClipCurve clipCurveGameObject = (target as CinemaActorClipCurve); if (clipCurveGameObject == null || clipCurveGameObject.Actor == null) { EditorGUILayout.HelpBox(ERROR_MSG, UnityEditor.MessageType.Error); return; } GameObject actor = clipCurveGameObject.Actor.gameObject; List <KeyValuePair <string, string> > currentCurves = new List <KeyValuePair <string, string> >(); EditorGUILayout.PropertyField(editorRevert); EditorGUILayout.PropertyField(runtimeRevert); SerializedProperty curveData = actorClipCurve.FindProperty("curveData"); if (curveData.arraySize > 0) { isDataFolded = EditorGUILayout.Foldout(isDataFolded, dataContent); if (isDataFolded) { for (int i = 0; i < curveData.arraySize; i++) { SerializedProperty member = curveData.GetArrayElementAtIndex(i); SerializedProperty typeProperty = member.FindPropertyRelative("Type"); SerializedProperty memberProperty = member.FindPropertyRelative("PropertyName"); KeyValuePair <string, string> curveStrings = new KeyValuePair <string, string>(typeProperty.stringValue, memberProperty.stringValue); currentCurves.Add(curveStrings); Component c = actor.GetComponent(typeProperty.stringValue); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(new GUIContent(string.Format("{0}.{1}", typeProperty.stringValue, DirectorHelper.GetUserFriendlyName(typeProperty.stringValue, memberProperty.stringValue)), EditorGUIUtility.ObjectContent(c, c.GetType()).image)); if (GUILayout.Button("-", GUILayout.Width(24f))) { curveData.DeleteArrayElementAtIndex(i); } EditorGUILayout.EndHorizontal(); } } GUILayout.Space(5); } isNewCurveFolded = EditorGUILayout.Foldout(isNewCurveFolded, addContent); if (isNewCurveFolded) { List <GUIContent> componentSelectionList = new List <GUIContent>(); List <GUIContent> propertySelectionList = new List <GUIContent>(); Component[] components = DirectorHelper.getValidComponents(actor); for (int i = 0; i < components.Length; i++) { Component component = components[i]; if (component != null) { componentSelectionList.Add(new GUIContent(component.GetType().Name)); } } componentSeletion = EditorGUILayout.Popup(new GUIContent("Component"), componentSeletion, componentSelectionList.ToArray()); MemberInfo[] members = DirectorHelper.getValidMembers(components[componentSeletion]); List <MemberInfo> newMembers = new List <MemberInfo>(); for (int i = 0; i < members.Length; i++) { MemberInfo memberInfo = members[i]; if (!currentCurves.Contains(new KeyValuePair <string, string>(components[componentSeletion].GetType().Name, memberInfo.Name))) { newMembers.Add(memberInfo); } } members = newMembers.ToArray(); for (int i = 0; i < members.Length; i++) { MemberInfo memberInfo = members[i]; string name = DirectorHelper.GetUserFriendlyName(components[componentSeletion], memberInfo); propertySelectionList.Add(new GUIContent(name)); } propertySelection = EditorGUILayout.Popup(new GUIContent("Property"), propertySelection, propertySelectionList.ToArray()); if (GUILayout.Button("Add Curve") && members.Length > 0) { Type t = null; PropertyInfo property = members[propertySelection] as PropertyInfo; FieldInfo field = members[propertySelection] as FieldInfo; bool isProperty = false; if (property != null) { t = property.PropertyType; isProperty = true; } else if (field != null) { t = field.FieldType; isProperty = false; } clipCurveGameObject.AddClipCurveData(components[componentSeletion], members[propertySelection].Name, isProperty, t); } } actorClipCurve.ApplyModifiedProperties(); }