2022-09-15 05:17:44 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
using SFB;
|
|
|
|
|
|
|
|
|
|
namespace RimWorldAnimationStudio
|
|
|
|
|
{
|
|
|
|
|
public class ApplicationManager : Singleton<ApplicationManager>
|
|
|
|
|
{
|
|
|
|
|
public DialogBox exitDialog;
|
|
|
|
|
public SelectAnimationDialog selectAnimationDialog;
|
|
|
|
|
|
|
|
|
|
public void TryToCloseApplication()
|
|
|
|
|
{
|
|
|
|
|
exitDialog.Pop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void CloseApplication()
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("Exiting application");
|
|
|
|
|
Application.Quit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void TryToLoadAnimation()
|
|
|
|
|
{
|
|
|
|
|
var paths = StandaloneFileBrowser.OpenFilePanel("Open AnimationDef File", "", "xml", false);
|
|
|
|
|
|
|
|
|
|
if (paths == null || paths.Any() == false)
|
|
|
|
|
{ Debug.LogError("Selected file was null or invalid"); return; }
|
|
|
|
|
|
|
|
|
|
Defs defs = XmlUtility.ReadXML<Defs>(paths[0]);
|
|
|
|
|
|
|
|
|
|
if (defs?.animationDefs == null)
|
|
|
|
|
{ Debug.LogError("Selected file contains no animation data"); return; }
|
|
|
|
|
|
|
|
|
|
if (defs.animationDefs.Count == 1)
|
|
|
|
|
{ LoadAnimation(defs.animationDefs[0]); return; }
|
|
|
|
|
|
|
|
|
|
selectAnimationDialog.Initialize(defs);
|
|
|
|
|
selectAnimationDialog.Pop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void LoadAnimation(AnimationDef animationDef)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("Loaded AnimationDef: " + animationDef.defName);
|
|
|
|
|
|
|
|
|
|
Workspace.animationDef = animationDef;
|
2022-09-16 22:50:15 +00:00
|
|
|
|
animationDef.Initialize();
|
2022-09-15 05:17:44 +00:00
|
|
|
|
Workspace.isDirty = true;
|
|
|
|
|
|
|
|
|
|
var animationDefCards = Resources.FindObjectsOfTypeAll(typeof(AnimationDefCard)) as AnimationDefCard[];
|
2022-09-16 14:18:06 +00:00
|
|
|
|
|
2022-09-15 05:17:44 +00:00
|
|
|
|
if (animationDefCards != null)
|
|
|
|
|
{
|
|
|
|
|
animationDefCards[0].Initialize();
|
|
|
|
|
animationDefCards[0].gameObject.SetActive(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void TrySaveAnimation()
|
|
|
|
|
{
|
|
|
|
|
if (Workspace.animationDef == null)
|
|
|
|
|
{ return; }
|
|
|
|
|
|
|
|
|
|
string defName = Workspace.animationDef.defName != null && Workspace.animationDef.defName != "" ? Workspace.animationDef.defName : "newAnimationDef";
|
|
|
|
|
|
|
|
|
|
var path = StandaloneFileBrowser.SaveFilePanel("Save AnimationDef File", "", defName, "xml");
|
|
|
|
|
|
|
|
|
|
if (path != null && path != "")
|
|
|
|
|
{ SaveAnimation(path); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SaveAnimation(string path)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("Saving AnimationDef: " + Workspace.animationDef.defName);
|
|
|
|
|
|
2022-09-16 22:50:15 +00:00
|
|
|
|
AnimationDef animationDef = Workspace.animationDef;
|
|
|
|
|
|
|
|
|
|
foreach (AnimationStage stage in animationDef.animationStages)
|
|
|
|
|
{
|
|
|
|
|
foreach (PawnAnimationClip clip in stage.animationClips)
|
|
|
|
|
{
|
|
|
|
|
clip.keyframes = clip.keyframes.OrderBy(x => x.atTick).ToList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2022-09-15 05:17:44 +00:00
|
|
|
|
Defs defs = new Defs();
|
2022-09-16 22:50:15 +00:00
|
|
|
|
defs.animationDefs.Add(animationDef);
|
2022-09-15 05:17:44 +00:00
|
|
|
|
|
|
|
|
|
XmlUtility.WriteXML(defs, path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void NewAnimation()
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
AnimationDef animationDef = new AnimationDef();
|
|
|
|
|
|
|
|
|
|
// Add one stage, add one actor, add one clip, add one frame
|
|
|
|
|
|
|
|
|
|
Workspace.animationDef = new AnimationDef();
|
|
|
|
|
Workspace.isDirty = true;
|
|
|
|
|
|
|
|
|
|
var animationDefCards = Resources.FindObjectsOfTypeAll(typeof(AnimationDefCard)) as GameObject[];
|
|
|
|
|
|
|
|
|
|
if (animationDefCards != null)
|
|
|
|
|
{ animationDefCards[0].SetActive(true); }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|