This commit is contained in:
2021-06-13 10:28:03 +02:00
parent eb70603c85
commit df2d24cbd3
7487 changed files with 943244 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
using UnityEngine;
namespace UnityEditor.U2D.Sprites
{
internal interface IAssetDatabase
{
string GetAssetPath(Object o);
AssetImporter GetAssetImporterFromPath(string path);
}
internal class AssetDatabaseSystem : IAssetDatabase
{
public string GetAssetPath(Object o)
{
return AssetDatabase.GetAssetPath(o);
}
public AssetImporter GetAssetImporterFromPath(string path)
{
return AssetImporter.GetAtPath(path);
}
}
}

View File

@@ -0,0 +1,99 @@
using UnityEngine;
using UnityEvent = UnityEngine.Event;
namespace UnityEditor.U2D.Sprites
{
internal interface IEvent
{
EventType type { get; }
string commandName { get; }
bool control { get; }
bool alt { get; }
bool shift { get; }
KeyCode keyCode { get; }
Vector2 mousePosition { get; }
int button { get; }
EventModifiers modifiers { get; }
EventType GetTypeForControl(int id);
void Use();
}
internal class Event : IEvent
{
UnityEvent m_Event;
public Event()
{
m_Event = UnityEvent.current;
}
public EventType type
{
get { return m_Event.type; }
}
public string commandName
{
get { return m_Event.commandName; }
}
public bool control
{
get { return m_Event.control; }
}
public bool alt
{
get { return m_Event.alt; }
}
public bool shift
{
get { return m_Event.shift; }
}
public KeyCode keyCode
{
get { return m_Event.keyCode; }
}
public Vector2 mousePosition
{
get { return m_Event.mousePosition; }
}
public int button
{
get { return m_Event.button; }
}
public void Use()
{
m_Event.Use();
}
public EventModifiers modifiers
{
get { return m_Event.modifiers; }
}
public EventType GetTypeForControl(int id)
{
return m_Event.GetTypeForControl(id);
}
}
internal interface IEventSystem
{
IEvent current { get; }
}
internal class EventSystem : IEventSystem
{
public IEvent current
{
get { return new Event(); }
}
}
}

View File

@@ -0,0 +1,64 @@
namespace UnityEngine.U2D.Sprites
{
internal interface IGL
{
void PushMatrix();
void PopMatrix();
void MultMatrix(Matrix4x4 m);
void Begin(int mode);
void End();
void Color(Color c);
void Vertex(Vector3 v);
}
internal class GLSystem : IGL
{
static IGL m_GLSystem;
internal static void SetSystem(IGL system)
{
m_GLSystem = system;
}
internal static IGL GetSystem()
{
if (m_GLSystem == null)
m_GLSystem = new GLSystem();
return m_GLSystem;
}
public void PushMatrix()
{
GL.PushMatrix();
}
public void PopMatrix()
{
GL.PopMatrix();
}
public void MultMatrix(Matrix4x4 m)
{
GL.MultMatrix(m);
}
public void Begin(int mode)
{
GL.Begin(mode);
}
public void End()
{
GL.End();
}
public void Color(Color c)
{
GL.Color(c);
}
public void Vertex(Vector3 v)
{
GL.Vertex(v);
}
}
}

View File

@@ -0,0 +1,49 @@
using UnityEngine;
namespace UnityEditor.U2D.Sprites
{
internal interface IGUIUtility
{
int GetPermanentControlID();
int hotControl { get; set; }
int keyboardControl { get; set; }
int GetControlID(int hint, FocusType focus);
}
internal class GUIUtilitySystem : IGUIUtility
{
public int GetPermanentControlID()
{
return GUIUtility.GetPermanentControlID();
}
public int hotControl
{
get
{
return GUIUtility.hotControl;
}
set
{
GUIUtility.hotControl = value;
}
}
public int keyboardControl
{
get
{
return GUIUtility.keyboardControl;
}
set
{
GUIUtility.keyboardControl = value;
}
}
public int GetControlID(int hint, FocusType focus)
{
return GUIUtility.GetControlID(hint, focus);
}
}
}

View File

@@ -0,0 +1,74 @@
using UnityEngine;
using UnityHandles = UnityEditor.Handles;
using UnityTexture2D = UnityEngine.Texture2D;
namespace UnityEditor.U2D.Sprites
{
internal interface IHandles
{
Color color { get; set; }
Matrix4x4 matrix { get; set; }
Vector3[] MakeBezierPoints(Vector3 startPosition, Vector3 endPosition, Vector3 startTangent, Vector3 endTangent, int division);
void DrawAAPolyLine(ITexture2D lineTex, float width, params Vector3[] points);
void DrawAAPolyLine(ITexture2D lineTex, params Vector3[] points);
void DrawLine(Vector3 p1, Vector3 p2);
void SetDiscSectionPoints(Vector3[] dest, Vector3 center, Vector3 normal, Vector3 from, float angle, float radius);
}
internal class HandlesSystem : IHandles
{
static IHandles m_System;
static public void SetSystem(IHandles system)
{
m_System = system;
}
static public IHandles GetSystem()
{
if (m_System == null)
m_System = new HandlesSystem();
return m_System;
}
public Color color
{
get { return UnityHandles.color; }
set { UnityHandles.color = value; }
}
public Matrix4x4 matrix
{
get { return UnityHandles.matrix; }
set { UnityHandles.matrix = value; }
}
public Vector3[] MakeBezierPoints(Vector3 startPosition, Vector3 endPosition, Vector3 startTangent, Vector3 endTangent, int division)
{
return UnityHandles.MakeBezierPoints(startPosition, endPosition, startTangent, endTangent, division);
}
public void DrawAAPolyLine(ITexture2D lineTex, float width, params Vector3[] points)
{
UnityHandles.DrawAAPolyLine((UnityTexture2D)lineTex, width, points);
}
public void DrawAAPolyLine(ITexture2D lineTex, params Vector3[] points)
{
UnityHandles.DrawAAPolyLine((UnityTexture2D)lineTex, points);
}
public void DrawLine(Vector3 p1, Vector3 p2)
{
UnityHandles.DrawLine(p1, p2);
}
public void SetDiscSectionPoints(Vector3[] dest, Vector3 center, Vector3 normal, Vector3 from, float angle, float radius)
{
UnityHandles.SetDiscSectionPoints(dest, center, normal, from, angle, radius);
}
}
}

View File

@@ -0,0 +1,158 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.U2D;
using UnityObject = UnityEngine.Object;
namespace UnityEditor.U2D.Sprites
{
/// <summary>An interface that allows Sprite Editor Window to edit Sprite data for user custom importer.</summary>
/// <remarks>Implement this interface for [[ScriptedImporter]] to leverage on Sprite Editor Window to edit Sprite data.</remarks>
public interface ISpriteEditorDataProvider
{
/// <summary>SpriteImportMode to indicate how Sprite data will be imported.</summary>
SpriteImportMode spriteImportMode { get; }
/// <summary>The number of pixels in the sprite that correspond to one unit in world space.</summary>
float pixelsPerUnit { get; }
/// <summary>The object that this data provider is acquiring its data from.</summary>
UnityObject targetObject { get; }
/// <summary>Returns an array of SpriteRect representing Sprite data the provider has.</summary>
/// <returns>Array of SpriteRect.</returns>
SpriteRect[] GetSpriteRects();
/// <summary>Sets the data provider's current SpriteRect.</summary>
/// <param name="spriteRects">Updated array of SpriteRect.</param>
void SetSpriteRects(SpriteRect[] spriteRects);
/// <summary>Applying any changed data.</summary>
void Apply();
/// <summary>Allows the data provider to initialize any data if needed.</summary>
void InitSpriteEditorDataProvider();
/// <summary>Gets other data providers that might be supported by ISpriteEditorDataProvider.targetObject.</summary>
/// <typeparam name="T">The data provider type to acquire.</typeparam>
/// <returns>Data provider type.</returns>
T GetDataProvider<T>() where T : class;
/// <summary>Queries if ISpriteEditorDataProvider.targetObject supports the data provider type.</summary>
/// <param name="type">Data provider type.</param>
/// <returns>True if supports, false otherwise.</returns>
bool HasDataProvider(Type type);
}
/// <summary>
/// Data Provider interface that deals with Sprite Bone data.
/// </summary>
public interface ISpriteBoneDataProvider
{
/// <summary>
/// Returns the list of SpriteBone for the corresponding Sprite ID.
/// </summary>
/// <param name="guid">Sprite ID.</param>
/// <returns>The list of SpriteBone associated with the Sprite</returns>
List<SpriteBone> GetBones(GUID guid);
/// <summary>Sets a new set of SpriteBone for the corresponding Sprite ID.</summary>
/// <param name = "guid" > Sprite ID.</param>
/// <param name = "bones" > List of SpriteBone to associate with the Sprite.</param>
void SetBones(GUID guid, List<SpriteBone> bones);
}
/// <summary>Data provider that provides the outline data for SpriteRect.</summary>
/// <remarks>The outline data is used to tessellate a Sprite's mesh.</remarks>
public interface ISpriteOutlineDataProvider
{
/// <summary>Given a GUID, returns the outline data used for tessellating the SpriteRect.</summary>
/// <param name="guid">GUID of the SpriteRect.</param>
/// <returns>Outline data for theSpriteRect.</returns>
List<Vector2[]> GetOutlines(GUID guid);
/// <summary>Given a GUID, sets the outline data used for tessellating the SpriteRect.</summary>
/// <param name="guid">GUID of the SpriteRect.</param>
/// <param name="data">Outline data for theSpriteRect.</param>
void SetOutlines(GUID guid, List<Vector2[]> data);
/// <summary>Given a GUID, returns the tessellation detail.Tessellation value should be between 0 to 1.</summary>
/// <param name = "guid" > GUID of the SpriteRect.</param>
/// <returns>The tessellation value.</returns>
float GetTessellationDetail(GUID guid);
/// <summary>Given a GUID, sets the tessellation detail.Tessellation value should be between 0 to 1.</summary>
/// <param name = "guid" > GUID of the SpriteRect.</param>
/// <param name="value">The tessellation value.</param>
void SetTessellationDetail(GUID guid, float value);
}
/// <summary>Data provider that provides the Physics outline data for SpriteRect.</summary>
/// <remarks>Uses the outline data to generate the Sprite's Physics shape for Polygon Collider 2D.</remarks>
public interface ISpritePhysicsOutlineDataProvider
{
/// <summary>Given a GUID, returns the Physics outline data used for the SpriteRect.</summary>
/// <param name="guid">GUID of the SpriteRect.</param>
/// <returns>Physics outline data for the SpriteRect.</returns>
List<Vector2[]> GetOutlines(GUID guid);
/// <summary>Given a GUID, sets the Physics outline data used for the SpriteRect.</summary>
/// <param name="guid">GUID of the SpriteRect.</param>
/// <param name="data">Physics outline data for the SpriteRect.</param>
void SetOutlines(GUID guid, List<Vector2[]> data);
/// <summary>Given a GUID, returns the tessellation detail.Tessellation value should be between 0 to 1.</summary>
/// <param name = "guid" > GUID of the SpriteRect.</param>
/// <returns>The tessellation value.</returns>
float GetTessellationDetail(GUID guid);
/// <summary>Given a GUID, sets the tessellation detail.Tessellation value should be between 0 to 1.</summary>
/// <param name = "guid" > GUID of the SpriteRect.</param>
/// <param name="value">The tessellation value.</param>
void SetTessellationDetail(GUID guid, float value);
}
/// <summary>Data provider that provides texture data needed for Sprite Editor Window.</summary>
public interface ITextureDataProvider
{
/// <summary>Texture2D representation of the data provider.</summary>
Texture2D texture { get; }
/// <summary>Texture2D that represents the preview for ITextureDataProvider.texture.</summary>
Texture2D previewTexture { get; }
/// <summary>The actual width and height of the texture data.</summary>
/// <param name="width">Out value for width.</param>
/// <param name="height">Out value for height.</param>
void GetTextureActualWidthAndHeight(out int width , out int height);
/// <summary>Readable version of ITextureProvider.texture.</summary>
/// <returns>Texture2D that is readable.</returns>
Texture2D GetReadableTexture2D();
}
/// <summary>Data provider that provides secoondary texture data needed for Sprite Editor Window.</summary>
public interface ISecondaryTextureDataProvider
{
/// <summary>
/// Get set method for an array of SecondarySpriteTexture in the Data Provider
/// </summary>
SecondarySpriteTexture[] textures { get; set; }
}
/// <summary>A structure that contains meta data about vertices in a Sprite.</summary>
[Serializable]
public struct Vertex2DMetaData
{
/// <summary>The position of the vertex.</summary>
public Vector2 position;
/// <summary>The BoneWeight of the vertex.</summary>
public BoneWeight boneWeight;
}
/// <summary>Data Provider interface that deals with Sprite mesh data.</summary>
public interface ISpriteMeshDataProvider
{
/// <summary>Returns the list of vertex datas for the corresponding Sprite ID.</summary>
/// <param name = "guid" > Sprite ID.</param>
Vertex2DMetaData[] GetVertices(GUID guid);
/// <summary>Sets a new list of vertices for the corresponding Sprite ID.</summary>
/// <param name = "guid" > Sprite ID.</param>
void SetVertices(GUID guid, Vertex2DMetaData[] vertices);
/// <summary>Returns the list of mesh index for the corresponding Sprite ID.</summary>
/// <param name = "guid" > Sprite ID.</param>
int[] GetIndices(GUID guid);
/// <summary>Sets a new list of indices for the corresponding Sprite ID.</summary>
/// <param name = "guid" > Sprite ID.</param>
void SetIndices(GUID guid, int[] indices);
/// <summary>Returns the list of mesh edges for the corresponding Sprite ID.</summary>
/// <param name = "guid" > Sprite ID.</param>
Vector2Int[] GetEdges(GUID guid);
/// <summary>Sets a new list of edges for the corresponding Sprite ID.</summary>
/// <param name = "guid" > Sprite ID.</param>
void SetEdges(GUID guid, Vector2Int[] edges);
}
}

View File

@@ -0,0 +1,141 @@
using UnityEngine;
using UnityTexture2D = UnityEngine.Texture2D;
using System;
namespace UnityEditor.U2D.Sprites
{
internal abstract class ITexture2D
{
public abstract int width { get; }
public abstract int height { get; }
public abstract TextureFormat format { get; }
public abstract Color32[] GetPixels32();
public abstract FilterMode filterMode { get; set; }
public abstract string name { get; }
public abstract void SetPixels(Color[] c);
public abstract void Apply();
public abstract float mipMapBias { get; }
public static bool operator==(ITexture2D t1, ITexture2D t2)
{
if (object.ReferenceEquals(t1, null))
{
return object.ReferenceEquals(t2, null) || t2 == null;
}
return t1.Equals(t2);
}
public static bool operator!=(ITexture2D t1, ITexture2D t2)
{
if (object.ReferenceEquals(t1, null))
{
return !object.ReferenceEquals(t2, null) && t2 != null;
}
return !t1.Equals(t2);
}
public override bool Equals(object other)
{
throw new NotImplementedException();
}
public override int GetHashCode()
{
throw new NotImplementedException();
}
public static implicit operator UnityEngine.Object(ITexture2D t)
{
return object.ReferenceEquals(t, null) ? null : t.ToUnityObject();
}
public static implicit operator UnityEngine.Texture2D(ITexture2D t)
{
return object.ReferenceEquals(t, null) ? null : t.ToUnityTexture();
}
protected abstract UnityEngine.Object ToUnityObject();
protected abstract UnityEngine.Texture2D ToUnityTexture();
}
internal class Texture2DWrapper : ITexture2D
{
UnityTexture2D m_Texture;
public Texture2DWrapper(UnityTexture2D texture)
{
m_Texture = texture;
}
public override int width
{
get { return m_Texture.width; }
}
public override int height
{
get { return m_Texture.height; }
}
public override TextureFormat format
{
get { return m_Texture.format; }
}
public override Color32[] GetPixels32()
{
return m_Texture.GetPixels32();
}
public override FilterMode filterMode
{
get { return m_Texture.filterMode; }
set { m_Texture.filterMode = value; }
}
public override float mipMapBias
{
get { return m_Texture.mipMapBias; }
}
public override string name
{
get { return m_Texture.name; }
}
public override bool Equals(object other)
{
Texture2DWrapper t = other as Texture2DWrapper;
if (object.ReferenceEquals(t, null))
return m_Texture == null;
return m_Texture == t.m_Texture;
}
public override int GetHashCode()
{
return m_Texture.GetHashCode();
}
public override void SetPixels(Color[] c)
{
m_Texture.SetPixels(c);
}
public override void Apply()
{
m_Texture.Apply();
}
protected override UnityEngine.Object ToUnityObject()
{
return m_Texture;
}
protected override UnityEngine.Texture2D ToUnityTexture()
{
return m_Texture;
}
}
}

View File

@@ -0,0 +1,41 @@
using UnityEngine;
namespace UnityEditor.U2D.Sprites
{
internal interface IUndoSystem
{
void RegisterUndoCallback(Undo.UndoRedoCallback undoCallback);
void UnregisterUndoCallback(Undo.UndoRedoCallback undoCallback);
void RegisterCompleteObjectUndo(ScriptableObject obj, string undoText);
void ClearUndo(ScriptableObject obj);
}
internal class UndoSystem : IUndoSystem
{
public void RegisterUndoCallback(Undo.UndoRedoCallback undoCallback)
{
Undo.undoRedoPerformed += undoCallback;
}
public void UnregisterUndoCallback(Undo.UndoRedoCallback undoCallback)
{
Undo.undoRedoPerformed -= undoCallback;
}
public void RegisterCompleteObjectUndo(ScriptableObject so, string undoText)
{
if (so != null)
{
Undo.RegisterCompleteObjectUndo(so, undoText);
}
}
public void ClearUndo(ScriptableObject so)
{
if (so != null)
{
Undo.ClearUndo(so);
}
}
}
}