summaryrefslogtreecommitdiff
path: root/Runtime/Export/SpritesBindings.txt
blob: 3f9dc97ca9053f47d14d5a4245aff9b69fd4d9a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
C++RAW
#include "UnityPrefix.h"
#include "Configuration/UnityConfigure.h"
#include "Runtime/Scripting/ScriptingExportUtility.h"
#include "Runtime/Scripting/Scripting.h"
#if ENABLE_SPRITES
#include "Runtime/Mono/MonoBehaviour.h"
#include "Runtime/Filters/Mesh/SpriteRenderer.h"
#include "Runtime/Graphics/SpriteFrame.h"
#include "Runtime/Graphics/Texture2D.h"
#include "Runtime/Scripting/ScriptingExportUtility.h"
#endif //ENABLE_SPRITES

CSRAW
using UnityEngine;
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Collections;

#if ENABLE_SPRITES
namespace UnityEngine
{
CSRAW
	ENUM public SpriteAlignment
		Center = 0,
		TopLeft = 1,
		TopCenter = 2,
		TopRight = 3,
		LeftCenter = 4,
		RightCenter = 5,
		BottomLeft = 6,
		BottomCenter = 7,
		BottomRight = 8,
		Custom = 9,
	END

CONDITIONAL ENABLE_SPRITES
ENUM SpritePackingMode
	Tight = 0,
	Rectangle
END

CONDITIONAL ENABLE_SPRITES
ENUM SpritePackingRotation
	None = 0,
	// Reserved
	Any = 15
END

CONDITIONAL ENABLE_SPRITES
ENUM SpriteMeshType
	FullRect = 0,
	Tight = 1
END

CONDITIONAL ENABLE_SPRITES
/// Describes one sprite frame.
CLASS Sprite : Object

	CUSTOM public static Sprite Create(Texture2D texture, Rect rect, Vector2 pivot, float pixelsToUnits = 100.0f, uint extrude = 0, SpriteMeshType meshType = SpriteMeshType.Tight)
	{
		if (texture.IsNull())
			return NULL;
	
		Sprite* sprite = CreateObjectFromCode<Sprite>();
		sprite->Initialize(texture, rect, pivot, pixelsToUnits, extrude, meshType);
		return Scripting::ScriptingWrapperFor(sprite);
	}

	CUSTOM_PROP Bounds bounds
	{
		return self->GetBounds();
	}

	// Sprite definition rectangle on source texture (in texels).
	CUSTOM_PROP Rect rect
	{
		return self->GetRect();
	}

	CUSTOM_PROP Texture2D texture
	{
		return Scripting::ScriptingWrapperFor(self->GetRenderDataForPlayMode().texture);
	}

	// Sprite rectangle on texture (in texels).
	CUSTOM_PROP Rect textureRect
	{
		const SpriteRenderData& rd = self->GetRenderDataForPlayMode(); // RenderData must match <texture> accessor's behavior.
		if (rd.settings.packed && rd.settings.packingMode != kSPMRectangle)
			Scripting::RaiseMonoException("Sprite is not rectangle-packed. TextureRect is invalid.");
		return rd.textureRect;
	}

	// Sprite rectangle offset in sprite definition rectangle space (in texels).
	CSRAW public Vector2 textureRectOffset
	{
		get
		{
			Vector2 v;
			Internal_GetTextureRectOffset(this, out v);
			return v;
		}
	} 

	CUSTOM_PROP bool packed
	{
		return self->GetIsPacked();
	}

	CUSTOM_PROP SpritePackingMode packingMode
	{
		const SpriteRenderData& rd = self->GetRenderData(true); // RenderData must always come from atlasing.
		if (!rd.settings.packed)
			Scripting::RaiseMonoException("Sprite is not packed.");
		return (SpritePackingMode)rd.settings.packingMode;
	}

	CUSTOM_PROP SpritePackingRotation packingRotation
	{
		const SpriteRenderData& rd = self->GetRenderData(true); // RenderData must always come from atlasing.
		if (!rd.settings.packed)
			Scripting::RaiseMonoException("Sprite is not packed.");
		return (SpritePackingRotation)rd.settings.packingRotation;
	}

	CUSTOM private static void Internal_GetTextureRectOffset(Sprite sprite, out Vector2 output)
	{
		const SpriteRenderData& rd = sprite->GetRenderDataForPlayMode(); // RenderData must match <texture> accessor's behavior.
		if (rd.settings.packed && rd.settings.packingMode != kSPMRectangle)
			Scripting::RaiseMonoException("Sprite is not rectangle-packed. TextureRectOffset is invalid.");
		output->x = rd.textureRectOffset.x;
		output->y = rd.textureRectOffset.y;
	}

	CONDITIONAL ENABLE_SPRITECOLLIDER
	CUSTOM_PROP int colliderPathCount
	{
		return self->GetPoly().GetPathCount();
	}

	CONDITIONAL ENABLE_SPRITECOLLIDER
	CUSTOM public Vector2[] GetColliderPath(int index)
	{
		if (index >= self->GetPoly().GetPathCount())
		{
			Scripting::RaiseOutOfRangeException("Path %d does not exist.", index);
			return SCRIPTING_NULL;
		}
				
		const Polygon2D::TPath& path = self->GetPoly().GetPath(index);
		return CreateScriptingArrayStride<Vector2f>(path.data(), path.size(), MONO_COMMON.vector2, sizeof(*path.data()));
	}

END

CONDITIONAL ENABLE_SPRITES
/// Renders a Sprite.
CLASS SpriteRenderer : Renderer

	CSRAW
	public Sprite sprite
	{
		get
		{
			return GetSprite_INTERNAL();
		}
		set
		{
			SetSprite_INTERNAL(value);
		}
	}
		
	CUSTOM private Sprite GetSprite_INTERNAL()
	{
		return Scripting::ScriptingWrapperFor(self->GetSprite());
	}

	CUSTOM private void SetSprite_INTERNAL(Sprite sprite)
	{
		self->SetSprite(sprite);
	}
	
	AUTO_PROP Color color GetColor SetColor

END

}

#endif //ENABLE_SPRITES