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
53 lines
1.7 KiB
C#
53 lines
1.7 KiB
C#
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;
|
|
}
|
|
}
|
|
}
|