mirror of
https://gitgud.io/AbstractConcept/rimworld-animation-studio.git
synced 2024-08-15 00:43:27 +00:00
v 1.0.0
This commit is contained in:
parent
0828ecd037
commit
2998865184
9821 changed files with 90 additions and 90 deletions
60
Source/Assets/Scripts/Graphics/GraphicData.cs
Normal file
60
Source/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
Source/Assets/Scripts/Graphics/GraphicData.cs.meta
Normal file
11
Source/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:
|
49
Source/Assets/Scripts/Graphics/MultiDirectionalGraphic.cs
Normal file
49
Source/Assets/Scripts/Graphics/MultiDirectionalGraphic.cs
Normal file
|
@ -0,0 +1,49 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RimWorldAnimationStudio
|
||||
{
|
||||
[Serializable]
|
||||
public class MultiDirectionalGraphic
|
||||
{
|
||||
public string bodyType = "None";
|
||||
public SingleGraphic northGraphic = new SingleGraphic();
|
||||
public SingleGraphic eastGraphic = new SingleGraphic();
|
||||
public SingleGraphic southGraphic = new SingleGraphic();
|
||||
|
||||
public bool ShouldSerializenorthGraphic() { return string.IsNullOrEmpty(northGraphic.path) == false; }
|
||||
public bool ShouldSerializeeastGraphic() { return string.IsNullOrEmpty(eastGraphic.path) == false; }
|
||||
public bool ShouldSerializesouthGraphic() { return string.IsNullOrEmpty(southGraphic.path) == false; }
|
||||
|
||||
public MultiDirectionalGraphic() { }
|
||||
|
||||
public MultiDirectionalGraphic(string bodyType)
|
||||
{
|
||||
this.bodyType = bodyType;
|
||||
}
|
||||
|
||||
public bool HasValidPathForDirection(CardinalDirection facing)
|
||||
{
|
||||
string path;
|
||||
|
||||
switch (facing)
|
||||
{
|
||||
case CardinalDirection.North: path = northGraphic.path; break;
|
||||
case CardinalDirection.East: path = eastGraphic.path; break;
|
||||
case CardinalDirection.South: path = southGraphic.path; break;
|
||||
default: path = eastGraphic.path; break;
|
||||
}
|
||||
|
||||
if (path == null || path.Any() == false || Path.GetExtension(path) != ".png")
|
||||
{ return false; }
|
||||
|
||||
if (File.Exists(path) == false && File.Exists(Path.GetFullPath(Path.Combine(Application.streamingAssetsPath, path))) == false)
|
||||
{ return false; }
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 86cb79b8d4c053f4a981ed17b86ae9bb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
53
Source/Assets/Scripts/Graphics/SingleGraphic.cs
Normal file
53
Source/Assets/Scripts/Graphics/SingleGraphic.cs
Normal file
|
@ -0,0 +1,53 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Serialization;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RimWorldAnimationStudio
|
||||
{
|
||||
[Serializable]
|
||||
public class SingleGraphic
|
||||
{
|
||||
public string path;
|
||||
[XmlIgnore] public Sprite sprite = null;
|
||||
|
||||
public void SetPath(string path)
|
||||
{
|
||||
string streamingAssets = Path.GetFullPath(Application.streamingAssetsPath);
|
||||
string combinedPath = Path.GetFullPath(Path.Combine(streamingAssets, path));
|
||||
|
||||
if (path == null || path.Any() == false || Path.GetExtension(path) != ".png")
|
||||
{ this.path = null; return; }
|
||||
|
||||
if (File.Exists(path) == false && File.Exists(combinedPath) == false)
|
||||
{ this.path = null; return; }
|
||||
|
||||
if (path.Contains(streamingAssets))
|
||||
{
|
||||
path = path.Replace(streamingAssets, "");
|
||||
path = path.TrimStart(new char[] { '\\', '/' });
|
||||
}
|
||||
|
||||
this.path = path;
|
||||
sprite = LoadSprite(Path.GetFullPath(Path.Combine(streamingAssets, path)));
|
||||
}
|
||||
|
||||
public Sprite LoadSprite(string path)
|
||||
{
|
||||
if (path == null || path.Any() == false || File.Exists(path) == false || Path.GetExtension(path) != ".png") return null;
|
||||
|
||||
byte[] pngBytes = File.ReadAllBytes(path);
|
||||
|
||||
Texture2D texture = new Texture2D(2, 2);
|
||||
texture.LoadImage(pngBytes);
|
||||
|
||||
float scale = Mathf.Min(texture.width, texture.height) / 128f;
|
||||
|
||||
Sprite 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
Source/Assets/Scripts/Graphics/SingleGraphic.cs.meta
Normal file
11
Source/Assets/Scripts/Graphics/SingleGraphic.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7eb64887148d9f44793b32cf5393c7ad
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue