mirror of
https://gitgud.io/AbstractConcept/rimworld-animation-studio.git
synced 2024-08-05 11:53:08 +00:00
74 lines
2.9 KiB
C#
74 lines
2.9 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
|
|
namespace RimWorldAnimationStudio
|
|
{
|
|
public class ActorBody : MonoBehaviour, IPointerClickHandler, IDragHandler
|
|
{
|
|
public int actorID;
|
|
|
|
public SpriteRenderer bodyRenderer;
|
|
public SpriteRenderer headRenderer;
|
|
|
|
public void Initialize(int actorID)
|
|
{
|
|
this.actorID = actorID;
|
|
}
|
|
|
|
public void OnPointerClick(PointerEventData eventData)
|
|
{
|
|
if (eventData.pointerCurrentRaycast.gameObject.GetComponent<ActorBody>() == null)
|
|
{ return; }
|
|
|
|
foreach (ActorBody actorBody in AnimationController.Instance.actorBodies)
|
|
{
|
|
if (actorBody == this)
|
|
{ continue; }
|
|
|
|
actorBody.bodyRenderer.color = new Color(1f, 1f, 1f);
|
|
actorBody.headRenderer.color = new Color(1f, 1f, 1f);
|
|
}
|
|
|
|
bodyRenderer.color = new Color(0f, 1f, 0f);
|
|
headRenderer.color = new Color(0f, 1f, 0f);
|
|
|
|
Workspace.actorID = actorID;
|
|
}
|
|
|
|
public void OnDrag(PointerEventData eventData)
|
|
{
|
|
Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
|
|
|
|
|
if (Workspace.actorManipulationMode == ActorManipulationMode.Pan)
|
|
{
|
|
Workspace.animationDef.animationStages[Workspace.stageID].animationClips[actorID].keyframes.FirstOrDefault(x => x.keyframeID == Workspace.keyframeID).bodyOffsetX = mousePosition.x;
|
|
Workspace.animationDef.animationStages[Workspace.stageID].animationClips[actorID].keyframes.FirstOrDefault(x => x.keyframeID == Workspace.keyframeID).bodyOffsetZ = mousePosition.y;
|
|
}
|
|
|
|
else if (Workspace.actorManipulationMode == ActorManipulationMode.Rotate)
|
|
{
|
|
float angle = Vector2.SignedAngle(Vector2.down, (Vector2)mousePosition - (Vector2)transform.position);
|
|
Workspace.animationDef.animationStages[Workspace.stageID].animationClips[actorID].keyframes.FirstOrDefault(x => x.keyframeID == Workspace.keyframeID).bodyAngle = 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[actorID].keyframes.FirstOrDefault(x => x.keyframeID == Workspace.keyframeID).bodyFacing = facing;
|
|
}
|
|
|
|
PawnAnimationClip clip = Workspace.Instance.GetPawnAnimationClip(actorID);
|
|
clip.BuildSimpleCurves();
|
|
}
|
|
}
|
|
}
|