Improved adding and removal of anim events

This commit is contained in:
AbstractConcept 2022-09-17 19:06:33 -05:00
parent f0d46df3d6
commit 8523abf957
276 changed files with 1401 additions and 5422 deletions

View file

@ -33,5 +33,26 @@ namespace RimWorldAnimationStudio
public bool ShouldSerializecontrolGenitalAngle() { return controlGenitalAngle != null; }
public bool ShouldSerializeisFucking() { return isFucking != null; }
public bool ShouldSerializeisFucked() { return isFucked != null; }
public bool MakeNew()
{
if (Workspace.animationDef == null)
{ Debug.LogWarning("Cannot make new actor - there is no AnimationDef"); return false; }
Workspace.animationDef.actors.Add(this);
foreach (AnimationStage stage in Workspace.animationDef.animationStages)
{
PawnAnimationClip clip = new PawnAnimationClip();
if (clip.MakeNew())
{
stage.animationClips.Add(clip);
stage.Initialize();
}
}
return true;
}
}
}

View file

@ -1,67 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.EventSystems;
namespace RimWorldAnimationStudio
{
public class ActorBodyPart : MonoBehaviour, IDragHandler, IPointerClickHandler
{
public SpriteRenderer bodyPartRenderer;
public ActorBody parent;
public void OnPointerClick(PointerEventData eventData)
{
if (eventData.pointerCurrentRaycast.gameObject.GetComponent<ActorBodyPart>() == null)
{ return; }
foreach (ActorBody actorBody in AnimationController.Instance.actorBodies)
{
actorBody.bodyRenderer.color = new Color(1f, 1f, 1f);
actorBody.headRenderer.color = new Color(1f, 1f, 1f);
}
bodyPartRenderer.color = new Color(0f, 1f, 0f);
}
public void OnDrag(PointerEventData eventData)
{
Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
PawnKeyframe keyframe = Workspace.animationDef.animationStages[Workspace.stageID].animationClips[parent.actorID].keyframes.FirstOrDefault(x => x.keyframeID == Workspace.keyframeID);
if (Workspace.actorManipulationMode == ActorManipulationMode.Pan)
{
float distance = ((Vector2)mousePosition - (Vector2)transform.position).y;
Vector3 headOffset = new Vector3(0f, 0.34f, 0f);
headOffset = Quaternion.Euler(0, 0, keyframe.bodyAngle) * headOffset;
distance = Vector2.Dot(parent.transform.up, (Vector2)(mousePosition - parent.transform.position - headOffset));
Debug.Log(headOffset.ToString());
Workspace.animationDef.animationStages[Workspace.stageID].animationClips[parent.actorID].keyframes.FirstOrDefault(x => x.keyframeID == Workspace.keyframeID).headBob = distance;
}
else if (Workspace.actorManipulationMode == ActorManipulationMode.Rotate)
{
float angle = Vector2.SignedAngle(Vector2.down, (Vector2)mousePosition - (Vector2)transform.position);
Workspace.animationDef.animationStages[Workspace.stageID].animationClips[parent.actorID].keyframes.FirstOrDefault(x => x.keyframeID == Workspace.keyframeID).headAngle = angle;
}
else if (Workspace.actorManipulationMode == ActorManipulationMode.Face)
{
float angle = Vector2.SignedAngle(Vector2.up, (Vector2)mousePosition - (Vector2)transform.position);
int facing = -Mathf.RoundToInt(angle / 90f);
facing = facing < 0 ? facing + 4 : facing;
Debug.Log(facing.ToString());
Workspace.animationDef.animationStages[Workspace.stageID].animationClips[parent.actorID].keyframes.FirstOrDefault(x => x.keyframeID == Workspace.keyframeID).headFacing = facing;
}
PawnAnimationClip clip = Workspace.Instance.GetPawnAnimationClip(parent.actorID);
clip.BuildSimpleCurves();
}
}
}

View file

@ -30,7 +30,6 @@ namespace RimWorldAnimationStudio
BodyFacing.Clear();
HeadBob.Clear();
GenitalAngle.Clear();
SoundEffects.Clear();
int duration = 0;
@ -60,9 +59,6 @@ namespace RimWorldAnimationStudio
if (keyframe.genitalAngle.HasValue)
{ GenitalAngle.Add((float)keyframe.atTick / (float)duration, keyframe.genitalAngle.Value, true); }
if (keyframe.soundEffect != null)
{ SoundEffects.Add((int)keyframe.atTick, keyframe.soundEffect); }
if (i + 1 < keyframes.Count)
{ keyframes[i].tickDuration = keyframes[i + 1].atTick.Value - keyframes[i].atTick.Value; }
}
@ -78,10 +74,7 @@ namespace RimWorldAnimationStudio
HeadBob.Add((float)keyframePosition / (float)duration, keyframe.headBob, true);
if (keyframe.genitalAngle.HasValue)
GenitalAngle.Add((float)keyframePosition / (float)duration, keyframe.genitalAngle.Value, true);
if (keyframe.soundEffect != null)
{ SoundEffects.Add(keyframePosition, keyframe.soundEffect); }
{ GenitalAngle.Add((float)keyframePosition / (float)duration, keyframe.genitalAngle.Value, true); }
if (keyframe.tickDuration != 1 && keyframe.quiver.HasValue)
{
@ -96,5 +89,19 @@ namespace RimWorldAnimationStudio
keyframes[keyframes.Count - 1].tickDuration = 1;
}
public bool MakeNew()
{
PawnKeyframe keyframeA = new PawnKeyframe();
keyframeA.tickDuration = 60;
keyframes.Add(keyframeA);
PawnKeyframe keyframeB = new PawnKeyframe();
keyframes.Add(keyframeB);
BuildSimpleCurves();
return true;
}
}
}

View file

@ -1,16 +1,17 @@
using System.Collections.Generic;
using System.Xml;
using System.Xml.Serialization;
using UnityEngine;
namespace RimWorldAnimationStudio
{
public class AnimationStage
{
public string stageName = "default";
public string stageName = "NewStage";
public int stageIndex = 0;
public int playTimeTicks = 0;
public int playTimeTicksQuick = -1;
public bool isLooping = true;
public bool isLooping = false;
[XmlArray("animationClips"), XmlArrayItem("li")]
public List<PawnAnimationClip> animationClips = new List<PawnAnimationClip>();
@ -26,5 +27,25 @@ namespace RimWorldAnimationStudio
{ playTimeTicks = clip.duration; }
}
}
public bool MakeNew()
{
if (Workspace.animationDef == null)
{ Debug.LogWarning("Cannot make new animation stage - there is no AnimationDef"); return false; }
foreach(Actor actor in Workspace.animationDef.actors)
{
PawnAnimationClip clip = new PawnAnimationClip();
if (clip.MakeNew())
{ animationClips.Add(clip); }
}
Initialize();
Workspace.animationDef.animationStages.Add(this);
return true;
}
}
}

View file

@ -0,0 +1,13 @@
using System.Collections.Generic;
using System.Xml;
using System.Xml.Serialization;
namespace RimWorldAnimationStudio
{
[XmlRoot("Defs", IsNullable = false)]
public class Defs
{
[XmlElement("Rimworld_Animations.AnimationDef")]
public List<AnimationDef> animationDefs = new List<AnimationDef>();
}
}

View file

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: b23e33f312d52c642b86f5f2138f4030
guid: 92804390faa29b945818e67cf808b49c
MonoImporter:
externalObjects: {}
serializedVersion: 2