예제 #1
0
    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];
    }
예제 #2
0
    //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;
    }
예제 #3
0
	void OnGUI () {
		GUILayout.Label ("Image to Export", EditorStyles.boldLabel);
		exportImg = (UPAImage)EditorGUILayout.ObjectField (exportImg, typeof(UPAImage), false);
		
		GUILayout.Label ("Export Settings", EditorStyles.boldLabel);
		texExtension = (TextureExtension)EditorGUILayout.EnumPopup("Save As:", texExtension);
		if (texExtension == TextureExtension.JPG) {
			#if UNITY_4_2
			GUILayout.Label ("Error: Export to JPG requires Unity 4.5+");
			#elif UNITY_4_3
			GUILayout.Label ("Error: Export to JPG requires Unity 4.5+");
			#endif
			
			GUILayout.Label ("Warning: JPG files will lose transparency.");
		}
		texType = (TextureType)EditorGUILayout.EnumPopup("Texture Type:", texType);
		
		EditorGUILayout.Space ();
		
		if ( GUILayout.Button ("Export", GUILayout.Height(30)) ) {
			
			if (exportImg == null) {
				EditorUtility.DisplayDialog(
					"Select Image",
					"You Must Select an Image first!",
					"Ok");
				return;
			}	
			
			bool succes = UPASession.ExportImage ( exportImg, texType, texExtension );
			if (succes)
				this.Close();
			UPAEditorWindow.window.Repaint();
		}
	}
예제 #4
0
    public static bool ExportImage(UPAImage img, TextureType type, TextureExtension extension)
    {
        string path = EditorUtility.SaveFilePanel(
            "Export image as " + extension.ToString(),
            "Assets/",
            img.name + "." + extension.ToString().ToLower(),
            extension.ToString().ToLower());

        if (path.Length == 0)
            return false;

        byte[] bytes;
        if (extension == TextureExtension.PNG) {
            // Encode texture into PNG
            bytes = img.GetFinalImage(true).EncodeToPNG();
        } else {
            // Encode texture into JPG

            #if UNITY_4_2
            bytes = img.GetFinalImage(true).EncodeToPNG();
            #elif UNITY_4_3
            bytes = img.GetFinalImage(true).EncodeToPNG();
            #elif UNITY_4_5
            bytes = img.GetFinalImage(true).EncodeToJPG();
            #else
            bytes = img.GetFinalImage(true).EncodeToJPG();
            #endif
        }

        path = FileUtil.GetProjectRelativePath(path);

        //Write to a file in the project folder
        File.WriteAllBytes(path, bytes);
        AssetDatabase.Refresh();

        TextureImporter texImp = AssetImporter.GetAtPath(path) as TextureImporter;

        if (type == TextureType.texture)
            texImp.textureType = TextureImporterType.Image;
        else if (type == TextureType.sprite) {
            texImp.textureType = TextureImporterType.Sprite;

            #if UNITY_4_2
            texImp.spritePixelsToUnits = 10;
            #elif UNITY_4_3
            texImp.spritePixelsToUnits = 10;
            #elif UNITY_4_5
            texImp.spritePixelsToUnits = 10;
            #else
            texImp.spritePixelsPerUnit = 10;
            #endif
        }

        texImp.filterMode = FilterMode.Point;
        texImp.textureFormat = TextureImporterFormat.AutomaticTruecolor;

        AssetDatabase.ImportAsset(path);

        return true;
    }
예제 #5
0
        public ApplicationContext(
            UndoRedoManager undoRedoManager,
            Channels channels,
            TextureResolution textureResolution,
            ImmutableTextureResolution chunkResolution,
            string cacheDirectory,
            TextureExtension cacheTextureExtension)
        {
            Assert.ArgumentNotNull(undoRedoManager, nameof(undoRedoManager));
            Assert.ArgumentNotNull(channels, nameof(channels));
            Assert.ArgumentNotNull(textureResolution, nameof(textureResolution));
            Assert.ArgumentNotNull(chunkResolution, nameof(chunkResolution));
            Assert.ArgumentNotNullOrEmptry(cacheDirectory, nameof(cacheDirectory));

            UndoRedoManager   = undoRedoManager;
            Channels          = channels;
            TextureResolution = textureResolution;

            CacheDirectory               = cacheDirectory;
            ResourcesCacheDirectory      = Path.Combine(CacheDirectory, "Resources");
            CacheTextureResolution       = cacheTextureExtension;
            CacheTextureResolutionString = CacheTextureResolution.ToString();

            initialChunkResolution = new ImmutableTextureResolution(chunkResolution.AsEnum);

            CalculateChunkProperties();

            Channels.Changed          += (s, e) => NotifyChanged();
            TextureResolution.Changed += (s, e) =>
            {
                CalculateChunkProperties();
                NotifyChanged();
            };
        }
예제 #6
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));
    }
예제 #7
0
        public void FillBrush(Vector2 world_point)
        {
            Vector3 v3           = rectTransform.InverseTransformPoint(new Vector3(world_point.x, world_point.y, 0));
            Vector2 canvas_point = new Vector2(v3.x, v3.y) - rectTransform.offsetMin;

            TextureExtension.FloodFillArea(drawable_texture, Convert.ToInt32(canvas_point.x), Convert.ToInt32(canvas_point.y), FreeDraw.Drawable.Pen_Colour);
            drawable_texture.Apply();
            cur_colors             = drawable_texture.GetPixels32();  //TODO: Использовать внутри FloodFillArea, Можно убрать нужна только для корректной команды Undo
            previous_drag_position = world_point;
        }
예제 #8
0
        public override bool Write(GH_IWriter writer)
        {
            writer.SetString("Image", ImageFile);
            writer.SetString("ImTexInterpolation", Interpolation.ToString());
            writer.SetString("ImTexColorSpace", ColorSpace.ToString());
            writer.SetString("ImTexTextureExtension", TextureExtension.ToString());
            writer.SetString("ImTexProjection", Projection.ToString());

            return(base.Write(writer));
        }
예제 #9
0
    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();
    }
예제 #10
0
        public void appendTextureExtensionMenu(TextureExtension it, ToolStripDropDown menu)
        {
            var u = this;

            Menu_AppendItem(
                menu,
                Utils.TextureExtensionToStringR(it),
                ((_, __) =>
            {
                u.TextureExtension = it; u.ExpireSolution(true);
            }),
                true, u.TextureExtension == it);
        }
예제 #11
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);

        resetThreshold();
        float match_percentage;
        bool  matching = TextureExtension.AreTexturesSameByColor(t1, current_texture, min_matching_percentage, out match_percentage);

        levelmgr.UpdateMatchPercentage(match_percentage);
        return(matching);
    }
예제 #12
0
    // 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();
    }
예제 #13
0
    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;
        }
    }
예제 #14
0
        public ResourceMetadata(ApplicationContext context, string name, Guid guid, TextureExtension textureExtension, ResourceType resourceType)
        {
            Assert.ArgumentNotNull(context, nameof(context));
            Assert.ArgumentNotNullOrEmptry(name, nameof(name));

            Name             = name;
            Guid             = guid;
            TextureExtension = textureExtension;
            ResourceType     = resourceType;

            Context = context;
            ResourceCacheDirectory = Path.Combine(context.ResourcesCacheDirectory, name + "_" + guid.ToString());
            TextureExtensionString = textureExtension.ToString();
        }
예제 #15
0
    //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;
    }
예제 #16
0
    void OnGUI()
    {
        GUILayout.Label("Image to Export", EditorStyles.boldLabel);
        exportImg = (UPAImage)EditorGUILayout.ObjectField(exportImg, typeof(UPAImage), false);

        GUILayout.Label("Export Settings", EditorStyles.boldLabel);
        texExtension = (TextureExtension)EditorGUILayout.EnumPopup("Save As:", texExtension);
        if (texExtension == TextureExtension.JPG)
        {
                        #if UNITY_4_2
            GUILayout.Label("Error: Export to JPG requires Unity 4.5+");
                        #elif UNITY_4_3
            GUILayout.Label("Error: Export to JPG requires Unity 4.5+");
                        #endif

            GUILayout.Label("Warning: JPG files will lose transparency.");
        }
        texType = (TextureType)EditorGUILayout.EnumPopup("Texture Type:", texType);

        EditorGUILayout.Space();

        if (GUILayout.Button("Export", GUILayout.Height(30)))
        {
            if (exportImg == null)
            {
                EditorUtility.DisplayDialog(
                    "Select Image",
                    "You Must Select an Image first!",
                    "Ok");
                return;
            }

            bool succes = UPASession.ExportImage(exportImg, texType, texExtension);
            if (succes)
            {
                this.Close();
            }
            UPAEditorWindow.window.Repaint();
        }
    }
예제 #17
0
    public static bool ExportImage(UPAImage img, TextureType type, TextureExtension extension)
    {
        string path = EditorUtility.SaveFilePanel(
            "Export image as " + extension.ToString(),
            "Assets/",
            img.name + "." + extension.ToString(),
            extension.ToString());

        if (path.Length == 0)
        {
            return(false);
        }

        Texture2D tex = new Texture2D(img.width, img.height, TextureFormat.RGBA32, false);

        for (int x = 0; x < img.width; x++)
        {
            for (int y = 0; y < img.height; y++)
            {
                tex.SetPixel(x, img.height - y - 1, img.map[x + y * img.width].color);
            }
        }

        tex.Apply();

        byte[] bytes;
        if (extension == TextureExtension.PNG)
        {
            // Encode texture into PNG
            bytes = tex.EncodeToPNG();
        }
        else
        {
            // Encode texture into JPG

                        #if UNITY_4_2
            bytes = tex.EncodeToPNG();
                        #elif UNITY_4_3
            bytes = tex.EncodeToPNG();
                        #elif UNITY_4_5
            bytes = tex.EncodeToJPG();
                        #else
            bytes = tex.EncodeToJPG();
                        #endif
        }

        GameObject.DestroyImmediate(tex);

        path = FileUtil.GetProjectRelativePath(path);

        //Write to a file in the project folder
        File.WriteAllBytes(path, bytes);
        AssetDatabase.Refresh();

        TextureImporter texImp = AssetImporter.GetAtPath(path) as TextureImporter;

        if (type == TextureType.texture)
        {
            texImp.textureType = TextureImporterType.Image;
        }
        else if (type == TextureType.sprite)
        {
            texImp.textureType = TextureImporterType.Sprite;

                        #if UNITY_4_2
            texImp.spritePixelsToUnits = 10;
                        #elif UNITY_4_3
            texImp.spritePixelsToUnits = 10;
                        #elif UNITY_4_5
            texImp.spritePixelsToUnits = 10;
                        #else
            texImp.spritePixelsPerUnit = 10;
                        #endif
        }

        texImp.filterMode = FilterMode.Point;

        AssetDatabase.ImportAsset(path);

        return(true);
    }
예제 #18
0
 public ResourceMetadata(ApplicationContext context, string name, TextureExtension textureExtension, ResourceType resourceType)
     : this(context, name, Guid.NewGuid(), textureExtension, resourceType)
 {
 }
예제 #19
0
 public static string TextureExtensionToStringR(TextureExtension d) => d.ToString().Replace("_", " ");
예제 #20
0
    public static bool ExportImage(UPAImage img, TextureType type, TextureExtension extension)
    {
        var folder   = "Assets/";
        var fileName = img.name + "." + extension.ToString().ToLower();

        if (PlayerPrefs.HasKey("pixelfile"))
        {
            folder   = PlayerPrefs.GetString("pixelfolder");
            fileName = PlayerPrefs.GetString("pixelfile");
        }

        string path = EditorUtility.SaveFilePanel(
            "Export image as " + extension.ToString(),
            folder,
            fileName,
            extension.ToString().ToLower());

        if (path.Length == 0)
        {
            return(false);
        }

        byte[] bytes;
        if (extension == TextureExtension.PNG)
        {
            // Encode texture into PNG
            bytes = img.GetFinalImage(true).EncodeToPNG();
        }
        else
        {
            // Encode texture into JPG

                        #if UNITY_4_2
            bytes = img.GetFinalImage(true).EncodeToPNG();
                        #elif UNITY_4_3
            bytes = img.GetFinalImage(true).EncodeToPNG();
                        #elif UNITY_4_5
            bytes = img.GetFinalImage(true).EncodeToJPG();
                        #else
            bytes = img.GetFinalImage(true).EncodeToJPG();
                        #endif
        }

        path = FileUtil.GetProjectRelativePath(path);

        PlayerPrefs.SetString("pixeldir", Path.GetDirectoryName(path));
        PlayerPrefs.SetString("pixelfile", Path.GetFileName(path));
        PlayerPrefs.Save();

        //Write to a file in the project folder
        File.WriteAllBytes(path, bytes);
        AssetDatabase.Refresh();

        TextureImporter texImp = AssetImporter.GetAtPath(path) as TextureImporter;

        if (type == TextureType.texture)
        {
            texImp.textureType = TextureImporterType.Default;
        }
        else if (type == TextureType.sprite)
        {
            texImp.textureType = TextureImporterType.Sprite;

                        #if UNITY_4_2
            texImp.spritePixelsToUnits = 10;
                        #elif UNITY_4_3
            texImp.spritePixelsToUnits = 10;
                        #elif UNITY_4_5
            texImp.spritePixelsToUnits = 10;
                        #else
            texImp.spritePixelsPerUnit = 32;
                        #endif
        }

        texImp.filterMode         = FilterMode.Point;
        texImp.textureCompression = TextureImporterCompression.Uncompressed;

        AssetDatabase.ImportAsset(path);

        return(true);
    }
예제 #21
0
    public static bool ExportImage(UPAImage img, TextureType type, TextureExtension extension)
    {
        string path = EditorUtility.SaveFilePanel(
            "Export image as " + extension.ToString(),
            "Assets/",
            img.name + "." + extension.ToString().ToLower(),
            extension.ToString().ToLower());

        if (path.Length == 0)
        {
            return(false);
        }

        byte[] bytes;
        if (extension == TextureExtension.PNG)
        {
            // Encode texture into PNG
            bytes = img.GetFinalImage(true).EncodeToPNG();
        }
        else
        {
            // Encode texture into JPG

                        #if UNITY_4_2
            bytes = img.GetFinalImage(true).EncodeToPNG();
                        #elif UNITY_4_3
            bytes = img.GetFinalImage(true).EncodeToPNG();
                        #elif UNITY_4_5
            bytes = img.GetFinalImage(true).EncodeToJPG();
                        #else
            bytes = img.GetFinalImage(true).EncodeToJPG();
                        #endif
        }

        path = FileUtil.GetProjectRelativePath(path);

        //Write to a file in the project folder
        File.WriteAllBytes(path, bytes);
        AssetDatabase.Refresh();

        TextureImporter texImp = AssetImporter.GetAtPath(path) as TextureImporter;

        if (type == TextureType.texture)
        {
            texImp.textureType = TextureImporterType.Default;
        }
        else if (type == TextureType.sprite)
        {
            texImp.textureType = TextureImporterType.Sprite;

                        #if UNITY_4_2
            texImp.spritePixelsToUnits = 10;
                        #elif UNITY_4_3
            texImp.spritePixelsToUnits = 10;
                        #elif UNITY_4_5
            texImp.spritePixelsToUnits = 10;
                        #else
            texImp.spritePixelsPerUnit = 10;
                        #endif
        }

        texImp.filterMode    = FilterMode.Point;
        texImp.textureFormat = TextureImporterFormat.AutomaticTruecolor;

        AssetDatabase.ImportAsset(path);

        return(true);
    }