mirror of
https://gitgud.io/AbstractConcept/rimworld-animation-studio.git
synced 2024-08-15 00:43:27 +00:00
bb2cc29393
commitaf4dab5546
Author: AbstractConcept <abstract.concept@mail.com> Date: Mon Oct 31 19:58:41 2022 -0500 Code refactor commite14a12f2ab
Author: AbstractConcept <abstract.concept@mail.com> Date: Mon Oct 31 00:44:53 2022 -0500 Code refactor commit5ca7e486f8
Author: AbstractConcept <abstract.concept@mail.com> Date: Fri Oct 28 19:52:58 2022 -0500 Code refactor commita55ba7b95b
Author: AbstractConcept <abstract.concept@mail.com> Date: Fri Oct 28 00:28:51 2022 -0500 Code refactor commit757badf4f6
Author: AbstractConcept <abstract.concept@mail.com> Date: Thu Oct 27 00:56:04 2022 -0500 Code refactor
60 lines
1.7 KiB
C#
60 lines
1.7 KiB
C#
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;
|
|
}
|
|
}
|
|
}
|