//Detect current clicks on the GameObject (the one with the script attached) public void OnPointerDown(PointerEventData pointerEventData) { tex = TextureExtension.textureFromSprite(editable_map.GetComponent <Image>().sprite); Rect r = editable_map.GetComponent <RectTransform>().rect; Vector2 localPoint; RectTransformUtility.ScreenPointToLocalPointInRectangle(editable_map.GetComponent <RectTransform>(), Input.mousePosition, null, out localPoint); int px = Mathf.Clamp(0, (int)(((localPoint.x - r.x) * tex.width) / r.width), tex.width); int py = Mathf.Clamp(0, (int)(((localPoint.y - r.y) * tex.height) / r.height), tex.height); Color32 col = tex.GetPixel(px, py); Color32 color32 = tex.GetPixel(px, py); //Debug.Log("(LocalPoint X/Y:" + localPoint.x + ", " + localPoint.y + ") "); //Debug.Log("(Rect X/Y:" + r.x + ", " + r.y + ") "); //Debug.Log("(Rect W/H:" + r.width + ", " + r.height + ") "); //Debug.Log("(Pixel X/Y:" + px + ", " + py + ") "); //Debug.Log("(Texture W/H:" + tex.width + ", " + tex.height + ") "); tex.FloodFillAreaWithTolerance(px, py, ColorStatus.current_color, ColorStatus.flood_fill_tolerance); //texture.DrawRectangle(new Rect(px, (tex.height - py), 20, 20), Color.red); tex.Apply(); if (gameObject.GetComponent <InitMap>().AreImagesMatching(tex)) { var sprite = Resources.Load <Sprite>("done"); editable_map.GetComponent <Image>().sprite = sprite; Debug.Log("Yohooooo"); } //editable_map.GetComponent<Image>().sprite = tex; }
void SetColorButtons() { GameObject color_btn = GameObject.Find("Color1"); GameObject parent = GameObject.Find("Colors"); foreach (Transform child in parent.transform) { GameObject.Destroy(child.gameObject); } Transform btn_transform = color_btn.transform; Texture2D t1 = TextureExtension.textureFromSprite(original_map.GetComponent <Image>().sprite); Color[] colors_comparable = TextureExtension.GetMainColorsFromTexture2(t1, min_pixels_per_color); Debug.Log("Colors found in original image:" + colors_comparable.Length); for (int i = 0; i < colors_comparable.Length; ++i) { //string button_name = "Color" + (i+1).ToString(); //GameObject btn = GameObject.Find(button_name); GameObject colorbtn = Instantiate(color_btn); colorbtn.GetComponent <Image>().color = colors_comparable[i];// colors_comparable[i].ToColor32(); Debug.Log(colors_comparable[i]); colorbtn.transform.SetParent(parent.transform); } ColorStatus.current_color = colors_comparable[0]; GameObject selected_color = GameObject.Find("selected_color"); selected_color.GetComponent <Image>().color = colors_comparable[0]; }
public bool AreImagesMatching(Texture2D current_texture) { Texture2D t1 = TextureExtension.textureFromSprite(original_map.GetComponent <Image>().sprite); //Texture2D t2 = TextureExtension.textureFromSprite(editable_map.GetComponent<Image>().sprite); return(TextureExtension.AreTexturesSameByColor(t1, current_texture, min_matching_percentage)); }
public void Init() { original_map.SetActive(false); editable_map.SetActive(true); levelmgr = GameObject.Find("LevelManager").GetComponent <LevelManager>(); GameObject.Find("CountryName").GetComponent <Text>().text = levelmgr.GetCountryForLevel(levelmgr.GetCurrentLevel()); SetColorButtons(); Initial_Texture = new Texture2D((int)editable_map.GetComponent <Image>().sprite.rect.width, (int)editable_map.GetComponent <Image>().sprite.rect.height, TextureExtension.textureFromSprite(editable_map.GetComponent <Image>().sprite).format, false); Graphics.CopyTexture(TextureExtension.textureFromSprite(editable_map.GetComponent <Image>().sprite), Initial_Texture); Initial_Texture.Apply(); }
public bool AreImagesMatching(Texture2D current_texture) { Texture2D t1 = TextureExtension.textureFromSprite(original_map.GetComponent <Image>().sprite); //Texture2D t2 = TextureExtension.textureFromSprite(editable_map.GetComponent<Image>().sprite); resetThreshold(); float match_percentage; bool matching = TextureExtension.AreTexturesSameByColor(t1, current_texture, min_matching_percentage, out match_percentage); levelmgr.UpdateMatchPercentage(match_percentage); return(matching); }
// Use this for initialization void Start() { original_map = GameObject.Find("OriginalMap"); editable_map = GameObject.Find("EditableMap"); original_map.SetActive(false); editable_map.SetActive(true); SetColorButtons(); Initial_Texture = new Texture2D((int)editable_map.GetComponent <Image>().sprite.rect.width, (int)editable_map.GetComponent <Image>().sprite.rect.height, TextureExtension.textureFromSprite(editable_map.GetComponent <Image>().sprite).format, false); Graphics.CopyTexture(TextureExtension.textureFromSprite(editable_map.GetComponent <Image>().sprite), Initial_Texture); Initial_Texture.Apply(); Reset(); }
void Button_active() { GameObject myEditable_map = GameObject.Find("EditableMap"); Texture2D editable_Texture = TextureExtension.textureFromSprite(myEditable_map.GetComponent <Image>().sprite); if (myEditable_map == true) { button.GetComponent <Button>().interactable = true; } else { button.GetComponent <Button>().interactable = true; } }
//Detect current clicks on the GameObject (the one with the script attached) public void OnPointerDown(PointerEventData pointerEventData) { tex = TextureExtension.textureFromSprite(editable_map.GetComponent <Image>().sprite); Rect r = editable_map.GetComponent <RectTransform>().rect; Vector2 localPoint; RectTransformUtility.ScreenPointToLocalPointInRectangle(editable_map.GetComponent <RectTransform>(), Input.mousePosition, null, out localPoint); int px = Mathf.Clamp(0, (int)(((localPoint.x - r.x) * tex.width) / r.width), tex.width); int py = Mathf.Clamp(0, (int)(((localPoint.y - r.y) * tex.height) / r.height), tex.height); Color32 col = tex.GetPixel(px, py); Color32 color32 = tex.GetPixel(px, py); audio2.Play(); //Debug.Log("(LocalPoint X/Y:" + localPoint.x + ", " + localPoint.y + ") "); //Debug.Log("(Rect X/Y:" + r.x + ", " + r.y + ") "); //Debug.Log("(Rect W/H:" + r.width + ", " + r.height + ") "); //Debug.Log("(Pixel X/Y:" + px + ", " + py + ") "); //Debug.Log("(Texture W/H:" + tex.width + ", " + tex.height + ") "); tex.FloodFillAreaWithTolerance(px, py, ColorStatus.current_color, ColorStatus.flood_fill_tolerance); //texture.DrawRectangle(new Rect(px, (tex.height - py), 20, 20), Color.red); tex.Apply(); if (gameObject.GetComponent <InitMap>().AreImagesMatching(tex)) { original_map.SetActive(true); //editable_map.SetActive(false); //TODO Right Now its a hack in the layer it is pasted //var sprite = Resources.Load<Sprite>("done"); audio1.Play(); //editable_map.GetComponent<Image>().sprite = sprite; //Debug.Log("Yohooooo"); Button next_btn = GameObject.Find("Next_button").GetComponent <Button>(); next_btn.interactable = true; dykPopup.SetActive(true); LevelManager levelManager = GameObject.Find("LevelManager").GetComponent <LevelManager>(); levelManager.boTimerActive = false; //Disabling Timer TODO - Better to create a delegate here particles.SetActive(true); } //editable_map.GetComponent<Image>().sprite = tex; }