mirror of
https://gitgud.io/AbstractConcept/rimworld-animation-studio.git
synced 2024-08-15 00:43:27 +00:00
108 lines
3.7 KiB
C#
108 lines
3.7 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 string bodyType = "Male";
|
|
public bool isSelected = false;
|
|
|
|
public SpriteRenderer bodyRenderer;
|
|
public SpriteRenderer headRenderer;
|
|
public SpriteRenderer appendageRenderer;
|
|
|
|
public bool actorBodyPartSelected { get { return GetComponentsInChildren<ActorBodyPart>().Any(x => x.isSelected); } }
|
|
|
|
public void Initialize(int actorID)
|
|
{
|
|
this.actorID = actorID;
|
|
}
|
|
|
|
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"));
|
|
}
|
|
|
|
public void OnPointerClick(PointerEventData eventData)
|
|
{
|
|
if (eventData.pointerCurrentRaycast.gameObject.GetComponent<ActorBody>() == null)
|
|
{ return; }
|
|
|
|
Activate();
|
|
}
|
|
|
|
public void OnDrag(PointerEventData eventData)
|
|
{
|
|
Activate();
|
|
|
|
PawnKeyframe keyframe = Workspace.Instance.GetCurrentPawnKeyframe(true);
|
|
|
|
if (keyframe == null)
|
|
{ Debug.LogWarning("Cannot alter actor - no keyframe data available"); return; }
|
|
|
|
Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
|
|
|
if (Workspace.actorManipulationMode == ActorManipulationMode.Pan)
|
|
{
|
|
keyframe.bodyOffsetX = mousePosition.x;
|
|
keyframe.bodyOffsetZ = mousePosition.y;
|
|
}
|
|
|
|
else if (Workspace.actorManipulationMode == ActorManipulationMode.Rotate)
|
|
{
|
|
float angle = Vector2.SignedAngle(Vector2.down, (Vector2)mousePosition - (Vector2)transform.position);
|
|
keyframe.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;
|
|
|
|
keyframe.bodyFacing = facing;
|
|
}
|
|
|
|
PawnAnimationClip clip = Workspace.Instance.GetPawnAnimationClip(actorID);
|
|
clip.BuildSimpleCurves();
|
|
}
|
|
|
|
public void Activate()
|
|
{
|
|
Workspace.actorID = actorID;
|
|
Workspace.selectedBodyPart = null;
|
|
|
|
/*foreach (ActorBody actorBody in AnimationController.Instance.actorBodies.GetComponentsInChildren<ActorBody>())
|
|
{
|
|
if (actorBody == this)
|
|
{ continue; }
|
|
|
|
actorBody.bodyRenderer.color = Constants.ColorWhite;
|
|
actorBody.headRenderer.color = Constants.ColorWhite;
|
|
actorBody.appendageRenderer.color = Constants.ColorWhite;
|
|
|
|
actorBody.isSelected = false;
|
|
}
|
|
|
|
bodyRenderer.color = Constants.ColorGreen;
|
|
headRenderer.color = Constants.ColorGreen;
|
|
appendageRenderer.color = Constants.ColorGreen;
|
|
|
|
foreach (ActorBodyPart actorBodyPartSelected in GetComponentsInChildren<ActorBodyPart>())
|
|
{ actorBodyPartSelected.isSelected = false; }
|
|
|
|
isSelected = true;*/
|
|
}
|
|
}
|
|
}
|