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 string bodyType = "Male";
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
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; }
|
|
|
|
|
|
|
|
|
|
appendageRenderer.gameObject.SetActive(Workspace.animationDef.actors[actorID].requiredGenitals.Any(x => x == "Penis" || x == "Any appendage"));
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-16 22:50:15 +00:00
|
|
|
|
public void OnPointerClick(PointerEventData eventData)
|
|
|
|
|
{
|
|
|
|
|
if (eventData.pointerCurrentRaycast.gameObject.GetComponent<ActorBody>() == null)
|
|
|
|
|
{ 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; }
|
|
|
|
|
|
|
|
|
|
Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
2022-09-16 22:50:15 +00:00
|
|
|
|
|
|
|
|
|
if (Workspace.actorManipulationMode == ActorManipulationMode.Pan)
|
|
|
|
|
{
|
2022-09-18 00:06:33 +00:00
|
|
|
|
keyframe.bodyOffsetX = mousePosition.x;
|
|
|
|
|
keyframe.bodyOffsetZ = mousePosition.y;
|
2022-09-16 22:50:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (Workspace.actorManipulationMode == ActorManipulationMode.Rotate)
|
|
|
|
|
{
|
|
|
|
|
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-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-20 06:03:55 +00:00
|
|
|
|
/*foreach (ActorBody actorBody in AnimationController.Instance.actorBodies.GetComponentsInChildren<ActorBody>())
|
2022-09-18 00:06:33 +00:00
|
|
|
|
{
|
|
|
|
|
if (actorBody == this)
|
|
|
|
|
{ continue; }
|
|
|
|
|
|
2022-09-18 06:52:54 +00:00
|
|
|
|
actorBody.bodyRenderer.color = Constants.ColorWhite;
|
|
|
|
|
actorBody.headRenderer.color = Constants.ColorWhite;
|
2022-09-20 06:03:55 +00:00
|
|
|
|
actorBody.appendageRenderer.color = Constants.ColorWhite;
|
|
|
|
|
|
|
|
|
|
actorBody.isSelected = false;
|
2022-09-18 00:06:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 06:52:54 +00:00
|
|
|
|
bodyRenderer.color = Constants.ColorGreen;
|
|
|
|
|
headRenderer.color = Constants.ColorGreen;
|
2022-09-20 06:03:55 +00:00
|
|
|
|
appendageRenderer.color = Constants.ColorGreen;
|
|
|
|
|
|
|
|
|
|
foreach (ActorBodyPart actorBodyPartSelected in GetComponentsInChildren<ActorBodyPart>())
|
|
|
|
|
{ actorBodyPartSelected.isSelected = false; }
|
|
|
|
|
|
|
|
|
|
isSelected = true;*/
|
2022-09-18 00:06:33 +00:00
|
|
|
|
}
|
2022-09-13 05:36:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|