UIAnimation.AnimationSection GetFrameAnimationSection(SerializedProperty section) { UIAnimation anim = target as UIAnimation; System.Reflection.PropertyInfo frameListPropInfo = anim.GetType().GetProperty("_AnimationFrames"); IList frameListI = frameListPropInfo.GetValue(anim, null) as IList; System.Reflection.PropertyInfo sectionProp = frameListPropInfo.PropertyType.GetGenericArguments()[0].GetProperty("_" + section.name); foreach (var listItem in frameListI) { if (frameListI.IndexOf(listItem) == chosenFrame) { UIAnimation.AnimationSection s = sectionProp.GetValue(listItem, null) as UIAnimation.AnimationSection; return(s); } } return(null); }
void DrawAnimationSection(SerializedProperty section, ref bool foldout, ref AnimBool animBool) { #region Properties Initialization SerializedProperty useSection = section.FindPropertyRelative("UseSection"); SerializedProperty type = section.FindPropertyRelative("Type"); SerializedProperty wantedVectorValue = section.FindPropertyRelative("WantedVectorValue"); SerializedProperty wantedFloatValue = section.FindPropertyRelative("WantedFloatValue"); SerializedProperty duration = section.FindPropertyRelative("Duration"); SerializedProperty easingParams = section.FindPropertyRelative("easingParams"); SerializedProperty curFrame = animationFrames.GetArrayElementAtIndex(chosenFrame); SerializedProperty goToStartValue = curFrame.FindPropertyRelative("Start" + section.name.Substring(0, section.name.Length - 7)); SerializedProperty movementHidingPosition = curFrame.FindPropertyRelative("MovementHidingPosition"); SerializedProperty edgeGap = curFrame.FindPropertyRelative("EdgeGap"); SerializedProperty localCustomPosition = curFrame.FindPropertyRelative("LocalCustomPosition"); SerializedProperty direction = curFrame.FindPropertyRelative("Direction"); #endregion string sectionName = section.displayName.Substring(0, section.displayName.Length - 8); #region Header EditorStyles.foldout.fontStyle = FontStyle.Bold; string chosenType = useSection.boolValue ? type.enumDisplayNames[type.enumValueIndex] : "None"; foldout = EditorGUILayout.Foldout(foldout, sectionName + " (" + chosenType + ")", true); EditorStyles.foldout.fontStyle = FontStyle.Normal; #endregion if (foldout) { EditorGUILayout.PropertyField(useSection, new GUIContent("Use " + sectionName + "*")); animBool.target = useSection.boolValue; if (EditorGUILayout.BeginFadeGroup(animBool.faded)) { EditorGUILayout.PropertyField(type); EditorGUILayout.PropertyField(goToStartValue, new GUIContent("Go To Normal?")); #region Wanted Values if (sectionName == "Movement" && !goToStartValue.boolValue) { EditorGUILayout.PropertyField(movementHidingPosition, new GUIContent("Hiding Position")); if (movementHidingPosition.enumValueIndex == 8) //Custom position { #region Discard Button if (recordingPosition) { EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("X", GUILayout.Width(50), GUILayout.Height(15))) { DiscardRecording(); } EditorGUILayout.EndHorizontal(); } #endregion #region Record Button EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (recordingPosition) { GUI.color = Color.red; } recordingPosition = GUILayout.Toggle(recordingPosition, !recordingPosition ? "Record Position" : "Finish Recording", EditorStyles.miniButton); GUI.color = Color.white; EditorGUILayout.EndHorizontal(); curLocalCustomPosition = localCustomPosition.boolValue; if (lastRecordingState != recordingPosition) { //If recording start if (recordingPosition) { StartRecording(wantedVectorValue.vector3Value); } //If recording end if (!recordingPosition) { EndRecording(); } } lastRecordingState = recordingPosition; #endregion Vector2 customVec = wantedVectorValue.vector3Value; wantedVectorValue.vector3Value = EditorGUILayout.Vector2Field(new GUIContent("Wanted Position", "Custom position as percentage of the screen."), customVec); EditorGUILayout.PropertyField(localCustomPosition, new GUIContent("Local?")); } else { EditorGUILayout.PropertyField(edgeGap); } } else if (sectionName == "Rotation") { if (!goToStartValue.boolValue) { EditorGUILayout.PropertyField(wantedVectorValue, new GUIContent("Wanted Rotation", "The rotation this element should change to.")); } EditorGUILayout.PropertyField(direction); } else if (sectionName == "Scale" && !goToStartValue.boolValue) { EditorGUILayout.PropertyField(wantedVectorValue, new GUIContent("Wanted Scale", "The scale this element should change to.")); } else if (sectionName == "Opacity" && !goToStartValue.boolValue) { EditorGUILayout.Slider(wantedFloatValue, 0, 1, new GUIContent("Wanted Opacity", "The opacity this element should fade to.")); } else if (sectionName == "Slice" && !goToStartValue.boolValue) { EditorGUILayout.Slider(wantedFloatValue, 0, 1, new GUIContent("Wanted Fill Amount", "The fill amount this element's image should change to.")); } #endregion //Ease Function Parameters Drawing DrawEasingParams(type.enumNames[type.enumValueIndex], easingParams); #region Custom Properties #region Custom Properties Drawing if (duration.floatValue >= 0) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(duration); if (GUILayout.Button("Delete", EditorStyles.miniButtonRight)) { Undo.RecordObject(target, "Delete Custom Duration"); UIAnimation.AnimationSection s = GetFrameAnimationSection(section); s.Duration = -1; } EditorGUILayout.EndHorizontal(); } #endregion //Seperate in case there an option to add custom property if (duration.floatValue < 0) { EditorGUILayout.Space(); } #region Custom Properties Adding if (duration.floatValue < 0) { string txt = targets.Length == 1 ? "Add custom \"" + duration.displayName + "\"" : "Add custom \"" + duration.displayName + "\" to all"; string tooltip = "Add a custom \"" + duration.displayName + "\" for this animation section, meaning this section will ignore general \"" + duration.displayName + "\"."; EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button(new GUIContent(txt, tooltip), EditorStyles.miniButtonRight, GUILayout.Width(EditorGUIUtility.currentViewWidth / 2))) { Undo.RecordObject(target, "Add Custom Duration"); UIAnimation anim = target as UIAnimation; UIAnimation.AnimationSection s = GetFrameAnimationSection(section); s.Duration = anim.AnimationFrames[chosenFrame].Duration; } EditorGUILayout.EndHorizontal(); } #endregion #endregion EditorGUILayout.EndFadeGroup(); } } }