private void GUIFrameDataLayout(HitboxManager m_Target, SerializedProperty clip, SerializedProperty framedata, UnityEngine.Object oldclip) { //New animations need their frame data populated if (oldclip != clip.objectReferenceValue && clip.objectReferenceValue != null || framedata.arraySize == 0) { framedata.ClearArray(); framedata.arraySize = 0; ApplySerializedProperties(); for (int i = 0, j = m_Target.GetNumFrames(SelectedAnimation); i < j; i++) { framedata.InsertArrayElementAtIndex(0); } ApplySerializedProperties(); } GUILayout.Label("Frame Data", EditorStyles.boldLabel); // showFrameData = EditorGUILayout.Foldout(showFrameData, "Frame Data", true); // if (showFrameData) { GUILayout.Label("Frames in clip: " + m_Target.GetNumFrames(SelectedAnimation)); SelectedFrame = EditorGUILayout.IntSlider(SelectedFrame, 0, Mathf.Max(0, m_Target.GetNumFrames(SelectedAnimation) - 1)); EditorGUI.indentLevel++; if (SelectedFrame < framedata.arraySize) { var events = framedata.GetArrayElementAtIndex(SelectedFrame).FindPropertyRelative("events"); EditorGUILayout.PropertyField(events, true); // var collider = framedata.GetArrayElementAtIndex(SelectedFrame).FindPropertyRelative("collider"); } else { for (int i = framedata.arraySize; i <= SelectedFrame; i++) { framedata.InsertArrayElementAtIndex(i); ApplySerializedProperties(); } } } }
private void GUIAddNewAnimationButton(HitboxManager m_Target, SerializedProperty Animations) { if (GUILayout.Button("Add New Animation")) { string path = EditorUtility.OpenFilePanel("Select Animation Clip", "", "anim"); if (!string.IsNullOrEmpty(path)) { int indexOf = path.IndexOf("Assets/"); path = path.Substring(indexOf >= 0 ? indexOf : 0); var loadedClip = AssetDatabase.LoadAssetAtPath <AnimationClip>(path); if (loadedClip == null) { Debug.LogError("HITBOXMANAGER ERROR: Unable to load animation clip at path \"" + path + "\"\n\r Is this this animation located inside your project's assets folder?"); } else { Animations.InsertArrayElementAtIndex(Mathf.Max(0, Animations.arraySize - 1)); m_targetObject.ApplyModifiedProperties(); SerializedProperty HitboxData = Animations.GetArrayElementAtIndex(Animations.arraySize - 1); var clip = HitboxData.FindPropertyRelative("clip"); var framedata = HitboxData.FindPropertyRelative("frameData"); clip.objectReferenceValue = loadedClip; for (int i = 0, j = m_Target.GetNumFrames(Animations.arraySize - 1); i < j; i++) { framedata.InsertArrayElementAtIndex(0); framedata.GetArrayElementAtIndex(0).FindPropertyRelative("collider").ClearArray(); framedata.GetArrayElementAtIndex(0).FindPropertyRelative("events").ClearArray(); } SelectedAnimation = Animations.arraySize - 1; SelectedFrame = 0; m_targetObject.ApplyModifiedProperties(); } } } }
// private void GUIRemoveCurrentAnimationButton(HitboxManager m_Target, SerializedProperty Animations) // { // SetEditorColors(Color.red, Color.white); // if (GUILayout.Button("Remove Current Animation") // && EditorUtility.DisplayDialog("Remove " + m_AnimationOptionLabels[SelectedAnimation] + " from " + m_Target.transform.root.name + "?", // "Are you sure you want to remove this animation from " + m_Target.transform.root.name + "? All collider data, movement data, and other custom data for this animation on this character will be deleted.", "Yes", "No")) // { // Animations.MoveArrayElement(SelectedAnimation, Mathf.Max(0, Animations.arraySize - 1)); // Animations.DeleteArrayElementAtIndex(Mathf.Max(0, Animations.arraySize - 1)); // SelectedAnimation = Mathf.Max(0, SelectedAnimation - 1); // } // } /// <summary> /// アタッチされたアニメーターからアニメーション情報を追加取得 /// </summary> /// <param name="Animations"></param> private void GUIAddFromAttachedAnimatorButton(SerializedProperty animations) { SetEditorColors(Color.yellow, Color.white); if (GUILayout.Button("Add All Animations From Attached Animator")) { Animator animator = m_targetManager.GetComponent <Animator>(); AnimationClip[] allclips = animator.runtimeAnimatorController.animationClips; List <AnimationClip> allclipslist = new List <AnimationClip>(allclips); for (int i = 0; i < animations.arraySize; i++) { var currentclip = (AnimationClip)animations.GetArrayElementAtIndex(i).FindPropertyRelative("clip").objectReferenceValue; allclipslist.Remove(currentclip); } for (int i = 0; i < allclipslist.Count; i++) { animations.InsertArrayElementAtIndex(Mathf.Max(0, animations.arraySize - 1)); m_targetObject.ApplyModifiedProperties(); SerializedProperty hitboxData = animations.GetArrayElementAtIndex(animations.arraySize - 1); SerializedProperty clip = hitboxData.FindPropertyRelative("clip"); SerializedProperty frameData = hitboxData.FindPropertyRelative("frameData"); Debug.Log(clip); Debug.Log($"framedata : {frameData}"); clip.objectReferenceValue = allclipslist[i]; for (int k = 0, j = m_targetManager.GetNumFrames(animations.arraySize - 1); k < j; k++) { frameData.InsertArrayElementAtIndex(0); frameData.GetArrayElementAtIndex(0).FindPropertyRelative("collider").ClearArray(); frameData.GetArrayElementAtIndex(0).FindPropertyRelative("events").ClearArray(); } m_targetObject.ApplyModifiedProperties(); } } }