Ejemplo n.º 1
0
        //static SceneVersionCollection SceneVersionCollection;

        /// <summary>
        /// generate manifest from scene objects and upload to latest version of scene. should be done only after EditorCore.RefreshSceneVersion
        /// </summary>
        public static void UploadManifest(System.Action callback)
        {
            if (Manifest == null)
            {
                Manifest = new AggregationManifest();
            }
            //if (SceneVersionCollection == null) { Debug.LogError("SceneVersionCollection is null! Make sure RefreshSceneVersion was called before this"); return; }

            ObjectsInScene = null;

            AddOrReplaceDynamic(Manifest, GetDynamicObjectsInScene());

            if (Manifest.objects.Count == 0)
            {
                Debug.LogWarning("Aggregation Manifest has nothing in list!");
                return;
            }

            string json = "";

            if (ManifestToJson(out json))
            {
                var currentSettings = CognitiveVR_Preferences.FindCurrentScene();
                if (currentSettings != null && currentSettings.VersionNumber > 0)
                {
                    SendManifest(json, currentSettings.VersionNumber, callback);
                }
                else
                {
                    Util.logError("Could not find scene version for current scene");
                }
            }
        }
Ejemplo n.º 2
0
        static void AddOrReplaceDynamic(AggregationManifest manifest, List <DynamicObject> scenedynamics)
        {
            bool          meshNameMissing        = false;
            List <string> missingMeshGameObjects = new List <string>();

            foreach (var dynamic in scenedynamics)
            {
                var replaceEntry = manifest.objects.Find(delegate(AggregationManifest.AggregationManifestEntry obj) { return(obj.id == dynamic.CustomId.ToString()); });
                if (replaceEntry == null)
                {
                    //don't include meshes with empty mesh names in manifest
                    if (!string.IsNullOrEmpty(dynamic.MeshName))
                    {
                        manifest.objects.Add(new AggregationManifest.AggregationManifestEntry(dynamic.gameObject.name, dynamic.MeshName, dynamic.CustomId.ToString()));
                    }
                    else
                    {
                        missingMeshGameObjects.Add(dynamic.gameObject.name);
                        meshNameMissing = true;
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(dynamic.MeshName))
                    {
                        replaceEntry.mesh = dynamic.MeshName;
                        replaceEntry.name = dynamic.gameObject.name;
                    }
                    else
                    {
                        missingMeshGameObjects.Add(dynamic.gameObject.name);
                        meshNameMissing = true;
                    }
                }
            }

            if (meshNameMissing)
            {
                string debug = "Dynamic Objects missing mesh name:\n";
                foreach (var v in missingMeshGameObjects)
                {
                    debug += v + "\n";
                }
                Debug.LogWarning(debug);
                EditorUtility.DisplayDialog("Error", "One or more Dynamic Objects are missing a mesh name and were not uploaded to scene.\n\nSee Console for details", "Ok");
            }
        }
Ejemplo n.º 3
0
        void GetManifestResponse(int responsecode, string error, string text)
        {
            if (responsecode == 200)
            {
                //BuildManifest(getRequest.text);
                var allEntries = JsonUtil.GetJsonArray <AggregationManifest.AggregationManifestEntry>(text);

                Debug.Log("Number of Dynamic Objects in current Manifest: " + allEntries.Length);

                Manifest = new AggregationManifest();

                Manifest.objects = new List <AggregationManifest.AggregationManifestEntry>(allEntries);
                Repaint();

                //also hit settings to get the current version of the scene
                EditorCore.RefreshSceneVersion(null);
            }
            else
            {
                Util.logWarning("GetManifestResponse " + responsecode + " " + error);
            }
        }
Ejemplo n.º 4
0
        //only need id, mesh and name
        //static AggregationManifest Manifest;
        //static SceneVersionCollection SceneVersionCollection;

        /// <summary>
        /// generate manifest from scene objects and upload to latest version of scene. should be done only after EditorCore.RefreshSceneVersion
        /// </summary>
        public static void UploadManifest(AggregationManifest manifest, System.Action callback, System.Action nodynamicscallback = null)
        {
            //if (Manifest == null) { Manifest = new AggregationManifest(); }
            //if (SceneVersionCollection == null) { Debug.LogError("SceneVersionCollection is null! Make sure RefreshSceneVersion was called before this"); return; }

            if (manifest.objects.Count == 0)
            {
                Debug.LogWarning("Aggregation Manifest has nothing in list!");
                if (nodynamicscallback != null)
                {
                    nodynamicscallback.Invoke();
                }
                return;
            }

            string json = "";

            if (ManifestToJson(manifest, out json))
            {
                var currentSettings = CognitiveVR_Preferences.FindCurrentScene();
                if (currentSettings != null && currentSettings.VersionNumber > 0)
                {
                    SendManifest(json, currentSettings.VersionNumber, callback);
                }
                else
                {
                    Util.logError("Could not find scene version for current scene");
                }
            }
            else
            {
                Debug.LogWarning("Aggregation Manifest only contains dynamic objects with generated ids");
                if (nodynamicscallback != null)
                {
                    nodynamicscallback.Invoke();
                }
            }
        }
Ejemplo n.º 5
0
        static bool ManifestToJson(AggregationManifest manifest, out string json)
        {
            json = "{\"objects\":[";

            List <string> usedIds = new List <string>();

            bool containsValidEntry = false;

            foreach (var entry in manifest.objects)
            {
                if (string.IsNullOrEmpty(entry.mesh))
                {
                    Debug.LogWarning(entry.name + " missing meshname"); continue;
                }
                if (string.IsNullOrEmpty(entry.id))
                {
                    Debug.LogWarning(entry.name + " has empty dynamic id. This will not be aggregated"); continue;
                }
                if (usedIds.Contains(entry.id))
                {
                    Debug.LogWarning(entry.name + " using id (" + entry.id + ") that already exists in the scene. This may not be aggregated correctly");
                }
                usedIds.Add(entry.id);
                json += "{";
                json += "\"id\":\"" + entry.id + "\",";
                json += "\"mesh\":\"" + entry.mesh + "\",";
                json += "\"name\":\"" + entry.name + "\"";
                json += "},";
                containsValidEntry = true;
            }

            json  = json.Remove(json.Length - 1, 1);
            json += "]}";

            return(containsValidEntry);
        }
Ejemplo n.º 6
0
        private void OnGUI()
        {
            if (needsRefreshDevKey == true)
            {
                EditorCore.CheckForExpiredDeveloperKey(GetDevKeyResponse);
                needsRefreshDevKey = false;
            }
            GUI.skin = EditorCore.WizardGUISkin;

            GUI.DrawTexture(new Rect(0, 0, 500, 550), EditorGUIUtility.whiteTexture);

            var currentscene = CognitiveVR_Preferences.FindCurrentScene();

            if (string.IsNullOrEmpty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene().name))
            {
                GUI.Label(steptitlerect, "DYNAMIC OBJECTS   Scene Not Saved", "steptitle");
            }
            else if (currentscene == null || string.IsNullOrEmpty(currentscene.SceneId))
            {
                GUI.Label(steptitlerect, "DYNAMIC OBJECTS   Scene Not Uploaded", "steptitle");
            }
            else
            {
                GUI.Label(steptitlerect, "DYNAMIC OBJECTS   " + currentscene.SceneName + " Version: " + currentscene.VersionNumber, "steptitle");
            }

            GUI.Label(new Rect(30, 45, 440, 440), "These are the active <color=#8A9EB7FF>Dynamic Object components</color> currently found in your scene.", "boldlabel");

            //headers
            Rect mesh = new Rect(30, 95, 120, 30);

            GUI.Label(mesh, "Mesh Name", "dynamicheader");
            Rect gameobject = new Rect(190, 95, 120, 30);

            GUI.Label(gameobject, "GameObject", "dynamicheader");
            //Rect ids = new Rect(320, 95, 120, 30);
            //GUI.Label(ids, "Ids", "dynamicheader");
            Rect uploaded = new Rect(380, 95, 120, 30);

            GUI.Label(uploaded, "Exported Mesh", "dynamicheader");
            //IMPROVEMENT get list of uploaded mesh names from dashboard


            //content
            DynamicObject[] tempdynamics = GetDynamicObjects;

            if (tempdynamics.Length == 0)
            {
                GUI.Label(new Rect(30, 120, 420, 270), "No objects found.\n\nHave you attached any Dynamic Object components to objects?\n\nAre they active in your hierarchy?", "button_disabledtext");
            }

            DynamicObjectIdPool[] poolAssets = EditorCore.GetDynamicObjectPoolAssets;


            Rect innerScrollSize = new Rect(30, 0, 420, (tempdynamics.Length + poolAssets.Length) * 30);

            dynamicScrollPosition = GUI.BeginScrollView(new Rect(30, 120, 440, 285), dynamicScrollPosition, innerScrollSize, false, true);

            Rect dynamicrect;
            int  GuiOffset = 0;

            for (; GuiOffset < tempdynamics.Length; GuiOffset++)
            {
                if (tempdynamics[GuiOffset] == null)
                {
                    RefreshSceneDynamics(); GUI.EndScrollView(); return;
                }
                dynamicrect = new Rect(30, GuiOffset * 30, 460, 30);
                DrawDynamicObject(tempdynamics[GuiOffset], dynamicrect, GuiOffset % 2 == 0);
            }
            for (int i = 0; i < poolAssets.Length; i++)
            {
                //if (poolAssets[i] == null) { RefreshSceneDynamics(); GUI.EndScrollView(); return; }
                dynamicrect = new Rect(30, (i + GuiOffset) * 30, 460, 30);
                DrawDynamicObjectPool(poolAssets[i], dynamicrect, (i + GuiOffset) % 2 == 0);
            }
            GUI.EndScrollView();
            GUI.Box(new Rect(30, 120, 425, 285), "", "box_sharp_alpha");

            //buttons

            string scenename     = "Not Saved";
            int    versionnumber = 0;

            //string buttontextstyle = "button_bluetext";
            if (currentscene == null || string.IsNullOrEmpty(currentscene.SceneId))
            {
                //buttontextstyle = "button_disabledtext";
            }
            else
            {
                scenename     = currentscene.SceneName;
                versionnumber = currentscene.VersionNumber;
            }

            int selectionCount = 0;

            foreach (var v in Selection.gameObjects)
            {
                if (v.GetComponentInChildren <DynamicObject>())
                {
                    selectionCount++;
                }
            }

            //IMPROVEMENT enable mesh upload from selected dynamic object id pool that has exported mesh files
            //if (Selection.activeObject.GetType() == typeof(DynamicObjectIdPool))
            //{
            //    var pool = Selection.activeObject as DynamicObjectIdPool;
            //    if (EditorCore.HasDynamicExportFiles(pool.MeshName))
            //    {
            //        selectionCount++;
            //    }
            //}

            //texture resolution

            if (CognitiveVR_Preferences.Instance.TextureResize > 4)
            {
                CognitiveVR_Preferences.Instance.TextureResize = 4;
            }

            //resolution settings here
            EditorGUI.BeginDisabledGroup(DisableButtons);
            if (GUI.Button(new Rect(30, 415, 140, 35), new GUIContent("1/4 Resolution", DisableButtons?"":"Quarter resolution of dynamic object textures"), CognitiveVR_Preferences.Instance.TextureResize == 4 ? "button_blueoutline" : "button_disabledtext"))
            {
                CognitiveVR_Preferences.Instance.TextureResize = 4;
            }
            if (CognitiveVR_Preferences.Instance.TextureResize != 4)
            {
                GUI.Box(new Rect(30, 415, 140, 35), "", "box_sharp_alpha");
            }

            if (GUI.Button(new Rect(180, 415, 140, 35), new GUIContent("1/2 Resolution", DisableButtons ? "" : "Half resolution of dynamic object textures"), CognitiveVR_Preferences.Instance.TextureResize == 2 ? "button_blueoutline" : "button_disabledtext"))
            {
                CognitiveVR_Preferences.Instance.TextureResize = 2;
            }
            if (CognitiveVR_Preferences.Instance.TextureResize != 2)
            {
                GUI.Box(new Rect(180, 415, 140, 35), "", "box_sharp_alpha");
            }

            if (GUI.Button(new Rect(330, 415, 140, 35), new GUIContent("1/1 Resolution", DisableButtons ? "" : "Full resolution of dynamic object textures"), CognitiveVR_Preferences.Instance.TextureResize == 1 ? "button_blueoutline" : "button_disabledtext"))
            {
                CognitiveVR_Preferences.Instance.TextureResize = 1;
            }
            if (CognitiveVR_Preferences.Instance.TextureResize != 1)
            {
                GUI.Box(new Rect(330, 415, 140, 35), "", "box_sharp_alpha");
            }
            EditorGUI.EndDisabledGroup();


            EditorGUI.BeginDisabledGroup(currentscene == null || string.IsNullOrEmpty(currentscene.SceneId) || selectionCount == 0);
            if (GUI.Button(new Rect(30, 460, 200, 30), new GUIContent("Upload " + selectionCount + " Selected Meshes", DisableButtons ? "" : "Export and Upload to " + scenename + " version " + versionnumber)))
            {
                EditorCore.RefreshSceneVersion(() =>
                {
                    foreach (var go in Selection.gameObjects)
                    {
                        var dyn = go.GetComponent <DynamicObject>();
                        if (dyn == null)
                        {
                            continue;
                        }
                        //check if export files exist
                        if (!EditorCore.HasDynamicExportFiles(dyn.MeshName))
                        {
                            ExportUtility.ExportDynamicObject(dyn);
                        }
                        //check if thumbnail exists
                        if (!EditorCore.HasDynamicObjectThumbnail(dyn.MeshName))
                        {
                            EditorCore.SaveDynamicThumbnailAutomatic(dyn.gameObject);
                        }
                    }

                    EditorCore.RefreshSceneVersion(delegate()
                    {
                        var manifest = new AggregationManifest();
                        AddOrReplaceDynamic(manifest, GetDynamicObjectsInScene());
                        ManageDynamicObjects.UploadManifest(manifest, () => ExportUtility.UploadSelectedDynamicObjectMeshes(true));
                    });
                });
            }
            EditorGUI.EndDisabledGroup();

            EditorGUI.BeginDisabledGroup(currentscene == null || string.IsNullOrEmpty(currentscene.SceneId));
            if (GUI.Button(new Rect(270, 460, 200, 30), new GUIContent("Upload All Meshes", DisableButtons ? "" : "Export and Upload to " + scenename + " version " + versionnumber)))
            {
                EditorCore.RefreshSceneVersion(() =>
                {
                    var dynamics          = GameObject.FindObjectsOfType <DynamicObject>();
                    List <GameObject> gos = new List <GameObject>();
                    foreach (var v in dynamics)
                    {
                        gos.Add(v.gameObject);
                    }

                    Selection.objects = gos.ToArray();

                    foreach (var go in Selection.gameObjects)
                    {
                        var dyn = go.GetComponent <DynamicObject>();
                        if (dyn == null)
                        {
                            continue;
                        }
                        //check if export files exist
                        if (!EditorCore.HasDynamicExportFiles(dyn.MeshName))
                        {
                            ExportUtility.ExportDynamicObject(dyn);
                        }
                        //check if thumbnail exists
                        if (!EditorCore.HasDynamicObjectThumbnail(dyn.MeshName))
                        {
                            EditorCore.SaveDynamicThumbnailAutomatic(dyn.gameObject);
                        }
                    }

                    EditorCore.RefreshSceneVersion(delegate()
                    {
                        var manifest = new AggregationManifest();
                        AddOrReplaceDynamic(manifest, GetDynamicObjectsInScene());
                        ManageDynamicObjects.UploadManifest(manifest, () => ExportUtility.UploadSelectedDynamicObjectMeshes(true));
                    });
                });
            }
            EditorGUI.EndDisabledGroup();

            DrawFooter();
            Repaint(); //manually repaint gui each frame to make sure it's responsive
        }
Ejemplo n.º 7
0
        void DrawFooter()
        {
            GUI.color = EditorCore.BlueishGrey;
            GUI.DrawTexture(new Rect(0, 500, 550, 50), EditorGUIUtility.whiteTexture);
            GUI.color = Color.white;

            string tooltip = "";

            var currentScene = CognitiveVR_Preferences.FindCurrentScene();

            if (currentScene == null || string.IsNullOrEmpty(currentScene.SceneId))
            {
                tooltip = "Upload list of all Dynamic Object IDs. Scene settings not saved";
            }
            else
            {
                tooltip = "Upload list of all Dynamic Object IDs and Mesh Names to " + currentScene.SceneName + " version " + currentScene.VersionNumber;
            }

            bool enabled = !(currentScene == null || string.IsNullOrEmpty(currentScene.SceneId)) && lastResponseCode == 200;

            if (enabled)
            {
                if (GUI.Button(new Rect(80, 510, 350, 30), new GUIContent("Upload Ids to SceneExplorer for Aggregation", tooltip)))
                {
                    EditorCore.RefreshSceneVersion(delegate()
                    {
                        AggregationManifest manifest = new AggregationManifest();
                        AddOrReplaceDynamic(manifest, GetDynamicObjectsInScene());
                        //Important! this should never upload Id Pools automatically! possible these aren't wanted in a scene and will clutter dashboard
                        ManageDynamicObjects.UploadManifest(manifest, null);
                    });
                }
            }
            else
            {
                var    scene = UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene();
                string errorMessage;

                if (lastResponseCode != 200)
                {
                    errorMessage = "<color=#880000ff>The Developer Key is Invalid or Expired.\n\nPlease visit the project on our dashboard and update the key in the Scene Setup Window</color>";
                }
                else
                {
                    errorMessage = "<color=#880000ff>This scene <color=red>" + scene.name.ToUpper() + "</color> does not have a valid SceneId.\n\nPlease upload this scene using the Scene Setup Window</color>";
                }

                if (!EditorCore.IsDeveloperKeyValid)
                {
                    errorMessage = "Developer Key not set";
                }

                EditorGUI.BeginDisabledGroup(true);
                GUI.Button(new Rect(80, 510, 350, 30), new GUIContent("Upload Ids to SceneExplorer for Aggregation", tooltip));
                EditorGUI.EndDisabledGroup();

                GUI.color = new Color(1, 0.9f, 0.9f);
                GUI.DrawTexture(new Rect(0, 420, 550, 150), EditorGUIUtility.whiteTexture);
                GUI.color = Color.white;
                GUI.Label(new Rect(30, 430, 430, 30), errorMessage, "normallabel");

                if (GUI.Button(new Rect(380, 510, 80, 30), "Fix"))
                {
                    InitWizard.Init();
                }
            }
        }