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
e14a12f2ab
commit
af4dab5546
278 changed files with 468 additions and 668 deletions
|
@ -1,8 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ff71352a02fb53440a35dbeabb9ebc87
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -15,13 +15,12 @@ namespace RimWorldAnimationStudio
|
|||
public int? anchoringActor;
|
||||
public string anchorName;
|
||||
public string layer = "Pawn";
|
||||
public float? scale;
|
||||
public GraphicData graphicData;
|
||||
public bool? render;
|
||||
|
||||
// Data serialization control
|
||||
public bool ShouldSerializeanchorName() { return string.IsNullOrEmpty(anchorName) == false && anchorName.ToLower() != "none"; }
|
||||
public bool ShouldSerializeanchoringActor() { return anchoringActor.HasValue; }
|
||||
public bool ShouldSerializescale() { return scale.HasValue; }
|
||||
public bool ShouldSerializerender() { return render == true; }
|
||||
|
||||
// Data helper functions
|
||||
|
@ -49,10 +48,11 @@ namespace RimWorldAnimationStudio
|
|||
set { layer = value; }
|
||||
}
|
||||
|
||||
[XmlIgnore] public float Scale
|
||||
[XmlIgnore]
|
||||
public GraphicData GraphicData
|
||||
{
|
||||
get { return scale.HasValue ? scale.Value : 0f; }
|
||||
set { scale = value; }
|
||||
get { return graphicData; }
|
||||
set { graphicData = value; }
|
||||
}
|
||||
|
||||
[XmlIgnore] public bool Render
|
||||
|
@ -69,10 +69,10 @@ namespace RimWorldAnimationStudio
|
|||
// Constructors
|
||||
public ActorAddon() { }
|
||||
|
||||
public ActorAddon(string addonName, float scale = 1f)
|
||||
public ActorAddon(ActorAddonDef actorAddonDef)
|
||||
{
|
||||
this.AddonName = addonName;
|
||||
this.Scale = scale;
|
||||
this.AddonName = actorAddonDef.addonName;
|
||||
this.GraphicData = actorAddonDef.graphicData.Copy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,5 +11,7 @@ namespace RimWorldAnimationStudio
|
|||
public string addonName;
|
||||
public string label;
|
||||
public float scale = 1f;
|
||||
|
||||
public GraphicData graphicData;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,6 +62,10 @@ namespace RimWorldAnimationStudio
|
|||
// Methods
|
||||
public void BuildSimpleCurves()
|
||||
{
|
||||
// Add addon data (if missing)
|
||||
foreach (ActorAddonDef actorAddonDef in ActorAddonDefs.allDefs)
|
||||
{ AddActorAddon(actorAddonDef); }
|
||||
|
||||
// Clear simple curve data
|
||||
BodyAngle.Clear();
|
||||
HeadAngle.Clear();
|
||||
|
@ -72,10 +76,6 @@ namespace RimWorldAnimationStudio
|
|||
HeadBob.Clear();
|
||||
GenitalAngle.Clear();
|
||||
|
||||
AddActorAddon("left hand", 0.667f);
|
||||
AddActorAddon("right hand", 0.667f);
|
||||
AddActorAddon("dildo");
|
||||
|
||||
foreach (ActorAddon addon in Addons)
|
||||
{
|
||||
addon.PosX.Clear();
|
||||
|
@ -83,7 +83,7 @@ namespace RimWorldAnimationStudio
|
|||
addon.Rotation.Clear();
|
||||
}
|
||||
|
||||
// Start
|
||||
// Start building simple curves
|
||||
int keyframePosition = 0;
|
||||
int duration = 0;
|
||||
|
||||
|
@ -151,17 +151,15 @@ namespace RimWorldAnimationStudio
|
|||
}
|
||||
}
|
||||
|
||||
public void AddActorAddon(string addonName, float scale = 1f)
|
||||
public void AddActorAddon(ActorAddonDef actorAddonDef)
|
||||
{
|
||||
if (Addons.Any(x => x.AddonName == addonName) == false)
|
||||
{
|
||||
Addons.Add(new ActorAddon(addonName, scale));
|
||||
}
|
||||
if (Addons.Any(x => x.AddonName == actorAddonDef.addonName) == false)
|
||||
{ Addons.Add(new ActorAddon(actorAddonDef)); }
|
||||
|
||||
foreach (PawnKeyframe keyframe in Keyframes)
|
||||
{
|
||||
if (keyframe.AddonKeyframes.Any(x => x.AddonName == addonName) == false)
|
||||
{ keyframe.AddonKeyframes.Add(new AddonKeyframe(addonName)); }
|
||||
if (keyframe.AddonKeyframes.Any(x => x.AddonName == actorAddonDef.addonName) == false)
|
||||
{ keyframe.AddonKeyframes.Add(new AddonKeyframe(actorAddonDef.addonName)); }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ namespace RimWorldAnimationStudio
|
|||
{
|
||||
public int actorID;
|
||||
public SpriteRenderer bodyRenderer;
|
||||
public ActorBodyPart actorBodyPartPrefab;
|
||||
|
||||
private Vector3 dragDelta = new Vector3();
|
||||
|
||||
|
@ -20,6 +21,12 @@ namespace RimWorldAnimationStudio
|
|||
|
||||
if (Workspace.ActorID == actorID)
|
||||
{ Activate(); }
|
||||
|
||||
foreach (ActorAddonDef actorAddonDef in ActorAddonDefs.allDefs)
|
||||
{
|
||||
ActorBodyPart actorBodyPart = Instantiate(actorBodyPartPrefab, transform);
|
||||
actorBodyPart.Initialize(this, actorAddonDef);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnActorBodySelected(ActorBody actorBody)
|
||||
|
|
|
@ -14,8 +14,10 @@ namespace RimWorldAnimationStudio
|
|||
|
||||
private Vector3 dragDelta = new Vector3();
|
||||
|
||||
public void Start()
|
||||
private void Start()
|
||||
{
|
||||
if (parent == null) return;
|
||||
|
||||
EventsManager.onActorBodyPartSelected.AddListener(delegate (ActorBodyPart bodyPart) { OnActorBodyPartSelected(bodyPart); });
|
||||
EventsManager.onActorBodySelected.AddListener(delegate (ActorBody actorBody) { OnActorBodySelected(actorBody); });
|
||||
|
||||
|
@ -23,6 +25,17 @@ namespace RimWorldAnimationStudio
|
|||
{ parent.Activate(); }
|
||||
}
|
||||
|
||||
public void Initialize(ActorBody parent, ActorAddonDef actorAddonDef)
|
||||
{
|
||||
this.parent = parent;
|
||||
this.bodyPart = actorAddonDef.addonName;
|
||||
|
||||
bodyPartRenderer.sprite = actorAddonDef.graphicData.GetSprite();
|
||||
bodyPartRenderer.transform.localScale = (Vector3)actorAddonDef.graphicData.GetDrawSize();
|
||||
|
||||
Start();
|
||||
}
|
||||
|
||||
public void OnActorAddonChange(ActorAddon actorAddon)
|
||||
{
|
||||
if (actorAddon.AddonName == bodyPart)
|
||||
|
|
|
@ -52,6 +52,8 @@ namespace RimWorldAnimationStudio
|
|||
layerDropdown.SetValueWithoutNotify(layerDropdown.options.IndexOf(layerDropdown.options.First(x => x.text == clip.GetActorAddon(addonName).Layer)));
|
||||
anchoringPawnField.SetTextWithoutNotify(clip.GetActorAddon(addonName).AnchoringActor.ToString());
|
||||
toggle.SetIsOnWithoutNotify(clip.IsActorAddonVisible(addonName));
|
||||
|
||||
anchoringPawnField.interactable = anchorDropdown.value != 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 96cc86ae315a7c34c91b9af2499fa23c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9b19816966eab6a4eba748f04532fb61
|
||||
guid: 09b43781ddbab9c49b81b88c7a8b4076
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
60
Assets/Scripts/Graphics/GraphicData.cs
Normal file
60
Assets/Scripts/Graphics/GraphicData.cs
Normal file
|
@ -0,0 +1,60 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Reflection;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RimWorldAnimationStudio
|
||||
{
|
||||
[Serializable]
|
||||
public class GraphicData
|
||||
{
|
||||
public string texPath;
|
||||
public string graphicClass;
|
||||
public string shaderType;
|
||||
public string drawSize;
|
||||
|
||||
private Sprite sprite;
|
||||
|
||||
public void SetDrawSize(Vector2 drawSize)
|
||||
{
|
||||
this.drawSize = "(" + drawSize.x + ", " + drawSize.y + ")";
|
||||
}
|
||||
|
||||
public Vector3 GetDrawSize()
|
||||
{
|
||||
string drawSizeString = drawSize;
|
||||
|
||||
drawSizeString = drawSizeString.Trim();
|
||||
drawSizeString = drawSizeString.Replace("(", "");
|
||||
drawSizeString = drawSizeString.Replace(")", "");
|
||||
var drawSizeStrings = drawSizeString.Split(',');
|
||||
|
||||
return new Vector3(float.Parse(drawSizeStrings[0]), float.Parse(drawSizeStrings[1]));
|
||||
}
|
||||
|
||||
public Sprite GetSprite()
|
||||
{
|
||||
if (sprite != null) return sprite;
|
||||
|
||||
if (string.IsNullOrEmpty(texPath)) return null;
|
||||
|
||||
string fullPath = Path.GetFullPath(Path.Combine(Application.streamingAssetsPath, texPath)) + ".png";
|
||||
|
||||
if (File.Exists(fullPath) == false) return null;
|
||||
|
||||
byte[] pngBytes = File.ReadAllBytes(fullPath);
|
||||
|
||||
Texture2D texture = new Texture2D(2, 2);
|
||||
texture.LoadImage(pngBytes);
|
||||
|
||||
float scale = Mathf.Min(texture.width, texture.height) / 128f;
|
||||
sprite = Sprite.Create(texture, new Rect(0.0f, 0.0f, texture.width, texture.height), new Vector2(0.5f, 0.5f), 85.0f * scale);
|
||||
|
||||
return sprite;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Graphics/GraphicData.cs.meta
Normal file
11
Assets/Scripts/Graphics/GraphicData.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6e8b46532a4e0ce42b40b1a1fd03935a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue