void OnGUI_OnAddSequence() { var menu = new GenericMenu(); if (mCurrentSequenceIndex >= 0 && mAnimation._Sequences[mCurrentSequenceIndex] != null) { menu.AddItem(new GUIContent("Duplicate:" + mAnimation._Sequences[mCurrentSequenceIndex].GetTypeName()), false, DuplicateSequence, mAnimation._Sequences[mCurrentSequenceIndex]); } menu.AddSeparator(""); menu.AddItem(new GUIContent("Basic/Alpha"), false, AddBasicSequence, typeof(SE_AnimSequence_Alpha)); menu.AddItem(new GUIContent("Basic/Position"), false, AddBasicSequence, typeof(SE_AnimSequence_Position)); menu.AddItem(new GUIContent("Basic/Color"), false, AddBasicSequence, typeof(SE_AnimSequence_Color)); menu.AddItem(new GUIContent("Basic/Scale"), false, AddBasicSequence, typeof(SE_AnimSequence_Scale)); menu.AddItem(new GUIContent("Basic/Rotation"), false, AddBasicSequence, typeof(SE_AnimSequence_Rotation)); var mAnimPath = TextAnimation_Inspector.GetI2TextAnimationPath() + "/Presets/"; var len = mAnimPath.Length; foreach (var fileName in System.IO.Directory.GetFiles(mAnimPath, "*.asset", System.IO.SearchOption.AllDirectories)) { var option = fileName.Substring(len, fileName.Length - len - 6).Replace('\\', '/'); menu.AddItem(new GUIContent("Presets/" + option), false, AddPresetSequence, fileName); } menu.ShowAsContext(); }
void RegisterProperty_Animation() { mSerialized_OnEnable_PlayAnim = serializedObject.FindProperty("_OnEnable_PlayAnim"); mSerialized_AnimationSlots = serializedObject.FindProperty("_AnimationSlots"); mSerialized_TimeSource = serializedObject.FindProperty("_TimeSource"); mSerialized_OnAnimation_Finished = serializedObject.FindProperty("_OnAnimation_Finished"); mAnimationsReorderableList = new ReorderableList(serializedObject, mSerialized_AnimationSlots, true, true, true, true); mAnimationsReorderableList.drawHeaderCallback = (Rect rect) => { EditorGUI.LabelField(rect, "Animations"); }; mAnimationsReorderableList.drawElementCallback = OnGUI_Animation_AnimListElement; mAnimationsReorderableList.onRemoveCallback = OnRemoveAnimation; mAnimationsReorderableList.onAddCallback = OnAddAnimation; var mAnimPath = TextAnimation_Inspector.GetI2TextAnimationPath() + "/Presets/"; var len = mAnimPath.Length; mSavedAnimations = System.IO.Directory.GetFiles(mAnimPath, "*.asset", System.IO.SearchOption.AllDirectories).Select(f => f.Substring(len, f.Length - len - 6).Replace('\\', '/')).ToArray(); }
void OnGUI_Animation_AnimListElement(Rect rect, int index, bool isActive, bool isFocused) { rect.yMin += 1; rect.yMax -= 3; //var rectLocalBtn = Rect.MinMaxRect(rect.xMax - 55, rect.yMin, rect.xMax-15, rect.yMax); //var rectCloseBtn = Rect.MinMaxRect(rect.xMax - 15, rect.yMin, rect.xMax, rect.yMax); var rectLocalBtn = Rect.MinMaxRect(rect.xMax - 40, rect.yMin, rect.xMax, rect.yMax); rect.xMax = rect.xMax - 55; var prop_AnimSlot = mSerialized_AnimationSlots.GetArrayElementAtIndex(index); var prop_SlotPreset = prop_AnimSlot.FindPropertyRelative("_Preset"); var animPreset = prop_SlotPreset.objectReferenceValue as SE_AnimationPreset; var isLocal = animPreset == null; var rectPreset = Rect.MinMaxRect(isLocal ? (rect.xMin + rect.width * 0.6f) : rect.xMin, rect.yMin, rect.xMax - 15, rect.yMax); EditorGUI.BeginChangeCheck(); EditorGUI.PropertyField(rectPreset, prop_SlotPreset, GUITools.EmptyContent); if (EditorGUI.EndChangeCheck()) { DeselectAnimation(); mAnimationsReorderableList.index = index; prop_SlotPreset.serializedObject.ApplyModifiedProperties(); mTarget._AnimationSlots[index].CreateAnimation(); } var rectPresetList = Rect.MinMaxRect(rect.xMax - 15, rect.yMin, rect.xMax, rect.yMax); int newAnimIdx = EditorGUI.Popup(rectPresetList, -1, mSavedAnimations); if (newAnimIdx != -1) { var path = TextAnimation_Inspector.GetI2TextAnimationPath() + "/Presets/" + mSavedAnimations[newAnimIdx] + ".asset"; animPreset = AssetDatabase.LoadAssetAtPath(path, typeof(SE_AnimationPreset)) as SE_AnimationPreset; DeselectAnimation(); if (animPreset != null) { prop_SlotPreset.objectReferenceValue = animPreset; mAnimationsReorderableList.index = index; } prop_SlotPreset.serializedObject.ApplyModifiedProperties(); mTarget._AnimationSlots[index].CreateAnimation(); } if (isLocal) { var rectName = Rect.MinMaxRect(rect.xMin, rect.yMin, rect.xMin + rect.width * 0.6f, rect.yMax); GUI.Label(rectName, mTarget._AnimationSlots[index]._Animation.Name, EditorStyles.label); if (GUI.Button(rectLocalBtn, "Save", EditorStyles.miniButton)) { SaveAnimation(index); } } else { if (GUI.Button(rectLocalBtn, prop_SlotPreset.objectReferenceValue != null ? "Clone" : "New", EditorStyles.miniButton)) { CloneAnimation(index); } } }