mirror of
https://gitgud.io/AbstractConcept/rimworld-animation-studio.git
synced 2024-08-15 00:43:27 +00:00
131 lines
5.2 KiB
C#
131 lines
5.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace RimWorldAnimationStudio
|
|
{
|
|
public class ActorCard : MonoBehaviour
|
|
{
|
|
public Dropdown genderDropdown;
|
|
public Dropdown bodyTypeDropdown;
|
|
public InputField bodyOffsetXField;
|
|
public InputField bodyOffsetZField;
|
|
public InputField raceOffsetXField;
|
|
public InputField raceOffsetZField;
|
|
public Toggle initiatorToggle;
|
|
public Dropdown selectActorLayerDropdown;
|
|
|
|
public void Initialize()
|
|
{
|
|
Actor actor = Workspace.animationDef.actors[Workspace.actorID];
|
|
string bodyType = bodyTypeDropdown.options[bodyTypeDropdown.value].text;
|
|
bodyType = bodyType == null || bodyType == "" ? "Male" : bodyType;
|
|
|
|
initiatorToggle.isOn = actor.initiator;
|
|
bodyOffsetXField.text = actor.bodyTypeOffset.GetOffset(bodyType).x.ToString();
|
|
bodyOffsetZField.text = actor.bodyTypeOffset.GetOffset(bodyType).z.ToString();
|
|
}
|
|
|
|
public void OnBodyTypeChanged()
|
|
{
|
|
if (Workspace.animationDef == null) return;
|
|
|
|
Actor actor = Workspace.animationDef.actors[Workspace.actorID];
|
|
|
|
string bodyType = bodyTypeDropdown.options[bodyTypeDropdown.value].text;
|
|
bodyType = bodyType == null || bodyType == "" ? "Male" : bodyType;
|
|
|
|
AnimationController.Instance.actorBodies.GetComponentsInChildren<ActorBody>()[Workspace.actorID].bodyType = bodyType;
|
|
|
|
bodyOffsetXField.text = actor.bodyTypeOffset.GetOffset(bodyType).x.ToString();
|
|
bodyOffsetZField.text = actor.bodyTypeOffset.GetOffset(bodyType).z.ToString();
|
|
}
|
|
|
|
public void OnValueChanged()
|
|
{
|
|
if (Workspace.animationDef == null) return;
|
|
|
|
Actor actor = Workspace.animationDef.actors[Workspace.actorID];
|
|
|
|
string bodyType = bodyTypeDropdown.options[bodyTypeDropdown.value].text;
|
|
bodyType = bodyType == null || bodyType == "" ? "Male" : bodyType;
|
|
|
|
float.TryParse(bodyOffsetXField.text, out float x);
|
|
float.TryParse(bodyOffsetZField.text, out float z);
|
|
actor.bodyTypeOffset.SetOffset(bodyType, new Vector2(x, z));
|
|
|
|
actor.initiator = initiatorToggle.isOn;
|
|
|
|
switch (genderDropdown.value)
|
|
{
|
|
case 0: actor.requiredGender = new List<string>() { "Female" }; break;
|
|
case 2: actor.requiredGender = new List<string>() { "Male" }; break;
|
|
default: actor.requiredGender = null; break;
|
|
}
|
|
|
|
float.TryParse(raceOffsetXField.text, out x);
|
|
float.TryParse(raceOffsetZField.text, out z);
|
|
actor.SetAlienRaceOffset(new Vector2(x, z));
|
|
|
|
Workspace.Instance.RecordEvent("Actor body offset data");
|
|
}
|
|
|
|
public void OnActorLayerChange()
|
|
{
|
|
PawnAnimationClip clip = Workspace.Instance.GetCurrentPawnAnimationClip();
|
|
|
|
if (clip == null) return;
|
|
clip.layer = selectActorLayerDropdown.captionText.text;
|
|
|
|
Workspace.Instance.RecordEvent("Actor render layer " + clip.layer);
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
if (Workspace.animationDef == null) return;
|
|
|
|
if (Workspace.actorID >= AnimationController.Instance.actorBodies.GetComponentsInChildren<ActorBody>().Count())
|
|
{ Debug.Log("Waiting for actors to initialize..."); return; }
|
|
|
|
Actor actor = Workspace.animationDef.actors[Workspace.actorID];
|
|
ActorBody actorBody = AnimationController.Instance.actorBodies.GetComponentsInChildren<ActorBody>()[Workspace.actorID];
|
|
PawnAnimationClip clip = Workspace.Instance.GetCurrentPawnAnimationClip();
|
|
|
|
string bodyType = actorBody.bodyType;
|
|
bodyType = bodyType == null || bodyType == "" ? "Male" : bodyType;
|
|
|
|
bodyTypeDropdown.value = bodyTypeDropdown.options.IndexOf(bodyTypeDropdown.options.First(x => x.text == bodyType));
|
|
|
|
if (bodyOffsetXField.isFocused == false)
|
|
{ bodyOffsetXField.text = actor.bodyTypeOffset.GetOffset(bodyType).x.ToString(); }
|
|
|
|
if (bodyOffsetZField.isFocused == false)
|
|
{ bodyOffsetZField.text = actor.bodyTypeOffset.GetOffset(bodyType).z.ToString(); }
|
|
|
|
if (raceOffsetXField.isFocused == false)
|
|
{ raceOffsetXField.text = actor.GetAlienRaceOffset().x.ToString(); }
|
|
|
|
if (raceOffsetZField.isFocused == false)
|
|
{ raceOffsetZField.text = actor.GetAlienRaceOffset().z.ToString(); }
|
|
|
|
initiatorToggle.isOn = actor.initiator;
|
|
|
|
if (actor.requiredGender.Contains("Female"))
|
|
{ genderDropdown.SetValueWithoutNotify(0); }
|
|
|
|
else if (actor.requiredGender.Contains("Male"))
|
|
{ genderDropdown.SetValueWithoutNotify(2); }
|
|
|
|
else
|
|
{ genderDropdown.SetValueWithoutNotify(1); }
|
|
|
|
for (int i = 0; i < selectActorLayerDropdown.options.Count; i++)
|
|
{
|
|
if (selectActorLayerDropdown.options[i].text == clip.layer)
|
|
{ selectActorLayerDropdown.SetValueWithoutNotify(i); }
|
|
}
|
|
}
|
|
}
|
|
}
|