private static tk2dSpriteDefinition ConstructDefinition(Texture2D texture) { RuntimeAtlasSegment runtimeAtlasSegment = AtlasPacker.Pack(texture, false); Material material = new Material(ShaderCache.Acquire(PlayerController.DefaultShaderName)); material.mainTexture = runtimeAtlasSegment.texture; int width = texture.width; int height = texture.height; float num = 0f; float num2 = 0f; float num3 = width / 16f; float num4 = height / 16f; tk2dSpriteDefinition tk2dSpriteDefinition = new tk2dSpriteDefinition { normals = new Vector3[] { new Vector3(0f, 0f, -1f), new Vector3(0f, 0f, -1f), new Vector3(0f, 0f, -1f), new Vector3(0f, 0f, -1f) }, tangents = new Vector4[] { new Vector4(1f, 0f, 0f, 1f), new Vector4(1f, 0f, 0f, 1f), new Vector4(1f, 0f, 0f, 1f), new Vector4(1f, 0f, 0f, 1f) }, texelSize = new Vector2(0.0625f, 0.0625f), extractRegion = false, regionX = 0, regionY = 0, regionW = 0, regionH = 0, flipped = 0, complexGeometry = false, physicsEngine = tk2dSpriteDefinition.PhysicsEngine.Physics3D, colliderType = tk2dSpriteDefinition.ColliderType.None, collisionLayer = CollisionLayer.HighObstacle, position0 = new Vector3(num, num2, 0f), position1 = new Vector3(num + num3, num2, 0f), position2 = new Vector3(num, num2 + num4, 0f), position3 = new Vector3(num + num3, num2 + num4, 0f), material = material, materialInst = material, materialId = 0, uvs = runtimeAtlasSegment.uvs, boundsDataCenter = new Vector3(num3 / 2f, num4 / 2f, 0f), boundsDataExtents = new Vector3(num3, num4, 0f), untrimmedBoundsDataCenter = new Vector3(num3 / 2f, num4 / 2f, 0f), untrimmedBoundsDataExtents = new Vector3(num3, num4, 0f) }; tk2dSpriteDefinition.name = texture.name; return(tk2dSpriteDefinition); }
public static void ReplaceTexture(tk2dSpriteDefinition frame, Texture2D replacement, bool pack = true) { frame.flipped = tk2dSpriteDefinition.FlipMode.None; frame.materialInst = new Material(frame.material); frame.texelSize = replacement.texelSize; frame.extractRegion = pack; if (pack) { RuntimeAtlasSegment segment = Packer.Pack(replacement); frame.materialInst.mainTexture = segment.texture; frame.uvs = segment.uvs; } else { frame.materialInst.mainTexture = replacement; frame.uvs = _DefaultUVs; } }