mirror of
https://gitgud.io/AbstractConcept/rimworld-animation-studio.git
synced 2024-08-15 00:43:27 +00:00
Code refactor
This commit is contained in:
parent
cd4711a8e5
commit
757badf4f6
517 changed files with 2534 additions and 2221 deletions
101
Assets/Scripts/GUI/Actors/ActorBody.cs
Normal file
101
Assets/Scripts/GUI/Actors/ActorBody.cs
Normal file
|
@ -0,0 +1,101 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace RimWorldAnimationStudio
|
||||
{
|
||||
public class ActorBody : MonoBehaviour, IPointerClickHandler, IDragHandler, IEndDragHandler
|
||||
{
|
||||
public int actorID;
|
||||
public bool isSelected = false;
|
||||
|
||||
public SpriteRenderer bodyRenderer;
|
||||
public SpriteRenderer headRenderer;
|
||||
public SpriteRenderer appendageRenderer;
|
||||
|
||||
private Vector3 delta = new Vector3();
|
||||
|
||||
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; }
|
||||
|
||||
foreach (ActorAddon addon in Workspace.GetCurrentAnimationStage().AnimationClips[actorID].Addons)
|
||||
{
|
||||
ActorBodyPart bodyPart = GetComponentsInChildren<ActorBodyPart>(true).FirstOrDefault(x => x.addonName == addon.AddonName);
|
||||
bodyPart?.gameObject?.SetActive(addon.Render);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
if (eventData.pointerCurrentRaycast.gameObject.GetComponent<ActorBodyPart>())
|
||||
{ return; }
|
||||
|
||||
Activate();
|
||||
}
|
||||
|
||||
public void OnDrag(PointerEventData eventData)
|
||||
{
|
||||
Activate();
|
||||
|
||||
PawnKeyframe keyframe = Workspace.GetCurrentPawnKeyframe(true);
|
||||
|
||||
if (keyframe == null)
|
||||
{ Debug.LogWarning("Cannot alter actor - no keyframe data available"); return; }
|
||||
|
||||
Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
||||
|
||||
if (delta == Vector3.zero)
|
||||
{ delta = mousePosition - transform.position; }
|
||||
|
||||
if (Workspace.actorManipulationMode == ActorManipulationMode.Pan)
|
||||
{
|
||||
keyframe.BodyOffsetX = mousePosition.x - delta.x - Workspace.animationDef.Actors[actorID].GetFinalTransformOffset().x;
|
||||
keyframe.BodyOffsetZ = mousePosition.y - delta.y - Workspace.animationDef.Actors[actorID].GetFinalTransformOffset().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.GetPawnAnimationClip(actorID);
|
||||
clip.BuildSimpleCurves();
|
||||
}
|
||||
|
||||
public void OnEndDrag(PointerEventData eventData)
|
||||
{
|
||||
Workspace.RecordEvent("Actor position / orientation");
|
||||
delta = Vector3.zero;
|
||||
}
|
||||
|
||||
public void Activate()
|
||||
{
|
||||
Workspace.ActorID = actorID;
|
||||
Workspace.selectedBodyPart = null;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/GUI/Actors/ActorBody.cs.meta
Normal file
11
Assets/Scripts/GUI/Actors/ActorBody.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 511a9ed9093e7fc458dec8d3c657f9a5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
160
Assets/Scripts/GUI/Actors/ActorBodyPart.cs
Normal file
160
Assets/Scripts/GUI/Actors/ActorBodyPart.cs
Normal file
|
@ -0,0 +1,160 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace RimWorldAnimationStudio
|
||||
{
|
||||
public class ActorBodyPart : MonoBehaviour, IPointerClickHandler, IDragHandler, IEndDragHandler
|
||||
{
|
||||
public SpriteRenderer bodyPartRenderer;
|
||||
public ActorBody parent;
|
||||
public bool isHead = false;
|
||||
public string addonName;
|
||||
public bool isSelected = false;
|
||||
|
||||
private Vector3 delta = new Vector3();
|
||||
|
||||
public void Start()
|
||||
{
|
||||
//Workspace.onActorChanged.AddListener(delegate { });
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if ((Workspace.ActorID == parent.actorID && Workspace.selectedBodyPart == null) || Workspace.selectedBodyPart == this)
|
||||
{ bodyPartRenderer.color = Constants.ColorGreen; }
|
||||
|
||||
else
|
||||
{ bodyPartRenderer.color = Constants.ColorWhite; }
|
||||
}
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
if (eventData.pointerCurrentRaycast.gameObject.GetComponent<ActorBodyPart>() == null)
|
||||
{ return; }
|
||||
|
||||
Activate();
|
||||
}
|
||||
|
||||
public void OnDrag(PointerEventData eventData)
|
||||
{
|
||||
Activate();
|
||||
|
||||
PawnKeyframe keyframe = Workspace.GetCurrentPawnKeyframe(true);
|
||||
|
||||
if (keyframe == null)
|
||||
{ Debug.LogWarning("Cannot alter actor - no keyframe data available"); return; }
|
||||
|
||||
Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
||||
|
||||
if (delta == Vector3.zero)
|
||||
{ delta = mousePosition - transform.position; }
|
||||
|
||||
if (addonName != null && addonName != "")
|
||||
{
|
||||
AddonKeyframe addonKeyframe = keyframe.GetAddonKeyframe(addonName);
|
||||
ActorAddon addon = Workspace.GetCurrentPawnAnimationClip().GetActorAddon(addonName);
|
||||
|
||||
if (Workspace.actorManipulationMode == ActorManipulationMode.Pan)
|
||||
{
|
||||
Vector3 anchor;
|
||||
|
||||
ActorBody anchoringActorBody = AnimationController.Instance.actorBodies.GetComponentsInChildren<ActorBody>()?.FirstOrDefault(x => x.actorID == addon.AnchoringActor);
|
||||
Vector3 bodyPos = new Vector3(anchoringActorBody.transform.position.x, anchoringActorBody.transform.position.y, 0);
|
||||
PawnRaceDef pawnRaceDef = Workspace.animationDef.Actors[addon.AnchoringActor].GetPawnRaceDef();
|
||||
Actor anchoringActor = Workspace.animationDef.Actors[addon.AnchoringActor];
|
||||
int bodyFacing = (int)Workspace.GetCurrentAnimationStage().AnimationClips[addon.AnchoringActor].BodyFacing.Evaluate((float)Workspace.StageTick / Workspace.StageWindowSize);
|
||||
|
||||
switch (addon.AnchorName)
|
||||
{
|
||||
case "torso": anchor = bodyPos; break;
|
||||
case "head": anchor = new Vector3(anchoringActorBody.transform.Find("ActorHead").position.x, anchoringActorBody.transform.Find("ActorHead").position.y, 0); break;
|
||||
case "groin": anchor = bodyPos + Quaternion.AngleAxis(anchoringActorBody.transform.rotation.eulerAngles.z, Vector3.forward) * PawnUtility.GroinOffsetAt(anchoringActor.bodyType, bodyFacing).FlipAxes(); break;
|
||||
case "left breast": anchor = bodyPos + Quaternion.AngleAxis(anchoringActorBody.transform.rotation.eulerAngles.z, Vector3.forward) * PawnUtility.BreastLeftOffsetAt(anchoringActor.bodyType, bodyFacing).FlipAxes(); break;
|
||||
case "right breast": anchor = bodyPos + Quaternion.AngleAxis(anchoringActorBody.transform.rotation.eulerAngles.z, Vector3.forward) * PawnUtility.BreastRightOffsetAt(anchoringActor.bodyType, bodyFacing).FlipAxes(); break;
|
||||
default: anchor = new Vector3(); break;
|
||||
}
|
||||
|
||||
transform.position = new Vector3(mousePosition.x, mousePosition.y, 0f);
|
||||
|
||||
addonKeyframe.PosX = transform.position.x - anchor.x;
|
||||
addonKeyframe.PosZ = transform.position.y - anchor.y;
|
||||
|
||||
ActorKeyframeCard.Instance.transform.GetComponentsInChildren<ActorAddonCard>()?.FirstOrDefault(x => x.addonName == addonName)?.OnKeyframeValueChanged();
|
||||
}
|
||||
|
||||
else if (Workspace.actorManipulationMode == ActorManipulationMode.Rotate)
|
||||
{
|
||||
float angle = -Vector2.SignedAngle(Vector2.down, (Vector2)mousePosition - (Vector2)transform.position);
|
||||
addonKeyframe.Rotation = 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.headFacing = facing;
|
||||
}
|
||||
}
|
||||
|
||||
else if (isHead)
|
||||
{
|
||||
if (Workspace.actorManipulationMode == ActorManipulationMode.Pan)
|
||||
{
|
||||
// It's stupid but it works
|
||||
Vector3 localPosA = transform.localPosition;
|
||||
transform.position = mousePosition - delta;
|
||||
Vector3 localPosB = transform.localPosition;
|
||||
transform.localPosition = localPosA;
|
||||
|
||||
keyframe.HeadBob += localPosB.y - localPosA.y;
|
||||
}
|
||||
|
||||
else if (Workspace.actorManipulationMode == ActorManipulationMode.Rotate)
|
||||
{
|
||||
float angle = -Vector2.SignedAngle(Vector2.down, (Vector2)mousePosition - (Vector2)transform.position);
|
||||
keyframe.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;
|
||||
|
||||
keyframe.HeadFacing = facing;
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if (Workspace.actorManipulationMode == ActorManipulationMode.Rotate)
|
||||
{
|
||||
float angle = -Vector2.SignedAngle(Vector2.up, (Vector2)mousePosition - (Vector2)transform.position);
|
||||
keyframe.GenitalAngle = angle;
|
||||
|
||||
Workspace.GetCurrentActor().ControlGenitalAngle = Workspace.animationDef.AnimationStages.Any(x => x.AnimationClips[Workspace.ActorID].Keyframes.Any(y => y.GenitalAngle != 0));
|
||||
}
|
||||
}
|
||||
|
||||
PawnAnimationClip clip = Workspace.GetPawnAnimationClip(parent.actorID);
|
||||
clip.BuildSimpleCurves();
|
||||
}
|
||||
|
||||
public void OnEndDrag(PointerEventData eventData)
|
||||
{
|
||||
Workspace.RecordEvent("Actor position / orientation");
|
||||
delta = Vector3.zero;
|
||||
}
|
||||
|
||||
public void Activate()
|
||||
{
|
||||
Workspace.ActorID = parent.actorID;
|
||||
Workspace.selectedBodyPart = this;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/GUI/Actors/ActorBodyPart.cs.meta
Normal file
11
Assets/Scripts/GUI/Actors/ActorBodyPart.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b23e33f312d52c642b86f5f2138f4030
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue