8 using System.Collections;
9 using System.Collections.Generic;
19 [AddComponentMenu(
"SpriteManager 2/PackedSprite")]
28 public string staticTexGUID=
"";
57 get {
return _ser_stat_frame_info; }
73 public override Vector2 GetDefaultPixelSize(PathFromGUIDDelegate guid2Path, AssetLoaderDelegate loader)
75 if (staticTexGUID ==
"")
78 Texture2D tex = (Texture2D)loader(guid2Path(staticTexGUID), typeof(Texture2D));
79 Vector2 size =
new Vector2(tex.width * (1f / (_ser_stat_frame_info.scaleFactor.x * 2f)), tex.height * (1f / (_ser_stat_frame_info.scaleFactor.y * 2f)));
84 public override bool SupportsArbitraryAnimations
90 protected override void Awake()
95 staticFrameInfo = _ser_stat_frame_info.ToStruct();
103 public override void Start()
111 if (Application.isPlaying)
116 protected override void Init()
137 sp = (PackedSprite)s;
140 staticFrameInfo = sp._ser_stat_frame_info.ToStruct();
142 staticFrameInfo = sp.staticFrameInfo;
146 if (curAnim.
index == -1)
153 frameInfo = staticFrameInfo;
154 uvRect = frameInfo.uvs;
162 SetBleedCompensation();
167 public override void InitUVs()
169 frameInfo = staticFrameInfo;
170 uvRect = staticFrameInfo.uvs;
190 animations[animations.Length - 1] = anim;
199 public override void Aggregate(PathFromGUIDDelegate guid2Path, LoadAssetDelegate load, GUIDFromPathDelegate path2Guid)
201 List<Texture2D> texList =
new List<Texture2D>();
202 List<CSpriteFrame> frameList =
new List<CSpriteFrame>();
204 for (
int i = 0; i < textureAnimations.Length; ++i)
214 texList.Add((Texture2D)load(path, typeof(Texture2D)));
225 textureAnimations[i].spriteFrames =
new CSpriteFrame[textureAnimations[i].framePaths.Length];
226 for (
int j = 0; j < textureAnimations[i].spriteFrames.Length; ++j)
227 textureAnimations[i].spriteFrames[j] =
new CSpriteFrame();
229 for (
int j = 0; j < textureAnimations[i].framePaths.Length; ++j)
231 if (textureAnimations[i].framePaths[j].Length < 1)
235 textureAnimations[i].frameGUIDs[j] = path2Guid(textureAnimations[i].framePaths[j]);
237 texList.Add((Texture2D)load(textureAnimations[i].framePaths[j], typeof(Texture2D)));
238 frameList.Add(textureAnimations[i].spriteFrames[j]);
246 if(staticTexGUID.Length > 1)
255 texList.Add((Texture2D)load(
staticTexPath, typeof(Texture2D)));
256 frameList.Add(_ser_stat_frame_info);
258 sourceTextures = texList.ToArray();
259 spriteFrames = frameList.ToArray();
272 GameObject go =
new GameObject(name);
273 go.transform.position = pos;
287 GameObject go =
new GameObject(name);
288 go.transform.position = pos;
289 go.transform.rotation = rotation;
virtual void SetSize(float w, float h)
Sets the physical dimensions of the sprite in the plane selected
bool pixelPerfect
Automatically sizes the sprite so that it will display pixel-perfect on-screen. NOTE: If you change t...
TextureAnim[] textureAnimations
The animations as defined using individual textures. See TextureAnim
override void Copy(SpriteRoot s)
Copies all the attributes of another sprite.
int index
The index of this animation in the sprite's animation list. This value is only populated by and used ...
bool autoResize
Automatically resizes the sprite based on its new UV dimensions compared to its previous dimensions...
float width
Width of the sprite in world space.
void CalcSize()
Recalculates the width and height of the sprite based upon the change in its UV dimensions (autoResiz...
int defaultAnim
Index of the animation to play by default.
bool playAnimOnStart
When set to true, the sprite will play the default animation (see defaultAnim) when the sprite is ins...
void PlayAnim(UVAnimation anim, int frame)
Starts playing the specified animation Note: this doesn't resume from a pause, it completely restarts...
override void Aggregate(PathFromGUIDDelegate guid2Path, LoadAssetDelegate load, GUIDFromPathDelegate path2Guid)
Collects all textures intended for packing, as well as sprite frames, together into a standard form f...
static PackedSprite Create(string name, Vector3 pos, Quaternion rotation)
Creates a GameObject and attaches this component type to it.
The root class of all sprites. Does not assume any animation capabilities or atlas packing...
void AddAnimation(UVAnimation anim)
Adds an animation to the sprite for its use.
float height
Height of the sprite in world space.
override void SetState(int index)
Sets the sprite to the specified state/animation.
static PackedSprite Create(string name, Vector3 pos)
Creates a GameObject and attaches this component type to it.
UVAnimation[] animations
Holds the actual UV sequences that will be used at run-time.