public static ArrayList CreateSpots(Texture2D original, Texture2D fake, ref Texture2D tex) { if (original.width != fake.width || original.height != fake.height) { throw new ArgumentException("Not identical dimensions. " + "[" + original.width + ", " + original.height + "] != " + "[" + fake.width + ", " + fake.height + "]"); } for (var y = 0; y < original.height; ++y) { for (var x = 0; x < original.width; ++x) { var dif = original.GetPixel(x, y) - fake.GetPixel(x, y); if (!(dif).Equals(TransparentColor)) { dif.a = 1; tex.SetPixel(x, y, Color.red); } else { tex.SetPixel(x, y, Color.black); } } } var spots = new ArrayList(); for (var y = 0; y < original.height; ++y) { for (var x = 0; x < original.width; ++x) { var dif = original.GetPixel(x, y) - fake.GetPixel(x, y); if ((dif).Equals(TransparentColor)) { continue; } var bounds = FloodFill.floodFill(tex, Color.blue, new Vector2(x, y)); if (!bounds.Equals(new Rect())) { spots.Add(bounds); } } } return(spots); }
private void CreateMoochiSpots() { var d = Sprite.Create(levelTex, new Rect(differenceRect.x, differenceRect.y, differenceRect.width, differenceRect.height), new Vector2(0.5f, 0.5f), 128); var dTex = d.Crop(); Debug.Log("Fake: " + dTex.width + " " + dTex.height); // tolerance const float t = 20f; for (var y = 0; y < dTex.height; ++y) { for (var x = 0; x < dTex.width; ++x) { var c = dTex.GetPixel(x, y); if (c.r < ((254f - t) / 255f) || c.g < ((36f - t) / 255f) || c.g > ((37f + t) / 255f) || c.b > ((0f + t) / 255f)) { continue; } var bounds = FloodFill.floodFill(dTex, Color.blue, new Vector2(x, y)); if (!bounds.Equals(new Rect())) { spotFrames.Add(bounds); } } } Debug.Log(spotFrames.Count); dTex.Apply(); spriteTex = dTex; sprite = Sprite.Create(dTex, new Rect(0, 0, dTex.width, dTex.height), new Vector2(0.5f, 0.5f), 128); if (showDifferences) { replace.sprite = sprite; } }