mirror of
https://gitgud.io/AbstractConcept/rimworld-animation-studio.git
synced 2024-08-15 00:43:27 +00:00
Basic XML tweaking and export
This commit is contained in:
parent
3c7cc0c973
commit
f78d85de3b
153 changed files with 7705 additions and 2512 deletions
52
Assets/Scripts/ActorCard.cs
Normal file
52
Assets/Scripts/ActorCard.cs
Normal file
|
@ -0,0 +1,52 @@
|
|||
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 GameObject bodyPartsTags;
|
||||
|
||||
private AnimationDef animationDef;
|
||||
private int actorID = 0;
|
||||
|
||||
public string bodyType
|
||||
{
|
||||
get
|
||||
{
|
||||
string _bodyType = bodyTypeDropdown.options[bodyTypeDropdown.value].text;
|
||||
if (_bodyType == "") return "Male";
|
||||
|
||||
return _bodyType;
|
||||
}
|
||||
}
|
||||
|
||||
public void Initialize(AnimationDef animationDef, int actorID)
|
||||
{
|
||||
this.animationDef = animationDef;
|
||||
this.actorID = actorID;
|
||||
|
||||
UpdateBodyType();
|
||||
initiatorToggle.isOn = animationDef.actors[actorID].initiator;
|
||||
}
|
||||
|
||||
public void UpdateBodyType()
|
||||
{
|
||||
bodyOffsetXField.text = animationDef.actors[actorID].bodyTypeOffset.GetOffset(bodyType).x.ToString();
|
||||
bodyOffsetZField.text = animationDef.actors[actorID].bodyTypeOffset.GetOffset(bodyType).z.ToString();
|
||||
}
|
||||
|
||||
public void UpdateAnimationDef()
|
||||
{
|
||||
animationDef.actors[actorID].initiator = initiatorToggle.isOn;
|
||||
animationDef.actors[actorID].bodyTypeOffset.SetOffset(bodyType, new Vector2(float.Parse(bodyOffsetXField.text), float.Parse(bodyOffsetZField.text)));
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/ActorCard.cs.meta
Normal file
11
Assets/Scripts/ActorCard.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9731614c7527b624492dd33f9b006fcb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -9,15 +9,11 @@ namespace RimWorldAnimationStudio
|
|||
public string defName = "Undefined";
|
||||
public string label = "Undefined";
|
||||
public bool sounds = false;
|
||||
public int animationTimeTicks = 0;
|
||||
public List<string> sexTypes = new List<string>();
|
||||
public List<string> interactionDefTypes = new List<string>();
|
||||
|
||||
[XmlArray("actors"), XmlArrayItem("li")]
|
||||
public List<Actor> actors = new List<Actor>();
|
||||
|
||||
[XmlArray("animationStages"), XmlArrayItem("li")]
|
||||
public List<AnimationStage> animationStages = new List<AnimationStage>();
|
||||
[XmlIgnore] public int animationTimeTicks = 0;
|
||||
[XmlArray("sexTypes"), XmlArrayItem("li")] public List<string> sexTypes = new List<string>();
|
||||
[XmlArray("interactionDefTypes"), XmlArrayItem("li")] public List<string> interactionDefTypes = new List<string>();
|
||||
[XmlArray("actors"), XmlArrayItem("li")] public List<Actor> actors = new List<Actor>();
|
||||
[XmlArray("animationStages"), XmlArrayItem("li")] public List<AnimationStage> animationStages = new List<AnimationStage>();
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
|
|
|
@ -12,11 +12,25 @@ namespace RimWorldAnimationStudio
|
|||
public string Hulk;
|
||||
public string Fat;
|
||||
|
||||
public void SetOffset(string bodyType, Vector2 offset)
|
||||
{
|
||||
FieldInfo bodyTypeOffsetInfo = typeof(BodyTypeOffset).GetField(bodyType);
|
||||
|
||||
if (bodyTypeOffsetInfo == null)
|
||||
{ return; }
|
||||
|
||||
bodyTypeOffsetInfo.SetValue(this, offset.ToString());
|
||||
}
|
||||
|
||||
public Vector3 GetOffset(string bodyType)
|
||||
{
|
||||
Debug.Log(bodyType);
|
||||
|
||||
FieldInfo bodyTypeOffsetInfo = typeof(BodyTypeOffset).GetField(bodyType);
|
||||
|
||||
if (bodyTypeOffsetInfo == null)
|
||||
{ return new Vector2(); }
|
||||
|
||||
string bodyTypeOffsetString = (string)bodyTypeOffsetInfo.GetValue(this);
|
||||
|
||||
if (bodyTypeOffsetString == null || bodyTypeOffsetString == "")
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
|
@ -27,11 +28,14 @@ namespace RimWorldAnimationStudio
|
|||
|
||||
public ActorBody actorBodyPrefab;
|
||||
public List<ActorBody> actorBodies = new List<ActorBody>();
|
||||
public List<Dropdown> bodyTypeDropdowns = new List<Dropdown>();
|
||||
//public List<Dropdown> bodyTypeDropdowns = new List<Dropdown>();
|
||||
|
||||
public Text stageTickField;
|
||||
public Text stageLengthField;
|
||||
|
||||
public Transform actorCards;
|
||||
public GameObject actorCardPrefab;
|
||||
|
||||
private float currentTime = 0;
|
||||
|
||||
public T ReadDataFromXML<T>(string inputPath)
|
||||
|
@ -55,10 +59,34 @@ namespace RimWorldAnimationStudio
|
|||
anim = defs.animationDefs[0];
|
||||
InitializeAnimation(anim);
|
||||
|
||||
foreach (Actor actor in anim.actors)
|
||||
{
|
||||
AddActor();
|
||||
}
|
||||
|
||||
UpdateAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveXML()
|
||||
{
|
||||
if (anim == null)
|
||||
{ return; }
|
||||
|
||||
string path = StandaloneFileBrowser.SaveFilePanel("Save file", "", anim.defName + ".xml", ".xml");
|
||||
|
||||
if (path == null || path == "")
|
||||
{ return; }
|
||||
|
||||
XmlSerializer writer = new XmlSerializer(typeof(AnimationDef));
|
||||
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
|
||||
ns.Add("", "");
|
||||
FileStream file = File.Create(path);
|
||||
|
||||
writer.Serialize(file, anim, ns);
|
||||
file.Close();
|
||||
}
|
||||
|
||||
public void OpenFileDialog()
|
||||
{
|
||||
var paths = StandaloneFileBrowser.OpenFilePanel("Open File", "", "", false);
|
||||
|
@ -94,7 +122,8 @@ namespace RimWorldAnimationStudio
|
|||
|
||||
public void Update()
|
||||
{
|
||||
if (anim == null || isAnimating == false) return;
|
||||
if (anim == null) { return; }
|
||||
if (isAnimating == false) { UpdateAnimation(); return; }
|
||||
|
||||
currentTime += Time.deltaTime;
|
||||
|
||||
|
@ -119,6 +148,12 @@ namespace RimWorldAnimationStudio
|
|||
UpdateAnimation();
|
||||
}
|
||||
|
||||
public void AddActor()
|
||||
{
|
||||
GameObject actorCardObject = Instantiate(actorCardPrefab, actorCards);
|
||||
actorCardObject.GetComponent<ActorCard>().Initialize(anim, actorCards.childCount - 1);
|
||||
}
|
||||
|
||||
public void InitializeAnimation(AnimationDef anim)
|
||||
{
|
||||
ResetAnimation();
|
||||
|
@ -153,7 +188,7 @@ namespace RimWorldAnimationStudio
|
|||
for (int actorID = 0; actorID < actorBodies.Count; actorID++)
|
||||
{
|
||||
ActorBody actorBody = actorBodies[actorID];
|
||||
string bodyType = bodyTypeDropdowns[actorID].options[bodyTypeDropdowns[actorID].value].text;
|
||||
string bodyType = actorCards.transform.GetChild(actorID).GetComponent<ActorCard>().bodyType; //bodyTypeDropdowns[actorID].options[bodyTypeDropdowns[actorID].value].text;
|
||||
|
||||
PawnAnimationClip clip = anim.animationStages[stageID].animationClips[actorID];
|
||||
float clipPercent = (float)(stageTick % clip.duration) / clip.duration;
|
||||
|
|
|
@ -4,7 +4,7 @@ using System.Xml.Serialization;
|
|||
|
||||
namespace RimWorldAnimationStudio
|
||||
{
|
||||
[XmlRoot("Defs")]
|
||||
[XmlRoot("Defs", IsNullable = false)]
|
||||
public class Defs
|
||||
{
|
||||
[XmlElement("Rimworld_Animations.AnimationDef")]
|
||||
|
|
35
Assets/Scripts/DialogBox.cs
Normal file
35
Assets/Scripts/DialogBox.cs
Normal file
|
@ -0,0 +1,35 @@
|
|||
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 Image backSplash;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
//backSplash = Instanitate(new Image() { SpriteRenderer }, transform);
|
||||
//SpriteRenderer spriteRenderer = backSplash.GetComponent<SpriteRenderer>();
|
||||
//spriteRenderer.sprite = Resources.Load("whiteSquare");
|
||||
//spriteRenderer.color = new Color(0f, 0f, 0f, 0f.2f);
|
||||
|
||||
//panelRectTransform.anchorMin = new Vector2(1, 0);
|
||||
//panelRectTransform.anchorMax = new Vector2(0, 1);
|
||||
//panelRectTransform.pivot = new Vector2(0.5f, 0.5f);
|
||||
|
||||
// Set layer to backsplash?
|
||||
}
|
||||
|
||||
public void Pop()
|
||||
{
|
||||
//backSplash.SetActive(gameObject.activeSelf == false);
|
||||
gameObject.SetActive(gameObject.activeSelf == false);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/DialogBox.cs.meta
Normal file
11
Assets/Scripts/DialogBox.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5a554bad525e79e4fb3dea0d391daf48
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
35
Assets/Scripts/Tag.cs
Normal file
35
Assets/Scripts/Tag.cs
Normal file
|
@ -0,0 +1,35 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace RimWorldAnimationStudio
|
||||
{
|
||||
public class Tag : MonoBehaviour
|
||||
{
|
||||
public string tagName = "New Tag";
|
||||
public Text tagText;
|
||||
public GameObject tagPrefab;
|
||||
|
||||
public void Initialize(string tagName)
|
||||
{
|
||||
this.tagName = tagName;
|
||||
tagText.text = tagName;
|
||||
}
|
||||
|
||||
public void AddTag()
|
||||
{
|
||||
GameObject newTag = Instantiate(tagPrefab, transform.parent);
|
||||
newTag.GetComponent<Tag>().Initialize(tagText.text);
|
||||
|
||||
tagText.text = tagName;
|
||||
transform.SetAsLastSibling();
|
||||
}
|
||||
|
||||
public void DeleteTag()
|
||||
{
|
||||
//SendMessageUpwards("DeleteTag", this);
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Tag.cs.meta
Normal file
11
Assets/Scripts/Tag.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e3306014932bdc74ca0fe3ff85867c58
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
84
Assets/Scripts/Workspace.cs
Normal file
84
Assets/Scripts/Workspace.cs
Normal file
|
@ -0,0 +1,84 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RimWorldAnimationStudio
|
||||
{
|
||||
public class Workspace : MonoBehaviour
|
||||
{
|
||||
public AnimationDef animationDef;
|
||||
public int stageID = 0;
|
||||
public bool isDirty = false;
|
||||
|
||||
public List<WorkspaceSnapShot> workspaceHistory = new List<WorkspaceSnapShot>();
|
||||
public int maxHistoryDepth = 100;
|
||||
public int historyIndex = 0;
|
||||
|
||||
public void TryToCloseApplication()
|
||||
{
|
||||
if (isDirty)
|
||||
{
|
||||
//exitDialog.Pop();
|
||||
return;
|
||||
}
|
||||
|
||||
CloseApplication();
|
||||
}
|
||||
|
||||
public void CloseApplication()
|
||||
{
|
||||
Application.Quit();
|
||||
}
|
||||
|
||||
public void GenerateLoadOptions(Defs defs)
|
||||
{
|
||||
for (int i = 0; i < defs.animationDefs.Count - 1; i++)
|
||||
{
|
||||
//Instantiate child button
|
||||
//button.text
|
||||
//buttoncallback = LoadADef(list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public void TrackChanges()
|
||||
{
|
||||
if (historyIndex < workspaceHistory.Count - 1)
|
||||
{ workspaceHistory.RemoveRange(historyIndex + 1, workspaceHistory.Count - historyIndex); }
|
||||
|
||||
if (workspaceHistory.Any() && workspaceHistory.Count >= maxHistoryDepth)
|
||||
{ workspaceHistory.RemoveAt(0); }
|
||||
|
||||
WorkspaceSnapShot workspaceSnapShot = new WorkspaceSnapShot();
|
||||
workspaceSnapShot.animationDef = animationDef;
|
||||
workspaceSnapShot.stageID = stageID;
|
||||
|
||||
workspaceHistory.Add(workspaceSnapShot);
|
||||
|
||||
// track bType for actors, stageID, isdirty
|
||||
|
||||
historyIndex++;
|
||||
}
|
||||
|
||||
public void Undo()
|
||||
{
|
||||
historyIndex = Mathf.Clamp(historyIndex - 1, 0, workspaceHistory.Count - 1);
|
||||
LoadHistoricState();
|
||||
}
|
||||
|
||||
public void Redo()
|
||||
{
|
||||
historyIndex = Mathf.Clamp(historyIndex - 1, 0, workspaceHistory.Count - 1);
|
||||
LoadHistoricState();
|
||||
}
|
||||
|
||||
public void LoadHistoricState()
|
||||
{
|
||||
animationDef = workspaceHistory[historyIndex].animationDef;
|
||||
|
||||
// All other data
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Workspace.cs.meta
Normal file
11
Assets/Scripts/Workspace.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bf0f782b7c407bf4896b633d509f5568
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
14
Assets/Scripts/WorkspaceSnapShot.cs
Normal file
14
Assets/Scripts/WorkspaceSnapShot.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RimWorldAnimationStudio
|
||||
{
|
||||
public class WorkspaceSnapShot
|
||||
{
|
||||
public AnimationDef animationDef;
|
||||
public int stageID = 0;
|
||||
}
|
||||
}
|
11
Assets/Scripts/WorkspaceSnapShot.cs.meta
Normal file
11
Assets/Scripts/WorkspaceSnapShot.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d877470affbfa194db9947e8bdd1bcb9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
37
Assets/Scripts/XmlUtility.cs
Normal file
37
Assets/Scripts/XmlUtility.cs
Normal file
|
@ -0,0 +1,37 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.IO;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace RimWorldAnimationStudio
|
||||
{
|
||||
public class XmlUtility
|
||||
{
|
||||
public T ReadXML<T>(string path)
|
||||
{
|
||||
using (StreamReader stringReader = new StreamReader(path))
|
||||
{
|
||||
XmlSerializer serializer = new XmlSerializer(typeof(T));
|
||||
|
||||
return (T)serializer.Deserialize(stringReader);
|
||||
}
|
||||
}
|
||||
|
||||
public void WriteXML(AnimationDef animationDef, string path)
|
||||
{
|
||||
if (animationDef == null || path == null || path == "")
|
||||
{ return; }
|
||||
|
||||
XmlSerializer writer = new XmlSerializer(typeof(AnimationDef));
|
||||
XmlSerializerNamespaces nameSpaces = new XmlSerializerNamespaces();
|
||||
nameSpaces.Add("", "");
|
||||
|
||||
FileStream file = File.Create(path);
|
||||
writer.Serialize(file, animationDef, nameSpaces);
|
||||
file.Close();
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/XmlUtility.cs.meta
Normal file
11
Assets/Scripts/XmlUtility.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 98d85a0061a130d47863c6a7b14df10f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue