78 lines
2.7 KiB
C#
78 lines
2.7 KiB
C#
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; }
|
|
|
|
Activate();
|
|
}
|
|
|
|
public void OnDrag(PointerEventData eventData)
|
|
{
|
|
Activate();
|
|
|
|
PawnKeyframe keyframe = Workspace.Instance.GetCurrentPawnKeyframe();
|
|
|
|
if (Workspace.Instance.GetCurrentPawnKeyframe() == null)
|
|
{ Debug.LogWarning("Cannot alter actor - no keyframe data available"); return; }
|
|
|
|
Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
|
|
|
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));
|
|
|
|
keyframe.headBob = distance;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
PawnAnimationClip clip = Workspace.Instance.GetPawnAnimationClip(parent.actorID);
|
|
clip.BuildSimpleCurves();
|
|
}
|
|
|
|
public void Activate()
|
|
{
|
|
Workspace.actorID = parent.actorID;
|
|
|
|
foreach (ActorBody actorBody in AnimationController.Instance.actorBodies.GetComponentsInChildren<ActorBody>())
|
|
{
|
|
actorBody.bodyRenderer.color = Constants.ColorWhite;
|
|
actorBody.headRenderer.color = Constants.ColorWhite;
|
|
}
|
|
|
|
bodyPartRenderer.color = Constants.ColorGreen;
|
|
}
|
|
}
|
|
}
|