mirror of
https://gitgud.io/AbstractConcept/rimworld-animation-studio.git
synced 2024-08-15 00:43:27 +00:00
68 lines
3 KiB
C#
68 lines
3 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; }
|
|||
|
|
|||
|
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();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|