public Atlas(string def, string alt1, string alt2, string alt3, string alt4, string txa, int z_order, float scale_coefficient_ = 1) { textures[0] = Textures.loadTexture(def, z_order); textures[1] = Textures.loadTexture(alt1, z_order, false); textures[2] = Textures.loadTexture(alt2, z_order, false); textures[3] = Textures.loadTexture(alt3, z_order, false); textures[4] = Textures.loadTexture(alt4, z_order, false); texture = textures[0]; active_texture = 0; max_textures = 5; texture.z_order = z_order; for (int i = 0; i < max_textures; ++i) { textures[i].z_order = z_order; } scale_coefficient = scale_coefficient_; BinReader tr = new BinReader(Path.Combine(Application.streamingAssetsPath, txa)); if (txa.EndsWith(txa_extension)) { readTxa(tr); } else if (txa.EndsWith(fnt_extension)) { readFnt(tr); } }
public void addSprite(GHTexture texture, Vector2 position, float angle, Vector2 size, Bounds uv, Vector4 color, Vector2 center) { if (angle == 0 && center == Vector2.zero) { addSprite(texture, position + new Vector2(-size.x, -size.y), position + new Vector2(size.x, -size.y), position + new Vector2(size.x, size.y), position + new Vector2(-size.x, size.y), uv, color); } else { matrix = Matrix.Identity(matrix); matrix = Matrix.Translation(matrix, -center); matrix = Matrix.Scale(matrix, size * 2); matrix = Matrix.Rotate(matrix, angle); matrix = Matrix.Translation(matrix, position); addSprite(texture, new Vector2(matrix[0, 2], matrix[1, 2]), new Vector2(matrix[0, 0] + matrix[0, 2], matrix[1, 0] + matrix[1, 2]), new Vector2(matrix[0, 0] + matrix[0, 1] + matrix[0, 2], matrix[1, 0] + matrix[1, 1] + matrix[1, 2]), new Vector2(matrix[0, 1] + matrix[0, 2], matrix[1, 1] + matrix[1, 2]), uv, color); } }
public Atlas(string png, int z_order, float scale_coefficient_ = 1) { textures[0] = Textures.loadTexture(png, z_order); texture = textures[0]; active_texture = 0; max_textures = 1; texture.z_order = z_order; for (int i = 0; i < max_textures; ++i) { textures[i].z_order = z_order; } Texture2D t = texture.texture(); scale_coefficient = scale_coefficient_; n_sprites = 1; sprites = new AtlasSprite[1]; sprites[0].bounds = new Bounds(new Vector2(0.0f, 1.0f), new Vector2(1.0f, 0.0f)); sprites[0].bounds.uv_index = 0; sprites[0].center = new Vector2(0.5f, 0.5f); sprites[0].size = new Vector2(t.width, t.height); }
public static void draw() { if (reset_scene) { //Resources.UnloadUnusedAssets(); reset_scene = false; } if (wipe_textures) { GHTexture.freeLRU(); //Resources.UnloadUnusedAssets(); System.GC.Collect(); wipe_textures = false; return; } if (textures.stage_drdog_noon == null) { textures.loadTheRest(); } background.draw(); top_state.draw(); renderer.blit(); renderer.clearScene(); }
public void addSprite(GHTexture texture, Vector2 position, Vector2 size, Bounds uv, Vector4 color, float amp, bool outline) { addSprite(texture, position + new Vector2(-size.x, -size.y), position + new Vector2(size.x, -size.y), position + new Vector2(size.x, size.y), position + new Vector2(-size.x, size.y), uv, color, 0, amp, outline); }
public GHTexture(GHTexture to_clone) { hud = to_clone.hud; scissored = to_clone.hud; texture2d = to_clone.texture2d; last_touched = to_clone.last_touched; filename = to_clone.filename; mipmap = to_clone.mipmap; pf = to_clone.pf; }
public static GHTexture loadTexture(string name, int z_order, bool upd = true) { var result = new GHTexture("" + name, false); if (upd) { AppMain.renderer.addTexture(result, z_order); } return(result); }
public Atlas(string png, Vector2 sprite_size, int z_order) { textures[0] = Textures.loadTexture(png, z_order); texture = textures[0]; active_texture = 0; max_textures = 1; texture.z_order = z_order; for (int n = 0; n < max_textures; ++n) { textures[n].z_order = z_order; } Texture2D t = texture.texture(); Vector2 dimensions = new Vector2(t.width / sprite_size.x, t.height / sprite_size.y); n_sprites = (int)System.Math.Ceiling(dimensions.x) * (int)System.Math.Ceiling(dimensions.y); sprites = new AtlasSprite[n_sprites]; Vector2 size = new Vector2(1.0f / dimensions.x, 1.0f / dimensions.y); int i = 0; for (int y = 0; y < dimensions.y; ++y) { for (int x = 0; x < dimensions.x; ++x) { sprites[i].center = new Vector2(0.5f, 0.5f); sprites[i].size = sprite_size; sprites[i].bounds = new Bounds(new Vector2(size.x * x * 1.0f, 1.0f - size.y * y * 1.0f), new Vector2(size.x * ((x + 1) * 1.0f), 1.0f - size.y * ((y + 1) * 1.0f))); sprites[i].bounds.uv_index = i; i++; } } }
public MeshInfoPair addTexture(GHTexture texture, int z_order) { MeshInfoPair m; if (meshinfos.ContainsKey(texture)) { m = meshinfos[texture]; /* NOTE(shane): this is required for pallet swapped assets */ if (texture.flag_z_order_reattach) { texture.flag_z_order_reattach = false; texture_order[z_order] = texture; } } else { m = new MeshInfoPair(); meshinfos[texture] = m; texture_order[z_order] = texture; } return(m); }
public void switchTexture(int set) { active_texture = Mathf.Clamp(set, 0, max_textures - 1); texture = textures[active_texture]; texture.flag_z_order_reattach = true; }
public void addSprite(GHTexture texture, Vector2 tl, Vector2 tr, Vector2 br, Vector2 bl, Bounds uv, Vector4 color, int stamp = 0, float amp = 0.0f, bool outline = false) { if (color.w == 0) { return; } texture.touch(); float z = -10 - texture.z_order; MeshInfoPair mp = addTexture(texture, texture.z_order); MeshInfo m = outline ? mp.m[1] : mp.m[0]; // outline is m[1], normal is m[0] m.material = texture.material; // this is a ref not a copy but that's okay float highlight_amt = 0; if (amp >= 1) { highlight_amt = color.x - 0.5f; color = Vector4.one; } // technically, topleft and sizes should not be vertex attributes, but uniforms. // however, the materialpropertyblock thingie doesn't seem to be working properly for some reason, // and this is pre-scissor so hey m.topleft.Add(tl); m.topleft.Add(tl); m.topleft.Add(tl); m.topleft.Add(tl); Vector2 sizes = br - tl; m.sizes.Add(sizes); m.sizes.Add(sizes); m.sizes.Add(sizes); m.sizes.Add(sizes); if (texture.scissored) { doScissor(ref uv, ref tl, ref tr, ref br, ref bl, ref color); } m.vertices.Add(new Vector3(tl.x, tl.y, z)); m.vertices.Add(new Vector3(tr.x, tr.y, z)); m.vertices.Add(new Vector3(br.x, br.y, z)); m.vertices.Add(new Vector3(bl.x, bl.y, z)); m.uvs.Add(uv.Point00); m.uvs.Add(uv.Point10); m.uvs.Add(uv.Point11); m.uvs.Add(uv.Point01); m.colors.Add(color); m.colors.Add(color); m.colors.Add(color); m.colors.Add(color); m.indices.Add(m.index); m.indices.Add(m.index + 2); m.indices.Add(m.index + 1); m.indices.Add(m.index); m.indices.Add(m.index + 3); m.indices.Add(m.index + 2); m.index += 4; // add highlight polygon to replicate amplification if (amp >= 1) { addSprite(AppMain.textures.highlight.texture, tl, tr, br, bl, new Bounds(new Vector2(0, 0), new Vector2(1, 1)), new Vector4(1, 1, 1, highlight_amt), stamp, 0, outline); } }