// save all entries textures to one Texture2d, this function doesn't store result texture to asset or to the file public Texture2D buildAtlasTexture2d() { Texture2D atlasTexture = UFTTextureUtil.getBlankTexture((int)atlasWidth, (int)atlasHeight); Color32[] atlasColors = atlasTexture.GetPixels32(); foreach (UFTAtlasEntry entry in atlasEntries) { Texture2D entryTexture = entry.texture; Color32[] entryColors = entryTexture.GetPixels32(); int rowPosition = 0; int offset = (int)(atlasColors.Length - ((entry.canvasRect.y + entry.canvasRect.height) * (int)atlasWidth) + entry.canvasRect.x); for (int i = 0; i < entryColors.Length; i++) { if (rowPosition == entry.canvasRect.width) { rowPosition = 0; offset = offset + (int)atlasWidth; } atlasColors[offset + rowPosition] = entryColors[i]; rowPosition++; } } atlasTexture.SetPixels32(atlasColors); atlasTexture.Apply(); return(atlasTexture); }
//this function build atlas texture, create atlas metadata and return it public UFTAtlasMetadata saveAtlasTextureAndGetMetadata(string assetPath) { List <UFTAtlasEntryMetadata> entryMeta = atlasEntries.ConvertAll(new Converter <UFTAtlasEntry, UFTAtlasEntryMetadata>(entryToEntryMetaConverter)); Texture2D texture = buildAtlasTexture2d(); texture = UFTTextureUtil.saveTexture2DToAssets(texture, assetPath); UFTAtlasMetadata atlasMetadata = UFTAtlasMetadata.CreateInstance <UFTAtlasMetadata>(); atlasMetadata.entries = entryMeta.ToArray(); atlasMetadata.texture = texture; atlasMetadata.atlasName = atlasName; return(atlasMetadata); }
void initParams() { borderTexture = UFTTextureUtil.createOnePxBorderTexture(); if (atlasEntries == null) { atlasEntries = new List <UFTAtlasEntry>(); } //init listeners UFTAtlasEditorEventManager.onDragInProgress += onDragInProgressListener; UFTAtlasEditorEventManager.onStopDragging += onStopDraggingListener; UFTAtlasEditorEventManager.onStartDragging += onStartDraggingListener; UFTAtlasEditorEventManager.onAtlasSizeChanged += onAtlasSizeChanged; onAtlasSizeChanged((int)atlasWidth, (int)atlasHeight); }
void initParams() { borderTexture = UFTTextureUtil.createOnePxBorderTexture(); pivotImage = UnityEditor.AssetDatabase.LoadAssetAtPath("Assets/HoneyFramework/3rd party/UFTAtlasEditor/Pivot.psd", typeof(Texture2D)) as Texture2D; if (atlasEntries == null) { atlasEntries = new List <UFTAtlasEntry>(); } //init listeners UFTAtlasEditorEventManager.onDragInProgress += onDragInProgressListener; UFTAtlasEditorEventManager.onStopDragging += onStopDraggingListener; UFTAtlasEditorEventManager.onStartDragging += onStartDraggingListener; UFTAtlasEditorEventManager.onAtlasSizeChanged += onAtlasSizeChanged; onAtlasSizeChanged((int)atlasWidth, (int)atlasHeight); }
//return true if texture has been trimmed, or false if not public bool trimTexture() { Texture2D newTexture = UFTTextureUtil.trimTextureAlpha(texture); if (newTexture != texture) { canvasRect.width = newTexture.width; canvasRect.height = newTexture.height; isTrimmed = true; texture = newTexture; if (UFTAtlasEditorEventManager.onTextureSizeChanged != null) { UFTAtlasEditorEventManager.onTextureSizeChanged(this); } return(true); } return(false); }
public void readPropertiesFromMetadata(UFTAtlasEntryMetadata metadata) { Texture2D texture = UFTTextureUtil.importTexture(metadata.assetPath); if (texture == null) { throw new TextureDoesNotExistsException(metadata.assetPath); } else { this.texture = texture; this.canvasRect = metadata.pixelRect; this.textureName = metadata.name; this.isTrimmed = metadata.isTrimmed; if (this.isTrimmed) { trimTexture(); } } }