Commit 3857ad31 authored by Sylvain Renault's avatar Sylvain Renault
Browse files

New baseWindow class for the UI editor windows.

Messagebox is shown before deleting an object from its window.
Some enhanced UI updates.
parent 9dbc0e0c
Loading
Loading
Loading
Loading
+117
Changes for Assets/ETSI.ARF/ARF World Storage API/Editor/Windows/BaseWindow.cs: 117 added lines, 0 removed lines.
Original line number Original line Diff line number Diff line
//
// ARF - Augmented Reality Framework (ETSI ISG ARF)
//
// Copyright 2024 ETSI
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Last change: June 2024
//

#define isDEBUG

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;

using UnityEngine;
using UnityEditor;
using TMPro;

using ETSI.ARF.WorldStorage.REST;
using ETSI.ARF.OpenAPI.WorldStorage;

namespace ETSI.ARF.WorldStorage.UI
{
    public abstract class BaseWindow<T> : EditorWindow
    {
        [HideInInspector] public WorldStorageServer worldStorageServer;
        [HideInInspector] public WorldStorageUser worldStorageUser;

        [SerializeField] public List<string> trackables = new List<string>();

        //
        // Keyvalues
        //
        [SerializeField] protected KeyvalueTagList keyValueTags = new KeyvalueTagList();
        protected List<(string, string)> keyValuesFixed = new List<(string, string)>(3)
        {
            ("", ""),("", ""),("", "")
        };
        protected void OutputKeyValue(int n)
        {
            string i1 = keyValuesFixed[n].Item1;
            string i2 = keyValuesFixed[n].Item2;
            i1 = EditorGUILayout.TextField("Key " + n, i1);
            i2 = EditorGUILayout.TextField("Value " + n, i2);
            keyValuesFixed[n] = (i1, i2);
        }

        //
        // UI stuffs
        //
        protected bool groupEnabled;
        protected bool repaint = false;
        protected Vector2 scrollPos;
        protected Color ori;
        protected GUIStyle gsTest;

        public void Update()
        {
            if (repaint)
            {
                Repaint();
                repaint = false;
            }
        }

        void OnGUI()
        {
            ori = GUI.backgroundColor; // remember ori color

            gsTest = new GUIStyle("window");
            //gsTest.normal.textColor = WorldStorageWindow.arfColors[0];
            gsTest.fontStyle = FontStyle.Bold;
            gsTest.alignment = TextAnchor.UpperLeft;
            gsTest.fontSize = 16;

            scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.ExpandWidth(true));
            WorldStorageWindow.DrawCopyright();

            DrawUIStuffs();

            EditorGUILayout.EndScrollView();

            if (GUILayout.Button("Close Window"))
            {
                Close();
            }
        }

        public abstract void DrawUIStuffs();

        public virtual void GetParams()
        {
        }

        public virtual void AddObject()
        {
        }

        public virtual T GenerateObject()
        {
            return default(T);
        }
    }
}
 No newline at end of file
+14
Changes for Assets/ETSI.ARF/ARF World Storage API/Editor/Windows/BaseWindow.cs.meta: 14 added lines, 0 removed lines.
Original line number Original line Diff line number Diff line
fileFormatVersion: 2
guid: b879c85f4eccbee40a78e1a01aaf77ca
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences:
  - m_ViewDataDictionary: {instanceID: 0}
  - worldStorageServer: {fileID: 11400000, guid: 4f997253243de534dad12937f1284975, type: 2}
  - worldStorageUser: {instanceID: 0}
  executionOrder: 0
  icon: {instanceID: 0}
  userData: 
  assetBundleName: 
  assetBundleVariant: 
+72 −52
Changes for Assets/ETSI.ARF/ARF World Storage API/Editor/Windows/TrackableWindow.cs: 72 added lines, 52 removed lines.
Original line number Original line Diff line number Diff line
@@ -34,21 +34,15 @@ using ETSI.ARF.OpenAPI.WorldStorage;


namespace ETSI.ARF.WorldStorage.UI
namespace ETSI.ARF.WorldStorage.UI
{
{
    public class TrackableWindow : EditorWindow
    public class TrackableWindow : BaseWindow<Trackable>
    {
    {
        static public TrackableWindow winSingleton;
        static public TrackableWindow winSingleton;


        [HideInInspector] public WorldStorageServer worldStorageServer;
        [HideInInspector] public WorldStorageUser worldStorageUser;

        [SerializeField] public List<string> trackables = new List<string>();

        bool groupEnabled;

        // Trackable params
        // Trackable params
        string UUID = System.Guid.Empty.ToString();
        string UUID = System.Guid.Empty.ToString();
        string customName = "NotDefined";
        string customName = "NotDefined";
        string creatorUUID = System.Guid.Empty.ToString();
        string creatorUUID = System.Guid.Empty.ToString();
        double confidence = 0f;
        TrackableType type = TrackableType.OTHER;
        TrackableType type = TrackableType.OTHER;
        UnitSystem unit = UnitSystem.CM;
        UnitSystem unit = UnitSystem.CM;
        Vector3 trackableSize;
        Vector3 trackableSize;
@@ -56,20 +50,16 @@ namespace ETSI.ARF.WorldStorage.UI
        Vector3 localCRS_rot;
        Vector3 localCRS_rot;
        byte[] trackablePayload = new byte[1] { 0 };
        byte[] trackablePayload = new byte[1] { 0 };


        [SerializeField] KeyvalueTagList keyValueTags = new KeyvalueTagList();
        string key1 = "";
        string value1 = "";

        // UI stuffs
        private Vector2 scrollPos;
        private Color ori;
        private GUIStyle gsTest;

        //graph params to generate the node
        //graph params to generate the node
        public bool useCoord;
        public bool useCoord;
        public float nodePosX = 0;
        public float nodePosX = 0;
        public float nodePosY = 0;
        public float nodePosY = 0;


        public TrackableWindow()
        {
            // init somne stuffs
        }

        public static void ShowWindow(WorldStorageServer ws, WorldStorageUser user, string UUID = "")
        public static void ShowWindow(WorldStorageServer ws, WorldStorageUser user, string UUID = "")
        {
        {
            winSingleton = EditorWindow.GetWindow(typeof(TrackableWindow), false, "ETSI ARF - Trackable") as TrackableWindow;
            winSingleton = EditorWindow.GetWindow(typeof(TrackableWindow), false, "ETSI ARF - Trackable") as TrackableWindow;
@@ -78,12 +68,12 @@ namespace ETSI.ARF.WorldStorage.UI
            if (!string.IsNullOrEmpty(UUID))
            if (!string.IsNullOrEmpty(UUID))
            {
            {
                winSingleton.UUID = UUID;
                winSingleton.UUID = UUID;
                winSingleton.GetTrackableParams();
                winSingleton.GetParams();
            }
            }
            else
            else
            {
            {
                // Create new one
                // Create new one
                winSingleton.AddTrackable();
                winSingleton.AddObject();
            }
            }
        }
        }


@@ -108,11 +98,6 @@ namespace ETSI.ARF.WorldStorage.UI
            return visual;
            return visual;
        }
        }


        public TrackableWindow()
        {
            // init somne stuffs
        }

        void OnGUI()
        void OnGUI()
        {
        {
            ori = GUI.backgroundColor; // remember ori color
            ori = GUI.backgroundColor; // remember ori color
@@ -126,7 +111,7 @@ namespace ETSI.ARF.WorldStorage.UI
            scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.ExpandWidth(true));
            scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.ExpandWidth(true));
            WorldStorageWindow.DrawCopyright();
            WorldStorageWindow.DrawCopyright();


            DrawTrackableStuffs();
            DrawUIStuffs();


            EditorGUILayout.EndScrollView();
            EditorGUILayout.EndScrollView();


@@ -136,7 +121,7 @@ namespace ETSI.ARF.WorldStorage.UI
            }
            }
        }
        }


        void DrawTrackableStuffs()// Trackable trackable)
        public override void DrawUIStuffs()// Trackable trackable)
        {
        {
            GUILayout.BeginVertical(); // "Trackable Editor", gsTest);
            GUILayout.BeginVertical(); // "Trackable Editor", gsTest);
            EditorGUILayout.Space();
            EditorGUILayout.Space();
@@ -157,11 +142,12 @@ namespace ETSI.ARF.WorldStorage.UI
            GUILayout.Label("User: " + worldStorageUser.userName, EditorStyles.whiteLargeLabel);
            GUILayout.Label("User: " + worldStorageUser.userName, EditorStyles.whiteLargeLabel);
            EditorGUILayout.Space();
            EditorGUILayout.Space();


            customName = EditorGUILayout.TextField("Name of Trackable:", customName);
#if isDEBUG
#if isDEBUG
            GUILayout.Label("UUID: " + UUID, EditorStyles.miniLabel); // readonly
            GUILayout.Label("UUID: " + UUID, EditorStyles.miniLabel); // readonly
            GUILayout.Label("Creator UID: " + creatorUUID, EditorStyles.miniLabel); // readonly
            GUILayout.Label("Creator UID: " + creatorUUID, EditorStyles.miniLabel); // readonly
            EditorGUILayout.Space();
#endif
#endif
            customName = EditorGUILayout.TextField("Name of Trackable:", customName);
            EditorGUILayout.Space();
            EditorGUILayout.Space();


            // ---------------------
            // ---------------------
@@ -175,7 +161,7 @@ namespace ETSI.ARF.WorldStorage.UI


                if (!string.IsNullOrEmpty(UUID) && UUID != "0" && UUID != System.Guid.Empty.ToString())
                if (!string.IsNullOrEmpty(UUID) && UUID != "0" && UUID != System.Guid.Empty.ToString())
                {
                {
                    Trackable obj = GenerateTrackable();
                    Trackable obj = GenerateObject();
                    TrackableRequest.UpdateTrackableAsync(worldStorageServer, obj, (response) =>
                    TrackableRequest.UpdateTrackableAsync(worldStorageServer, obj, (response) =>
                    {
                    {
                        UUID = response.result;
                        UUID = response.result;
@@ -184,7 +170,7 @@ namespace ETSI.ARF.WorldStorage.UI
                        if (WorldStorageWindow.WorldStorageWindowSingleton != null)
                        if (WorldStorageWindow.WorldStorageWindowSingleton != null)
                        {
                        {
                            WorldStorageWindow.WorldStorageWindowSingleton.GetTrackables();
                            WorldStorageWindow.WorldStorageWindowSingleton.GetTrackables();
                            WorldStorageWindow.WorldStorageWindowSingleton.Repaint();
                            WorldStorageWindow.WorldStorageWindowSingleton.repaint = true;
                        }
                        }
                        Close();
                        Close();
                    });
                    });
@@ -193,6 +179,8 @@ namespace ETSI.ARF.WorldStorage.UI


            GUI.backgroundColor = WorldStorageWindow.arfColors[3];
            GUI.backgroundColor = WorldStorageWindow.arfColors[3];
            if (GUILayout.Button("Delete"))
            if (GUILayout.Button("Delete"))
            {
                if (EditorUtility.DisplayDialog("Delete", "Are you sure you want to delete this Trackable?", "Delete", "Cancel"))
                {
                {
                    Debug.Log("Delete Trackable");
                    Debug.Log("Delete Trackable");
                    TrackableRequest.DeleteTrackableAsync(worldStorageServer, Guid.Parse(UUID), (response) =>
                    TrackableRequest.DeleteTrackableAsync(worldStorageServer, Guid.Parse(UUID), (response) =>
@@ -200,16 +188,18 @@ namespace ETSI.ARF.WorldStorage.UI
                        UUID = System.Guid.Empty.ToString();
                        UUID = System.Guid.Empty.ToString();
                        customName = "Warning: Object deleted !";
                        customName = "Warning: Object deleted !";
                        creatorUUID = System.Guid.Empty.ToString();
                        creatorUUID = System.Guid.Empty.ToString();
                        confidence = 0f;
                        type = TrackableType.OTHER;
                        type = TrackableType.OTHER;
                        unit = UnitSystem.CM;
                        unit = UnitSystem.CM;
                        if (WorldStorageWindow.WorldStorageWindowSingleton != null)
                        if (WorldStorageWindow.WorldStorageWindowSingleton != null)
                        {
                        {
                            WorldStorageWindow.WorldStorageWindowSingleton.GetTrackables();
                            WorldStorageWindow.WorldStorageWindowSingleton.GetTrackables();
                        WorldStorageWindow.WorldStorageWindowSingleton.Repaint();
                            WorldStorageWindow.WorldStorageWindowSingleton.repaint = true;
                        }
                        }
                        Close();
                        Close();
                    });
                    });
                }
                }
            }
            GUI.backgroundColor = ori;
            GUI.backgroundColor = ori;


            GUI.backgroundColor = WorldStorageWindow.arfColors[5];
            GUI.backgroundColor = WorldStorageWindow.arfColors[5];
@@ -226,6 +216,7 @@ namespace ETSI.ARF.WorldStorage.UI
            // ---------------------
            // ---------------------
            type = (TrackableType)EditorGUILayout.EnumPopup("Trackable Type:", type);
            type = (TrackableType)EditorGUILayout.EnumPopup("Trackable Type:", type);
            unit = (UnitSystem)EditorGUILayout.EnumPopup("Unit System:", unit);
            unit = (UnitSystem)EditorGUILayout.EnumPopup("Unit System:", unit);
            confidence = EditorGUILayout.DoubleField("Confidence:", confidence);


            EditorGUILayout.Space();
            EditorGUILayout.Space();
            trackableSize = EditorGUILayout.Vector3Field("Trackable Size:", trackableSize);
            trackableSize = EditorGUILayout.Vector3Field("Trackable Size:", trackableSize);
@@ -246,17 +237,26 @@ namespace ETSI.ARF.WorldStorage.UI
                }
                }
            }
            }


            // ---------------------
            // Keyvalues
            // ---------------------
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            groupEnabled = EditorGUILayout.BeginToggleGroup("Optional Parameters:", groupEnabled);
            groupEnabled = EditorGUILayout.BeginToggleGroup("Optional Parameters:", groupEnabled);
            key1 = EditorGUILayout.TextField("Key 1", key1);
            if (keyValuesFixed.Count > 0)
            value1 = EditorGUILayout.TextField("Value 1", value1);
            {
                OutputKeyValue(0);
                OutputKeyValue(1);
                OutputKeyValue(2);
            }
            EditorGUILayout.EndToggleGroup();
            EditorGUILayout.EndToggleGroup();
            //
            //
            GUILayout.EndVertical();
            GUILayout.EndVertical();
        }
        }


        private void GetTrackableParams()
        public override void GetParams()
        {
        {
            customName = "Requesting information...";

            TrackableRequest.GetTrackableAsync(worldStorageServer, Guid.Parse(UUID), (response) =>
            TrackableRequest.GetTrackableAsync(worldStorageServer, Guid.Parse(UUID), (response) =>
            {
            {
                Trackable obj = response.result;
                Trackable obj = response.result;
@@ -264,6 +264,7 @@ namespace ETSI.ARF.WorldStorage.UI
                creatorUUID = obj.CreatorUUID.ToString();
                creatorUUID = obj.CreatorUUID.ToString();
                type = obj.TrackableType;
                type = obj.TrackableType;
                unit = obj.Unit;
                unit = obj.Unit;
                confidence = obj.Confidence;
                if (obj.TrackableSize.Count == 3)
                if (obj.TrackableSize.Count == 3)
                {
                {
                    trackableSize = new Vector3((float)obj.TrackableSize[0], (float)obj.TrackableSize[1], (float)obj.TrackableSize[2]);
                    trackableSize = new Vector3((float)obj.TrackableSize[0], (float)obj.TrackableSize[1], (float)obj.TrackableSize[2]);
@@ -282,32 +283,44 @@ namespace ETSI.ARF.WorldStorage.UI
                    localCRS_rot = Vector3.zero;
                    localCRS_rot = Vector3.zero;
                }
                }


                // Read a key value (demo)
                // ---------------------
                var first = WorldStorageWindow.GetFirstKeyValueTags(obj.KeyvalueTags);
                // Keyvalues
                key1 = first.Item1;
                // ---------------------
                value1 = first.Item2;
                //var first = WorldStorageWindow.GetFirstKeyValueTags(obj.KeyvalueTags);
                //keyValuesFixed.Clear(); // no
                for (int i = 0; i < keyValuesFixed.Count; i++) keyValuesFixed[i] = ("", "");


                this.Repaint();
                if (obj.KeyvalueTags.Count > 0)
                {
                    int cnt = 0;
                    foreach (var item in obj.KeyvalueTags)
                    {
                        if (item.Key == "unityAuthoringPosX" || item.Key == "unityAuthoringPosY") continue; // ignore internal params
                        if (cnt < keyValuesFixed.Count) keyValuesFixed[cnt] = (item.Key, item.Value[0]);
                        cnt++;
                    }
                }
                repaint = true;
            });
            });
        }
        }


        public void AddTrackable()
        public override void AddObject()
        {
        {
            Debug.Log("POST Trackable");
            Debug.Log("POST Trackable");
            UUID = System.Guid.Empty.ToString();
            UUID = System.Guid.Empty.ToString();
            customName = "Default Trackable";
            customName = "Default Trackable";


            Trackable obj = GenerateTrackable();
            Trackable obj = GenerateObject();
            TrackableRequest.CreateTrackableAsync(worldStorageServer, obj, (response) =>
            TrackableRequest.CreateTrackableAsync(worldStorageServer, obj, (response) =>
            {
            {
                UUID = response.result;
                UUID = response.result;
                UUID = UUID.Trim('"'); //Bugfix: remove " from server return value
                UUID = UUID.Trim('"'); //Bugfix: remove " from server return value
                WorldStorageWindow.WorldStorageWindowSingleton.GetTrackables();
                WorldStorageWindow.WorldStorageWindowSingleton.GetTrackables();
                WorldStorageWindow.WorldStorageWindowSingleton.Repaint();
                WorldStorageWindow.WorldStorageWindowSingleton.repaint = true;
            });
            });
        }
        }


        public Trackable GenerateTrackable()
        public override Trackable GenerateObject()
        {
        {
            EncodingInformationStructure trackableEncodingInformation = new EncodingInformationStructure()
            EncodingInformationStructure trackableEncodingInformation = new EncodingInformationStructure()
            {
            {
@@ -327,9 +340,23 @@ namespace ETSI.ARF.WorldStorage.UI
            localCRS = Matrix4x4.TRS(localCRS_pos, Quaternion.Euler(localCRS_rot), Vector3.one);
            localCRS = Matrix4x4.TRS(localCRS_pos, Quaternion.Euler(localCRS_rot), Vector3.one);
            Transform3D _localCRS = WorldStorageUnityHelper.ConvertUnityToETSIARFTransform3D(localCRS);
            Transform3D _localCRS = WorldStorageUnityHelper.ConvertUnityToETSIARFTransform3D(localCRS);


            // Create a key value (one from demo)
            // Remember the position of the Unity graph node
            var posX = new Collection<String>();
            posX.Add(nodePosX.ToString());
            var posY = new Collection<String>();
            posY.Add(nodePosY.ToString());

            // ---------------------
            // Keyvalues
            // ---------------------
            keyValueTags.Clear();
            keyValueTags.Clear();
            keyValueTags.Add(key1, new Collection<string> { value1 });
            keyValueTags.Add("unityAuthoringPosX", posX);
            keyValueTags.Add("unityAuthoringPosY", posY);
            if (keyValuesFixed.Count > 0)
                foreach (var item in keyValuesFixed)
                {
                    if (!string.IsNullOrEmpty(item.Item1)) keyValueTags.Add(item.Item1, new Collection<string> { item.Item2 });
                }


            System.Guid _uuid = System.Guid.Parse(UUID);
            System.Guid _uuid = System.Guid.Parse(UUID);
            System.Guid _creator = System.Guid.Parse(worldStorageUser.UUID);
            System.Guid _creator = System.Guid.Parse(worldStorageUser.UUID);
@@ -342,17 +369,10 @@ namespace ETSI.ARF.WorldStorage.UI
                TrackablePayload = trackablePayload,
                TrackablePayload = trackablePayload,
                LocalCRS = _localCRS,
                LocalCRS = _localCRS,
                Unit = unit,
                Unit = unit,
                Confidence = confidence,
                TrackableSize = _trackableSize,
                TrackableSize = _trackableSize,
                KeyvalueTags = keyValueTags
                KeyvalueTags = keyValueTags
            };
            };

            var posX = new Collection<String>();
            posX.Add(nodePosX.ToString());
            t.KeyvalueTags["unityAuthoringPosX"] = posX;
            var posY = new Collection<String>();
            posY.Add(nodePosY.ToString());
            t.KeyvalueTags["unityAuthoringPosY"] = posY;

            return t;
            return t;
        }
        }
    }
    }
+64 −53
Changes for Assets/ETSI.ARF/ARF World Storage API/Editor/Windows/WorldAnchorWindow.cs: 64 added lines, 53 removed lines.
Original line number Original line Diff line number Diff line
@@ -34,17 +34,10 @@ using ETSI.ARF.OpenAPI.WorldStorage;


namespace ETSI.ARF.WorldStorage.UI
namespace ETSI.ARF.WorldStorage.UI
{
{
    public class WorldAnchorWindow : EditorWindow
    public class WorldAnchorWindow : BaseWindow<WorldAnchor>
    {
    {
        static public WorldAnchorWindow winSingleton;
        static public WorldAnchorWindow winSingleton;


        [HideInInspector] public WorldStorageServer worldStorageServer;
        [HideInInspector] public WorldStorageUser worldStorageUser;

        [SerializeField] public List<string> anchors = new List<string>();

        bool groupEnabled;

        // World Anchors params
        // World Anchors params
        string UUID = System.Guid.Empty.ToString();
        string UUID = System.Guid.Empty.ToString();
        string customName = "NotDefined";
        string customName = "NotDefined";
@@ -54,20 +47,16 @@ namespace ETSI.ARF.WorldStorage.UI
        Vector3 localCRS_pos;
        Vector3 localCRS_pos;
        Vector3 localCRS_rot;
        Vector3 localCRS_rot;


        [SerializeField] KeyvalueTagList keyValueTags = new KeyvalueTagList();
        string key1 = "";
        string value1 = "";

        // UI stuffs
        private Vector2 scrollPos;
        private Color ori;
        private GUIStyle gsTest;

        //graph params to generate the node
        //graph params to generate the node
        public bool useCoord;
        public bool useCoord;
        public float nodePosX = 0;
        public float nodePosX = 0;
        public float nodePosY = 0;
        public float nodePosY = 0;


        public WorldAnchorWindow()
        {
            // init somne stuffs
        }

        public static void ShowWindow(WorldStorageServer ws, WorldStorageUser user, string UUID = "")
        public static void ShowWindow(WorldStorageServer ws, WorldStorageUser user, string UUID = "")
        {
        {
            winSingleton = EditorWindow.GetWindow(typeof(WorldAnchorWindow), false, "ETSI ARF - World Anchor") as WorldAnchorWindow;
            winSingleton = EditorWindow.GetWindow(typeof(WorldAnchorWindow), false, "ETSI ARF - World Anchor") as WorldAnchorWindow;
@@ -76,12 +65,12 @@ namespace ETSI.ARF.WorldStorage.UI
            if (!string.IsNullOrEmpty(UUID))
            if (!string.IsNullOrEmpty(UUID))
            {
            {
                winSingleton.UUID = UUID;
                winSingleton.UUID = UUID;
                winSingleton.GetWorldAnchorParams();
                winSingleton.GetParams();
            }
            }
            else
            else
            {
            {
                // Create new one
                // Create new one
                winSingleton.AddAnchor();
                winSingleton.AddObject();
            }
            }
        }
        }


@@ -106,11 +95,6 @@ namespace ETSI.ARF.WorldStorage.UI
            return visual;
            return visual;
        }
        }


        public WorldAnchorWindow()
        {
            // init somne stuffs
        }

        void OnGUI()
        void OnGUI()
        {
        {
            ori = GUI.backgroundColor; // remember ori color
            ori = GUI.backgroundColor; // remember ori color
@@ -124,7 +108,7 @@ namespace ETSI.ARF.WorldStorage.UI
            scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.ExpandWidth(true));
            scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.ExpandWidth(true));
            WorldStorageWindow.DrawCopyright();
            WorldStorageWindow.DrawCopyright();


            DrawAnchorStuffs();
            DrawUIStuffs();


            EditorGUILayout.EndScrollView();
            EditorGUILayout.EndScrollView();


@@ -134,7 +118,7 @@ namespace ETSI.ARF.WorldStorage.UI
            }
            }
        }
        }


        void DrawAnchorStuffs()
        public override void DrawUIStuffs()
        {
        {
            GUILayout.BeginVertical(); // "World Anchor Editor", gsTest);
            GUILayout.BeginVertical(); // "World Anchor Editor", gsTest);
            EditorGUILayout.Space();
            EditorGUILayout.Space();
@@ -155,11 +139,12 @@ namespace ETSI.ARF.WorldStorage.UI
            GUILayout.Label("User: " + worldStorageUser.userName, EditorStyles.whiteLargeLabel);
            GUILayout.Label("User: " + worldStorageUser.userName, EditorStyles.whiteLargeLabel);
            EditorGUILayout.Space();
            EditorGUILayout.Space();


            customName = EditorGUILayout.TextField("Name of Anchor:", customName);
#if isDEBUG
#if isDEBUG
            GUILayout.Label("UUID: " + UUID, EditorStyles.miniLabel); // readonly
            GUILayout.Label("UUID: " + UUID, EditorStyles.miniLabel); // readonly
            GUILayout.Label("Creator UID: " + creatorUUID, EditorStyles.miniLabel); // readonly
            GUILayout.Label("Creator UID: " + creatorUUID, EditorStyles.miniLabel); // readonly
            EditorGUILayout.Space();
#endif
#endif
            customName = EditorGUILayout.TextField("Name of Anchor:", customName);
            EditorGUILayout.Space();
            EditorGUILayout.Space();


            // ---------------------
            // ---------------------
@@ -173,23 +158,25 @@ namespace ETSI.ARF.WorldStorage.UI


                if (!string.IsNullOrEmpty(UUID) && UUID != "0" && UUID != System.Guid.Empty.ToString())
                if (!string.IsNullOrEmpty(UUID) && UUID != "0" && UUID != System.Guid.Empty.ToString())
                {
                {
                    WorldAnchor obj = GenerateWorldAnchor();
                    WorldAnchor obj = GenerateObject();
                    WorldAnchorRequest.UpdateWorldAnchorAsync(worldStorageServer, obj, (response) =>
                    WorldAnchorRequest.UpdateWorldAnchorAsync(worldStorageServer, obj, (response) =>
                    {
                    {
                        UUID = response.result;
                        UUID = response.result;
                        UUID = UUID.Trim('"'); //Bugfix: remove " from server return value
                        UUID = UUID.Trim('"'); //Bugfix: remove " from server return value

                        if (WorldStorageWindow.WorldStorageWindowSingleton != null)
                        if (WorldStorageWindow.WorldStorageWindowSingleton != null)
                        {
                        {
                            WorldStorageWindow.WorldStorageWindowSingleton.GetWorldAnchors();
                            WorldStorageWindow.WorldStorageWindowSingleton.GetWorldAnchors();
                            WorldStorageWindow.WorldStorageWindowSingleton.Repaint();
                        }
                        }
                        Close();
                    });
                    });
                }
                }
                Close();
            }
            }


            GUI.backgroundColor = WorldStorageWindow.arfColors[3];
            GUI.backgroundColor = WorldStorageWindow.arfColors[3];
            if (GUILayout.Button("Delete"))
            if (GUILayout.Button("Delete"))
            {
                if (EditorUtility.DisplayDialog("Delete", "Are you sure you want to delete this World Anchor?", "Delete", "Cancel"))
                {
                {
                    Debug.Log("Delete World Anchor");
                    Debug.Log("Delete World Anchor");
                    WorldAnchorRequest.DeleteWorldAnchorAsync(worldStorageServer, Guid.Parse(UUID), (response) =>
                    WorldAnchorRequest.DeleteWorldAnchorAsync(worldStorageServer, Guid.Parse(UUID), (response) =>
@@ -201,11 +188,11 @@ namespace ETSI.ARF.WorldStorage.UI
                        if (WorldStorageWindow.WorldStorageWindowSingleton != null)
                        if (WorldStorageWindow.WorldStorageWindowSingleton != null)
                        {
                        {
                            WorldStorageWindow.WorldStorageWindowSingleton.GetWorldAnchors();
                            WorldStorageWindow.WorldStorageWindowSingleton.GetWorldAnchors();
                        WorldStorageWindow.WorldStorageWindowSingleton.Repaint();
                        }
                        }
                        Close();
                        Close();
                    });
                    });
                }
                }
            }
            GUI.backgroundColor = ori;
            GUI.backgroundColor = ori;


            GUI.backgroundColor = WorldStorageWindow.arfColors[5];
            GUI.backgroundColor = WorldStorageWindow.arfColors[5];
@@ -230,16 +217,23 @@ namespace ETSI.ARF.WorldStorage.UI
            localCRS_pos = EditorGUILayout.Vector3Field("   Position:", localCRS_pos);
            localCRS_pos = EditorGUILayout.Vector3Field("   Position:", localCRS_pos);
            localCRS_rot = EditorGUILayout.Vector3Field("   Rotation:", localCRS_rot);
            localCRS_rot = EditorGUILayout.Vector3Field("   Rotation:", localCRS_rot);


            // ---------------------
            // Keyvalues
            // ---------------------
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            groupEnabled = EditorGUILayout.BeginToggleGroup("Optional Parameters:", groupEnabled);
            groupEnabled = EditorGUILayout.BeginToggleGroup("Optional Parameters:", groupEnabled);
            key1 = EditorGUILayout.TextField("Key 1", key1);
            if (keyValuesFixed.Count > 0)
            value1 = EditorGUILayout.TextField("Value 1", value1);
            {
                OutputKeyValue(0);
                OutputKeyValue(1);
                OutputKeyValue(2);
            }
            EditorGUILayout.EndToggleGroup();
            EditorGUILayout.EndToggleGroup();
            //
            //
            GUILayout.EndVertical();
            GUILayout.EndVertical();
        }
        }


        private void GetWorldAnchorParams()
        public override void GetParams()
        {
        {
            WorldAnchorRequest.GetWorldAnchorAsync(worldStorageServer, Guid.Parse(UUID), (response) =>
            WorldAnchorRequest.GetWorldAnchorAsync(worldStorageServer, Guid.Parse(UUID), (response) =>
            {
            {
@@ -265,32 +259,43 @@ namespace ETSI.ARF.WorldStorage.UI
                    localCRS_rot = Vector3.zero;
                    localCRS_rot = Vector3.zero;
                }
                }


                // Read a key value (demo)
                // ---------------------
                var first = WorldStorageWindow.GetFirstKeyValueTags(obj.KeyvalueTags);
                // Keyvalues
                key1 = first.Item1;
                // ---------------------
                value1 = first.Item2;
                //var first = WorldStorageWindow.GetFirstKeyValueTags(obj.KeyvalueTags);
                //keyValuesFixed.Clear(); // no
                for (int i = 0; i < keyValuesFixed.Count; i++) keyValuesFixed[i] = ("", "");


                this.Repaint();
                if (obj.KeyvalueTags.Count > 0)
                {
                    int cnt = 0;
                    foreach (var item in obj.KeyvalueTags)
                    {
                        if (item.Key == "unityAuthoringPosX" || item.Key == "unityAuthoringPosY") continue; // ignore internal params
                        if (cnt < keyValuesFixed.Count) keyValuesFixed[cnt] = (item.Key, item.Value[0]);
                        cnt++;
                    }
                }
                repaint = true;
            });
            });
        }
        }


        public void AddAnchor()
        public override void AddObject()
        {
        {
            Debug.Log("POST World Anchor");
            Debug.Log("POST World Anchor");
            UUID = System.Guid.Empty.ToString();
            UUID = System.Guid.Empty.ToString();
            customName = "Default Anchor";
            customName = "Default Anchor";


            WorldAnchor obj = GenerateWorldAnchor();
            WorldAnchor obj = GenerateObject();
            WorldAnchorRequest.CreateWorldAnchorAsync(worldStorageServer, obj, (response) =>
            WorldAnchorRequest.CreateWorldAnchorAsync(worldStorageServer, obj, (response) =>
            {
            {
                UUID = response.result;
                UUID = response.result;
                UUID = UUID.Trim('"'); //Bugfix: remove " from server return value
                UUID = UUID.Trim('"'); //Bugfix: remove " from server return value
                WorldStorageWindow.WorldStorageWindowSingleton.GetWorldAnchors();
                WorldStorageWindow.WorldStorageWindowSingleton.GetWorldAnchors();
                WorldStorageWindow.WorldStorageWindowSingleton.Repaint();
            });
            });
        }
        }


        public WorldAnchor GenerateWorldAnchor()
        public override WorldAnchor GenerateObject()
        {
        {
            Size _worldAnchorSize = new Size();
            Size _worldAnchorSize = new Size();
            _worldAnchorSize.Add(worldAnchorSize.x);
            _worldAnchorSize.Add(worldAnchorSize.x);
@@ -302,9 +307,23 @@ namespace ETSI.ARF.WorldStorage.UI
            localCRS = Matrix4x4.TRS(localCRS_pos, Quaternion.Euler(localCRS_rot), Vector3.one);
            localCRS = Matrix4x4.TRS(localCRS_pos, Quaternion.Euler(localCRS_rot), Vector3.one);
            Transform3D _localCRS = WorldStorageUnityHelper.ConvertUnityToETSIARFTransform3D(localCRS);
            Transform3D _localCRS = WorldStorageUnityHelper.ConvertUnityToETSIARFTransform3D(localCRS);


            // Create a key value (one from demo)
            // Remember the position of the Unity graph node
            var posX = new Collection<String>();
            posX.Add(nodePosX.ToString());
            var posY = new Collection<String>();
            posY.Add(nodePosY.ToString());

            // ---------------------
            // Keyvalues
            // ---------------------
            keyValueTags.Clear();
            keyValueTags.Clear();
            keyValueTags.Add(key1, new Collection<string> { value1 });
            keyValueTags.Add("unityAuthoringPosX", posX);
            keyValueTags.Add("unityAuthoringPosY", posY);
            if (keyValuesFixed.Count > 0)
                foreach (var item in keyValuesFixed)
                {
                    if (!string.IsNullOrEmpty(item.Item1)) keyValueTags.Add(item.Item1, new Collection<string> { item.Item2 });
                }


            Guid _uuid = Guid.Parse(UUID);
            Guid _uuid = Guid.Parse(UUID);
            Guid _creator = Guid.Parse(worldStorageUser.UUID);
            Guid _creator = Guid.Parse(worldStorageUser.UUID);
@@ -317,14 +336,6 @@ namespace ETSI.ARF.WorldStorage.UI
                WorldAnchorSize = _worldAnchorSize,
                WorldAnchorSize = _worldAnchorSize,
                KeyvalueTags = keyValueTags
                KeyvalueTags = keyValueTags
            };
            };

            var posX = new Collection<String>();
            posX.Add(nodePosX.ToString());
            t.KeyvalueTags["unityAuthoringPosX"] = posX;
            var posY = new Collection<String>();
            posY.Add(nodePosY.ToString());
            t.KeyvalueTags["unityAuthoringPosY"] = posY;

            return t;
            return t;
        }
        }
    }
    }
+62 −38

File changed.

Preview size limit exceeded, changes collapsed.

Loading