Improved adding and removal of anim events

This commit is contained in:
AbstractConcept 2022-09-17 19:06:33 -05:00
parent f0d46df3d6
commit 8523abf957
276 changed files with 1401 additions and 5422 deletions

View file

@ -0,0 +1,83 @@
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 SpriteRenderer bodyRenderer;
public SpriteRenderer headRenderer;
public void Initialize(int actorID)
{
this.actorID = actorID;
}
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();
if (Workspace.Instance.GetCurrentPawnKeyframe() == 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;
foreach (ActorBody actorBody in AnimationController.Instance.GetComponentsInChildren<ActorBody>())
{
if (actorBody == this)
{ continue; }
actorBody.bodyRenderer.color = new Color(1f, 1f, 1f);
actorBody.headRenderer.color = new Color(1f, 1f, 1f);
}
bodyRenderer.color = new Color(0f, 1f, 0f);
headRenderer.color = new Color(0f, 1f, 0f);
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 511a9ed9093e7fc458dec8d3c657f9a5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,76 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.EventSystems;
namespace RimWorldAnimationStudio
{
public class ActorBodyPart : MonoBehaviour, IDragHandler, IPointerClickHandler
{
public SpriteRenderer bodyPartRenderer;
public ActorBody parent;
public void OnPointerClick(PointerEventData eventData)
{
if (eventData.pointerCurrentRaycast.gameObject.GetComponent<ActorBodyPart>() == null)
{ return; }
Activate();
}
public void OnDrag(PointerEventData eventData)
{
Activate();
Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
PawnKeyframe keyframe = Workspace.animationDef.animationStages[Workspace.stageID].animationClips[parent.actorID].keyframes.FirstOrDefault(x => x.keyframeID == Workspace.keyframeID);
if (Workspace.actorManipulationMode == ActorManipulationMode.Pan)
{
float distance = ((Vector2)mousePosition - (Vector2)transform.position).y;
Vector3 headOffset = new Vector3(0f, 0.34f, 0f);
headOffset = Quaternion.Euler(0, 0, keyframe.bodyAngle) * headOffset;
distance = Vector2.Dot(parent.transform.up, (Vector2)(mousePosition - parent.transform.position - headOffset));
Debug.Log(headOffset.ToString());
Workspace.animationDef.animationStages[Workspace.stageID].animationClips[parent.actorID].keyframes.FirstOrDefault(x => x.keyframeID == Workspace.keyframeID).headBob = distance;
}
else if (Workspace.actorManipulationMode == ActorManipulationMode.Rotate)
{
float angle = Vector2.SignedAngle(Vector2.down, (Vector2)mousePosition - (Vector2)transform.position);
Workspace.animationDef.animationStages[Workspace.stageID].animationClips[parent.actorID].keyframes.FirstOrDefault(x => x.keyframeID == Workspace.keyframeID).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;
Debug.Log(facing.ToString());
Workspace.animationDef.animationStages[Workspace.stageID].animationClips[parent.actorID].keyframes.FirstOrDefault(x => x.keyframeID == Workspace.keyframeID).headFacing = facing;
}
PawnAnimationClip clip = Workspace.Instance.GetPawnAnimationClip(parent.actorID);
clip.BuildSimpleCurves();
}
public void Activate()
{
Workspace.actorID = parent.actorID;
foreach (ActorBody actorBody in AnimationController.Instance.GetComponentsInChildren<ActorBody>())
{
actorBody.bodyRenderer.color = new Color(1f, 1f, 1f);
actorBody.headRenderer.color = new Color(1f, 1f, 1f);
}
bodyPartRenderer.color = new Color(0f, 1f, 0f);
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b23e33f312d52c642b86f5f2138f4030
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,70 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace RimWorldAnimationStudio
{
public class ActorCard : MonoBehaviour
{
public Dropdown genderDropdown;
public Dropdown bodyTypeDropdown;
public InputField bodyOffsetXField;
public InputField bodyOffsetZField;
public Toggle initiatorToggle;
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 UpdateAnimationDef()
{
Actor actor = Workspace.animationDef.actors[Workspace.actorID];
string bodyType = bodyTypeDropdown.options[bodyTypeDropdown.value].text;
bodyType = bodyType == null || bodyType == "" ? "Male" : bodyType;
Debug.Log(bodyType);
AnimationController.Instance.transform.GetChild(Workspace.actorID).GetComponent<ActorBody>().bodyType = 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;
}
public void OpenSelectBodyPartsDialog()
{
Actor actor = Workspace.animationDef.actors[Workspace.actorID];
var dialog = Resources.FindObjectsOfTypeAll(typeof(SelectBodyPartsDialog)) as SelectBodyPartsDialog[];
if (dialog != null)
{ dialog[0].Initialize(actor); dialog[0].Pop(); }
}
public void OpenSelectDefNamesDialog()
{
Actor actor = Workspace.animationDef.actors[Workspace.actorID];
var dialog = Resources.FindObjectsOfTypeAll(typeof(SelectDefNamesDialog)) as SelectDefNamesDialog[];
if (dialog != null)
{ dialog[0].Initialize(actor); dialog[0].Pop(); }
}
public void OpenSelectBodyDefTypesDialog()
{
Actor actor = Workspace.animationDef.actors[Workspace.actorID];
var dialog = Resources.FindObjectsOfTypeAll(typeof(SelectBodyDefTypesDialog)) as SelectBodyDefTypesDialog[];
if (dialog != null)
{ dialog[0].Initialize(actor); dialog[0].Pop(); }
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9731614c7527b624492dd33f9b006fcb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -20,8 +20,11 @@ namespace RimWorldAnimationStudio
if ((Workspace.animationDef == null || AnimationController.Instance.stageTick == lastTick) && isDirty == false)
{ return; }
ActorBody actorBody = AnimationController.Instance.actorBodies[Workspace.actorID];
string bodyType = AnimationController.Instance.actorCards.transform.GetChild(Workspace.actorID).GetComponent<ActorCard>().bodyType;
if (Workspace.actorID >= AnimationController.Instance.transform.childCount)
{ return; }
ActorBody actorBody = AnimationController.Instance.transform.GetChild(Workspace.actorID).GetComponent<ActorBody>();
string bodyType = actorBody.bodyType;
PawnAnimationClip clip = Workspace.animationDef.animationStages[Workspace.stageID].animationClips[Workspace.actorID];
float clipPercent = (float)(AnimationController.Instance.stageTick % clip.duration) / clip.duration;

View file

@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
namespace RimWorldAnimationStudio
{
public class AnimationDefCard : MonoBehaviour
{
public InputField defNameField;
public InputField labelField;
public Toggle playSoundsToggle;
public void Initialize()
{
defNameField.text = Workspace.animationDef.defName;
labelField.text = Workspace.animationDef.label;
playSoundsToggle.isOn = Workspace.animationDef.sounds;
}
public void UpdateAnimationDef()
{
Workspace.animationDef.defName = defNameField.text;
Workspace.animationDef.label = labelField.text;
Workspace.animationDef.sounds = playSoundsToggle.isOn;
}
public void OpenSelectSexTypesDialog()
{
var dialog = Resources.FindObjectsOfTypeAll(typeof(SelectSexTypesDialog)) as SelectSexTypesDialog[];
if (dialog != null)
{ dialog[0].Initialize(); dialog[0].Pop(); }
}
public void OpenSelectInteractionDefsDialog()
{
var dialog = Resources.FindObjectsOfTypeAll(typeof(SelectInteractionDefsDialog)) as SelectInteractionDefsDialog[];
if (dialog != null)
{ dialog[0].Initialize(); dialog[0].Pop(); }
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e1d8f33927e6b4d44914a445362b802d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -17,6 +17,8 @@ namespace RimWorldAnimationStudio
{
this.actorID = actorID;
Reset();
PawnAnimationClip clip = Workspace.Instance.GetPawnAnimationClip(actorID);
if (clip == null || clip.keyframes.NullOrEmpty())
@ -35,22 +37,22 @@ namespace RimWorldAnimationStudio
}
}
public void AddKeyFrame(int atTick)
public void Reset()
{
foreach(KeyframeSlider keyframeSlider in GetComponentsInChildren<KeyframeSlider>())
{ Destroy(keyframeSlider.gameObject); }
}
public bool CanAddKeyFrameAtTick(int atTick)
public void AddPawnKeyFrame(int keyframeID)
{
foreach (Transform child in transform)
{
KeyframeSlider keyframeSlider = child.GetComponent<KeyframeSlider>();
KeyframeSlider keyframeSlider = Instantiate(keyframeSliderPrefab, transform);
keyframeSlider.Initialize(this, actorID, keyframeID);
}
if (keyframeSlider != null && Workspace.Instance.GetPawnKeyframe(keyframeSlider.actorID, keyframeSlider.keyframeID).atTick == atTick)
{ return false; }
}
return true;
public void RemovePawnKeyFrame(int keyframeID)
{
KeyframeSlider keyframeSlider = GetComponentsInChildren<KeyframeSlider>().FirstOrDefault(x => x.keyframeID == keyframeID);
Destroy(keyframeSlider?.gameObject);
}
}
}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: eabe165e5b1a70744a8073c1b5b541a7
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
namespace RimWorldAnimationStudio
{
public class DialogBox : MonoBehaviour
{
public List<GameObject> cloneObjects;
public void Pop()
{
gameObject.SetActive(gameObject.activeSelf == false);
}
public void RemoveCloneObjectsFromParent(Transform parent)
{
for (int i = 0; i < parent.childCount; i++)
{ Destroy(parent.transform.GetChild(i).gameObject); }
}
public GameObject AddCloneObjectToParent(Transform parent, int i = 0)
{
GameObject cloneObject = null;
if (cloneObjects != null && cloneObjects.Count > i)
{ cloneObject = Instantiate(cloneObjects[i], parent); }
return cloneObject;
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5a554bad525e79e4fb3dea0d391daf48
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
namespace RimWorldAnimationStudio
{
public class SelectAnimationDialog : DialogBox
{
public void Initialize(Defs defs)
{
Transform contentWindow = transform.FindDeepChild("Content");
Reset();
for (int i = 0; i < defs.animationDefs.Count; i++)
{
AnimationDef animationDef = defs.animationDefs[i];
Transform _optionButton = AddCloneObjectToParent(contentWindow).transform;
_optionButton.Find("Text").GetComponent<Text>().text = animationDef.defName;
Button buttonComp = _optionButton.GetComponent<Button>();
buttonComp.onClick.AddListener(delegate { Pop(); ApplicationManager.Instance.LoadAnimation(animationDef); });
}
}
public void Reset()
{
Transform contentWindow = transform.FindDeepChild("Content");
RemoveCloneObjectsFromParent(contentWindow);
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6db038d692d34c441b171c72c78e0066
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,87 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
namespace RimWorldAnimationStudio
{
public class SelectBodyDefTypesDialog : DialogBox
{
private Actor actor;
public void Start()
{
Initialize();
}
public void AddBodyDefType(InputField field)
{
Debug.Log("Attempting to add new body def type");
if (field?.text == null || field.text == "")
{ Debug.LogWarning("Input field is null"); return; }
if (Workspace.bodyDefTypes.Contains(field.text))
{ Debug.LogWarning("Body def type is null"); field.text = ""; return; }
Debug.Log("Added new body type def: " + field.text);
Workspace.bodyDefTypes.Add(field.text);
Initialize();
}
public void Initialize(Actor actor = null)
{
if (actor != null)
{ this.actor = actor; }
if (actor == null)
{ actor = this.actor; }
if (actor == null) return;
foreach (string bodyDefType in actor.bodyDefTypes)
{
if (Workspace.bodyDefTypes.Contains(bodyDefType) == false)
{ Workspace.bodyDefTypes.Add(bodyDefType); }
}
Transform contentWindow = transform.FindDeepChild("Content");
Reset();
for (int i = 0; i < Workspace.bodyDefTypes.Count; i++)
{
string bodyDefType = Workspace.bodyDefTypes[i];
Transform _optionToggle = AddCloneObjectToParent(contentWindow).transform;
_optionToggle.Find("Text").GetComponent<Text>().text = bodyDefType;
Toggle toggleComp = _optionToggle.GetComponent<Toggle>();
toggleComp.isOn = actor.bodyDefTypes.Contains(bodyDefType);
toggleComp.onValueChanged.AddListener(delegate {
if (toggleComp.isOn && actor.bodyDefTypes.Contains(bodyDefType) == false)
{ actor.bodyDefTypes.Add(bodyDefType); }
else if (toggleComp.isOn == false && actor.bodyDefTypes.Contains(bodyDefType))
{ actor.bodyDefTypes.Remove(bodyDefType); }
});
}
Transform _optionField = AddCloneObjectToParent(contentWindow, 1).transform;
_optionField.Find("Placeholder").GetComponent<Text>().text = "Enter new body def type...";
InputField fieldComp = _optionField.GetComponent<InputField>();
fieldComp.onEndEdit.AddListener(delegate { AddBodyDefType(fieldComp); });
}
public void Reset()
{
Transform contentWindow = transform.FindDeepChild("Content");
RemoveCloneObjectsFromParent(contentWindow);
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b66fb83b0bed5a0438f6fbe11f0c35e0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,87 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
namespace RimWorldAnimationStudio
{
public class SelectBodyPartsDialog : DialogBox
{
private Actor actor;
public void Start()
{
Initialize();
}
public void AddBodyPart(InputField field)
{
Debug.Log("Attempting to add new body part");
if (field?.text == null || field.text == "")
{ Debug.LogWarning("Input field is null"); return; }
if (Workspace.bodyParts.Contains(field.text))
{ Debug.LogWarning("Body part is null"); field.text = ""; return; }
Debug.Log("Add new body part: " + field.text);
Workspace.bodyParts.Add(field.text);
Initialize();
}
public void Initialize(Actor actor = null)
{
if (actor != null)
{ this.actor = actor; }
if (actor == null)
{ actor = this.actor; }
if (actor == null) return;
foreach (string bodyPart in actor.requiredGenitals)
{
if (Workspace.bodyParts.Contains(bodyPart) == false)
{ Workspace.bodyParts.Add(bodyPart); }
}
Transform contentWindow = transform.FindDeepChild("Content");
Reset();
for (int i = 0; i < Workspace.bodyParts.Count; i++)
{
string bodyPart = Workspace.bodyParts[i];
Transform _optionToggle = AddCloneObjectToParent(contentWindow).transform;
_optionToggle.Find("Text").GetComponent<Text>().text = bodyPart;
Toggle toggleComp = _optionToggle.GetComponent<Toggle>();
toggleComp.isOn = actor.requiredGenitals.Contains(bodyPart);
toggleComp.onValueChanged.AddListener(delegate {
if (toggleComp.isOn && actor.requiredGenitals.Contains(bodyPart) == false)
{ actor.requiredGenitals.Add(bodyPart); }
else if (toggleComp.isOn == false && actor.requiredGenitals.Contains(bodyPart))
{ actor.requiredGenitals.Remove(bodyPart); }
});
}
Transform _optionField = AddCloneObjectToParent(contentWindow, 1).transform;
_optionField.Find("Placeholder").GetComponent<Text>().text = "Enter new body part name...";
InputField fieldComp = _optionField.GetComponent<InputField>();
fieldComp.onEndEdit.AddListener(delegate { AddBodyPart(fieldComp); });
}
public void Reset()
{
Transform contentWindow = transform.FindDeepChild("Content");
RemoveCloneObjectsFromParent(contentWindow);
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 459a1b2a918e12f468445853ea5821e0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,87 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
namespace RimWorldAnimationStudio
{
public class SelectDefNamesDialog : DialogBox
{
private Actor actor;
public void Start()
{
Initialize();
}
public void AddDefName(InputField field)
{
Debug.Log("Attempting to add new def name");
if (field?.text == null || field.text == "")
{ Debug.LogWarning("Input field is null"); return; }
if (Workspace.defNames.Contains(field.text))
{ Debug.LogWarning("Def name is null"); field.text = ""; return; }
Debug.Log("Added new def name: " + field.text);
Workspace.defNames.Add(field.text);
Initialize();
}
public void Initialize(Actor actor = null)
{
if (actor != null)
{ this.actor = actor; }
if (actor == null)
{ actor = this.actor; }
if (actor == null) return;
foreach (string defName in actor.defNames)
{
if (Workspace.defNames.Contains(defName) == false)
{ Workspace.defNames.Add(defName); }
}
Transform contentWindow = transform.FindDeepChild("Content");
Reset();
for (int i = 0; i < Workspace.defNames.Count; i++)
{
string defName = Workspace.defNames[i];
Transform _optionToggle = AddCloneObjectToParent(contentWindow).transform;
_optionToggle.Find("Text").GetComponent<Text>().text = defName;
Toggle toggleComp = _optionToggle.GetComponent<Toggle>();
toggleComp.isOn = actor.defNames.Contains(defName);
toggleComp.onValueChanged.AddListener(delegate {
if (toggleComp.isOn && actor.defNames.Contains(defName) == false)
{ actor.defNames.Add(defName); }
else if (toggleComp.isOn == false && actor.defNames.Contains(defName))
{ actor.defNames.Remove(defName); }
});
}
Transform _optionField = AddCloneObjectToParent(contentWindow, 1).transform;
_optionField.Find("Placeholder").GetComponent<Text>().text = "Enter new def name...";
InputField fieldComp = _optionField.GetComponent<InputField>();
fieldComp.onEndEdit.AddListener(delegate { AddDefName(fieldComp); });
}
public void Reset()
{
Transform contentWindow = transform.FindDeepChild("Content");
RemoveCloneObjectsFromParent(contentWindow);
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9842b9e0fd45d4643af5bed7ba2de307
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
namespace RimWorldAnimationStudio
{
public class SelectInteractionDefsDialog : DialogBox
{
public void Start()
{
Initialize();
}
public void AddBodyPart(InputField field)
{
if (field?.text == null || field.text == "")
{ return; }
if (Workspace.bodyParts.Contains(field.text))
{ field.text = ""; return; }
Workspace.interactionDefTypes.Add(field.text);
Initialize();
}
public void Initialize()
{
if (Workspace.animationDef == null) return;
foreach (string interactionDefType in Workspace.animationDef.interactionDefTypes)
{
if (Workspace.interactionDefTypes.Contains(interactionDefType) == false)
{ Workspace.interactionDefTypes.Add(interactionDefType); }
}
Transform contentWindow = transform.FindDeepChild("Content");
Reset();
for (int i = 0; i < Workspace.bodyParts.Count; i++)
{
string interactionDefType = Workspace.interactionDefTypes[i];
Transform _optionToggle = AddCloneObjectToParent(contentWindow).transform;
_optionToggle.Find("Text").GetComponent<Text>().text = interactionDefType;
Toggle toggleComp = _optionToggle.GetComponent<Toggle>();
toggleComp.isOn = Workspace.animationDef.interactionDefTypes.Contains(interactionDefType);
toggleComp.onValueChanged.AddListener(delegate {
if (toggleComp.isOn && Workspace.animationDef.interactionDefTypes.Contains(interactionDefType) == false)
{ Workspace.animationDef.interactionDefTypes.Add(interactionDefType); }
else if (toggleComp.isOn == false && Workspace.animationDef.interactionDefTypes.Contains(interactionDefType))
{ Workspace.animationDef.interactionDefTypes.Remove(interactionDefType); }
});
}
Transform _optionField = AddCloneObjectToParent(contentWindow, 1).transform;
_optionField.Find("Placeholder").GetComponent<Text>().text = "Enter new interaction def type...";
InputField fieldComp = _optionField.GetComponent<InputField>();
fieldComp.onEndEdit.AddListener(delegate { AddBodyPart(fieldComp); });
}
public void Reset()
{
Transform contentWindow = transform.FindDeepChild("Content");
RemoveCloneObjectsFromParent(contentWindow);
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: cace588a3682dc649b94355d8eee4a77
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
namespace RimWorldAnimationStudio
{
public class SelectSexTypesDialog : DialogBox
{
public void Start()
{
Initialize();
}
public void AddSexType(InputField field)
{
if (field?.text == null || field.text == "")
{ return; }
if (Workspace.bodyParts.Contains(field.text))
{ field.text = ""; return; }
Workspace.sexTypes.Add(field.text);
Initialize();
}
public void Initialize()
{
if (Workspace.animationDef == null) return;
foreach (string sexType in Workspace.animationDef.sexTypes)
{
if (Workspace.sexTypes.Contains(sexType) == false)
{ Workspace.sexTypes.Add(sexType); }
}
Transform contentWindow = transform.FindDeepChild("Content");
Reset();
for (int i = 0; i < Workspace.bodyParts.Count; i++)
{
string sexType = Workspace.sexTypes[i];
Transform _optionToggle = AddCloneObjectToParent(contentWindow).transform;
_optionToggle.Find("Text").GetComponent<Text>().text = sexType;
Toggle toggleComp = _optionToggle.GetComponent<Toggle>();
toggleComp.isOn = Workspace.animationDef.sexTypes.Contains(sexType);
toggleComp.onValueChanged.AddListener(delegate {
if (toggleComp.isOn && Workspace.animationDef.sexTypes.Contains(sexType) == false)
{ Workspace.animationDef.sexTypes.Add(sexType); }
else if (toggleComp.isOn == false && Workspace.animationDef.sexTypes.Contains(sexType))
{ Workspace.animationDef.sexTypes.Remove(sexType); }
});
}
Transform _optionField = AddCloneObjectToParent(contentWindow, 1).transform;
_optionField.Find("Placeholder").GetComponent<Text>().text = "Enter new sex type...";
InputField fieldComp = _optionField.GetComponent<InputField>();
fieldComp.onEndEdit.AddListener(delegate { AddSexType(fieldComp); });
}
public void Reset()
{
Transform contentWindow = transform.FindDeepChild("Content");
RemoveCloneObjectsFromParent(contentWindow);
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1d4b7a5a5ddb7d744b726c3c13e2fc5e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -12,9 +12,6 @@ namespace RimWorldAnimationStudio
public class KeyframeSlider : Slider, IPointerClickHandler, IBeginDragHandler, IEndDragHandler
{
public AnimationTimeline timeline;
//public AnimationClip clip;
//public Keyframe keyframe;
public Transform ghostSliders;
public Slider ghostSliderPrefab;
public int maxGhosts = 4;
@ -22,18 +19,22 @@ namespace RimWorldAnimationStudio
public int actorID;
public int keyframeID;
private PawnAnimationClip clip;
private PawnKeyframe keyframe;
public void Initialize(AnimationTimeline timeline, int actorID, int keyframeID)
{
this.timeline = timeline;
//this.clip = clip;
//this.keyframe = keyframe;
this.clip = Workspace.Instance.GetPawnAnimationClip(actorID);
this.keyframe = Workspace.Instance.GetPawnKeyframe(actorID, keyframeID);
this.actorID = actorID;
this.keyframeID = keyframeID;
PawnKeyframe keyframe = Workspace.Instance.GetPawnKeyframe(actorID, keyframeID);
Debug.Log(keyframe.atTick);
value = (float)keyframe.atTick / Workspace.animationClipWindowSize;
maxValue = Workspace.animationClipWindowSize;
value = keyframe.atTick.Value;
OnValueChanged();
onValueChanged.AddListener(delegate (float value) { OnValueChanged(); });
@ -41,12 +42,7 @@ namespace RimWorldAnimationStudio
public void OnValueChanged()
{
PawnKeyframe keyframe = Workspace.Instance.GetPawnKeyframe(actorID, keyframeID);
PawnAnimationClip clip = Workspace.Instance.GetPawnAnimationClip(actorID);
int newTick = Mathf.RoundToInt(value * Workspace.animationClipWindowSize);
keyframe.atTick = newTick;
keyframe.atTick = (int)value;
UpdateGhostFrames();
@ -58,9 +54,6 @@ namespace RimWorldAnimationStudio
// Ghost sliders are non-interactable slider handle
public void UpdateGhostFrames()
{
PawnKeyframe keyframe = Workspace.Instance.GetPawnKeyframe(actorID, keyframeID);
PawnAnimationClip clip = Workspace.Instance.GetPawnAnimationClip(actorID);
if (maxGhosts == 0)
{ return; }
@ -79,7 +72,7 @@ namespace RimWorldAnimationStudio
Slider ghostSlider = ghostSliderObject.GetComponent<Slider>();
Debug.Log(ghostSlider);
ghostSlider.value = (float)((i + 1) * clip.duration + keyframe.atTick) / Workspace.animationClipWindowSize;
ghostSlider.value = (int)((i + 1) * clip.duration + keyframe.atTick);
float mult = 1f - Mathf.Pow((float)i / maxGhosts, 2);
ghostSlider.transform.FindDeepChild("Handle").GetComponent<Image>().color = new Color(0, 0.5f, 0.5f, 0.5f * mult);
@ -92,8 +85,6 @@ namespace RimWorldAnimationStudio
public int GetGhostFramesRequired()
{
PawnAnimationClip clip = Workspace.Instance.GetPawnAnimationClip(actorID);
if (Workspace.animationDef.animationStages[Workspace.stageID].isLooping == false)
{ return 0; }
@ -105,31 +96,48 @@ namespace RimWorldAnimationStudio
public void OnPointerClick(PointerEventData eventData)
{
PawnKeyframe keyframe = Workspace.Instance.GetPawnKeyframe(actorID, keyframeID);
foreach (KeyframeSlider keyframeSlider in timeline.transform.GetComponentsInChildren<KeyframeSlider>())
{
if (keyframeSlider == this)
{ continue; }
keyframeSlider.transform.FindDeepChild("Handle").GetComponent<Image>().color = new Color(1f, 1f, 1f);
}
transform.FindDeepChild("Handle").GetComponent<Image>().color = new Color(0f, 1f, 0f);
AnimationController.Instance.stageTick = keyframe.atTick.Value;
Workspace.keyframeID = keyframeID;
Activate();
}
public void OnBeginDrag(PointerEventData eventData)
{
Activate();
if (keyframe.atTick == 1)
{ return; }
interactable = true;
}
public override void OnDrag(PointerEventData eventData)
{
base.OnDrag(eventData);
Activate();
}
public void OnEndDrag(PointerEventData eventData)
{
interactable = false;
}
public void Activate()
{
AnimationController.Instance.stageTick = keyframe.atTick.Value;
Workspace.keyframeID = keyframeID;
foreach (AnimationTimeline _timeline in AnimationController.Instance.animationTimelines.GetComponentsInChildren<AnimationTimeline>())
{
foreach (KeyframeSlider keyframeSlider in _timeline.GetComponentsInChildren<KeyframeSlider>())
{
if (keyframeSlider.keyframe.atTick.Value == keyframe.atTick.Value)
{ keyframeSlider.transform.FindDeepChild("Handle").GetComponent<Image>().color = new Color(0f, 1f, 0f); }
else
{ keyframeSlider.transform.FindDeepChild("Handle").GetComponent<Image>().color = new Color(1f, 1f, 1f); }
}
}
}
}
}

View file

@ -2,23 +2,20 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
namespace RimWorldAnimationStudio
{
public class StageCard : MonoBehaviour
public class StageCard : MonoBehaviour, IPointerClickHandler
{
private Text stageName;
private InputField stageNameField;
private Image banner;
private Toggle toggle;
public void OnNameChange()
{
}
public void OnSelectStage()
{
if (GetComponent<Toggle>().isOn && Workspace.stageID != transform.GetSiblingIndex())
{ Workspace.stageID = transform.GetSiblingIndex(); }
stageName.text = stageNameField.text;
stageNameField.gameObject.SetActive(false);
}
public void OnMoveStage(int delta)
@ -32,30 +29,39 @@ namespace RimWorldAnimationStudio
}
}
public void Start()
public void Initialize(string stageName)
{
banner = transform.Find("Banner").GetComponent<Image>();
toggle = GetComponent<Toggle>();
toggle.group = StageCardManager.Instance.GetComponent<ToggleGroup>();
this.stageName = transform.Find("StageName").GetComponent<Text>();
this.stageNameField = transform.Find("StageNameField").GetComponent<InputField>();
this.banner = transform.Find("Banner").GetComponent<Image>();
this.stageName.text = stageName;
}
public void Update()
{
if (Workspace.stageID == transform.GetSiblingIndex())
{
banner.gameObject.SetActive(true);
if (toggle.isOn == false)
{ toggle.isOn = true; }
}
{ banner.gameObject.SetActive(true); }
else
{
banner.gameObject.SetActive(false);
if (toggle.isOn)
{ toggle.isOn = false; }
stageNameField.gameObject.SetActive(false);
}
}
public void OnPointerClick(PointerEventData eventData)
{
if (eventData.clickCount >= 2)
{
stageNameField.text = stageName.text;
stageNameField.gameObject.SetActive(true);
}
Workspace.stageID = transform.GetSiblingIndex();
AnimationController.Instance.ResetAnimationTimeline();
AnimationController.Instance.InitializeAnimationTimeline();
}
}
}