예제 #1
0
        private void OnFetchGraphResponse(bool error, Spaces.Core.RestAPI.RestGetSpaceMetadataResponse metadata)
        {
            if (error)
            {
                ProcessError(Process.FetchingGraph);
            }
            else
            {
                //Graph = JsonUtility.FromJson<SpaceGraph>(metadata.metadata);
                Graph = metadata.spaceGraph;

                if (Graph == null)
                {
                    Graph = new SpaceGraph();
                }

                if (Graph.assetIDs == null)
                {
                    Graph.assetIDs = new List <string>(assetIDs);
                }
                else
                {
                    assetIDs = Graph.assetIDs;
                }

                isGraphFetched = true;
                SaveGraphToCache();
                ProcessEnd(Process.FetchingGraph);
            }
        }
예제 #2
0
        /// <summary>
        /// Write out the SpaceGraph of a Space, serialize it and update the server.
        /// </summary>
        /// <param name="spaceID">The ID of the Space.</param>
        /// <returns>The resulting SpaceGraph</returns>
        public static SpaceGraph Save(string spaceID)
        {
            var graph = SpaceGraph.Generate();

            // Serialize Graph into json.
            string json = JsonUtility.ToJson(graph);

            if (!string.IsNullOrEmpty(spaceID))
            {
                RestManager.Request.UpdateSpaceMetadata(spaceID, json, OnUpdateMetadataResponse);
            }

            return(graph);
        }
예제 #3
0
        /// <summary>
        /// Write out the SpaceGraph of a Space.
        /// </summary>
        /// <returns>The resulting SpaceGraph</returns>
        public static SpaceGraph Generate()
        {
            var roots     = new List <Transform>();
            var nodeRoots = new List <Node>();
            var assetIDs  = new List <string>();

            // Roots List determined by presence of Widget
            foreach (Widget w in GameObject.FindObjectsOfType <Widget>())
            {
                if (!roots.Contains(w.transform.root))
                {
                    roots.Add(w.transform.root);
                }

                // Asset IDs used in Space determined by AssetWidgets
                if (w is IAssetReference)
                {
                    foreach (string assetID in ((IAssetReference)w).GetAssetIDs())
                    {
                        if (!assetIDs.Contains(assetID))
                        {
                            assetIDs.Add(assetID);
                        }
                    }
                }
            }

            // Node tree created for each Root
            foreach (var root in roots)
            {
                var node = new Node(root.gameObject);
                nodeRoots.Add(node);
            }

            // Graph created with set of node Roots.
            var graph = new SpaceGraph(nodeRoots);

            // List of AssetIDs assigned in new Graph.
            graph.assetIDs = assetIDs;

            // Serialize Graph into json.
            //string json = JsonUtility.ToJson(graph);

            return(graph);
        }