Hello Community! I have been using Editor XR for one of my projects, and I created a new tool to get the coordinates where I am pointing the ray and save the vector coordinates into a JSON file(or .txt file). But it is not working, rather I am getting just empty curly braces in my file. What is the problem? Code (CSharp): using UnityEngine; using System; using System.IO; namespace UnityEditor.Experimental.EditorVR.Tools { [MainMenuItem("Json Exporter", "primitive", "Saving data to Json")] [SpatialMenuItem("Json Exporter", "primtive", "Saving data to Json")] sealed class JsonSaver : MonoBehaviour, ITool, IConnectInterfaces, IInstantiateMenuUI, IUsesSpatialHash, IUsesViewerScale, ISelectTool, IIsHoveringOverUI, IIsMainMenuVisible, IRayVisibilitySettings, IRequestFeedback, IMenuIcon { //public JsonData getdata; [SerializeField] Sprite m_Icon; [Serializable] public class VerticesData { public Vector3[] vertices = new Vector3[d]; } public VerticesData verticesData; string dataPath; public static int d; public Sprite icon { get { return m_Icon; } } public Transform rayOrigin { get; set; } void Start() { dataPath = Path.Combine(Application.persistentDataPath, "CharacterData.txt"); d = CreateTool.a; verticesData.vertices = CreateTool.VerticesData.vertices; } void Update() { SaveCharacter(verticesData, dataPath); Debug.Log(Application.persistentDataPath); } static void SaveCharacter(VerticesData data, string path) { string jsonString = JsonUtility.ToJson(data); using (StreamWriter streamWriter = File.CreateText(path)) { streamWriter.Write(jsonString); } } void OnDestroy() { //ObjectUtils.Destroy(m_ToolMenu); if (rayOrigin == null) return; this.RemoveRayVisibilitySettings(rayOrigin, this); this.ClearFeedbackRequests(); } } } Here, CreateTool is a different tool which is getting the coordinates of ray pointer. Also, I am simply defining the variable vertices in CreateTool script. Code (CSharp): [Serializable] public class VerticesData { public static Vector3[] vertices = new Vector3[a]; } // and later in code putting value of vertices as sidesy = rayOrigin.position[1]; VerticesData.vertices[a] = rayOrigin.position + rayOrigin.forward * sidesy * this.GetViewerScale();; Am I defining the code in wrong manner? Thanks to everyone!! Awaiting your comments. If I have described something in a wrong way or their is a confusion, please feel free to ask.
Hi @KushMathur, were you able to figure this out? This is likely more of an issue with serialization than it is with EditorXR. For starters, you probably don't need a lot of interfaces that you are including. I think you'd only need ITool at the very least since you are copying data from CreateTool.
I did created a temporary solution for it, I am putting a non visible sphere where we point the mouse with a tag, and later a new script will take the tags and will take the transform.position of these spheres. It is working, I do not know but, maybe it will be having performance issue later in the project. Thanks for reply though!