2022-09-13 05:36:34 +00:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
2022-09-16 22:50:15 +00:00
|
|
|
|
using System.Linq;
|
2022-09-13 05:36:34 +00:00
|
|
|
|
using UnityEngine;
|
2022-09-16 22:50:15 +00:00
|
|
|
|
using UnityEngine.EventSystems;
|
2022-09-13 05:36:34 +00:00
|
|
|
|
|
|
|
|
|
namespace RimWorldAnimationStudio
|
|
|
|
|
{
|
2022-09-21 05:40:58 +00:00
|
|
|
|
public class ActorBody : MonoBehaviour, IPointerClickHandler, IDragHandler, IEndDragHandler
|
2022-09-13 05:36:34 +00:00
|
|
|
|
{
|
2022-09-16 22:50:15 +00:00
|
|
|
|
public int actorID;
|
2022-09-20 06:03:55 +00:00
|
|
|
|
public bool isSelected = false;
|
2022-09-16 22:50:15 +00:00
|
|
|
|
|
2022-09-13 05:36:34 +00:00
|
|
|
|
public SpriteRenderer bodyRenderer;
|
|
|
|
|
public SpriteRenderer headRenderer;
|
2022-09-20 06:03:55 +00:00
|
|
|
|
public SpriteRenderer appendageRenderer;
|
|
|
|
|
|
2022-09-26 04:10:41 +00:00
|
|
|
|
private Vector3 delta = new Vector3();
|
|
|
|
|
|
2022-09-20 06:03:55 +00:00
|
|
|
|
public bool actorBodyPartSelected { get { return GetComponentsInChildren<ActorBodyPart>().Any(x => x.isSelected); } }
|
2022-09-16 22:50:15 +00:00
|
|
|
|
|
|
|
|
|
public void Initialize(int actorID)
|
|
|
|
|
{
|
|
|
|
|
this.actorID = actorID;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-20 06:03:55 +00:00
|
|
|
|
public void Update()
|
|
|
|
|
{
|
|
|
|
|
if (Workspace.actorID == actorID && Workspace.selectedBodyPart == null)
|
|
|
|
|
{ bodyRenderer.color = Constants.ColorGreen; }
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{ bodyRenderer.color = Constants.ColorWhite; }
|
|
|
|
|
|
2022-09-21 21:15:25 +00:00
|
|
|
|
appendageRenderer.gameObject.SetActive(Workspace.animationDef.actors[actorID].requiredGenitals.Any(x => x == "Penis") || Workspace.animationDef.actors[actorID].isFucking);
|
2022-09-20 06:03:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-09-16 22:50:15 +00:00
|
|
|
|
public void OnPointerClick(PointerEventData eventData)
|
|
|
|
|
{
|
2022-09-24 07:17:40 +00:00
|
|
|
|
if (eventData.pointerCurrentRaycast.gameObject.GetComponent<ActorBodyPart>())
|
2022-09-16 22:50:15 +00:00
|
|
|
|
{ return; }
|
|
|
|
|
|
2022-09-18 00:06:33 +00:00
|
|
|
|
Activate();
|
2022-09-16 22:50:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnDrag(PointerEventData eventData)
|
|
|
|
|
{
|
2022-09-18 00:06:33 +00:00
|
|
|
|
Activate();
|
|
|
|
|
|
2022-09-20 06:03:55 +00:00
|
|
|
|
PawnKeyframe keyframe = Workspace.Instance.GetCurrentPawnKeyframe(true);
|
2022-09-18 00:06:33 +00:00
|
|
|
|
|
2022-09-20 06:03:55 +00:00
|
|
|
|
if (keyframe == null)
|
2022-09-18 00:06:33 +00:00
|
|
|
|
{ Debug.LogWarning("Cannot alter actor - no keyframe data available"); return; }
|
|
|
|
|
|
2022-09-26 04:10:41 +00:00
|
|
|
|
Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
|
|
|
|
|
|
|
|
|
if (delta == Vector3.zero)
|
|
|
|
|
{ delta = mousePosition - transform.position; }
|
2022-09-16 22:50:15 +00:00
|
|
|
|
|
|
|
|
|
if (Workspace.actorManipulationMode == ActorManipulationMode.Pan)
|
|
|
|
|
{
|
2022-09-27 23:29:08 +00:00
|
|
|
|
keyframe.bodyOffsetX = mousePosition.x - delta.x - Workspace.animationDef.actors[actorID].GetFinalTransformOffset().x;
|
|
|
|
|
keyframe.bodyOffsetZ = mousePosition.y - delta.y - Workspace.animationDef.actors[actorID].GetFinalTransformOffset().y;
|
2022-09-16 22:50:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (Workspace.actorManipulationMode == ActorManipulationMode.Rotate)
|
|
|
|
|
{
|
2022-09-24 07:17:40 +00:00
|
|
|
|
float angle = -Vector2.SignedAngle(Vector2.down, (Vector2)mousePosition - (Vector2)transform.position);
|
2022-09-18 00:06:33 +00:00
|
|
|
|
keyframe.bodyAngle = angle;
|
2022-09-16 22:50:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
2022-09-18 00:06:33 +00:00
|
|
|
|
keyframe.bodyFacing = facing;
|
2022-09-16 22:50:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PawnAnimationClip clip = Workspace.Instance.GetPawnAnimationClip(actorID);
|
|
|
|
|
clip.BuildSimpleCurves();
|
|
|
|
|
}
|
2022-09-18 00:06:33 +00:00
|
|
|
|
|
2022-09-21 05:40:58 +00:00
|
|
|
|
public void OnEndDrag(PointerEventData eventData)
|
|
|
|
|
{
|
|
|
|
|
Workspace.Instance.RecordEvent("Actor position / orientation");
|
2022-09-26 04:10:41 +00:00
|
|
|
|
delta = Vector3.zero;
|
2022-09-21 05:40:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 00:06:33 +00:00
|
|
|
|
public void Activate()
|
|
|
|
|
{
|
|
|
|
|
Workspace.actorID = actorID;
|
2022-09-20 06:03:55 +00:00
|
|
|
|
Workspace.selectedBodyPart = null;
|
2022-09-18 00:06:33 +00:00
|
|
|
|
}
|
2022-09-13 05:36:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|