public void BulkImport() { #if UNITY_EDITOR string path = UnityEditor.EditorUtility.OpenFolderPanel("Load png image textures", "", ""); StringBuilder scriptText = new StringBuilder(); foreach (string pngFile in System.IO.Directory.GetFiles(path, "*.png")) { string fileName = System.IO.Path.GetFileNameWithoutExtension(pngFile); int pos = fileName.IndexOf('_'); if (pos >= 0) { fileName = fileName.Substring(0, pos); } Texture2D tex = new Texture2D(1, 1, TextureFormat.ARGB32, false, false); tex.LoadImage(System.IO.File.ReadAllBytes(pngFile)); Texture2D scaled = ScaleTexture(tex, ImageGestureRecognizer.ImageRows, ImageGestureRecognizer.ImageColumns); ImageGestureImage image = CreateImageGestureImageFromTexture(scaled); Destroy(tex); Destroy(scaled); scriptText.Append(image.GetCodeForRowsInitialize(fileName)); scriptText.AppendLine(","); if (AutoAddImages) { ImageGesture.GestureImages.Add(image); RecognizableImages[image] = fileName; } } ScriptText.text = scriptText.ToString(); #endif }
private void UpdateImage() { Texture2D t = CreateTextureFromImageGestureImage(ImageGesture.Image); Image.texture = t; LastImage = ImageGesture.Image.Clone(); if (ImageGesture.MatchedGestureImage == null) { MatchLabel.text = "No match"; // no match add a script entry if (ScriptText != null) { ScriptText.text += LastImage.GetCodeForRowsInitialize(ImageNameText == null ? null : ImageNameText.text) + "," + System.Environment.NewLine; if (AutoAddImages && ImageNameText != null && ImageNameText.text.Length != 0) { ImageGesture.GestureImages.Add(LastImage); RecognizableImages[LastImage] = ImageNameText.text; } } } else { MatchLabel.text = "Match: " + RecognizableImages[ImageGesture.MatchedGestureImage]; } MatchLabel.text += " (" + ImageGesture.MatchedGestureCalculationTimeMilliseconds + " ms)"; ImageGesture.Reset(); }
public void CopyScriptToClipboard() { #if UNITY_EDITOR if (lastImage == null) { Debug.LogError("No image created yet"); } else { TextEditor te = new TextEditor(); te.text = lastImage.GetCodeForRowsInitialize(); te.SelectAll(); te.Copy(); } #endif }