mirror of
https://gitgud.io/AbstractConcept/rimworld-animation-studio.git
synced 2024-08-15 00:43:27 +00:00
Initial commit
This commit is contained in:
commit
3c7cc0c973
8391 changed files with 704313 additions and 0 deletions
|
@ -0,0 +1,3 @@
|
|||
using System.Runtime.CompilerServices;
|
||||
[assembly: InternalsVisibleTo("Unity.2D.Common.Tests.EditorTests")]
|
||||
[assembly: InternalsVisibleTo("Unity.2D.PsdImporter.Editor")]
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: cb006e3fa37420b42b3673eef90cd4b3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 534fa0647f988416eafbba143e1ff174
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,213 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityEditor.U2D.Common
|
||||
{
|
||||
internal interface IImagePackNodeVisitor
|
||||
{
|
||||
void Visit(ImagePackNode node);
|
||||
}
|
||||
|
||||
class CollectEmptyNodePositionVisitor : IImagePackNodeVisitor
|
||||
{
|
||||
public List<RectInt> emptyAreas = new List<RectInt>();
|
||||
public void Visit(ImagePackNode node)
|
||||
{
|
||||
if (node.imageId == -1)
|
||||
{
|
||||
emptyAreas.Add(node.rect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class CollectPackNodePositionVisitor : IImagePackNodeVisitor
|
||||
{
|
||||
public CollectPackNodePositionVisitor()
|
||||
{
|
||||
positions = new Vector2Int[0];
|
||||
}
|
||||
|
||||
public void Visit(ImagePackNode node)
|
||||
{
|
||||
if (node.imageId != -1)
|
||||
{
|
||||
if (positions.Length < node.imageId + 1)
|
||||
{
|
||||
var p = positions;
|
||||
Array.Resize(ref p, node.imageId + 1);
|
||||
positions = p;
|
||||
}
|
||||
|
||||
positions[node.imageId].x = node.rect.x;
|
||||
positions[node.imageId].y = node.rect.y;
|
||||
}
|
||||
}
|
||||
|
||||
public Vector2Int[] positions { get; private set; }
|
||||
}
|
||||
|
||||
internal class ImagePackNode
|
||||
{
|
||||
public ImagePackNode left;
|
||||
public ImagePackNode right;
|
||||
public RectInt rect;
|
||||
public Vector2Int imageWidth;
|
||||
public int imageId = -1;
|
||||
|
||||
public void AcceptVisitor(IImagePackNodeVisitor visitor)
|
||||
{
|
||||
visitor.Visit(this);
|
||||
if (left != null)
|
||||
left.AcceptVisitor(visitor);
|
||||
if (right != null)
|
||||
right.AcceptVisitor(visitor);
|
||||
}
|
||||
|
||||
public void AdjustSize(int oriWidth, int oriHeight, int deltaW, int deltaH, out int adjustx, out int adjusty)
|
||||
{
|
||||
adjustx = adjusty = 0;
|
||||
int adjustXleft = 0, adjustYleft = 0, adjustXRight = 0, adjustYRight = 0;
|
||||
if (imageId == -1 || left == null)
|
||||
{
|
||||
if (rect.x + rect.width == oriWidth)
|
||||
{
|
||||
rect.width += deltaW;
|
||||
adjustx = deltaW;
|
||||
}
|
||||
if (rect.y + rect.height == oriHeight)
|
||||
{
|
||||
rect.height += deltaH;
|
||||
adjusty = deltaH;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
left.AdjustSize(oriWidth, oriHeight, deltaW, deltaH, out adjustXleft, out adjustYleft);
|
||||
right.AdjustSize(oriWidth, oriHeight, deltaW, deltaH, out adjustXRight, out adjustYRight);
|
||||
|
||||
adjustx = Mathf.Max(adjustXleft, adjustXRight);
|
||||
rect.width += adjustx;
|
||||
adjusty = Mathf.Max(adjustYleft, adjustYRight);
|
||||
rect.height += adjusty;
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryInsert(ImagePacker.ImagePackRect insert, int padding, out Vector2Int remainingSpace)
|
||||
{
|
||||
remainingSpace = Vector2Int.zero;
|
||||
int insertWidth = insert.rect.width + padding * 2;
|
||||
int insertHeight = insert.rect.height + padding * 2;
|
||||
if (insertWidth > rect.width || insertHeight > rect.height)
|
||||
return false;
|
||||
|
||||
if (imageId == -1)
|
||||
{
|
||||
remainingSpace.x = rect.width - insertWidth;
|
||||
remainingSpace.y = rect.height - insertHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector2Int spaceLeft, spaceRight;
|
||||
bool insertLeft, insertRight;
|
||||
ImagePackNode tryLeft, tryRight;
|
||||
tryLeft = left;
|
||||
tryRight = right;
|
||||
if (left == null && !SplitRects(this, insert, padding, out tryLeft, out tryRight))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
insertLeft = tryLeft.TryInsert(insert, padding, out spaceLeft);
|
||||
insertRight = tryRight.TryInsert(insert, padding, out spaceRight);
|
||||
if (insertLeft && insertRight)
|
||||
{
|
||||
remainingSpace = spaceLeft.sqrMagnitude < spaceRight.sqrMagnitude ? spaceLeft : spaceRight;
|
||||
}
|
||||
else if (insertLeft)
|
||||
remainingSpace = spaceLeft;
|
||||
else if (insertRight)
|
||||
remainingSpace = spaceRight;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool SplitRects(ImagePackNode node, ImagePacker.ImagePackRect insert, int padding, out ImagePackNode left, out ImagePackNode right)
|
||||
{
|
||||
// Find the best way to split the rect based on a new rect
|
||||
left = right = null;
|
||||
var tryRects = new[]
|
||||
{
|
||||
new ImagePackNode(), new ImagePackNode(),
|
||||
new ImagePackNode(), new ImagePackNode()
|
||||
};
|
||||
|
||||
tryRects[0].rect = new RectInt(node.rect.x + node.imageWidth.x, node.rect.y, node.rect.width - node.imageWidth.x, node.rect.height);
|
||||
tryRects[1].rect = new RectInt(node.rect.x, node.rect.y + node.imageWidth.y, node.imageWidth.x, node.rect.height - node.imageWidth.y);
|
||||
tryRects[2].rect = new RectInt(node.rect.x, node.rect.y + node.imageWidth.y, node.rect.width, node.rect.height - node.imageWidth.y);
|
||||
tryRects[3].rect = new RectInt(node.rect.x + node.imageWidth.x, node.rect.y, node.rect.width - node.imageWidth.x, node.imageWidth.y);
|
||||
float smallestSpace = float.MinValue;
|
||||
for (int i = 0; i < tryRects.GetLength(0); ++i)
|
||||
{
|
||||
//for (int j = 0; j < tryRects.GetLength(1); ++j)
|
||||
{
|
||||
Vector2Int newSpaceLeft;
|
||||
if (tryRects[i].TryInsert(insert, padding, out newSpaceLeft))
|
||||
{
|
||||
if (smallestSpace < newSpaceLeft.sqrMagnitude)
|
||||
{
|
||||
smallestSpace = newSpaceLeft.sqrMagnitude;
|
||||
int index = i / 2 * 2;
|
||||
left = tryRects[index];
|
||||
right = tryRects[index + 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return left != null;
|
||||
}
|
||||
|
||||
public bool Insert(ImagePacker.ImagePackRect insert, int padding)
|
||||
{
|
||||
int insertWidth = insert.rect.width + padding * 2;
|
||||
int insertHeight = insert.rect.height + padding * 2;
|
||||
if (insertWidth > rect.width || insertHeight > rect.height)
|
||||
return false;
|
||||
|
||||
if (imageId == -1)
|
||||
{
|
||||
imageId = insert.index;
|
||||
imageWidth = new Vector2Int(insertWidth, insertHeight);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (left == null && !SplitRects(this, insert, padding, out left, out right))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// We assign to the node that has a better fit for the image
|
||||
Vector2Int spaceLeft, spaceRight;
|
||||
bool insertLeft, insertRight;
|
||||
insertLeft = left.TryInsert(insert, padding, out spaceLeft);
|
||||
insertRight = right.TryInsert(insert, padding, out spaceRight);
|
||||
if (insertLeft && insertRight)
|
||||
{
|
||||
if (spaceLeft.sqrMagnitude < spaceRight.sqrMagnitude)
|
||||
left.Insert(insert, padding);
|
||||
else
|
||||
right.Insert(insert, padding);
|
||||
}
|
||||
else if (insertLeft)
|
||||
left.Insert(insert, padding);
|
||||
else if (insertRight)
|
||||
right.Insert(insert, padding);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 488b804e650114066b55d51eefc85775
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,193 @@
|
|||
//#define PACKING_DEBUG
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using Unity.Collections;
|
||||
using Unity.Collections.LowLevel.Unsafe;
|
||||
|
||||
namespace UnityEditor.U2D.Common
|
||||
{
|
||||
internal static class ImagePacker
|
||||
{
|
||||
/// <summary>
|
||||
/// Given an array of rects, the method returns an array of rects arranged within outPackedWidth and outPackedHeight
|
||||
/// </summary>
|
||||
/// <param name="rects">Rects to pack</param>
|
||||
/// <param name="padding">Padding between each rect</param>
|
||||
/// <param name="outPackedRects">Rects arranged within outPackedWidth and outPackedHeight</param>
|
||||
/// <param name="outPackedWidth">Width of the packed rects</param>
|
||||
/// <param name="outPackedHeight">Height of the packed rects</param>
|
||||
public static void Pack(RectInt[] rects, int padding, out RectInt[] outPackedRects, out int outPackedWidth, out int outPackedHeight)
|
||||
{
|
||||
var packNode = InternalPack(rects, padding);
|
||||
outPackedWidth = packNode.rect.width;
|
||||
outPackedHeight = packNode.rect.height;
|
||||
var visitor = new CollectPackNodePositionVisitor();
|
||||
packNode.AcceptVisitor(visitor);
|
||||
|
||||
outPackedRects = new RectInt[rects.Length];
|
||||
for (int i = 0; i < rects.Length; ++i)
|
||||
outPackedRects[i] = new RectInt(visitor.positions[i].x + padding, visitor.positions[i].y + padding, rects[i].width, rects[i].height);
|
||||
#if PACKING_DEBUG
|
||||
var emptyNodeCollector = new CollectEmptyNodePositionVisitor();
|
||||
packNode.AcceptVisitor(emptyNodeCollector);
|
||||
Array.Resize(ref outPackedRects, rects.Length + emptyNodeCollector.emptyAreas.Count);
|
||||
for (int i = rects.Length; i < outPackedRects.Length; ++i)
|
||||
outPackedRects[i] = emptyNodeCollector.emptyAreas[i - rects.Length];
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Packs image buffer into a single buffer. Image buffers are assumed to be 4 bytes per pixel in RGBA format
|
||||
/// </summary>
|
||||
/// <param name="buffers">Image buffers to pack</param>
|
||||
/// <param name="width">Image buffers width</param>
|
||||
/// <param name="height">Image buffers height</param>
|
||||
/// <param name="padding">Padding between each packed image</param>
|
||||
/// <param name="outPackedBuffer">Packed image buffer</param>
|
||||
/// <param name="outPackedBufferWidth">Packed image buffer's width</param>
|
||||
/// <param name="outPackedBufferHeight">Packed iamge buffer's height</param>
|
||||
/// <param name="outPackedRect">Location of each image buffers in the packed buffer</param>
|
||||
/// <param name="outUVTransform">Translation data from image original buffer to packed buffer</param>
|
||||
public static void Pack(NativeArray<Color32>[] buffers, int width, int height, int padding, out NativeArray<Color32> outPackedBuffer, out int outPackedBufferWidth, out int outPackedBufferHeight, out RectInt[] outPackedRect, out Vector2Int[] outUVTransform)
|
||||
{
|
||||
UnityEngine.Profiling.Profiler.BeginSample("Pack");
|
||||
// Determine the area that contains data in the buffer
|
||||
outPackedBuffer = default(NativeArray<Color32>);
|
||||
try
|
||||
{
|
||||
var tightRects = FindTightRectJob.Execute(buffers, width, height);
|
||||
Pack(tightRects, padding, out outPackedRect, out outPackedBufferWidth, out outPackedBufferHeight);
|
||||
outUVTransform = new Vector2Int[tightRects.Length];
|
||||
for (int i = 0; i < outUVTransform.Length; ++i)
|
||||
{
|
||||
outUVTransform[i] = new Vector2Int(outPackedRect[i].x - tightRects[i].x, outPackedRect[i].y - tightRects[i].y);
|
||||
}
|
||||
outPackedBuffer = new NativeArray<Color32>(outPackedBufferWidth * outPackedBufferHeight, Allocator.Temp);
|
||||
|
||||
Blit(outPackedBuffer, outPackedRect, outPackedBufferWidth, buffers, tightRects, width, padding);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (outPackedBuffer.IsCreated)
|
||||
outPackedBuffer.Dispose();
|
||||
throw ex;
|
||||
}
|
||||
finally
|
||||
{
|
||||
UnityEngine.Profiling.Profiler.EndSample();
|
||||
}
|
||||
}
|
||||
|
||||
static ImagePackNode InternalPack(RectInt[] rects, int padding)
|
||||
{
|
||||
if (rects == null || rects.Length == 0)
|
||||
return new ImagePackNode() { rect = new RectInt(0, 0, 0, 0)};
|
||||
var sortedRects = new ImagePackRect[rects.Length];
|
||||
for (int i = 0; i < rects.Length; ++i)
|
||||
{
|
||||
sortedRects[i] = new ImagePackRect();
|
||||
sortedRects[i].rect = rects[i];
|
||||
sortedRects[i].index = i;
|
||||
}
|
||||
Array.Sort<ImagePackRect>(sortedRects);
|
||||
var root = new ImagePackNode();
|
||||
root.rect = new RectInt(0, 0, (int)NextPowerOfTwo((ulong)rects[0].width), (int)NextPowerOfTwo((ulong)rects[0].height));
|
||||
|
||||
for (int i = 0; i < rects.Length; ++i)
|
||||
{
|
||||
if (!root.Insert(sortedRects[i], padding)) // we can't fit
|
||||
{
|
||||
int newWidth = root.rect.width , newHeight = root.rect.height;
|
||||
if (root.rect.width < root.rect.height)
|
||||
newWidth = (int)NextPowerOfTwo((ulong)root.rect.width + 1);
|
||||
else
|
||||
newHeight = (int)NextPowerOfTwo((ulong)root.rect.height + 1);
|
||||
// Reset all packing and try again
|
||||
root = new ImagePackNode();
|
||||
root.rect = new RectInt(0, 0, newWidth, newHeight);
|
||||
i = -1;
|
||||
}
|
||||
}
|
||||
return root;
|
||||
}
|
||||
|
||||
public static unsafe void Blit(NativeArray<Color32> buffer, RectInt[] blitToArea, int bufferbytesPerRow, NativeArray<Color32>[] originalBuffer, RectInt[] blitFromArea, int bytesPerRow, int padding)
|
||||
{
|
||||
UnityEngine.Profiling.Profiler.BeginSample("Blit");
|
||||
|
||||
var c = (Color32*)buffer.GetUnsafePtr();
|
||||
for (int bufferIndex = 0; bufferIndex < blitToArea.Length && bufferIndex < originalBuffer.Length && bufferIndex < blitFromArea.Length; ++bufferIndex)
|
||||
{
|
||||
var b = (Color32*)originalBuffer[bufferIndex].GetUnsafeReadOnlyPtr();
|
||||
var rectFrom = blitFromArea[bufferIndex];
|
||||
var rectTo = blitToArea[bufferIndex];
|
||||
for (int i = 0; i < rectFrom.height; ++i)
|
||||
{
|
||||
for (int j = 0; j < rectFrom.width; ++j)
|
||||
{
|
||||
Color32 cc = b[(rectFrom.y + i) * bytesPerRow + rectFrom.x + j];
|
||||
c[((rectTo.y + i) * bufferbytesPerRow) + rectTo.x + j] = cc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if PACKING_DEBUG
|
||||
var emptyColors = new Color32[]
|
||||
{
|
||||
new Color32((byte)255, (byte)0, (byte)0, (byte)255),
|
||||
new Color32((byte)255, (byte)255, (byte)0, (byte)255),
|
||||
new Color32((byte)255, (byte)0, (byte)255, (byte)255),
|
||||
new Color32((byte)255, (byte)255, (byte)255, (byte)255),
|
||||
new Color32((byte)0, (byte)255, (byte)0, (byte)255),
|
||||
new Color32((byte)0, (byte)0, (byte)255, (byte)255)
|
||||
};
|
||||
|
||||
for (int k = originalBuffer.Length; k < blitToArea.Length; ++k)
|
||||
{
|
||||
var rectFrom = blitToArea[k];
|
||||
for (int i = 0; i < rectFrom.height; ++i)
|
||||
{
|
||||
for (int j = 0; j < rectFrom.width; ++j)
|
||||
{
|
||||
c[((rectFrom.y + i) * bufferbytesPerRow) + rectFrom.x + j] =
|
||||
emptyColors[k % emptyColors.Length];
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
UnityEngine.Profiling.Profiler.EndSample();
|
||||
}
|
||||
|
||||
internal static ulong NextPowerOfTwo(ulong v)
|
||||
{
|
||||
v -= 1;
|
||||
v |= v >> 16;
|
||||
v |= v >> 8;
|
||||
v |= v >> 4;
|
||||
v |= v >> 2;
|
||||
v |= v >> 1;
|
||||
return v + 1;
|
||||
}
|
||||
|
||||
internal class ImagePackRect : IComparable<ImagePackRect>
|
||||
{
|
||||
public RectInt rect;
|
||||
public int index;
|
||||
|
||||
public int CompareTo(ImagePackRect obj)
|
||||
{
|
||||
var lhsArea = rect.width * rect.height;
|
||||
var rhsArea = obj.rect.width * obj.rect.height;
|
||||
if (lhsArea > rhsArea)
|
||||
return -1;
|
||||
if (lhsArea < rhsArea)
|
||||
return 1;
|
||||
if (index < obj.index)
|
||||
return -1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6ea81e02715034d7e81c7c8e6f5e3329
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,300 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor.U2D.Sprites;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace UnityEditor.U2D.Common
|
||||
{
|
||||
internal class ImagePackerDebugEditor : EditorWindow
|
||||
{
|
||||
[MenuItem("internal:Window/2D/Common/Image Packer Debug Editor")]
|
||||
static void Launch()
|
||||
{
|
||||
var window = EditorWindow.GetWindow<ImagePackerDebugEditor>();
|
||||
var pos = window.position;
|
||||
pos.height = pos.width = 400;
|
||||
window.position = pos;
|
||||
window.Show();
|
||||
}
|
||||
|
||||
ReorderableList m_ReorderableList;
|
||||
ImagePacker.ImagePackRect[] m_PackingRect = null;
|
||||
List<RectInt> m_PackRects = new List<RectInt>();
|
||||
RectInt[] m_PackResult = null;
|
||||
SpriteRect[] m_SpriteRects = null;
|
||||
Texture2D m_Texture;
|
||||
int m_TextureActualWidth = 0;
|
||||
int m_TextureActualHeight = 0;
|
||||
int m_PackWidth = 0;
|
||||
int m_PackHeight = 0;
|
||||
int m_Padding = 0;
|
||||
Vector2 m_ConfigScroll = Vector2.zero;
|
||||
float m_Zoom = 1;
|
||||
IMGUIContainer m_PackArea;
|
||||
int m_PackStep = -1;
|
||||
protected const float k_MinZoomPercentage = 0.9f;
|
||||
protected const float k_WheelZoomSpeed = 0.03f;
|
||||
protected const float k_MouseZoomSpeed = 0.005f;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
var visualContainer = new VisualElement()
|
||||
{
|
||||
name = "Container",
|
||||
style =
|
||||
{
|
||||
flexGrow = 1,
|
||||
flexDirection = FlexDirection.Row
|
||||
}
|
||||
};
|
||||
this.rootVisualElement.Add(visualContainer);
|
||||
|
||||
var imgui = new IMGUIContainer(OnConfigGUI)
|
||||
{
|
||||
name = "Config",
|
||||
style =
|
||||
{
|
||||
width = 300
|
||||
}
|
||||
};
|
||||
|
||||
visualContainer.Add(imgui);
|
||||
|
||||
m_PackArea = new IMGUIContainer(OnImagePackerGUI)
|
||||
{
|
||||
name = "ImagePacker",
|
||||
style =
|
||||
{
|
||||
flexGrow = 1,
|
||||
}
|
||||
};
|
||||
visualContainer.Add(m_PackArea);
|
||||
SetupConfigGUI();
|
||||
}
|
||||
|
||||
void SetupConfigGUI()
|
||||
{
|
||||
m_ReorderableList = new ReorderableList(m_PackRects, typeof(RectInt), false, false, true, true);
|
||||
m_ReorderableList.elementHeightCallback = (int index) =>
|
||||
{
|
||||
return EditorGUIUtility.singleLineHeight * 2 + 6;
|
||||
};
|
||||
m_ReorderableList.drawElementCallback = DrawListElement;
|
||||
|
||||
m_ReorderableList.onAddCallback = (list) =>
|
||||
{
|
||||
m_PackRects.Add(new RectInt());
|
||||
};
|
||||
m_ReorderableList.onRemoveCallback = (list) =>
|
||||
{
|
||||
m_PackRects.RemoveAt(list.index);
|
||||
};
|
||||
}
|
||||
|
||||
void DrawListElement(Rect rect, int index, bool isactive, bool isfocused)
|
||||
{
|
||||
var rectInt = m_PackRects[index];
|
||||
var name = m_SpriteRects == null || index >= m_SpriteRects.Length ? index.ToString() : m_SpriteRects[index].
|
||||
name;
|
||||
rectInt.size = EditorGUI.Vector2IntField(rect, name, rectInt.size);
|
||||
m_PackRects[index] = rectInt;
|
||||
}
|
||||
|
||||
void OnConfigGUI()
|
||||
{
|
||||
EditorGUILayout.BeginVertical();
|
||||
m_ConfigScroll = EditorGUILayout.BeginScrollView(m_ConfigScroll);
|
||||
m_ReorderableList.DoLayoutList();
|
||||
EditorGUILayout.EndScrollView();
|
||||
GUILayout.FlexibleSpace();
|
||||
|
||||
m_PackStep = EditorGUILayout.IntSlider("Step", m_PackStep, 0, m_PackRects.Count);
|
||||
EditorGUI.BeginChangeCheck();
|
||||
m_Texture = EditorGUILayout.ObjectField(new GUIContent("Texture"), (Object)m_Texture, typeof(Texture2D), false) as Texture2D;
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
UpdateSpriteRect();
|
||||
m_Padding = EditorGUILayout.IntField("Padding", m_Padding);
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
if (GUILayout.Button("<<"))
|
||||
{
|
||||
m_PackStep = m_PackStep <= 0 ? 0 : m_PackStep - 1;
|
||||
Pack();
|
||||
}
|
||||
if (GUILayout.Button("Pack"))
|
||||
Pack();
|
||||
if (GUILayout.Button(">>"))
|
||||
{
|
||||
m_PackStep = m_PackStep > m_PackRects.Count ? m_PackRects.Count : m_PackStep + 1;
|
||||
Pack();
|
||||
}
|
||||
if (GUILayout.Button("Clear"))
|
||||
{
|
||||
m_PackRects.Clear();
|
||||
m_Texture = null;
|
||||
m_PackingRect = null;
|
||||
m_PackResult = null;
|
||||
m_SpriteRects = null;
|
||||
}
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
EditorGUILayout.EndVertical();
|
||||
}
|
||||
|
||||
void UpdateSpriteRect()
|
||||
{
|
||||
var dataProvider = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(m_Texture)) as ISpriteEditorDataProvider;
|
||||
if (dataProvider == null)
|
||||
return;
|
||||
dataProvider.InitSpriteEditorDataProvider();
|
||||
dataProvider.GetDataProvider<ITextureDataProvider>().GetTextureActualWidthAndHeight(out m_TextureActualWidth, out m_TextureActualHeight);
|
||||
m_SpriteRects = dataProvider.GetDataProvider<ISpriteEditorDataProvider>().GetSpriteRects();
|
||||
m_PackRects.Clear();
|
||||
m_PackRects.AddRange(m_SpriteRects.Select(x => new RectInt((int)x.rect.x, (int)x.rect.y, (int)x.rect.width, (int)x.rect.height)));
|
||||
m_PackResult = null;
|
||||
m_PackStep = m_PackRects.Count;
|
||||
}
|
||||
|
||||
void Pack()
|
||||
{
|
||||
int count = m_PackStep > 0 && m_PackStep < m_PackRects.Count ? m_PackStep : m_PackRects.Count;
|
||||
m_PackingRect = new ImagePacker.ImagePackRect[m_PackRects.Count];
|
||||
for (int i = 0; i < m_PackRects.Count; ++i)
|
||||
{
|
||||
m_PackingRect[i] = new ImagePacker.ImagePackRect()
|
||||
{
|
||||
rect = m_PackRects[i],
|
||||
index = i
|
||||
};
|
||||
}
|
||||
Array.Sort(m_PackingRect);
|
||||
ImagePacker.Pack(m_PackingRect.Take(count).Select(x => x.rect).ToArray(), m_Padding, out m_PackResult, out m_PackWidth, out m_PackHeight);
|
||||
}
|
||||
|
||||
void DrawLabel(Rect rect, string label)
|
||||
{
|
||||
rect.position = Handles.matrix.MultiplyPoint(rect.position);
|
||||
GUI.Label(rect, label);
|
||||
}
|
||||
|
||||
void OnImagePackerGUI()
|
||||
{
|
||||
if (m_PackResult == null)
|
||||
return;
|
||||
HandleZoom();
|
||||
var oldMatrix = Handles.matrix;
|
||||
SetupHandlesMatrix();
|
||||
Handles.DrawSolidRectangleWithOutline(new Rect(0, 0, m_PackWidth, m_PackHeight), Color.gray, Color.black);
|
||||
DrawLabel(new Rect(0, 0, m_PackWidth, m_PackHeight), m_PackWidth + "x" + m_PackHeight);
|
||||
|
||||
int index = 0;
|
||||
|
||||
foreach (var rect in m_PackResult)
|
||||
{
|
||||
Handles.DrawSolidRectangleWithOutline(new Rect(rect.x, rect.y, rect.width, rect.height), Color.white, Color.black);
|
||||
var rect1 = new Rect(rect.x, rect.y + rect.height * 0.5f, rect.width, EditorGUIUtility.singleLineHeight);
|
||||
DrawLabel(rect1, m_PackingRect[index].index.ToString());
|
||||
++index;
|
||||
}
|
||||
|
||||
index = 0;
|
||||
if (m_Texture != null && m_SpriteRects != null)
|
||||
{
|
||||
var material = new Material(Shader.Find("Sprites/Default"));
|
||||
material.mainTexture = m_Texture;
|
||||
material.SetPass(0);
|
||||
|
||||
int mouseOverIndex = -1;
|
||||
GL.PushMatrix();
|
||||
GL.LoadIdentity();
|
||||
GL.MultMatrix(GUI.matrix * Handles.matrix);
|
||||
GL.Begin(GL.QUADS);
|
||||
for (int i = 0; i < m_PackResult.Length; ++i)
|
||||
{
|
||||
index = m_PackingRect[i].index;
|
||||
if (index >= m_SpriteRects.Length)
|
||||
continue;
|
||||
var rect = m_PackResult[i];
|
||||
GL.TexCoord(new Vector3(m_SpriteRects[index].rect.x / m_TextureActualWidth, m_SpriteRects[index].rect.y / m_TextureActualHeight, 0));
|
||||
GL.Vertex(new Vector3(rect.x, rect.y, 0));
|
||||
GL.TexCoord(new Vector3(m_SpriteRects[index].rect.xMax / m_TextureActualWidth, m_SpriteRects[index].rect.y / m_TextureActualHeight, 0));
|
||||
GL.Vertex(new Vector3(rect.x + rect.width, rect.y, 0));
|
||||
GL.TexCoord(new Vector3(m_SpriteRects[index].rect.xMax / m_TextureActualWidth, m_SpriteRects[index].rect.yMax / m_TextureActualHeight, 0));
|
||||
GL.Vertex(new Vector3(rect.x + rect.width, rect.y + rect.height, 0));
|
||||
GL.TexCoord(new Vector3(m_SpriteRects[index].rect.x / m_TextureActualWidth, m_SpriteRects[index].rect.yMax / m_TextureActualHeight, 0));
|
||||
GL.Vertex(new Vector3(rect.x, rect.y + rect.height, 0));
|
||||
var m = Handles.matrix.inverse.MultiplyPoint(Event.current.mousePosition);
|
||||
if (rect.Contains(new Vector2Int((int)m.x, (int)m.y)))
|
||||
{
|
||||
mouseOverIndex = index;
|
||||
}
|
||||
++index;
|
||||
}
|
||||
|
||||
GL.End();
|
||||
GL.PopMatrix();
|
||||
if (mouseOverIndex >= 0)
|
||||
{
|
||||
var text = new GUIContent(m_SpriteRects[mouseOverIndex].name + " " + index);
|
||||
var length = EditorStyles.textArea.CalcSize(text);
|
||||
var rect1 = new Rect(m_PackResult[mouseOverIndex].x, m_PackResult[mouseOverIndex].y + m_PackResult[mouseOverIndex].height * 0.5f, length.x, length.y);
|
||||
rect1.position = Handles.matrix.MultiplyPoint(rect1.position);
|
||||
if (Event.current.type == EventType.Repaint)
|
||||
EditorStyles.textArea.Draw(rect1, text, false, false, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
Handles.matrix = oldMatrix;
|
||||
}
|
||||
|
||||
void SetupHandlesMatrix()
|
||||
{
|
||||
Vector3 handlesPos = new Vector3(0, m_PackHeight * m_Zoom, 0f);
|
||||
Vector3 handlesScale = new Vector3(m_Zoom, -m_Zoom, 1f);
|
||||
Handles.matrix = Matrix4x4.TRS(handlesPos, Quaternion.identity, handlesScale);
|
||||
}
|
||||
|
||||
protected void HandleZoom()
|
||||
{
|
||||
bool zoomMode = Event.current.alt && Event.current.button == 1;
|
||||
if (zoomMode)
|
||||
{
|
||||
EditorGUIUtility.AddCursorRect(m_PackArea.worldBound, MouseCursor.Zoom);
|
||||
}
|
||||
|
||||
if (
|
||||
((Event.current.type == EventType.MouseUp || Event.current.type == EventType.MouseDown) && zoomMode) ||
|
||||
((Event.current.type == EventType.KeyUp || Event.current.type == EventType.KeyDown) && Event.current.keyCode == KeyCode.LeftAlt)
|
||||
)
|
||||
{
|
||||
Repaint();
|
||||
}
|
||||
|
||||
if (Event.current.type == EventType.ScrollWheel || (Event.current.type == EventType.MouseDrag && Event.current.alt && Event.current.button == 1))
|
||||
{
|
||||
float zoomMultiplier = 1f - Event.current.delta.y * (Event.current.type == EventType.ScrollWheel ? k_WheelZoomSpeed : -k_MouseZoomSpeed);
|
||||
|
||||
// Clamp zoom
|
||||
float wantedZoom = m_Zoom * zoomMultiplier;
|
||||
|
||||
float currentZoom = Mathf.Clamp(wantedZoom, GetMinZoom(), 1);
|
||||
|
||||
if (currentZoom != m_Zoom)
|
||||
{
|
||||
m_Zoom = currentZoom;
|
||||
Event.current.Use();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected float GetMinZoom()
|
||||
{
|
||||
if (m_Texture == null)
|
||||
return 1.0f;
|
||||
return Mathf.Min(m_PackArea.worldBound.width / m_PackWidth, m_PackArea.worldBound.height / m_PackHeight, 0.05f) * k_MinZoomPercentage;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 13c5c1934f6f927419763b01ff95ed74
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 55c552c82618a429ebc328c8ba27b416
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,59 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
using Unity.Collections;
|
||||
using Unity.Collections.LowLevel.Unsafe;
|
||||
using Unity.Jobs;
|
||||
|
||||
namespace UnityEditor.U2D.Common
|
||||
{
|
||||
public struct FindTightRectJob : IJobParallelFor
|
||||
{
|
||||
[ReadOnly]
|
||||
[DeallocateOnJobCompletion]
|
||||
NativeArray<IntPtr> m_Buffers;
|
||||
[ReadOnly]
|
||||
int m_Width;
|
||||
[ReadOnly]
|
||||
int m_Height;
|
||||
NativeArray<RectInt> m_Output;
|
||||
|
||||
public unsafe void Execute(int index)
|
||||
{
|
||||
var rect = new RectInt(m_Width, m_Height, 0, 0);
|
||||
var color = (Color32*)m_Buffers[index].ToPointer();
|
||||
for (int i = 0; i < m_Height; ++i)
|
||||
{
|
||||
for (int j = 0; j < m_Width; ++j)
|
||||
{
|
||||
if (color->a != 0)
|
||||
{
|
||||
rect.x = Mathf.Min(j, rect.x);
|
||||
rect.y = Mathf.Min(i, rect.y);
|
||||
rect.width = Mathf.Max(j, rect.width);
|
||||
rect.height = Mathf.Max(i, rect.height);
|
||||
}
|
||||
++color;
|
||||
}
|
||||
}
|
||||
rect.width = Mathf.Max(0, rect.width - rect.x + 1);
|
||||
rect.height = Mathf.Max(0, rect.height - rect.y + 1);
|
||||
m_Output[index] = rect;
|
||||
}
|
||||
|
||||
public static unsafe RectInt[] Execute(NativeArray<Color32>[] buffers, int width, int height)
|
||||
{
|
||||
var job = new FindTightRectJob();
|
||||
job.m_Buffers = new NativeArray<IntPtr>(buffers.Length, Allocator.TempJob);
|
||||
for (int i = 0; i < buffers.Length; ++i)
|
||||
job.m_Buffers[i] = new IntPtr(buffers[i].GetUnsafeReadOnlyPtr());
|
||||
job.m_Output = new NativeArray<RectInt>(buffers.Length, Allocator.TempJob);
|
||||
job.m_Width = width;
|
||||
job.m_Height = height;
|
||||
// Ensure all jobs are completed before we return since we don't own the buffers
|
||||
job.Schedule(buffers.Length, 1).Complete();
|
||||
var rects = job.m_Output.ToArray();
|
||||
job.m_Output.Dispose();
|
||||
return rects;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9b3eb1ded0fb747809431ebbd42aa4f3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d59d6a57d3f6f4f17bbf31e5a13966e8
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,6 @@
|
|||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("Unity.2D.Animation.Editor")]
|
||||
[assembly: InternalsVisibleTo("Unity.2D.SpriteShape.Editor")]
|
||||
[assembly: InternalsVisibleTo("Unity.2D.SpriteShape.EditorTests")]
|
||||
[assembly: InternalsVisibleTo("Unity.2D.PsdImporter.Editor")]
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7fc947ed5e1e2b141bd741eca43b418c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"name": "Unity.InternalAPIEditorBridge.001",
|
||||
"references": [
|
||||
"Unity.2D.Sprite.Editor"
|
||||
],
|
||||
"optionalUnityReferences": [],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": []
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ce6baade223984afda3f24c7fca12584
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,106 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEditor.ShortcutManagement;
|
||||
using UnityEditor.U2D.Sprites;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace UnityEditor.U2D.Common
|
||||
{
|
||||
internal static class InternalEditorBridge
|
||||
{
|
||||
public static void RenderSortingLayerFields(SerializedProperty order, SerializedProperty layer)
|
||||
{
|
||||
SortingLayerEditorUtility.RenderSortingLayerFields(order, layer);
|
||||
}
|
||||
|
||||
public static void RepaintImmediately(EditorWindow window)
|
||||
{
|
||||
window.RepaintImmediately();
|
||||
}
|
||||
|
||||
public static ISpriteEditorDataProvider GetISpriteEditorDataProviderFromPath(string importedAsset)
|
||||
{
|
||||
return AssetImporter.GetAtPath(importedAsset) as ISpriteEditorDataProvider;
|
||||
}
|
||||
|
||||
public static void GenerateOutline(Texture2D texture, Rect rect, float detail, byte alphaTolerance, bool holeDetection, out Vector2[][] paths)
|
||||
{
|
||||
UnityEditor.Sprites.SpriteUtility.GenerateOutline(texture, rect, detail, alphaTolerance, holeDetection, out paths);
|
||||
}
|
||||
|
||||
public static bool DoesHardwareSupportsFullNPOT()
|
||||
{
|
||||
return ShaderUtil.hardwareSupportsFullNPOT;
|
||||
}
|
||||
|
||||
public static Texture2D CreateTemporaryDuplicate(Texture2D tex, int width, int height)
|
||||
{
|
||||
return UnityEditor.SpriteUtility.CreateTemporaryDuplicate(tex, width, height);
|
||||
}
|
||||
|
||||
public static void ShowSpriteEditorWindow()
|
||||
{
|
||||
SpriteUtilityWindow.ShowSpriteEditorWindow();
|
||||
}
|
||||
|
||||
public static void ApplyWireMaterial()
|
||||
{
|
||||
HandleUtility.ApplyWireMaterial();
|
||||
}
|
||||
|
||||
public static void ResetSpriteEditorView(ISpriteEditor spriteEditor)
|
||||
{
|
||||
if (spriteEditor != null)
|
||||
{
|
||||
Type t = spriteEditor.GetType();
|
||||
var zoom = t.GetField("m_Zoom", BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
if (zoom != null)
|
||||
{
|
||||
zoom.SetValue(spriteEditor, -1);
|
||||
}
|
||||
|
||||
var scrollPosition = t.GetField("m_ScrollPosition", BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
if (scrollPosition != null)
|
||||
{
|
||||
scrollPosition.SetValue(spriteEditor, new Vector2());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ShortcutContext : IShortcutToolContext
|
||||
{
|
||||
public Func<bool> isActive;
|
||||
public bool active
|
||||
{
|
||||
get
|
||||
{
|
||||
if (isActive != null)
|
||||
return isActive();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
public object context { get; set; }
|
||||
}
|
||||
|
||||
public static void RegisterShortcutContext(ShortcutContext context)
|
||||
{
|
||||
ShortcutIntegration.instance.contextManager.RegisterToolContext(context);
|
||||
}
|
||||
|
||||
public static void UnregisterShortcutContext(ShortcutContext context)
|
||||
{
|
||||
ShortcutIntegration.instance.contextManager.DeregisterToolContext(context);
|
||||
}
|
||||
|
||||
public static void AddEditorApplicationProjectLoadedCallback(UnityAction callback)
|
||||
{
|
||||
EditorApplication.projectWasLoaded += callback;
|
||||
}
|
||||
|
||||
public static void RemoveEditorApplicationProjectLoadedCallback(UnityAction callback)
|
||||
{
|
||||
EditorApplication.projectWasLoaded -= callback;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b410f2c9e86a44d35992f15c05361b29
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f190f89354fdfb5479d5f291d8cb8182
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,594 @@
|
|||
using System;
|
||||
using Unity.Collections;
|
||||
using UnityEditor.Experimental.AssetImporters;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityEditor.U2D.Common
|
||||
{
|
||||
internal interface ITextureSettings
|
||||
{
|
||||
void FillTextureGenerationSettings(ref TextureGenerationSettings settings);
|
||||
}
|
||||
|
||||
|
||||
[Serializable]
|
||||
internal class TextureSettings : ITextureSettings
|
||||
{
|
||||
[SerializeField]
|
||||
bool m_ColorTexture;
|
||||
[SerializeField]
|
||||
bool m_Readable;
|
||||
[SerializeField]
|
||||
TextureImporterNPOTScale m_NPOTScale;
|
||||
[SerializeField]
|
||||
FilterMode m_FilterMode;
|
||||
[SerializeField]
|
||||
int m_Aniso;
|
||||
[SerializeField]
|
||||
bool m_EnablePostProcessor;
|
||||
[SerializeField]
|
||||
SecondarySpriteTexture[] m_SecondaryTextures;
|
||||
|
||||
public TextureSettings()
|
||||
{
|
||||
colorTexture = true;
|
||||
readable = false;
|
||||
npotScale = TextureImporterNPOTScale.None;
|
||||
filterMode = FilterMode.Bilinear;
|
||||
aniso = 1;
|
||||
}
|
||||
|
||||
public TextureSettings(string assetPath, bool enablePostProcessor, bool colorTexture, bool readable, TextureImporterNPOTScale npotScale, FilterMode filterMode, int aniso, bool sourceContainsAlpha, bool sourceWasHDR)
|
||||
{
|
||||
this.assetPath = assetPath;
|
||||
this.enablePostProcessor = enablePostProcessor;
|
||||
this.colorTexture = colorTexture;
|
||||
this.readable = readable;
|
||||
this.npotScale = npotScale;
|
||||
this.filterMode = filterMode;
|
||||
this.aniso = aniso;
|
||||
this.containsAlpha = sourceContainsAlpha;
|
||||
this.hdr = sourceWasHDR;
|
||||
}
|
||||
|
||||
public bool colorTexture { get { return m_ColorTexture; } set { m_ColorTexture = value; } } //sRGBTexture
|
||||
public bool readable { get { return m_Readable; } set { m_Readable = value; } }
|
||||
public TextureImporterNPOTScale npotScale { get { return m_NPOTScale; } set { m_NPOTScale = value; } }
|
||||
public FilterMode filterMode { get { return m_FilterMode; } set { m_FilterMode = value; } }
|
||||
public int aniso
|
||||
{
|
||||
get { return m_Aniso; }
|
||||
set { m_Aniso = value; }
|
||||
}
|
||||
public bool enablePostProcessor
|
||||
{
|
||||
get { return m_EnablePostProcessor; }
|
||||
set { m_EnablePostProcessor = value; }
|
||||
}
|
||||
|
||||
public string assetPath { get; set; }
|
||||
public bool containsAlpha { get; set; }
|
||||
public bool hdr { get; set; }
|
||||
|
||||
public SecondarySpriteTexture[] secondaryTextures { get { return m_SecondaryTextures;} set { m_SecondaryTextures = value; } }
|
||||
|
||||
void ITextureSettings.FillTextureGenerationSettings(ref TextureGenerationSettings settings)
|
||||
{
|
||||
settings.textureImporterSettings.sRGBTexture = colorTexture;
|
||||
settings.textureImporterSettings.readable = readable;
|
||||
settings.textureImporterSettings.npotScale = npotScale;
|
||||
settings.textureImporterSettings.filterMode = filterMode;
|
||||
settings.textureImporterSettings.aniso = aniso;
|
||||
settings.assetPath = assetPath;
|
||||
settings.enablePostProcessor = enablePostProcessor;
|
||||
settings.sourceTextureInformation.containsAlpha = containsAlpha;
|
||||
settings.sourceTextureInformation.hdr = hdr;
|
||||
settings.secondarySpriteTextures = secondaryTextures;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
internal class TextureSpriteSettings : ITextureSettings
|
||||
{
|
||||
[SerializeField]
|
||||
string m_PackingTag;
|
||||
public string packingTag
|
||||
{
|
||||
get { return m_PackingTag; }
|
||||
set { m_PackingTag = value; }
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
float m_PixelsPerUnit;
|
||||
public float pixelsPerUnit
|
||||
{
|
||||
get { return m_PixelsPerUnit; }
|
||||
set { m_PixelsPerUnit = value; }
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
SpriteMeshType m_MeshType;
|
||||
public SpriteMeshType meshType
|
||||
{
|
||||
get { return m_MeshType; }
|
||||
set { m_MeshType = value; }
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
uint m_ExtrudeEdges;
|
||||
public uint extrudeEdges
|
||||
{
|
||||
get { return m_ExtrudeEdges; }
|
||||
set { m_ExtrudeEdges = value; }
|
||||
}
|
||||
|
||||
public bool qualifyForPacking { get; set; }
|
||||
public SpriteImportData[] spriteSheetData { get; set; }
|
||||
|
||||
public TextureSpriteSettings()
|
||||
{
|
||||
packingTag = "";
|
||||
pixelsPerUnit = 100;
|
||||
meshType = SpriteMeshType.Tight;
|
||||
extrudeEdges = 1;
|
||||
}
|
||||
|
||||
public TextureSpriteSettings(string packingTag, int pixelsPerUnit, SpriteMeshType meshType, uint extrudeEdges, bool qualifyForPacking, SpriteImportData[] spriteSheetData = null)
|
||||
{
|
||||
this.packingTag = packingTag;
|
||||
this.pixelsPerUnit = pixelsPerUnit;
|
||||
this.meshType = meshType;
|
||||
this.extrudeEdges = extrudeEdges;
|
||||
this.qualifyForPacking = qualifyForPacking;
|
||||
this.spriteSheetData = spriteSheetData;
|
||||
}
|
||||
|
||||
void ITextureSettings.FillTextureGenerationSettings(ref TextureGenerationSettings settings)
|
||||
{
|
||||
settings.textureImporterSettings.spritePixelsPerUnit = pixelsPerUnit;
|
||||
settings.textureImporterSettings.spriteMeshType = meshType;
|
||||
settings.textureImporterSettings.spriteExtrude = extrudeEdges;
|
||||
settings.spritePackingTag = packingTag;
|
||||
settings.qualifyForSpritePacking = qualifyForPacking;
|
||||
settings.spriteImportData = spriteSheetData;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
internal class TextureWrapSettings : ITextureSettings
|
||||
{
|
||||
[SerializeField]
|
||||
TextureWrapMode m_WrapMode;
|
||||
[SerializeField]
|
||||
TextureWrapMode m_WrapModeU;
|
||||
[SerializeField]
|
||||
TextureWrapMode m_WrapModeV;
|
||||
[SerializeField]
|
||||
TextureWrapMode m_WrapModeW;
|
||||
|
||||
public TextureWrapSettings()
|
||||
{
|
||||
wrapMode = wrapModeU = wrapModeV = wrapModeW = TextureWrapMode.Repeat;
|
||||
}
|
||||
|
||||
public TextureWrapSettings(TextureWrapMode wrapMpde, TextureWrapMode wrapModeU, TextureWrapMode wrapModeV, TextureWrapMode wrapModeW)
|
||||
{
|
||||
this.wrapMode = wrapMode;
|
||||
this.wrapModeU = wrapModeU;
|
||||
this.wrapModeV = wrapModeV;
|
||||
this.wrapModeW = wrapModeW;
|
||||
}
|
||||
|
||||
public TextureWrapMode wrapMode { get { return m_WrapMode; } set { m_WrapMode = value; } }
|
||||
public TextureWrapMode wrapModeU { get { return m_WrapModeU; } set { m_WrapModeU = value; } }
|
||||
public TextureWrapMode wrapModeV { get { return m_WrapModeV; } set { m_WrapModeV = value; } }
|
||||
public TextureWrapMode wrapModeW { get { return m_WrapModeW; } set { m_WrapModeW = value; } }
|
||||
|
||||
void ITextureSettings.FillTextureGenerationSettings(ref TextureGenerationSettings settings)
|
||||
{
|
||||
settings.textureImporterSettings.wrapMode = wrapMode;
|
||||
settings.textureImporterSettings.wrapModeU = wrapModeU;
|
||||
settings.textureImporterSettings.wrapModeV = wrapModeV;
|
||||
settings.textureImporterSettings.wrapModeW = wrapModeW;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
internal class TextureAlphaSettings : ITextureSettings
|
||||
{
|
||||
[SerializeField]
|
||||
float m_AlphaTolerance;
|
||||
public float alphaTolerance
|
||||
{
|
||||
get { return m_AlphaTolerance; }
|
||||
set { m_AlphaTolerance = value; }
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
TextureImporterAlphaSource m_AlphaSource;
|
||||
public TextureImporterAlphaSource alphaSource
|
||||
{
|
||||
get { return m_AlphaSource; }
|
||||
set { m_AlphaSource = value; }
|
||||
}
|
||||
|
||||
public TextureAlphaSettings()
|
||||
{
|
||||
alphaTolerance = 0.5f;
|
||||
alphaSource = TextureImporterAlphaSource.FromInput;
|
||||
}
|
||||
|
||||
public TextureAlphaSettings(TextureImporterAlphaSource alphaSource, float alphaTolerance)
|
||||
{
|
||||
this.alphaTolerance = alphaTolerance;
|
||||
this.alphaSource = alphaSource;
|
||||
}
|
||||
|
||||
void ITextureSettings.FillTextureGenerationSettings(ref TextureGenerationSettings settings)
|
||||
{
|
||||
settings.textureImporterSettings.alphaIsTransparency = alphaSource != TextureImporterAlphaSource.None;
|
||||
settings.textureImporterSettings.alphaSource = alphaSource;
|
||||
settings.textureImporterSettings.alphaTestReferenceValue = alphaTolerance;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
internal class TextureMipmapSettings : ITextureSettings
|
||||
{
|
||||
[SerializeField]
|
||||
TextureImporterMipFilter m_Filter;
|
||||
public TextureImporterMipFilter filter
|
||||
{
|
||||
get { return m_Filter; }
|
||||
set { m_Filter = value; }
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
bool m_BorderMipmap;
|
||||
public bool borderMipmap
|
||||
{
|
||||
get { return m_BorderMipmap; }
|
||||
set { m_BorderMipmap = value; }
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
bool m_Fadeout;
|
||||
public bool fadeout
|
||||
{
|
||||
get { return m_Fadeout; }
|
||||
set { m_Fadeout = value; }
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
bool m_PreserveCoverage;
|
||||
public bool preserveCoverage
|
||||
{
|
||||
get { return m_PreserveCoverage; }
|
||||
set { m_PreserveCoverage = value; }
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
int m_FadeDistanceStart;
|
||||
public int fadeDistanceStart
|
||||
{
|
||||
get { return m_FadeDistanceStart; }
|
||||
set { m_FadeDistanceStart = value; }
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
int m_FadeDistanceEnd;
|
||||
public int fadeDistanceEnd
|
||||
{
|
||||
get { return m_FadeDistanceEnd; }
|
||||
set { m_FadeDistanceEnd = value; }
|
||||
}
|
||||
|
||||
public TextureMipmapSettings()
|
||||
{
|
||||
filter = TextureImporterMipFilter.BoxFilter;
|
||||
borderMipmap = false;
|
||||
fadeout = false;
|
||||
preserveCoverage = false;
|
||||
fadeDistanceStart = 1;
|
||||
fadeDistanceEnd = 3;
|
||||
}
|
||||
|
||||
public TextureMipmapSettings(TextureImporterMipFilter filter, bool borderMipmap, bool fadeout, bool preserveCoverage, int fadeDistanceStart, int fadeDistanceEnd)
|
||||
{
|
||||
this.filter = filter;
|
||||
this.borderMipmap = borderMipmap;
|
||||
this.fadeout = fadeout;
|
||||
this.preserveCoverage = preserveCoverage;
|
||||
this.fadeDistanceStart = fadeDistanceStart;
|
||||
this.fadeDistanceEnd = fadeDistanceEnd;
|
||||
}
|
||||
|
||||
void ITextureSettings.FillTextureGenerationSettings(ref TextureGenerationSettings settings)
|
||||
{
|
||||
settings.textureImporterSettings.mipmapEnabled = true;
|
||||
settings.textureImporterSettings.mipmapFilter = filter;
|
||||
settings.textureImporterSettings.borderMipmap = borderMipmap;
|
||||
settings.textureImporterSettings.fadeOut = fadeout;
|
||||
settings.textureImporterSettings.mipmapFadeDistanceStart = fadeDistanceStart;
|
||||
settings.textureImporterSettings.mipmapFadeDistanceEnd = fadeDistanceEnd;
|
||||
settings.textureImporterSettings.mipMapsPreserveCoverage = preserveCoverage;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
internal class TextureNormalSettings : ITextureSettings
|
||||
{
|
||||
[SerializeField]
|
||||
TextureImporterNormalFilter m_Filter;
|
||||
public TextureImporterNormalFilter filter
|
||||
{
|
||||
get { return m_Filter; }
|
||||
set { m_Filter = value; }
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
bool m_GenerateFromGrayScale;
|
||||
public bool generateFromGrayScale
|
||||
{
|
||||
get { return m_GenerateFromGrayScale; }
|
||||
set { m_GenerateFromGrayScale = value; }
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
float m_Bumpiness;
|
||||
public float bumpiness
|
||||
{
|
||||
get { return m_Bumpiness; }
|
||||
set { m_Bumpiness = value; }
|
||||
}
|
||||
|
||||
public TextureNormalSettings()
|
||||
{
|
||||
filter = TextureImporterNormalFilter.Standard;
|
||||
generateFromGrayScale = false;
|
||||
bumpiness = 0.25f;
|
||||
}
|
||||
|
||||
public TextureNormalSettings(TextureImporterNormalFilter filter, bool generateFromGrayScale, float bumpiness)
|
||||
{
|
||||
this.filter = filter;
|
||||
this.generateFromGrayScale = generateFromGrayScale;
|
||||
this.bumpiness = bumpiness;
|
||||
}
|
||||
|
||||
void ITextureSettings.FillTextureGenerationSettings(ref TextureGenerationSettings settings)
|
||||
{
|
||||
settings.textureImporterSettings.normalMapFilter = filter;
|
||||
settings.textureImporterSettings.convertToNormalMap = generateFromGrayScale;
|
||||
settings.textureImporterSettings.heightmapScale = bumpiness;
|
||||
}
|
||||
}
|
||||
|
||||
// If this is provided, textureType will be cubemap
|
||||
[Serializable]
|
||||
internal class TextureCubemapSettings : ITextureSettings
|
||||
{
|
||||
[SerializeField]
|
||||
TextureImporterCubemapConvolution m_Convolution;
|
||||
public TextureImporterCubemapConvolution convolution
|
||||
{
|
||||
get { return m_Convolution; }
|
||||
set { m_Convolution = value; }
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
TextureImporterGenerateCubemap m_Mode;
|
||||
public TextureImporterGenerateCubemap mode
|
||||
{
|
||||
get { return m_Mode; }
|
||||
set { m_Mode = value; }
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
bool m_Seamless;
|
||||
public bool seamless
|
||||
{
|
||||
get { return m_Seamless; }
|
||||
set { m_Seamless = value; }
|
||||
}
|
||||
public TextureCubemapSettings()
|
||||
{
|
||||
convolution = TextureImporterCubemapConvolution.None;
|
||||
mode = TextureImporterGenerateCubemap.AutoCubemap;
|
||||
seamless = false;
|
||||
}
|
||||
|
||||
public TextureCubemapSettings(TextureImporterCubemapConvolution convolution, TextureImporterGenerateCubemap mode, bool seamless)
|
||||
{
|
||||
this.convolution = convolution;
|
||||
this.mode = mode;
|
||||
this.seamless = seamless;
|
||||
}
|
||||
|
||||
void ITextureSettings.FillTextureGenerationSettings(ref TextureGenerationSettings settings)
|
||||
{
|
||||
settings.textureImporterSettings.textureShape = TextureImporterShape.TextureCube;
|
||||
settings.textureImporterSettings.cubemapConvolution = convolution;
|
||||
settings.textureImporterSettings.generateCubemap = mode;
|
||||
settings.textureImporterSettings.seamlessCubemap = seamless;
|
||||
}
|
||||
}
|
||||
|
||||
internal static class TextureGeneratorHelper
|
||||
{
|
||||
public static TextureGenerationOutput GenerateTextureSprite(NativeArray<Color32> buffer, int bufferWidth, int bufferHeight, TextureSettings settings, TextureImporterPlatformSettings platformSettings,
|
||||
TextureSpriteSettings spriteSettings, TextureAlphaSettings alphaSettings = null, TextureMipmapSettings mipmapSettings = null, TextureWrapSettings wrapSettings = null)
|
||||
{
|
||||
if (alphaSettings == null)
|
||||
alphaSettings = new TextureAlphaSettings(TextureImporterAlphaSource.FromInput, 0.5f);
|
||||
if (wrapSettings == null)
|
||||
wrapSettings = new TextureWrapSettings(TextureWrapMode.Clamp, TextureWrapMode.Clamp, TextureWrapMode.Clamp, TextureWrapMode.Clamp);
|
||||
|
||||
return GenerateTexture(buffer, bufferWidth, bufferHeight, TextureImporterType.Sprite, platformSettings, settings, spriteSettings, alphaSettings, mipmapSettings, wrapSettings);
|
||||
}
|
||||
|
||||
public static TextureGenerationOutput GenerateLightmap(NativeArray<Color32> buffer, int bufferWidth, int bufferHeight, TextureSettings settings, TextureImporterPlatformSettings platformSettings,
|
||||
TextureMipmapSettings mipmapSettings = null, TextureWrapSettings wrapSettings = null)
|
||||
{
|
||||
settings.colorTexture = true;
|
||||
return GenerateTexture(buffer, bufferWidth, bufferHeight, TextureImporterType.Lightmap, platformSettings, settings, mipmapSettings, wrapSettings);
|
||||
}
|
||||
|
||||
public static TextureGenerationOutput GenerateCookie(NativeArray<Color32> buffer, int bufferWidth, int bufferHeight, TextureSettings settings, TextureImporterPlatformSettings platformSettings,
|
||||
TextureAlphaSettings alphaSettings = null, TextureMipmapSettings mipmapSettings = null, TextureCubemapSettings cubemapSettings = null, TextureWrapSettings wrapSettings = null)
|
||||
{
|
||||
return GenerateTexture(buffer, bufferWidth, bufferHeight, TextureImporterType.Cookie, platformSettings, settings, alphaSettings, mipmapSettings, cubemapSettings, wrapSettings);
|
||||
}
|
||||
|
||||
public static TextureGenerationOutput GenerateNormalMap(NativeArray<Color32> buffer, int bufferWidth, int bufferHeight, TextureSettings settings, TextureImporterPlatformSettings platformSettings,
|
||||
TextureNormalSettings normalSettings, TextureMipmapSettings mipmapSettings = null, TextureCubemapSettings cubemapSettings = null, TextureWrapSettings wrapSettings = null)
|
||||
{
|
||||
settings.colorTexture = false;
|
||||
return GenerateTexture(buffer, bufferWidth, bufferHeight, TextureImporterType.NormalMap, platformSettings, settings, normalSettings, mipmapSettings, cubemapSettings, wrapSettings);
|
||||
}
|
||||
|
||||
public static TextureGenerationOutput GenerateTextureGUI(NativeArray<Color32> buffer, int bufferWidth, int bufferHeight, TextureSettings settings, TextureImporterPlatformSettings platformSettings,
|
||||
TextureAlphaSettings alphaSettings = null, TextureMipmapSettings mipmapSettings = null, TextureWrapSettings wrapSettings = null)
|
||||
{
|
||||
settings.colorTexture = false;
|
||||
if (wrapSettings == null)
|
||||
wrapSettings = new TextureWrapSettings(TextureWrapMode.Clamp, TextureWrapMode.Clamp, TextureWrapMode.Clamp, TextureWrapMode.Clamp);
|
||||
return GenerateTexture(buffer, bufferWidth, bufferHeight, TextureImporterType.GUI, platformSettings, settings, alphaSettings, mipmapSettings, wrapSettings);
|
||||
}
|
||||
|
||||
public static TextureGenerationOutput GenerateTextureSingleChannel(NativeArray<Color32> buffer, int bufferWidth, int bufferHeight, TextureSettings settings, TextureImporterPlatformSettings platformSettings,
|
||||
TextureAlphaSettings alphaSettings = null, TextureMipmapSettings mipmapSettings = null, TextureCubemapSettings cubemapSettings = null, TextureWrapSettings wrapSettings = null)
|
||||
{
|
||||
settings.colorTexture = false;
|
||||
return GenerateTexture(buffer, bufferWidth, bufferHeight, TextureImporterType.SingleChannel, platformSettings, settings, alphaSettings, mipmapSettings, cubemapSettings, wrapSettings);
|
||||
}
|
||||
|
||||
public static TextureGenerationOutput GenerateTextureCursor(NativeArray<Color32> buffer, int bufferWidth, int bufferHeight, TextureSettings settings, TextureImporterPlatformSettings platformSettings,
|
||||
TextureAlphaSettings alphaSettings = null, TextureMipmapSettings mipmapSettings = null, TextureWrapSettings wrapSettings = null)
|
||||
{
|
||||
if (alphaSettings == null)
|
||||
alphaSettings = new TextureAlphaSettings(TextureImporterAlphaSource.FromInput, 0.5f);
|
||||
if (wrapSettings == null)
|
||||
wrapSettings = new TextureWrapSettings(TextureWrapMode.Clamp, TextureWrapMode.Clamp, TextureWrapMode.Clamp, TextureWrapMode.Clamp);
|
||||
|
||||
return GenerateTexture(buffer, bufferWidth, bufferHeight, TextureImporterType.Cursor, platformSettings, settings, alphaSettings, mipmapSettings, wrapSettings);
|
||||
}
|
||||
|
||||
public static TextureGenerationOutput GenerateTextureDefault(NativeArray<Color32> buffer, int bufferWidth, int bufferHeight, TextureSettings settings, TextureImporterPlatformSettings platformSettings,
|
||||
TextureAlphaSettings alphaSettings = null, TextureMipmapSettings mipmapSettings = null, TextureCubemapSettings cubemapSettings = null, TextureWrapSettings wrapSettings = null)
|
||||
{
|
||||
if (mipmapSettings == null)
|
||||
mipmapSettings = new TextureMipmapSettings(TextureImporterMipFilter.BoxFilter, false, false, false, 1, 3);
|
||||
|
||||
return GenerateTexture(buffer, bufferWidth, bufferHeight, TextureImporterType.Default, platformSettings, settings, alphaSettings, mipmapSettings, cubemapSettings, wrapSettings);
|
||||
}
|
||||
|
||||
static TextureGenerationOutput GenerateTexture(NativeArray<Color32> imageBuffer, int imageBufferWidth, int imageBufferHeight, TextureImporterType type, TextureImporterPlatformSettings platformSettings, params ITextureSettings[] otherSettings)
|
||||
{
|
||||
var textureGenerationSettings = new TextureGenerationSettings();
|
||||
textureGenerationSettings.platformSettings = platformSettings;
|
||||
|
||||
textureGenerationSettings.sourceTextureInformation = new SourceTextureInformation();
|
||||
textureGenerationSettings.sourceTextureInformation.height = imageBufferHeight;
|
||||
textureGenerationSettings.sourceTextureInformation.width = imageBufferWidth;
|
||||
|
||||
textureGenerationSettings.textureImporterSettings = new TextureImporterSettings();
|
||||
textureGenerationSettings.textureImporterSettings.textureType = type;
|
||||
textureGenerationSettings.textureImporterSettings.textureShape = TextureImporterShape.Texture2D;
|
||||
|
||||
textureGenerationSettings.textureImporterSettings.alphaIsTransparency = false;
|
||||
textureGenerationSettings.textureImporterSettings.convertToNormalMap = false;
|
||||
textureGenerationSettings.textureImporterSettings.mipmapEnabled = false;
|
||||
textureGenerationSettings.textureImporterSettings.sRGBTexture = true;
|
||||
textureGenerationSettings.textureImporterSettings.readable = false;
|
||||
textureGenerationSettings.textureImporterSettings.fadeOut = false;
|
||||
textureGenerationSettings.textureImporterSettings.wrapMode = TextureWrapMode.Repeat;
|
||||
textureGenerationSettings.textureImporterSettings.wrapModeU = TextureWrapMode.Repeat;
|
||||
textureGenerationSettings.textureImporterSettings.wrapModeV = TextureWrapMode.Repeat;
|
||||
textureGenerationSettings.textureImporterSettings.wrapModeW = TextureWrapMode.Repeat;
|
||||
|
||||
foreach (var otherSetting in otherSettings)
|
||||
{
|
||||
if (otherSetting != null)
|
||||
otherSetting.FillTextureGenerationSettings(ref textureGenerationSettings);
|
||||
}
|
||||
return TextureGenerator.GenerateTexture(textureGenerationSettings, imageBuffer);
|
||||
}
|
||||
|
||||
static public TextureSettings ExtractTextureSettings(this TextureImporterSettings tis)
|
||||
{
|
||||
var ts = new TextureSettings();
|
||||
ts.colorTexture = tis.sRGBTexture;
|
||||
ts.readable = tis.readable;
|
||||
ts.npotScale = tis.npotScale;
|
||||
ts.filterMode = tis.filterMode;
|
||||
ts.aniso = tis.aniso;
|
||||
return ts;
|
||||
}
|
||||
|
||||
static public TextureSpriteSettings ExtractTextureSpriteSettings(this TextureImporterSettings tis)
|
||||
{
|
||||
var ts = new TextureSpriteSettings();
|
||||
ts.pixelsPerUnit = tis.spritePixelsPerUnit;
|
||||
ts.meshType = tis.spriteMeshType;
|
||||
ts.extrudeEdges = tis.spriteExtrude;
|
||||
return ts;
|
||||
}
|
||||
|
||||
static public TextureWrapSettings ExtractTextureWrapSettings(this TextureImporterSettings tis)
|
||||
{
|
||||
var ts = new TextureWrapSettings();
|
||||
ts.wrapMode = tis.wrapMode;
|
||||
ts.wrapModeU = tis.wrapModeU;
|
||||
ts.wrapModeV = tis.wrapModeV;
|
||||
ts.wrapModeW = tis.wrapModeW;
|
||||
return ts;
|
||||
}
|
||||
|
||||
static public TextureAlphaSettings ExtractTextureAlphaSettings(this TextureImporterSettings settings)
|
||||
{
|
||||
if (settings.alphaIsTransparency == false)
|
||||
return null;
|
||||
|
||||
var ts = new TextureAlphaSettings();
|
||||
ts.alphaSource = settings.alphaSource;
|
||||
ts.alphaTolerance = settings.alphaTestReferenceValue;
|
||||
return ts;
|
||||
}
|
||||
|
||||
static public TextureMipmapSettings ExtractTextureMipmapSettings(this TextureImporterSettings settings)
|
||||
{
|
||||
if (!settings.mipmapEnabled)
|
||||
return null;
|
||||
|
||||
var ts = new TextureMipmapSettings();
|
||||
ts.filter = settings.mipmapFilter;
|
||||
ts.borderMipmap = settings.borderMipmap;
|
||||
ts.fadeout = settings.fadeOut;
|
||||
ts.fadeDistanceStart = settings.mipmapFadeDistanceStart;
|
||||
ts.fadeDistanceEnd = settings.mipmapFadeDistanceEnd;
|
||||
ts.preserveCoverage = settings.mipMapsPreserveCoverage;
|
||||
return ts;
|
||||
}
|
||||
|
||||
static public TextureNormalSettings ExtractTextureNormalSettings(this TextureImporterSettings settings)
|
||||
{
|
||||
var ts = new TextureNormalSettings();
|
||||
ts.filter = settings.normalMapFilter;
|
||||
ts.generateFromGrayScale = settings.convertToNormalMap;
|
||||
ts.bumpiness = settings.heightmapScale;
|
||||
return ts;
|
||||
}
|
||||
|
||||
static public TextureCubemapSettings ExtractTextureCubemapSettings(this TextureImporterSettings settings)
|
||||
{
|
||||
if (settings.textureShape != TextureImporterShape.TextureCube)
|
||||
return null;
|
||||
var ts = new TextureCubemapSettings();
|
||||
ts.convolution = settings.cubemapConvolution;
|
||||
ts.mode = settings.generateCubemap;
|
||||
ts.seamless = settings.seamlessCubemap;
|
||||
return ts;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f4f814197752ea84db033f3822b113b2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"name": "Unity.2D.Common.Editor",
|
||||
"references": [
|
||||
"Unity.2D.Common.Runtime",
|
||||
"Unity.2D.Sprite.Editor"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": true,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": []
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bd2461be96e5f744bbe6bdbc5276eb61
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue