mirror of
https://gitgud.io/AbstractConcept/rimworld-animation-studio.git
synced 2024-08-15 00:43:27 +00:00
105 lines
3.7 KiB
C#
105 lines
3.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
|
|
namespace RimWorldAnimationStudio
|
|
{
|
|
public class ActorBodyPart : MonoBehaviour, IPointerClickHandler, IDragHandler, IEndDragHandler
|
|
{
|
|
public SpriteRenderer bodyPartRenderer;
|
|
public ActorBody parent;
|
|
public bool isHead = false;
|
|
public bool isSelected = false;
|
|
|
|
private Vector3 delta = new Vector3();
|
|
|
|
public void Update()
|
|
{
|
|
if ((Workspace.actorID == parent.actorID && Workspace.selectedBodyPart == null) || Workspace.selectedBodyPart == this)
|
|
{ bodyPartRenderer.color = Constants.ColorGreen; }
|
|
|
|
else
|
|
{ bodyPartRenderer.color = Constants.ColorWhite; }
|
|
}
|
|
|
|
public void OnPointerClick(PointerEventData eventData)
|
|
{
|
|
if (eventData.pointerCurrentRaycast.gameObject.GetComponent<ActorBodyPart>() == null)
|
|
{ return; }
|
|
|
|
Activate();
|
|
}
|
|
|
|
public void OnDrag(PointerEventData eventData)
|
|
{
|
|
Activate();
|
|
|
|
PawnKeyframe keyframe = Workspace.Instance.GetCurrentPawnKeyframe(true);
|
|
|
|
if (keyframe == null)
|
|
{ Debug.LogWarning("Cannot alter actor - no keyframe data available"); return; }
|
|
|
|
Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
|
|
|
if (delta == Vector3.zero)
|
|
{ delta = mousePosition - transform.position; }
|
|
|
|
if (isHead)
|
|
{
|
|
if (Workspace.actorManipulationMode == ActorManipulationMode.Pan)
|
|
{
|
|
// It's stupid but it works
|
|
Vector3 localPosA = transform.localPosition;
|
|
transform.position = mousePosition - delta;
|
|
Vector3 localPosB = transform.localPosition;
|
|
transform.localPosition = localPosA;
|
|
|
|
keyframe.headBob += localPosB.y - localPosA.y;
|
|
}
|
|
|
|
else if (Workspace.actorManipulationMode == ActorManipulationMode.Rotate)
|
|
{
|
|
float angle = -Vector2.SignedAngle(Vector2.down, (Vector2)mousePosition - (Vector2)transform.position);
|
|
keyframe.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;
|
|
|
|
keyframe.headFacing = facing;
|
|
}
|
|
}
|
|
|
|
else
|
|
{
|
|
if (Workspace.actorManipulationMode == ActorManipulationMode.Rotate)
|
|
{
|
|
float angle = -Vector2.SignedAngle(Vector2.up, (Vector2)mousePosition - (Vector2)transform.position);
|
|
keyframe.genitalAngle = angle;
|
|
|
|
Workspace.animationDef.actors[Workspace.actorID].controlGenitalAngle = Workspace.animationDef.animationStages.Any(x => x.animationClips[Workspace.actorID].keyframes.Any(y => y.genitalAngle != 0));
|
|
}
|
|
}
|
|
|
|
PawnAnimationClip clip = Workspace.Instance.GetPawnAnimationClip(parent.actorID);
|
|
clip.BuildSimpleCurves();
|
|
}
|
|
|
|
public void OnEndDrag(PointerEventData eventData)
|
|
{
|
|
Workspace.Instance.RecordEvent("Actor position / orientation");
|
|
delta = Vector3.zero;
|
|
}
|
|
|
|
public void Activate()
|
|
{
|
|
Workspace.actorID = parent.actorID;
|
|
Workspace.selectedBodyPart = this;
|
|
}
|
|
}
|
|
}
|