public virtual void Remove(Sprite sprite) { ShaderGroup s = GetShaderGroupOrDefault(sprite.Shader); if (s == null) { return; } TextureGroup t = s.GetTextureGroupOrDefault(sprite.Texture); if (t == null) { return; } lock (group_lock) { if (t.group.Contains(sprite)) { t.group.Remove(sprite); sprite.Unload(); } valid = false; } count--; }
public virtual void Add(Sprite sprite) { lock (group_lock) { ShaderGroup s = GetShaderGroupOrDefault(sprite.Shader); TextureGroup t = s.GetTextureGroupOrDefault(sprite.Texture); t.group.Add(sprite); valid = false; } count++; }
public virtual bool Contains(Sprite sprite) { ShaderGroup group = GetShaderGroup(sprite.Shader); if (group != null) { TextureGroup tgroup = group.GetTextureGroup(sprite.Texture); if (tgroup != null) { return(tgroup.group.Contains(sprite)); } } return(false); }
public virtual ShaderGroup GetShaderGroupOrDefault(Shader shader) { foreach (ShaderGroup s in group) { if (s.key == shader) { return(s); } } var ss = new ShaderGroup { key = shader }; group.Add(ss); return(ss); }
public virtual void ForEach(Action <Sprite> callBack) { List <Sprite> invalids = new List <Sprite>(); List <TextureGroup> invalid_group = new List <TextureGroup>(); foreach (ShaderGroup shader in group) { foreach (TextureGroup texture in shader.group) { foreach (Sprite sprite in texture.group) { if (sprite.Texture.ID != texture.key.ID) { invalids.Add(sprite); invalid_group.Add(texture); continue; } callBack(sprite); } } } for (int i = 0; i < invalids.Count; i++) { Sprite sprite = invalids[i]; TextureGroup t = invalid_group[i]; ShaderGroup s = GetShaderGroupOrDefault(sprite.Shader); lock (group_lock) { if (t.group.Contains(sprite)) { t.group.Remove(sprite); } } Add(sprite); } invalids.Clear(); }