mirror of
https://github.com/BlackMATov/unity-flash-tools.git
synced 2026-09-27 23:37:42 +07:00
AtlasForceSquare wip
This commit is contained in:
@@ -145,7 +145,7 @@ Camera:
|
||||
far clip plane: 1000
|
||||
field of view: 60
|
||||
orthographic: 1
|
||||
orthographic size: 3
|
||||
orthographic size: 4
|
||||
m_Depth: 0
|
||||
m_CullingMask:
|
||||
serializedVersion: 2
|
||||
|
||||
@@ -15,7 +15,8 @@ MonoBehaviour:
|
||||
MaxAtlasSize: 1024
|
||||
AtlasPadding: 1
|
||||
PixelsPerUnit: 100
|
||||
AtlasPowerOfTwo: 0
|
||||
GenerateMipMaps: 1
|
||||
AtlasPowerOfTwo: 1
|
||||
AtlasForceSquare: 0
|
||||
AtlasFilterMode: 1
|
||||
AtlasImporterFormat: -3
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cda4fb87dc8624946bdaed871b60f0b8
|
||||
timeCreated: 1471847086
|
||||
timeCreated: 1471880348
|
||||
licenseType: Free
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
|
||||
@@ -22,9 +22,16 @@ namespace FlashTools.Internal {
|
||||
|
||||
void ApplyOverriddenSettings() {
|
||||
if ( _asset ) {
|
||||
_asset.Settings = _asset.Overridden;
|
||||
if ( File.Exists(GetSwfPath()) ) {
|
||||
_asset.Settings = _asset.Overridden;
|
||||
ReconvertAnimation();
|
||||
} else {
|
||||
Debug.LogErrorFormat(
|
||||
"Swf source for animation not found: '{0}'",
|
||||
GetSwfPath());
|
||||
RevertOverriddenSettings();
|
||||
}
|
||||
}
|
||||
ReconvertAnimation();
|
||||
}
|
||||
|
||||
void ReconvertAnimation() {
|
||||
@@ -76,7 +83,7 @@ namespace FlashTools.Internal {
|
||||
prefab,
|
||||
ReplacePrefabOptions.ConnectToPrefab);
|
||||
}
|
||||
DestroyImmediate(anim_go);
|
||||
GameObject.DestroyImmediate(anim_go, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -184,11 +184,41 @@ namespace FlashTools.Internal {
|
||||
.Select (p => LoadTextureFromBitmapDefine(p.Value))
|
||||
.ToArray();
|
||||
|
||||
var atlas = new Texture2D(0, 0, TextureFormat.ARGB32, false);
|
||||
var atlas_padding = Mathf.Max(0, asset.Settings.AtlasPadding);
|
||||
var max_atlas_size = (asset.Settings.AtlasPowerOfTwo && !Mathf.IsPowerOfTwo(asset.Settings.MaxAtlasSize))
|
||||
? Mathf.NextPowerOfTwo(asset.Settings.MaxAtlasSize)
|
||||
: asset.Settings.MaxAtlasSize;
|
||||
|
||||
var atlas = new Texture2D(0, 0);
|
||||
var atlas_rects = atlas.PackTextures(
|
||||
textures,
|
||||
asset.Settings.AtlasPadding,
|
||||
asset.Settings.MaxAtlasSize);
|
||||
atlas_padding,
|
||||
Mathf.Max(32, max_atlas_size));
|
||||
|
||||
if ( asset.Settings.AtlasForceSquare && atlas.width != atlas.height ) {
|
||||
var atlas_size = Mathf.Max(atlas.width, atlas.height);
|
||||
var new_atlas = new Texture2D(atlas_size, atlas_size, TextureFormat.ARGB32, false);
|
||||
for ( var i = 0; i < atlas_rects.Length; ++i ) {
|
||||
var new_position = atlas_rects[i].position;
|
||||
new_position.x *= (float)(atlas.width )/atlas_size;
|
||||
new_position.y *= (float)(atlas.height)/atlas_size;
|
||||
|
||||
var new_size = atlas_rects[i].size;
|
||||
new_size.x *= (float)(atlas.width )/atlas_size;
|
||||
new_size.y *= (float)(atlas.height)/atlas_size;
|
||||
|
||||
atlas_rects[i] = new Rect(new_position, new_size);
|
||||
}
|
||||
var empty_pixels = new Color32[atlas_size * atlas_size];
|
||||
for ( var i = 0; i < atlas_size * atlas_size; ++i ) {
|
||||
empty_pixels[i] = new Color(1,1,1,0);
|
||||
}
|
||||
new_atlas.SetPixels32(empty_pixels);
|
||||
new_atlas.SetPixels32(0, 0, atlas.width, atlas.height, atlas.GetPixels32());
|
||||
new_atlas.Apply();
|
||||
GameObject.DestroyImmediate(atlas, true);
|
||||
atlas = new_atlas;
|
||||
}
|
||||
|
||||
File.WriteAllBytes(
|
||||
GetAtlasPath(swf_asset),
|
||||
|
||||
@@ -12,19 +12,21 @@ namespace FlashTools {
|
||||
public int MaxAtlasSize;
|
||||
public int AtlasPadding;
|
||||
public int PixelsPerUnit;
|
||||
public bool AtlasPowerOfTwo;
|
||||
public bool GenerateMipMaps;
|
||||
public bool AtlasPowerOfTwo;
|
||||
public bool AtlasForceSquare; //TODO: implme
|
||||
public FilterMode AtlasFilterMode;
|
||||
public TextureImporterFormat AtlasImporterFormat;
|
||||
|
||||
public bool Equal(Settings other) {
|
||||
return
|
||||
MaxAtlasSize == other.MaxAtlasSize &&
|
||||
AtlasPadding == other.AtlasPadding &&
|
||||
PixelsPerUnit == other.PixelsPerUnit &&
|
||||
AtlasPowerOfTwo == other.AtlasPowerOfTwo &&
|
||||
GenerateMipMaps == other.GenerateMipMaps &&
|
||||
AtlasFilterMode == other.AtlasFilterMode &&
|
||||
MaxAtlasSize == other.MaxAtlasSize &&
|
||||
AtlasPadding == other.AtlasPadding &&
|
||||
PixelsPerUnit == other.PixelsPerUnit &&
|
||||
GenerateMipMaps == other.GenerateMipMaps &&
|
||||
AtlasPowerOfTwo == other.AtlasPowerOfTwo &&
|
||||
AtlasForceSquare == other.AtlasForceSquare &&
|
||||
AtlasFilterMode == other.AtlasFilterMode &&
|
||||
AtlasImporterFormat == other.AtlasImporterFormat;
|
||||
}
|
||||
|
||||
@@ -34,8 +36,9 @@ namespace FlashTools {
|
||||
MaxAtlasSize = 1024,
|
||||
AtlasPadding = 1,
|
||||
PixelsPerUnit = 100,
|
||||
AtlasPowerOfTwo = false,
|
||||
GenerateMipMaps = true,
|
||||
AtlasPowerOfTwo = true,
|
||||
AtlasForceSquare = false,
|
||||
AtlasFilterMode = FilterMode.Bilinear,
|
||||
AtlasImporterFormat = TextureImporterFormat.AutomaticTruecolor};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user