public void ColoredPixelsFinalDecodingPass(List <Vector2Int> pixels) /////Does cleaning up of the data that was parsed { if (pixels.Count != 0) { List <GameObject> spawnedCubes = new List <GameObject>(0); int i = 0; while (i < pixels.Count) { Vector3 spawnPosXYZ = new Vector3(pixels[i].x, pixels[i].y, 0); GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube); cube.transform.position = spawnPosXYZ; spawnedCubes.Add(cube); parsedTrackedPositions.Add(new Vector2Int((int)spawnPosXYZ.x, (int)spawnPosXYZ.y)); Collider[] hitColliders = Physics.OverlapSphere(cube.transform.position, minDotDistance); for (int j = 0; j < hitColliders.Length; j++) { if (hitColliders[j].gameObject != cube) { if (parsedTrackedPositions.Contains(new Vector2Int((int)hitColliders[j].transform.position.x, (int)hitColliders[j].transform.position.y))) { parsedTrackedPositions.Remove(new Vector2Int((int)hitColliders[j].transform.position.x, (int)hitColliders[j].transform.position.y)); } spawnedCubes.Remove(hitColliders[j].gameObject); DestroyImmediate(hitColliders[j].gameObject); } } i++; } if (saveAsText) { JsonSerialising.SerialiseList(fileLocation, fileName, parsedTrackedPositions); //deserialisedPositions = JsonSerialising.DeserialiseVector2IntList(fileLocation, fileName); } for (int j = 0; j < spawnedCubes.Count; j++) { DestroyImmediate(spawnedCubes[j]); spawnedCubes.RemoveAt(j); } } else { Debug.Log("No red pixels in this image."); } }
private void OnGUI() { showAssets = EditorGUILayout.Foldout(showAssets, "TEXT ASSETS"); if (showAssets) { if (GUILayout.Button("ADD FRAME")) { assets.Add(new TextAsset()); } if (GUILayout.Button("REMOVE FRAME") && assets.Count >= 1) { assets.RemoveAt(assets.Count - 1); } EditorGUILayout.LabelField("Drop text-assets here:"); for (int i = 0; i < assets.Count; i++) { assets[i] = EditorGUILayout.ObjectField(assets[i], typeof(TextAsset), true) as TextAsset; } } frameToDecode = EditorGUILayout.IntField("FRAME TO DECODE", frameToDecode); EditorGUILayout.LabelField("NOTE: TEXT ASSETS ARE NOT THE SAME THING AS .TXT FILES!", EditorStyles.boldLabel); if (GUILayout.Button("DECODE SINGLE TEXT ASSET")) { DecodeSingleImage(frameToDecode); } if (GUILayout.Button("DECODE ALL TEXT ASSETS")) { DecodeAllImages(); } saveAsText = EditorGUILayout.Toggle("Save as text file", saveAsText); EditorGUILayout.LabelField(".TXT FILE SAVING AND LOADING VARIABLES", EditorStyles.boldLabel); EditorGUILayout.LabelField("FILE LOCATION"); fileLocation = EditorGUILayout.TextField(fileLocation); EditorGUILayout.LabelField("FILE NAME"); fileName = EditorGUILayout.TextField(fileName); EditorGUILayout.LabelField("ANIMATIONS"); if (curveX != null && curveY != null) { curveX = EditorGUILayout.CurveField("Animation on X", curveX); curveY = EditorGUILayout.CurveField("Animation on Y", curveY); } if (GUILayout.Button("DESERIALISE TEXT FILE INTO XY COÖRDINATES")) { deserialisedList = JsonSerialising.DeserialiseVector2IntList(fileLocation, fileName); } EditorGUILayout.LabelField("DESERIALISED .TXT FILE DATA", EditorStyles.boldLabel); foreach (Vector2Int pair in deserialisedList) { EditorGUILayout.LabelField("X: " + pair.x.ToString() + ", Y: " + pair.y.ToString()); } //EditorGUILayout.LabelField("Add animation here:"); SAVEN ALS ANIMATIE GING HELAAS NIET, OMDAT UNITY'S OBJECTFIELD BIJ ANIMATION'S NOG DE LEGACYVERSIE GEBRUIKT, WAARDOOR JE GEEN ANIMATION KAN ASSIGNEN IN EEN CUSTOM EDITOR. //anim = EditorGUILayout.ObjectField(anim, typeof(Animation), true) as Animation; /* * if(GUILayout.Button("SAVE AS ANIMATIONCLIP")) * { * //SaveAsAnimationClip(curveX, curveY); * } */ }