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
a55ba7b95b
commit
5ca7e486f8
243 changed files with 1065 additions and 625 deletions
|
@ -11,9 +11,6 @@ namespace RimWorldAnimationStudio
|
|||
{
|
||||
public class AnimationController : Singleton<AnimationController>
|
||||
{
|
||||
[Header("Animation settings")]
|
||||
public bool isAnimating = false;
|
||||
|
||||
[Header("Object references")]
|
||||
public Transform animationTimelines;
|
||||
public Transform actorBodies;
|
||||
|
@ -40,7 +37,7 @@ namespace RimWorldAnimationStudio
|
|||
if (Workspace.animationDef == null) return;
|
||||
|
||||
// Update stage tick / loop count if animating
|
||||
if (isAnimating)
|
||||
if (Workspace.IsAnimating)
|
||||
{
|
||||
timeSinceLastUpdate += Time.deltaTime;
|
||||
|
||||
|
@ -50,54 +47,54 @@ namespace RimWorldAnimationStudio
|
|||
timeSinceLastUpdate -= 1 / (playBackSpeed * 60f);
|
||||
Workspace.StageTick += 1;
|
||||
|
||||
if (Workspace.StageTick > Workspace.StageWindowSize)
|
||||
if (Workspace.StageTick >= Workspace.StageWindowSize)
|
||||
{
|
||||
switch (stageLoopDropdown.value)
|
||||
{
|
||||
case 1: Workspace.StageTick = Constants.minTick; break;
|
||||
case 2: UpdateLoopCount(Workspace.GetCurrentAnimationStage().StageLoopsNormal); break;
|
||||
case 3: UpdateLoopCount(Workspace.GetCurrentAnimationStage().StageLoopsQuick); break;
|
||||
default: break;
|
||||
default: Workspace.IsAnimating = false; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update animation preview
|
||||
UpdateAnimationPReview();
|
||||
UpdateAnimationPreview();
|
||||
}
|
||||
|
||||
public void UpdateLoopCount(int stageLoops)
|
||||
{
|
||||
++loopCount;
|
||||
loopCount++;
|
||||
Workspace.StageTick = Constants.minTick;
|
||||
|
||||
if (loopCount >= stageLoops)
|
||||
{
|
||||
++Workspace.StageID;
|
||||
loopCount = 0;
|
||||
}
|
||||
if (Workspace.StageID >= Workspace.animationDef.AnimationStages.Count - 1)
|
||||
{ Workspace.IsAnimating = false; }
|
||||
|
||||
if (Workspace.StageID >= Workspace.animationDef.AnimationStages.Count - 1)
|
||||
{
|
||||
Workspace.StageTick = Workspace.StageWindowSize;
|
||||
Workspace.isAnimating = false;
|
||||
else
|
||||
{
|
||||
Workspace.StageID++;
|
||||
loopCount = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateAnimationPReview()
|
||||
public void UpdateAnimationPreview()
|
||||
{
|
||||
if (Workspace.animationDef == null || Workspace.StageID >= Workspace.animationDef?.AnimationStages.Count) return;
|
||||
|
||||
List<ActorBody> actorBodiesList = actorBodies.GetComponentsInChildren<ActorBody>().ToList();
|
||||
|
||||
for (int actorID = 0; actorID < actorBodiesList.Count; actorID++)
|
||||
for (int actorID = 0; actorID < Workspace.animationDef.actors.Count; actorID++)
|
||||
{
|
||||
// Get the current actor and their animation clip
|
||||
Actor actor = Workspace.GetActor(actorID);
|
||||
PawnAnimationClip clip = Workspace.GetPawnAnimationClip(actorID);
|
||||
|
||||
// Get flags
|
||||
bool quiver = isAnimating && Workspace.GetCurrentOrPreviousKeyframe(actorID).Quiver == true;
|
||||
bool quiver = Workspace.IsAnimating && Workspace.GetCurrentOrPreviousKeyframe(actorID).Quiver == true;
|
||||
bool requiresGenitals = actor.RequiredGenitals.Any(x => x == "Penis") || actor.IsFucking;
|
||||
|
||||
// Get clip percentage
|
||||
|
@ -193,9 +190,6 @@ namespace RimWorldAnimationStudio
|
|||
{
|
||||
Debug.Log("Initializing animation preview");
|
||||
|
||||
foreach (Transform child in transform)
|
||||
{ child.gameObject.SetActive(true); }
|
||||
|
||||
int actorCount = Workspace.animationDef.Actors.Count;
|
||||
int childCount = animationTimelines.GetComponentsInChildren<AnimationTimeline>().Count();
|
||||
|
||||
|
@ -227,15 +221,17 @@ namespace RimWorldAnimationStudio
|
|||
}
|
||||
}
|
||||
|
||||
foreach (AnimationTimeline timeline in animationTimelines.GetComponentsInChildren<AnimationTimeline>())
|
||||
{ timeline.InitiateUpdateOfGhostFrames(); }
|
||||
EventsManager.OnAnimationTimelinesChanged();
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
Workspace.isAnimating = false;
|
||||
Workspace.IsAnimating = false;
|
||||
timeSinceLastUpdate = 0;
|
||||
loopCount = 0;
|
||||
|
||||
foreach (Transform child in transform)
|
||||
{ child.gameObject.SetActive(true); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,17 +64,21 @@ namespace RimWorldAnimationStudio
|
|||
{
|
||||
UpdateCustomArrays(animationDef);
|
||||
RunPostLoadOperations(animationDef);
|
||||
animationDef.Initialize();
|
||||
|
||||
Debug.Log("Loaded AnimationDef: " + animationDef.DefName);
|
||||
|
||||
Workspace.Reset();
|
||||
Workspace.animationDef = animationDef;
|
||||
animationDef.Initialize();
|
||||
|
||||
AnimationController.Instance.Reset();
|
||||
Workspace.Reset();
|
||||
|
||||
AnimationController.Instance.Initialize();
|
||||
|
||||
EventsManager.OnAnimationChanged();
|
||||
Workspace.RecordEvent("AnimationDef loaded");
|
||||
|
||||
Workspace.ActorID = 0;
|
||||
EventsManager.OnActorIDChanged();
|
||||
}
|
||||
|
||||
public void RunPostLoadOperations(AnimationDef animationDef)
|
||||
|
|
68
Assets/Scripts/Managers/EventsManager.cs
Normal file
68
Assets/Scripts/Managers/EventsManager.cs
Normal file
|
@ -0,0 +1,68 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace RimWorldAnimationStudio
|
||||
{
|
||||
public static class EventsManager
|
||||
{
|
||||
// Event classes
|
||||
public class WorkspaceIntEvent : UnityEvent<int> { }
|
||||
public class ActorEvent : UnityEvent<Actor> { }
|
||||
public class AnimationStageEvent : UnityEvent<AnimationStage> { }
|
||||
public class PawnAnimationClipEvent : UnityEvent<PawnAnimationClip> { }
|
||||
public class PawnKeyframeEvent : UnityEvent<PawnKeyframe> { }
|
||||
public class ActorAddonEvent : UnityEvent<ActorAddon> { }
|
||||
public class AddonKeyframeEvent : UnityEvent<AddonKeyframe> { }
|
||||
public class ActorBodyEvent : UnityEvent<ActorBody> { }
|
||||
public class ActorBodyPartEvent : UnityEvent<ActorBodyPart> { }
|
||||
|
||||
// Event list
|
||||
public static UnityEvent onAnimationTimelinesChanged = new UnityEvent();
|
||||
public static UnityEvent onAnimationToggled = new UnityEvent();
|
||||
public static UnityEvent onAnimationChanged = new UnityEvent();
|
||||
public static UnityEvent onAnimationDefChanged = new UnityEvent();
|
||||
public static WorkspaceIntEvent onActorIDChanged = new WorkspaceIntEvent();
|
||||
public static WorkspaceIntEvent onStageIDChanged = new WorkspaceIntEvent();
|
||||
public static WorkspaceIntEvent onStageTickChanged = new WorkspaceIntEvent();
|
||||
public static WorkspaceIntEvent onStageCountChanged = new WorkspaceIntEvent();
|
||||
public static WorkspaceIntEvent onActorCountChanged = new WorkspaceIntEvent();
|
||||
public static WorkspaceIntEvent onKeyframeCountChanged = new WorkspaceIntEvent();
|
||||
public static ActorEvent onActorChanged = new ActorEvent();
|
||||
public static AnimationStageEvent onAnimationStageChanged = new AnimationStageEvent();
|
||||
public static AnimationStageEvent onStageWindowSizeChanged = new AnimationStageEvent();
|
||||
public static PawnAnimationClipEvent onPawnAnimationClipChanged = new PawnAnimationClipEvent();
|
||||
public static PawnKeyframeEvent onPawnKeyframeChanged = new PawnKeyframeEvent();
|
||||
public static ActorAddonEvent onActorAddonChanged = new ActorAddonEvent();
|
||||
public static AddonKeyframeEvent onAddonKeyframeChanged = new AddonKeyframeEvent();
|
||||
public static UnityEvent onDefNamesChanged = new UnityEvent();
|
||||
public static ActorBodyEvent onActorBodySelected = new ActorBodyEvent();
|
||||
public static ActorBodyPartEvent onActorBodyPartSelected = new ActorBodyPartEvent();
|
||||
|
||||
// Event invoking
|
||||
public static void OnAnimationTimelinesChanged() { onAnimationTimelinesChanged.Invoke(); }
|
||||
public static void OnAnimationToggled() { onAnimationToggled.Invoke(); }
|
||||
public static void OnAnimationChanged() { onAnimationChanged.Invoke(); }
|
||||
public static void OnAnimationDefChanged() { onAnimationDefChanged.Invoke(); }
|
||||
public static void OnActorIDChanged() { onActorIDChanged.Invoke(Workspace.ActorID); }
|
||||
public static void OnStageIDChanged() { onStageIDChanged.Invoke(Workspace.ActorID); }
|
||||
public static void OnStageTickChanged() { onStageTickChanged.Invoke(Workspace.StageTick); }
|
||||
public static void OnStageCountChanged() { onStageCountChanged.Invoke(Workspace.animationDef.AnimationStages.Count); }
|
||||
public static void OnActorCountChanged() { onActorCountChanged.Invoke(Workspace.animationDef.Actors.Count); }
|
||||
public static void OnKeyframeCountChanged(PawnAnimationClip clip) { onKeyframeCountChanged.Invoke(clip.Keyframes.Count); }
|
||||
public static void OnActorChanged(Actor actor) { onActorChanged.Invoke(actor); }
|
||||
public static void OnAnimationStageChanged(AnimationStage stage) { onAnimationStageChanged.Invoke(stage); }
|
||||
public static void OnStageWindowSizeChanged(AnimationStage stage) { onStageWindowSizeChanged.Invoke(stage); }
|
||||
public static void OnPawnAnimationClipChanged(PawnAnimationClip clip) { onPawnAnimationClipChanged.Invoke(clip); }
|
||||
public static void OnPawnKeyframeChanged(PawnKeyframe keyframe) { onPawnKeyframeChanged.Invoke(keyframe); }
|
||||
public static void OnActorAddonChanged(ActorAddon actorAddon) { onActorAddonChanged.Invoke(actorAddon); }
|
||||
public static void OnAddonKeyframeChanged(AddonKeyframe addonKeyframe) { onAddonKeyframeChanged.Invoke(addonKeyframe); }
|
||||
public static void OnDefNamesChanged() { onDefNamesChanged.Invoke(); }
|
||||
public static void OnActorBodySelected(ActorBody actorBody) { onActorBodySelected.Invoke(actorBody); }
|
||||
public static void OnActorBodyPartSelected(ActorBodyPart bodyPart) { onActorBodyPartSelected.Invoke(bodyPart); }
|
||||
}
|
||||
}
|
11
Assets/Scripts/Managers/EventsManager.cs.meta
Normal file
11
Assets/Scripts/Managers/EventsManager.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b4b96f2652caaa44985765ae416ac6ea
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -204,7 +204,7 @@ namespace RimWorldAnimationStudio
|
|||
public void ToggleAnimationPreview()
|
||||
{
|
||||
if (Workspace.animationDef == null) return;
|
||||
Workspace.isAnimating = !Workspace.isAnimating;
|
||||
Workspace.IsAnimating = !Workspace.IsAnimating;
|
||||
}
|
||||
|
||||
public void AddKeyframe()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue