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
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