public void Export(string _outfilename) { Debug.Log("Exporting sprite to " + _outfilename); int numFrames = m_imageConfig.GetNumFrames(); int flags = 0x00; flags |= m_imageConfig.m_importAsBSprite ? 0x01 : 0x00; int outsize = 6 + numFrames; // 1 extra byte per frame, for the frame time byte[] outBytes = new byte[outsize]; Halp.Write8(outBytes, 0, m_imageConfig.GetSpriteWidth()); Halp.Write8(outBytes, 1, m_imageConfig.GetSpriteHeight()); Halp.Write8(outBytes, 2, numFrames); Halp.Write8(outBytes, 3, flags); Halp.Write16(outBytes, 4, 0xdead); // Put file handle here! int iFrame; for (iFrame = 0; iFrame < numFrames; iFrame++) { Halp.Write8(outBytes, 6 + iFrame, m_imageConfig.GetFrameTime(iFrame)); } System.IO.File.WriteAllBytes(_outfilename, outBytes); }
void OnDrawImageSettings(int _id) { m_spriteFrameTimeScroll = GUILayout.BeginScrollView(m_spriteFrameTimeScroll); bool dirty = false; bool before = m_currentImageConfig.m_importAsSprite; m_currentImageConfig.m_importAsSprite = GUILayout.Toggle(before, "Import as sprite"); if (m_currentImageConfig.m_importAsSprite != before) { dirty = true; } if (m_currentImageConfig.m_importAsSprite) { bool beforeB = m_currentImageConfig.m_importAsBSprite; m_currentImageConfig.m_importAsBSprite = GUILayout.Toggle(beforeB, "Import as B-sprite"); if (m_currentImageConfig.m_importAsBSprite != beforeB) { dirty = true; } GUILayout.Label("Sprite w=" + m_currentImageConfig.GetSpriteWidth() + ", h=" + m_currentImageConfig.GetSpriteHeight()); GUILayout.BeginHorizontal(); GUILayout.Label("Num frames"); string beforeString = m_currentFramesString; string newstring = GUILayout.TextField(beforeString); GUILayout.EndHorizontal(); m_currentFramesString = newstring; if (beforeString.CompareTo(newstring) != 0) { int newint; if (int.TryParse(newstring, out newint)) { m_currentImageConfig.SetNumFrames(newint); dirty = true; } } GUILayout.Label(""); GUILayout.Label("Frame times"); int i; for (i = 0; i < m_currentImageConfig.GetNumFrames(); i++) { int time = m_currentImageConfig.GetFrameTime(i); GUILayout.BeginHorizontal(); GUILayout.Label("Frame " + i + ":"); if (m_currentFrameTimesString.ContainsKey(i) == false) { m_currentFrameTimesString[i] = m_currentImageConfig.GetFrameTime(i).ToString(); } beforeString = m_currentFrameTimesString[i]; string newString = GUILayout.TextField(beforeString);; m_currentFrameTimesString[i] = newString; if (beforeString != newString) { int newValue; if (int.TryParse(newString, out newValue)) { m_currentImageConfig.SetFrameTime(i, newValue); dirty = true; } } GUILayout.EndHorizontal(); } GUILayout.Label("Hotspot"); m_currentImageConfig.m_hotSpotX = EditorGUILayout.IntField("X:", m_currentImageConfig.m_hotSpotX); m_currentImageConfig.m_hotSpotY = EditorGUILayout.IntField("Y:", m_currentImageConfig.m_hotSpotY); } if (dirty) { m_currentImageConfig.Save(); } GUI.DragWindow(); GUILayout.EndScrollView(); }