static public Sprite RequestSprite(Sprite originalSprite, Request.Type type) { if (originalSprite == null) { return(null); } Sprite spriteObject = null; Dictionary <Sprite, Sprite> dictionary = dictionaries.Get(type); bool exist = dictionary.TryGetValue(originalSprite, out spriteObject); if (exist) { if (spriteObject == null || spriteObject.texture == null) { Request.requestList.Add(new Request(originalSprite, type)); return(null); } return(spriteObject); } else { Request.requestList.Add(new Request(originalSprite, type)); return(null); } }
static public Sprite RequestAccess(Sprite originalSprite, Request.Type type) { Sprite spriteObject = null; Dictionary <Sprite, Sprite> dictionary = dictionaries.Get(type); bool exist = dictionary.TryGetValue(originalSprite, out spriteObject); if (exist) { if (spriteObject == null || spriteObject.texture == null) { dictionary.Remove(originalSprite); spriteObject = AddSprite(originalSprite, type); dictionary.Add(originalSprite, spriteObject); } return(spriteObject); } else { spriteObject = AddSprite(originalSprite, type); dictionary.Add(originalSprite, spriteObject); return(spriteObject); } }
public void Post(Request.Type t, Action before, Action after) { var r = new Request(); r.type = t; r.before = before; r.after = after; q.Enqueue(r); }
static private Sprite AddSprite(Sprite sprite, Request.Type type) { if (sprite == null || sprite.texture == null) { return(null); } return(GenerateSprite(sprite, type)); }
void Execute(ref Request req) { HandleImpl handle = req.handle; Request.Type type = req.type; if (handle.done) { // 終わってれば前の要求に重なっている。でもバグじゃね? Debug.Assert(false, "Handle.done == true. バグじゃね?"); } else if (type == Request.Type.None) { // 何もしない Debug.Assert(false, "Request.type == None. バグじゃね?"); } else if (type == Request.Type.Begin) // 開いてない。開ける要求と解釈する { Debug.Assert(!handle.opened); handle.BeginWrite(_root, _temporaryFilePostfix); } else if (type == Request.Type.End) // 書き込むものがない。閉じる要求と解釈する { handle.EndWrite(_root); } else if (type == Request.Type.Abort) { handle.Abort(); } else if (type == Request.Type.Write) { int length0 = Mathf.Min(_buffer.Length - req.offset, req.length); handle.Write(_buffer, req.offset, length0); int length1 = req.length - length0; if (length1 > 0) { handle.Write(_buffer, 0, length1); } int rp = _readPos; rp += req.length; if (rp >= _buffer.Length) { rp -= _buffer.Length; } Interlocked.Exchange(ref _readPos, rp); } else { Debug.Assert(false, "Unknown RequestType. " + (int)type); } }
void Enqueue(Request.Type type, Handle handle, int offset, int length) { Request req; req.type = type; req.handle = handle as HandleImpl; req.offset = offset; req.length = length; lock (_thread) // ロック消したい { _requestQueue.Enqueue(req); } _semaphore.Release(); }
public List <Sprite> GetList(Request.Type type) { List <Sprite> list = null; switch (type) { case Request.Type.Normal: list = spritesDefaultMask; break; case Request.Type.WhiteMask: list = spritesWhiteMask; break; case Request.Type.BlackMask: list = spritesBlackMask; break; } return(list); }
public Dictionary <Sprite, Sprite> Get(Request.Type type) { Dictionary <Sprite, Sprite> dictionary = null; switch (type) { case Request.Type.Normal: dictionary = defaultMask; break; case Request.Type.WhiteMask: dictionary = whiteMask; break; case Request.Type.BlackMask: dictionary = blackMask; break; } return(dictionary); }
static public Sprite GenerateSprite(Sprite sprite, Request.Type type) { Texture atlasTexture = GetAtlasPage(); Texture2D texture = atlasTexture.GetTexture(); if (texture == null) { return(null); } if (atlasTexture.currentX + sprite.rect.width >= AtlasSystem.Texture.atlasSize) { atlasTexture.currentX = 1; atlasTexture.currentY += atlasTexture.currentHeight; atlasTexture.currentHeight = 0; } if (atlasTexture.currentY + sprite.rect.height >= AtlasSystem.Texture.atlasSize) { Debug.Log("Error: Lighting Atlas Overhead (" + AtlasSystem.Texture.atlasSize + ") (" + sprite + ")"); Lighting2D.disable = true; return(null); } Texture2D myTexture2D = GetTextureFromSprite(sprite); Color[] intputPixels = myTexture2D.GetPixels(0, 0, myTexture2D.width, myTexture2D.height); int inTextureWidth = myTexture2D.width; int inTextureHeight = myTexture2D.height; int inLength = intputPixels.Length; Color[] outputPixels = texture.GetPixels(0, 0, texture.width, texture.height); int textureWidth = texture.width; int textureHeight = texture.height; Color color; switch (type) { case Request.Type.Normal: for (int i = 0; i < inLength; i++) { color = intputPixels[i]; color.a = 1; int ix = atlasTexture.currentX + (i % inTextureWidth); int iy = atlasTexture.currentY + (i / inTextureHeight); outputPixels[ix + textureWidth * iy] = color; } break; case Request.Type.WhiteMask: for (int i = 0; i < inLength; i++) { color = intputPixels[i]; color.r = 1; color.g = 1; color.g = 1; int ix = atlasTexture.currentX + (i % inTextureWidth); int iy = atlasTexture.currentY + (i / inTextureHeight); outputPixels[ix + textureWidth * iy] = color; } break; case Request.Type.BlackMask: for (int i = 0; i < inLength; i++) { color = intputPixels[i]; color.a = ((1 - color.r) + (1 - color.g) + (1 - color.b)) / 3; color.r = 0; color.g = 0; color.b = 0; int ix = atlasTexture.currentX + (i % inTextureWidth); int iy = atlasTexture.currentY + (i / inTextureHeight); outputPixels[ix + textureWidth * iy] = color; } break; } texture.SetPixels(0, 0, textureWidth, textureHeight, outputPixels); texture.Apply(); atlasTexture.spriteCount++; Vector2 pivot = new Vector2(sprite.pivot.x / sprite.rect.width, sprite.pivot.y / sprite.rect.height); Sprite output = Sprite.Create(texture, new Rect(atlasTexture.currentX, atlasTexture.currentY, myTexture2D.width, myTexture2D.height), pivot, sprite.pixelsPerUnit); atlasTexture.currentX += (int)sprite.rect.width; atlasTexture.currentHeight = Mathf.Max(atlasTexture.currentHeight, (int)sprite.rect.height); return(output); }