本文整理汇总了C#中tk2dSpriteCollection类的典型用法代码示例。如果您正苦于以下问题:C# tk2dSpriteCollection类的具体用法?C# tk2dSpriteCollection怎么用?C# tk2dSpriteCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
tk2dSpriteCollection类属于命名空间,在下文中一共展示了tk2dSpriteCollection类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: ValidateLinkedSpriteCollection
public static void ValidateLinkedSpriteCollection(tk2dSpriteCollection gen) {
if (gen.linkParent == null) {
return;
}
if (gen.textureParams.Length != gen.linkParent.textureParams.Length) {
Debug.LogError("Linked sprite collection mismatch. Please rebuild source collection");
gen.linkParent = null;
}
}
开发者ID:maynull,项目名称:LeftRightXoX,代码行数:10,代码来源:tk2dSpriteCollectionLinkBuilder.cs
示例2: ValidateTextureParam
public static void ValidateTextureParam(tk2dSpriteCollection gen, int i) {
var param = gen.textureParams[i];
if (param.texture != null && gen.linkParent != null) {
if (gen.linkParent.textureParams[i].texture == null ||
gen.linkParent.textureParams[i].texture.width != param.texture.width ||
gen.linkParent.textureParams[i].texture.height != param.texture.height) {
Debug.LogError("Linked sprite collection mismatch " + param.texture.name);
}
}
}
开发者ID:maynull,项目名称:LeftRightXoX,代码行数:10,代码来源:tk2dSpriteCollectionLinkBuilder.cs
示例3: CheckAndFixUpParams
public static bool CheckAndFixUpParams(tk2dSpriteCollection gen)
{
if (gen.DoNotUse__TextureRefs != null && gen.textureParams != null && gen.DoNotUse__TextureRefs.Length != gen.textureParams.Length)
{
tk2dSpriteCollectionDefinition[] newDefs = new tk2dSpriteCollectionDefinition[gen.DoNotUse__TextureRefs.Length];
int c = Mathf.Min( newDefs.Length, gen.textureParams.Length );
if (gen.DoNotUse__TextureRefs.Length > gen.textureParams.Length)
{
Texture2D[] newTexRefs = new Texture2D[gen.DoNotUse__TextureRefs.Length - gen.textureParams.Length];
System.Array.Copy(gen.DoNotUse__TextureRefs, gen.textureParams.Length, newTexRefs, 0, newTexRefs.Length);
System.Array.Sort(newTexRefs, (Texture2D a, Texture2D b) => tk2dSpriteGuiUtility.NameCompare(a?a.name:"", b?b.name:""));
System.Array.Copy(newTexRefs, 0, gen.DoNotUse__TextureRefs, gen.textureParams.Length, newTexRefs.Length);
}
for (int i = 0; i < c; ++i)
{
newDefs[i] = new tk2dSpriteCollectionDefinition();
newDefs[i].CopyFrom( gen.textureParams[i] );
}
for (int i = c; i < newDefs.Length; ++i)
{
newDefs[i] = new tk2dSpriteCollectionDefinition();
newDefs[i].pad = gen.defaults.pad;
newDefs[i].additive = gen.defaults.additive;
newDefs[i].anchor = gen.defaults.anchor;
newDefs[i].scale = gen.defaults.scale;
newDefs[i].colliderType = gen.defaults.colliderType;
}
gen.textureParams = newDefs;
}
// clear thumbnails on build
foreach (var param in gen.textureParams)
{
param.thumbnailTexture = null;
}
foreach (var param in gen.textureParams)
{
if (gen.allowMultipleAtlases && param.dice)
{
EditorUtility.DisplayDialog("Error",
"Multiple atlas spanning is not allowed when there are textures with dicing enabled in the SpriteCollection.",
"Ok");
gen.allowMultipleAtlases = false;
return false;
}
}
return true;
}
开发者ID:AtwoodDeng,项目名称:GGJ2015,代码行数:54,代码来源:tk2dSpriteCollectionBuilderDeprecated.cs
示例4: TrimTextureList
public static void TrimTextureList(tk2dSpriteCollection gen)
{
// trim textureRefs & textureParams
int lastNonEmpty = -1;
for (int i = 0; i < gen.DoNotUse__TextureRefs.Length; ++i)
{
if (gen.DoNotUse__TextureRefs[i] != null) lastNonEmpty = i;
}
Texture2D[] textureRefs = gen.DoNotUse__TextureRefs;
System.Array.Resize(ref textureRefs, lastNonEmpty + 1);
System.Array.Resize(ref gen.textureParams, lastNonEmpty + 1);
gen.DoNotUse__TextureRefs = textureRefs;
}
开发者ID:AtwoodDeng,项目名称:GGJ2015,代码行数:13,代码来源:tk2dSpriteCollectionBuilderDeprecated.cs
示例5: GetOrCreateDataPath
public static string GetOrCreateDataPath(tk2dSpriteCollection gen)
{
if (gen.spriteCollection != null)
{
return System.IO.Path.GetDirectoryName(AssetDatabase.GetAssetPath(gen.spriteCollection));
}
else
{
string path = System.IO.Path.GetDirectoryName(AssetDatabase.GetAssetPath(gen)) + "/" + gen.name + " Data";
if (!System.IO.Directory.Exists(path))
System.IO.Directory.CreateDirectory(path);
return path;
}
}
开发者ID:Collegiennes,项目名称:Malisse,代码行数:14,代码来源:tk2dSpriteCollectionBuilder.cs
示例6: InitializeSpriteCollectionPlatforms
public static void InitializeSpriteCollectionPlatforms(tk2dSpriteCollection gen, string root)
{
// Create all missing platform directories and sprite collection objects
for (int i = 0; i < gen.platforms.Count; ++i)
{
tk2dSpriteCollectionPlatform plat = gen.platforms[i];
if (plat.name.Length > 0 && !plat.spriteCollection)
{
plat.spriteCollection = tk2dSpriteCollectionEditor.CreateSpriteCollection(root, gen.name + "@" + plat.name);
plat.spriteCollection.managedSpriteCollection = true;
EditorUtility.SetDirty(gen.spriteCollection);
}
}
}
开发者ID:aprildd,项目名称:CG_BombGame,代码行数:14,代码来源:tk2dSpriteCollectionPlatformBuilder.cs
示例7: Build
public static void Build(tk2dSpriteCollection data)
{
if (data.linkedSpriteCollections.Count > 0 && !data.disableTrimming) {
return;
}
string errors = "";
int errorCount = 0;
string root = System.IO.Path.GetDirectoryName(AssetDatabase.GetAssetPath(data)) + "/Linked";
foreach (tk2dLinkedSpriteCollection link in data.linkedSpriteCollections) {
if (link.spriteCollection == null) {
if (!System.IO.Directory.Exists(root)) {
System.IO.Directory.CreateDirectory(root);
}
link.spriteCollection = tk2dSpriteCollectionEditor.CreateSpriteCollection(root, data.name + link.name);
}
tk2dEditor.SpriteCollectionEditor.SpriteCollectionProxy proxy = new tk2dEditor.SpriteCollectionEditor.SpriteCollectionProxy(data, false);
proxy.CopyBuiltFromSource(link.spriteCollection);
proxy.linkedSpriteCollections.Clear(); // stop recursion
string thisErrors = "";
foreach (tk2dSpriteCollectionDefinition tp in proxy.textureParams) {
if (tp.texture != null) {
Texture2D repl = FindReplacementTexture(tp.texture, link.name);
if (repl == null) {
thisErrors += string.Format("Unable to find replacement for texture '{0}' for link '{1}'\n", tp.texture.name, link.name);
++errorCount;
}
tp.texture = repl;
}
}
if (thisErrors.Length == 0) {
proxy.CopyToTarget(link.spriteCollection);
link.spriteCollection.linkParent = data;
EditorUtility.SetDirty(link.spriteCollection);
tk2dSpriteCollectionBuilder.Rebuild(link.spriteCollection);
}
else {
errors += thisErrors;
}
}
if (errors.Length > 0) {
Debug.LogError("There were " + errorCount.ToString() + " errors building the sprite collection\n" + errors);
}
}
开发者ID:Wuzseen,项目名称:RollerGolf,代码行数:49,代码来源:tk2dSpriteCollectionLinkBuilder.cs
示例8: CreateDataObject
// Create the sprite collection data object
// Its a prefab for historic reasons
static void CreateDataObject(tk2dSpriteCollection gen, string prefabObjectPath)
{
// Create prefab
if (gen.spriteCollection == null)
{
prefabObjectPath = AssetDatabase.GenerateUniqueAssetPath(prefabObjectPath);
GameObject go = new GameObject();
go.AddComponent<tk2dSpriteCollectionData>();
#if (UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4)
Object p = EditorUtility.CreateEmptyPrefab(prefabObjectPath);
EditorUtility.ReplacePrefab(go, p);
#else
Object p = PrefabUtility.CreateEmptyPrefab(prefabObjectPath);
PrefabUtility.ReplacePrefab(go, p);
#endif
GameObject.DestroyImmediate(go);
AssetDatabase.SaveAssets();
gen.spriteCollection = AssetDatabase.LoadAssetAtPath(prefabObjectPath, typeof(tk2dSpriteCollectionData)) as tk2dSpriteCollectionData;
}
}
开发者ID:Collegiennes,项目名称:Malisse,代码行数:24,代码来源:tk2dSpriteCollectionBuilder.cs
示例9: UpdateVertexCache
static void UpdateVertexCache(tk2dSpriteCollection gen, float scale, tk2dEditor.Atlas.Data[] packers, tk2dSpriteCollectionData coll, List<SpriteLut> spriteLuts)
{
for (int i = 0; i < sourceTextures.Length; ++i)
{
SpriteLut _lut = null;
for (int j = 0; j < spriteLuts.Count; ++j)
{
if (spriteLuts[j].source == i)
{
_lut = spriteLuts[j];
break;
}
}
int padAmount = GetPadAmount(gen, i);
tk2dSpriteCollectionDefinition thisTexParam = gen.textureParams[i];
tk2dEditor.Atlas.Data packer = null;
tk2dEditor.Atlas.Entry atlasEntry = null;
int atlasIndex = 0;
foreach (var p in packers)
{
if ((atlasEntry = p.FindEntryWithIndex(_lut.atlasIndex)) != null)
{
packer = p;
break;
}
++atlasIndex;
}
float fwidth = packer.width;
float fheight = packer.height;
int tx = atlasEntry.x + padAmount, ty = atlasEntry.y + padAmount, tw = atlasEntry.w - padAmount * 2, th = atlasEntry.h - padAmount * 2;
int sd_y = packer.height - ty - th;
float uvOffsetX = 0.001f / fwidth;
float uvOffsetY = 0.001f / fheight;
Vector2 v0 = new Vector2(tx / fwidth + uvOffsetX, 1.0f - (sd_y + th) / fheight + uvOffsetY);
Vector2 v1 = new Vector2((tx + tw) / fwidth - uvOffsetX, 1.0f - sd_y / fheight - uvOffsetY);
Mesh mesh = null;
Transform meshTransform = null;
GameObject instantiated = null;
Vector3 colliderOrigin = new Vector3();
if (thisTexParam.overrideMesh)
{
// Disabled
instantiated = GameObject.Instantiate(thisTexParam.overrideMesh) as GameObject;
MeshFilter meshFilter = instantiated.GetComponentInChildren<MeshFilter>();
if (meshFilter == null)
{
Debug.LogError("Unable to find mesh");
GameObject.DestroyImmediate(instantiated);
}
else
{
mesh = meshFilter.sharedMesh;
meshTransform = meshFilter.gameObject.transform;
}
}
Vector3 untrimmedPos0 = Vector3.zero, untrimmedPos1 = Vector3.one;
if (mesh)
{
coll.spriteDefinitions[i].positions = new Vector3[mesh.vertices.Length];
coll.spriteDefinitions[i].uvs = new Vector2[mesh.vertices.Length];
for (int j = 0; j < mesh.vertices.Length; ++j)
{
coll.spriteDefinitions[i].positions[j] = meshTransform.TransformPoint(mesh.vertices[j]);
coll.spriteDefinitions[i].uvs[j] = new Vector2(v0.x + (v1.x - v0.x) * mesh.uv[j].x, v0.y + (v1.y - v0.y) * mesh.uv[j].y);
}
coll.spriteDefinitions[i].indices = new int[mesh.triangles.Length];
for (int j = 0; j < mesh.triangles.Length; ++j)
{
coll.spriteDefinitions[i].indices[j] = mesh.triangles[j];
}
GameObject.DestroyImmediate(instantiated);
}
else
{
Texture2D thisTextureRef = sourceTextures[i];
int texHeightI = thisTextureRef?thisTextureRef.height:2;
int texWidthI = thisTextureRef?thisTextureRef.width:2;
float texHeight = texHeightI;
float texWidth = texWidthI;
float h = thisTextureRef?thisTextureRef.height:64;
float w = thisTextureRef?thisTextureRef.width:64;
h *= thisTexParam.scale.y;
w *= thisTexParam.scale.x;
float scaleX = w * scale;
float scaleY = h * scale;
// anchor coordinate system is (0, 0) = top left, to keep it the same as photoshop, etc.
//.........这里部分代码省略.........
开发者ID:Collegiennes,项目名称:Malisse,代码行数:101,代码来源:tk2dSpriteCollectionBuilder.cs
示例10: UpdateVertexCache
static void UpdateVertexCache(tk2dSpriteCollection gen, tk2dAtlas.AtlasData[] packers, tk2dSpriteCollectionData coll, List<SCGE.SpriteLut> spriteLuts)
{
float scale = 2.0f * gen.targetOrthoSize / gen.targetHeight;
int padAmount = GetPadAmount(gen);
for (int i = 0; i < sourceTextures.Length; ++i)
{
SCGE.SpriteLut _lut = null;
for (int j = 0; j < spriteLuts.Count; ++j)
{
if (spriteLuts[j].source == i)
{
_lut = spriteLuts[j];
break;
}
}
tk2dSpriteCollectionDefinition thisTexParam = gen.textureParams[i];
tk2dAtlas.AtlasData packer = null;
tk2dAtlas.AtlasEntry atlasEntry = null;
int atlasIndex = 0;
foreach (var p in packers)
{
if ((atlasEntry = p.FindEntryWithIndex(_lut.atlasIndex)) != null)
{
packer = p;
break;
}
++atlasIndex;
}
float fwidth = packer.width;
float fheight = packer.height;
int tx = atlasEntry.x + padAmount, ty = atlasEntry.y + padAmount, tw = atlasEntry.w - padAmount * 2, th = atlasEntry.h - padAmount * 2;
int sd_y = packer.height - ty - th;
float uvOffsetX = 0.001f / fwidth;
float uvOffsetY = 0.001f / fheight;
Vector2 v0 = new Vector2(tx / fwidth + uvOffsetX, 1.0f - (sd_y + th) / fheight + uvOffsetY);
Vector2 v1 = new Vector2((tx + tw) / fwidth - uvOffsetX, 1.0f - sd_y / fheight - uvOffsetY);
Mesh mesh = null;
Transform meshTransform = null;
GameObject instantiated = null;
Vector3 colliderOrigin = new Vector3();
if (thisTexParam.overrideMesh)
{
// Disabled
instantiated = GameObject.Instantiate(thisTexParam.overrideMesh) as GameObject;
MeshFilter meshFilter = instantiated.GetComponentInChildren<MeshFilter>();
if (meshFilter == null)
{
Debug.LogError("Unable to find mesh");
GameObject.DestroyImmediate(instantiated);
}
else
{
mesh = meshFilter.sharedMesh;
meshTransform = meshFilter.gameObject.transform;
}
}
if (mesh)
{
coll.spriteDefinitions[i].positions = new Vector3[mesh.vertices.Length];
coll.spriteDefinitions[i].uvs = new Vector2[mesh.vertices.Length];
for (int j = 0; j < mesh.vertices.Length; ++j)
{
coll.spriteDefinitions[i].positions[j] = meshTransform.TransformPoint(mesh.vertices[j]);
coll.spriteDefinitions[i].uvs[j] = new Vector2(v0.x + (v1.x - v0.x) * mesh.uv[j].x, v0.y + (v1.y - v0.y) * mesh.uv[j].y);
}
coll.spriteDefinitions[i].indices = new int[mesh.triangles.Length];
for (int j = 0; j < mesh.triangles.Length; ++j)
{
coll.spriteDefinitions[i].indices[j] = mesh.triangles[j];
}
coll.spriteDefinitions[i].material = gen.atlasMaterials[atlasIndex];
GameObject.DestroyImmediate(instantiated);
}
else
{
Texture2D thisTextureRef = sourceTextures[i];
float texHeight = thisTextureRef?thisTextureRef.height:2;
float texWidth = thisTextureRef?thisTextureRef.width:2;
float h = thisTextureRef?thisTextureRef.height:64;
float w = thisTextureRef?thisTextureRef.width:64;
h *= thisTexParam.scale.y;
w *= thisTexParam.scale.x;
float scaleX = w * scale;
float scaleY = h * scale;
Vector3 pos0 = new Vector3(-0.5f * scaleX, 0, -0.5f * scaleY);
switch (thisTexParam.anchor)
//.........这里部分代码省略.........
开发者ID:CodeStrumpet,项目名称:Elemental,代码行数:101,代码来源:tk2dSpriteCollectionBuilder.cs
示例11: UpdateFontData
static void UpdateFontData(tk2dSpriteCollection gen, float scale, tk2dEditor.Atlas.Data[] packers, List<SpriteLut> spriteLuts, tk2dSpriteCollectionFont font, tk2dEditor.Font.Info fontInfo)
{
Dictionary<int, SpriteLut> glyphLut = new Dictionary<int, SpriteLut>();
List<SpriteLut> values = new List<SpriteLut>();
foreach (var k in glyphLut.Keys) values.Add(glyphLut[k]);
foreach (var v in spriteLuts)
glyphLut[v.charId] = v;
int padAmount = GetPadAmount(gen, -1);
foreach (var c in fontInfo.chars)
{
if (glyphLut.ContainsKey(c.id))
{
var glyphSprite = glyphLut[c.id];
var atlasEntry = packers[0].FindEntryWithIndex(glyphSprite.atlasIndex);
c.texOffsetX = glyphSprite.rx;
if (font.flipTextureY)
{
// This is the offset from the bottom of the font
c.texOffsetY = glyphSprite.ry;
}
else
{
// ry is offset from top, we want offset from bottom
// height is the original glyph height before cropping, the remainder of which is
// the offset from bottom
c.texOffsetY = c.height - glyphSprite.rh - glyphSprite.ry;
}
c.texX = atlasEntry.x + padAmount;
c.texY = atlasEntry.y + padAmount;
c.texW = atlasEntry.w - padAmount * 2;
c.texH = atlasEntry.h - padAmount * 2;
c.texFlipped = atlasEntry.flipped;
}
else
{
var glyphSprite = glyphLut[-1];
var atlasEntry = packers[0].FindEntryWithIndex(glyphSprite.atlasIndex);
c.texOffsetX = 0;
c.texOffsetY = 0;
c.texX = atlasEntry.x + 1;
c.texY = atlasEntry.y + 1;
c.texW = 0;
c.texH = 0;
c.texFlipped = false;
}
c.texOverride = true;
}
tk2dEditor.Font.Builder.BuildFont(fontInfo, font.data, scale, font.charPadX, font.dupeCaps, font.flipTextureY, font.gradientTexture, font.gradientCount);
}
开发者ID:Collegiennes,项目名称:Malisse,代码行数:56,代码来源:tk2dSpriteCollectionBuilder.cs
示例12: SetGeneratorAndSelectedSprite
public void SetGeneratorAndSelectedSprite(tk2dSpriteCollection spriteCollection, int selectedSprite)
{
searchFilter = "";
SetGenerator(spriteCollection);
foreach (var entry in entries)
{
if (entry.type == SpriteCollectionEditorEntry.Type.Sprite && entry.index == selectedSprite)
{
entry.selected = true;
break;
}
}
UpdateSelection();
}
开发者ID:smclallen,项目名称:Galactic_Parcel_Service,代码行数:14,代码来源:tk2dSpriteCollectionEditorPopup.cs
示例13: Rebuild
public static bool Rebuild(tk2dSpriteCollection gen)
{
// avoid "recursive" build being triggered by texture watcher
if (currentBuild != null)
return false;
// Version specific checks. These need to be done before the sprite collection is upgraded.
if (gen.version < 2)
{
if (!tk2dEditor.SpriteCollectionBuilder.Deprecated.CheckAndFixUpParams(gen))
{
// Params failed check
return false;
}
tk2dEditor.SpriteCollectionBuilder.Deprecated.SetUpSpriteSheets(gen);
tk2dEditor.SpriteCollectionBuilder.Deprecated.TrimTextureList(gen);
}
currentBuild = gen;
gen.Upgrade(); // upgrade if necessary. could be invoked by texture watcher.
// Get some sensible paths to work with
string dataDirName = GetOrCreateDataPath(gen) + "/";
string prefabObjectPath = "";
if (gen.spriteCollection)
prefabObjectPath = AssetDatabase.GetAssetPath(gen.spriteCollection);
else
prefabObjectPath = dataDirName + gen.name + ".prefab";
BuildDirectoryToFile(prefabObjectPath);
// Create prefab object, needed for next stage
CreateDataObject( gen, prefabObjectPath );
// Special build for platform specific sprite collection
if (gen.HasPlatformData)
{
// Initialize required sprite collections
tk2dEditor.SpriteCollectionBuilder.PlatformBuilder.InitializeSpriteCollectionPlatforms(gen, System.IO.Path.GetDirectoryName(prefabObjectPath));
// The first sprite collection is always THIS
tk2dAssetPlatform baseAssetPlatform = tk2dSystem.GetAssetPlatform(gen.platforms[0].name);
float baseScale = (baseAssetPlatform != null)?baseAssetPlatform.scale:1.0f;
// Building platform specific data, allow recursive builds temporarily
currentBuild = null;
// Transfer to platform sprite collections, and build those
for (int i = 0; i < gen.platforms.Count; ++i)
{
tk2dSpriteCollectionPlatform platform = gen.platforms[i];
tk2dAssetPlatform thisAssetPlatform = tk2dSystem.GetAssetPlatform(gen.platforms[i].name);
float thisScale = (thisAssetPlatform != null)?thisAssetPlatform.scale:1.0f;
bool validPlatform = platform.name.Length > 0 && platform.spriteCollection != null;
bool isRootSpriteCollection = (i == 0);
if (validPlatform)
{
tk2dSpriteCollection thisPlatformCollection = gen.platforms[i].spriteCollection;
// Make sure data directory exists, material overrides will be created in here
string dataPath = GetOrCreateDataPath(thisPlatformCollection);
tk2dEditor.SpriteCollectionBuilder.PlatformBuilder.UpdatePlatformSpriteCollection(
gen, thisPlatformCollection, dataPath, isRootSpriteCollection, thisScale / baseScale, platform.name);
Rebuild(thisPlatformCollection);
}
}
// Pull atlas data from default platform
gen.atlasMaterials = gen.platforms[0].spriteCollection.atlasMaterials;
gen.altMaterials = gen.platforms[0].spriteCollection.altMaterials;
// Fill up our sprite collection data
List<string> platformNames = new List<string>();
List<string> platformGUIDs = new List<string>();
for (int i = 0; i < gen.platforms.Count; ++i)
{
tk2dSpriteCollectionPlatform platform = gen.platforms[i];
if (!platform.Valid) continue;
platformNames.Add(platform.name);
tk2dSpriteCollectionData data = platform.spriteCollection.spriteCollection;
string guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(data));
platformGUIDs.Add(guid);
// Make loadable
tk2dSystemUtility.MakeLoadableAsset(data, ""); // unnamed loadable object
}
// Set up fonts
for (int j = 0; j < gen.fonts.Length; ++j)
{
tk2dSpriteCollectionFont font = gen.fonts[j];
if (font == null) continue;
tk2dFontData data = font.data;
if (!data) continue;
data.hasPlatformData = true;
//.........这里部分代码省略.........
开发者ID:Collegiennes,项目名称:Malisse,代码行数:101,代码来源:tk2dSpriteCollectionBuilder.cs
示例14: Rebuild
public static bool Rebuild(tk2dSpriteCollection gen)
{
// avoid "recursive" build being triggered by texture watcher
if (currentBuild != null)
return false;
currentBuild = gen;
List<Texture2D> allocatedTextures = new List<Texture2D>();
string path = AssetDatabase.GetAssetPath(gen);
string subDirName = Path.GetDirectoryName( path.Substring(7) );
if (subDirName.Length > 0) subDirName += "/";
string dataDirFullPath = Application.dataPath + "/" + subDirName + Path.GetFileNameWithoutExtension(path) + "_Data";
string dataDirName = "Assets/" + dataDirFullPath.Substring( Application.dataPath.Length + 1 ) + "/";
if (gen.atlasTextures == null || gen.atlasTextures.Length == 0 ||
gen.atlasMaterials == null || gen.atlasMaterials.Length == 0 ||
gen.spriteCollection == null)
{
if (!Directory.Exists(dataDirFullPath)) Directory.CreateDirectory(dataDirFullPath);
AssetDatabase.Refresh();
}
string prefabObjectPath = gen.spriteCollection?AssetDatabase.GetAssetPath(gen.spriteCollection):(dataDirName + "data.prefab");
if (!CheckAndFixUpParams(gen))
{
// Params failed check
return false;
}
SetUpSourceTextureFormats(gen);
SetUpSpriteSheets(gen);
TrimTextureList(gen);
// blank texture used when texture has been deleted
Texture2D blankTexture = new Texture2D(2, 2);
blankTexture.SetPixel(0, 0, Color.magenta);
blankTexture.SetPixel(0, 1, Color.yellow);
blankTexture.SetPixel(1, 0, Color.cyan);
blankTexture.SetPixel(1, 1, Color.grey);
blankTexture.Apply();
// make local texture sources
sourceTextures = new Texture2D[gen.textureRefs.Length];
for (int i = 0; i < gen.textureParams.Length; ++i)
{
var param = gen.textureParams[i];
if (param.extractRegion && gen.textureRefs[i] != null)
{
Texture2D localTex = new Texture2D(param.regionW, param.regionH);
for (int y = 0; y < param.regionH; ++y)
{
for (int x = 0; x < param.regionW; ++x)
{
localTex.SetPixel(x, y, gen.textureRefs[i].GetPixel(param.regionX + x, param.regionY + y));
}
}
localTex.name = gen.textureRefs[i].name + "/" + param.regionId.ToString();
localTex.Apply();
allocatedTextures.Add(localTex);
sourceTextures[i] = localTex;
}
else
{
sourceTextures[i] = gen.textureRefs[i];
}
}
// catalog all textures to atlas
int numTexturesToAtlas = 0;
List<SpriteLut> spriteLuts = new List<SpriteLut>();
for (int i = 0; i < gen.textureParams.Length; ++i)
{
Texture2D currentTexture = sourceTextures[i];
if (sourceTextures[i] == null)
{
gen.textureParams[i].dice = false;
gen.textureParams[i].anchor = tk2dSpriteCollectionDefinition.Anchor.MiddleCenter;
gen.textureParams[i].name = "";
gen.textureParams[i].extractRegion = false;
gen.textureParams[i].fromSpriteSheet = false;
currentTexture = blankTexture;
}
else
{
if (gen.textureParams[i].name == null || gen.textureParams[i].name == "")
{
if (gen.textureParams[i].texture != currentTexture && !gen.textureParams[i].fromSpriteSheet)
{
gen.textureParams[i].name = currentTexture.name;
}
}
}
gen.textureParams[i].texture = currentTexture;
//.........这里部分代码省略.........
开发者ID:GennrichJ,项目名称:GalaxyWars,代码行数:101,代码来源:tk2dSpriteCollectionBuilder.cs
示例15: UpdatePlatformSpriteCollection
// Update target platforms
public static void UpdatePlatformSpriteCollection(tk2dSpriteCollection source, tk2dSpriteCollection target, string dataPath, bool root, float scale, string platformName)
{
tk2dEditor.SpriteCollectionEditor.SpriteCollectionProxy proxy = new tk2dEditor.SpriteCollectionEditor.SpriteCollectionProxy(source);
// Restore old sprite collection
proxy.spriteCollection = target.spriteCollection;
proxy.atlasTextures = target.atlasTextures;
proxy.atlasMaterials = target.atlasMaterials;
proxy.altMaterials = target.altMaterials;
// This must always be zero, as children cannot have nested platforms.
// That would open the door to a lot of unnecessary insanity
proxy.platforms = new List<tk2dSpriteCollectionPlatform>();
// Update atlas sizes
proxy.atlasWidth = (int)(proxy.atlasWidth * scale);
proxy.atlasHeight = (int)(proxy.atlasHeight * scale);
proxy.maxTextureSize = (int)(proxy.maxTextureSize * scale);
proxy.forcedTextureWidth = (int)(proxy.forcedTextureWidth * scale);
proxy.forcedTextureHeight = (int)(proxy.forcedTextureHeight * scale);
if (!proxy.useTk2dCamera)
proxy.targetOrthoSize *= 1.0f;
proxy.globalScale = 1.0f / scale;
// Don't bother changing stuff on the root object
// The root object is the one that the sprite collection is defined on initially
if (!root)
{
// Update textures
foreach (tk2dSpriteCollectionDefinition param in proxy.textureParams)
{
if (param.texture == null) continue;
string path = AssetDatabase.GetAssetPath(param.texture);
string platformTexture = FindAssetForPlatform(platformName, path, textureExtensions);
if (platformTexture.Length == 0)
{
LogNotFoundError(platformName, param.texture.name, "texture");
}
else
{
Texture2D tex = AssetDatabase.LoadAssetAtPath(platformTexture, typeof(Texture2D)) as Texture2D;
if (tex == null)
{
Debug.LogError("Unable to load platform specific texture '" + platformTexture + "'");
}
else
{
param.texture = tex;
}
}
// Handle spritesheets. Odd coordinates could cause issues
if (param.extractRegion)
{
param.regionX = (int)(param.regionX * scale);
param.regionY = (int)(param.regionY * scale);
param.regionW = (int)(param.regionW * scale);
param.regionH = (int)(param.regionH * scale);
}
if (param.anchor == tk2dSpriteCollectionDefinition.Anchor.Custom)
{
param.anchorX = (int)(param.anchorX * scale);
param.anchorY = (int)(param.anchorY * scale);
}
if (param.customSpriteGeometry)
{
foreach (tk2dSpriteColliderIsland geom in param.geometryIslands)
{
for (int p = 0; p < geom.points.Length; ++p)
geom.points[p] *= scale;
}
}
if (param.colliderType == tk2dSpriteCollectionDefinition.ColliderType.Polygon)
{
foreach (tk2dSpriteColliderIsland geom in param.polyColliderIslands)
{
for (int p = 0; p < geom.points.Length; ++p)
geom.points[p] *= scale;
}
}
else if (param.colliderType == tk2dSpriteCollectionDefinition.ColliderType.BoxCustom)
{
param.boxColliderMax *= scale;
param.boxColliderMin *= scale;
}
}
}
// We ALWAYS duplicate fonts
if (target.fonts == null) target.fonts = new tk2dSpriteCollectionFont[0];
for (int i = 0; i < proxy.fonts.Count; ++i)
{
//.........这里部分代码省略.........
开发者ID:aprildd,项目名称:CG_BombGame,代码行数:101,代码来源:tk2dSpriteCollectionPlatformBuilder.cs
示例16: ProcessTexture
static Texture2D ProcessTexture(tk2dSpriteCollection settings, bool additive, bool stretchPad, Texture2D srcTex, int sx, int sy, int tw, int th, ref SpriteLut spriteLut, int padAmount)
{
// Can't have additive without premultiplied alpha
if (!settings.premultipliedAlpha) additive = false;
bool allowTrimming = !settings.disableTrimming;
var textureCompression = settings.textureCompression;
int[] ww = new int[tw];
int[] hh = new int[th];
for (int x = 0; x < tw; ++x) ww[x] = 0;
for (int y = 0; y < th; ++y) hh[y] = 0;
int numNotTransparent = 0;
for (int x = 0; x < tw; ++x)
{
for (int y = 0; y < th; ++y)
{
Color col = srcTex.GetPixel(sx + x, sy + y);
if (col.a > 0)
{
ww[x] = 1;
hh[y] = 1;
numNotTransparent++;
}
}
}
if (numNotTransparent > 0)
{
int x0 = 0, x1 = 0, y0 = 0, y1 = 0;
for (int x = 0; x < tw; ++x) if (ww[x] == 1) { x0 = x; break; }
for (int x = tw - 1; x >= 0; --x) if (ww[x] == 1) { x1 = x; break; }
for (int y = 0; y < th; ++y) if (hh[y] == 1) { y0 = y; break; }
for (int y = th - 1; y >= 0; --y) if (hh[y] == 1) { y1 = y; break; }
int w1 = x1 - x0 + 1;
int h1 = y1 - y0 + 1;
if (!allowTrimming)
{
x0 = 0;
y0 = 0;
w1 = tw;
h1 = th;
}
Texture2D dtex = new Texture2D(w1 + padAmount * 2, h1 + padAmount * 2);
for (int x = 0; x < w1; ++x)
{
for (int y = 0; y < h1; ++y)
{
Color col = srcTex.GetPixel(sx + x0 + x, sy + y0 + y);
dtex.SetPixel(x + padAmount, y + padAmount, col);
}
}
if (settings.premultipliedAlpha)
{
for (int x = 0; x < dtex.width; ++x)
{
for (int y = 0; y < dtex.height; ++y)
{
Color col = dtex.GetPixel(x, y);
col.r *= col.a; col.g *= col.a; col.b *= col.a;
col.a = additive?0.0f:col.a;
dtex.SetPixel(x, y, col);
}
}
}
PadTexture(dtex, padAmount, stretchPad);
switch (textureCompression)
{
case tk2dSpriteCollection.TextureCompression.Dithered16Bit_4444:
tk2dEditor.TextureProcessing.FloydSteinbergDithering.DitherTexture(dtex, TextureFormat.ARGB4444, 0, 0, dtex.width, dtex.height); break;
case tk2dSpriteCollection.TextureCompression.Dithered16Bit_565:
tk2dEditor.TextureProcessing.FloydSteinbergDithering.DitherTexture(dtex, TextureFormat.RGB565, 0, 0, dtex.width, dtex.height); break;
}
dtex.Apply();
spriteLut.rx = sx + x0;
spriteLut.ry = sy + y0;
spriteLut.rw = w1;
spriteLut.rh = h1;
spriteLut.tex = dtex;
return dtex;
}
else
{
return null;
}
}
开发者ID:GennrichJ,项目名称:GalaxyWars,代码行数:92,代码来源:tk2dSpriteCollectionBuilder.cs
示例17: UpdateFontData
static void UpdateFontData(tk2dSpriteCollection gen, float scale, tk2dEditor.Atlas.Data[] packers, List<SpriteLut> spriteLuts, tk2dSpriteCollectionFont font, tk2dEditor.Font.Info fontInfo)
{
Dictionary<int, SpriteLut> glyphLut = new Dictionary<int, SpriteLut>();
List<SpriteLut> values = new List<SpriteLut>();
foreach (var k in glyphLut.Keys) values.Add(glyphLut[k]);
foreach (var v in spriteLuts)
glyphLut[v.charId] = v;
int padAmount = GetPadAmount(gen, -1);
foreach (var c in fontInfo.chars)
{
if (glyphLut.ContainsKey(c.id))
{
var glyphSprite = glyphLut[c.id];
var atlasEntry = packers[0].FindEntryWithIndex(glyphSprite.atlasIndex);
c.texOffsetX = glyphSprite.rx;
c.texOffsetY = glyphSprite.ry;
c.texX = atlasEntry.x + padAmount;
c.texY = atlasEntry.y + padAmount;
c.texW = atlasEntry.w - padAmount * 2;
c.texH = atlasEntry.h - padAmount * 2;
c.texFlipped = atlasEntry.flipped;
}
else
{
var glyphSprite = glyphLut[-1];
var atlasEntry = packers[0].FindEntryWithIndex(glyphSprite.atlasIndex);
c.texOffsetX = 0;
c.texOffsetY = 0;
c.texX = atlasEntry.x + 1;
c.texY = atlasEntry.y + 1;
c.texW = 0;
c.texH = 0;
c.texFlipped = false;
}
c.texOverride = true;
}
tk2dEditor.Font.Builder.BuildFont(fontInfo, font.data, scale, font.charPadX, font.dupeCaps, false, null, 0);
}
开发者ID:GennrichJ,项目名称:GalaxyWars,代码行数:44,代码来源:tk2dSpriteCollectionBuilder.cs
示例18: SetUpTargetTexture
static void SetUpTargetTexture(tk2dSpriteCollection gen, Texture2D tex)
{
bool textureDirty = false;
string targetTexPath = AssetDatabase.GetAssetPath(tex);
TextureImporter importer = (TextureImporter)TextureImporter.GetAtPath(targetTexPath);
if (gen.maxTextureSize != importer.maxTextureSize)
{
importer.maxTextureSize = gen.maxTextureSize;
textureDirty = true;
}
TextureImporterFormat targetFormat;
switch (gen.textureCompression)
{
case tk2dSpriteCollection.TextureCompression.Uncompressed: targetFormat = TextureImporterFormat.AutomaticTruecolor; break;
case tk2dSpriteCollection.TextureCompression.Reduced16Bit: targetFormat = TextureImporterFormat.Automatic16bit; break;
case tk2dSpriteCollection.TextureCompression.Dithered16Bit_4444: targetFormat = Tex
|
请发表评论