private void DrawFrames(AAnimationClip currentClip, AKeyframe currentKeyframe) { GUILayout.BeginHorizontal(); GUILayout.Label("Sprite", GUILayout.Width(70)); currentKeyframe.Sprite = EditorGUILayout.ObjectField(currentKeyframe.Sprite, typeof(Sprite), true) as Sprite; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Frame " + (keyframesIndex + 1) + "/" + currentClip.keyframes.Length); if (GUILayout.Button("<", GUILayout.Width(30))) { keyframesIndex--; if (keyframesIndex < 0) { keyframesIndex = currentClip.keyframes.Length - 1; } } if (GUILayout.Button(">", GUILayout.Width(30))) { keyframesIndex++; if (keyframesIndex >= currentClip.keyframes.Length) { keyframesIndex = 0; } } GUILayout.EndHorizontal(); }
private void FeedClipsFromAnimator(Animator animator) { if (animator != null) { for (int i = 0; i < animator.runtimeAnimatorController.animationClips.Length; i++) { AnimationClip clip = animator.runtimeAnimatorController.animationClips[i]; //targetAlphaHitbox.AnimationClips.Add(new AAnimationClip(clip.name)); zeroHitbox.AnimationClips[i] = new AAnimationClip(clip.name); var bindings = AnimationUtility.GetObjectReferenceCurveBindings(clip); for (int j = 0; j < bindings.Length; j++) { ObjectReferenceKeyframe[] keyframes = AnimationUtility.GetObjectReferenceCurve(clip, bindings[j]); //targetAlphaHitbox.AnimationClips[i].keyframes = new List<AKeyframe>(); zeroHitbox.AnimationClips[i].keyframes = new AKeyframe[keyframes.Length]; for (int k = 0; k < keyframes.Length; k++) { AKeyframe keyframe = new AKeyframe(keyframes[k].value as Sprite); //targetAlphaHitbox.AnimationClips[i].keyframes.Add(keyframe); zeroHitbox.AnimationClips[i].keyframes[k] = keyframe; } } } } }
public override void OnInspectorGUI() { GUILayout.BeginVertical(); GUI.skin.label.wordWrap = true; AAnimationClip currentClip = null; AKeyframe currentKeyframe = null; if (targetComponents.ZeroHitbox.AnimationClipsStringList != null && targetComponents.ZeroHitbox.AnimationClips.Length > 0) { DrawAnimationClips(); } else { GUILayout.Label("You don't have any animation clips in your Animator component. Add some so we can show them."); GUILayout.EndVertical(); return; } if (targetComponents.ZeroHitbox.HasLists) { currentClip = targetComponents.ZeroHitbox.AnimationClips[animationClipsIndex]; currentKeyframe = currentClip.keyframes[keyframesIndex]; DrawFrames(currentClip, currentKeyframe); } showHitboxesGUI = EditorGUILayout.Foldout(showHitboxesGUI, "Hitboxes"); if (showHitboxesGUI) { DrawHitboxes(currentKeyframe); } GUILayout.EndVertical(); }
private void DrawHitboxes(AKeyframe currentKeyframe) { if (currentKeyframe == null) { return; } if (currentKeyframe.hitboxes != null && currentKeyframe.hitboxes.Length > 0) { for (int i = 0; i < currentKeyframe.hitboxes.Length; i++) { GUILayout.BeginVertical(hitboxBackgroundStyle); GUILayout.Label("Hitbox " + i); GUILayout.BeginHorizontal(); currentKeyframe.hitboxes[i].Type = (HitboxType)EditorGUILayout.EnumPopup(currentKeyframe.hitboxes[i].Type, GUILayout.Width(100)); currentKeyframe.hitboxes[i].Shape = (HitboxShape)EditorGUILayout.EnumPopup(currentKeyframe.hitboxes[i].Shape, GUILayout.Width(100)); GUILayout.EndHorizontal(); if (currentKeyframe.hitboxes[i].Shape == HitboxShape.Rectangle) { currentKeyframe.hitboxes[i].Boundaries = EditorGUILayout.RectField(currentKeyframe.hitboxes[i].Boundaries); } else { //currentKeyframe.hitboxes[i].Boundaries = EditorGUILayout.FloatField("Radius ", currentKeyframe.hitboxes[i].Boundaries); } GUILayout.BeginHorizontal(); GUILayout.Label("", GUILayout.ExpandWidth(true)); if (GUILayout.Button("Remove", GUILayout.Width(60))) { for (int j = i; j < currentKeyframe.hitboxes.Length - 1; j++) { currentKeyframe.hitboxes[j] = currentKeyframe.hitboxes[j + 1]; } Array.Resize(ref currentKeyframe.hitboxes, currentKeyframe.hitboxes.Length - 1); SceneView.RepaintAll(); } GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUILayout.BeginVertical(GUILayout.Height(10)); GUILayout.Label("", GUILayout.Height(10)); GUILayout.EndVertical(); } } if (currentKeyframe.hitboxes.Length == 0 && GUILayout.Button("Copy previous frame Hitboxes", GUILayout.Width(250))) { if (keyframesIndex != 0) { Hitbox[] hitboxes = targetComponents.ZeroHitbox.AnimationClips[animationClipsIndex].keyframes[keyframesIndex - 1].hitboxes.Clone() as Hitbox[]; Array.Resize(ref currentKeyframe.hitboxes, hitboxes.Length); for (int i = 0; i < hitboxes.Length; i++) { Hitbox hitbox = new Hitbox(hitboxes[i].Boundaries, hitboxes[i].Type); hitbox.Shape = hitboxes[i].Shape; hitbox.Boundaries = hitboxes[i].Boundaries; currentKeyframe.hitboxes[i] = hitbox; } SceneView.RepaintAll(); } else { Debug.LogError("You are on the first frame, can't copy previous frame Hitboxes!"); } } if (GUILayout.Button("Add Hitbox", GUILayout.Width(100))) { Array.Resize(ref currentKeyframe.hitboxes, currentKeyframe.hitboxes.Length + 1); currentKeyframe.hitboxes[currentKeyframe.hitboxes.Length - 1] = new Hitbox(new Rect(0f, 0f, 1f, 1.5f), HitboxType.Hittable); SceneView.RepaintAll(); } }
private void DrawHitboxes(AKeyframe currentKeyframe) { if (currentKeyframe == null) return; if (currentKeyframe.hitboxes != null && currentKeyframe.hitboxes.Length > 0) { for (int i = 0; i < currentKeyframe.hitboxes.Length; i++) { GUILayout.BeginVertical(hitboxBackgroundStyle); GUILayout.Label("Hitbox " + i); GUILayout.BeginHorizontal(); currentKeyframe.hitboxes[i].Type = (HitboxType)EditorGUILayout.EnumPopup(currentKeyframe.hitboxes[i].Type, GUILayout.Width(100)); currentKeyframe.hitboxes[i].Shape = (HitboxShape)EditorGUILayout.EnumPopup(currentKeyframe.hitboxes[i].Shape, GUILayout.Width(100)); GUILayout.EndHorizontal(); if (currentKeyframe.hitboxes[i].Shape == HitboxShape.Rectangle) { currentKeyframe.hitboxes[i].Boundaries = EditorGUILayout.RectField(currentKeyframe.hitboxes[i].Boundaries); } else { //currentKeyframe.hitboxes[i].Boundaries = EditorGUILayout.FloatField("Radius ", currentKeyframe.hitboxes[i].Boundaries); } GUILayout.BeginHorizontal(); GUILayout.Label("", GUILayout.ExpandWidth(true)); if (GUILayout.Button("Remove", GUILayout.Width(60))) { for (int j = i; j < currentKeyframe.hitboxes.Length - 1; j++) { currentKeyframe.hitboxes[j] = currentKeyframe.hitboxes[j + 1]; } Array.Resize(ref currentKeyframe.hitboxes, currentKeyframe.hitboxes.Length - 1); SceneView.RepaintAll(); } GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUILayout.BeginVertical(GUILayout.Height(10)); GUILayout.Label("", GUILayout.Height(10)); GUILayout.EndVertical(); } } if (currentKeyframe.hitboxes.Length == 0 && GUILayout.Button("Copy previous frame Hitboxes", GUILayout.Width(250))) { if (keyframesIndex != 0) { Hitbox[] hitboxes = targetComponents.ZeroHitbox.AnimationClips[animationClipsIndex].keyframes[keyframesIndex - 1].hitboxes.Clone() as Hitbox[]; Array.Resize(ref currentKeyframe.hitboxes, hitboxes.Length); for (int i = 0; i < hitboxes.Length; i++) { Hitbox hitbox = new Hitbox(hitboxes[i].Boundaries, hitboxes[i].Type); hitbox.Shape = hitboxes[i].Shape; hitbox.Boundaries = hitboxes[i].Boundaries; currentKeyframe.hitboxes[i] = hitbox; } SceneView.RepaintAll(); } else { Debug.LogError("You are on the first frame, can't copy previous frame Hitboxes!"); } } if (GUILayout.Button("Add Hitbox", GUILayout.Width(100))) { Array.Resize(ref currentKeyframe.hitboxes, currentKeyframe.hitboxes.Length + 1); currentKeyframe.hitboxes[currentKeyframe.hitboxes.Length - 1] = new Hitbox(new Rect(0f, 0f, 1f, 1.5f), HitboxType.Hittable); SceneView.RepaintAll(); } }
private void DrawFrames(AAnimationClip currentClip, AKeyframe currentKeyframe) { GUILayout.BeginHorizontal(); GUILayout.Label("Sprite", GUILayout.Width(70)); currentKeyframe.Sprite = EditorGUILayout.ObjectField(currentKeyframe.Sprite, typeof(Sprite), true) as Sprite; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Frame " + (keyframesIndex + 1) + "/" + currentClip.keyframes.Length); if (GUILayout.Button("<", GUILayout.Width(30))) { keyframesIndex--; if (keyframesIndex < 0) keyframesIndex = currentClip.keyframes.Length - 1; } if (GUILayout.Button(">", GUILayout.Width(30))) { keyframesIndex++; if (keyframesIndex >= currentClip.keyframes.Length) { keyframesIndex = 0; } } GUILayout.EndHorizontal(); }