Пример #1
0
 /// <summary>
 /// Updates an existing visualization with the provided <see cref="VisProperties"/>.
 /// </summary>
 /// <param name="config">The struct containing the settings for the updated visualization.</param>
 /// <param name="syncWithRemote">Indicates whether this update should also happen on remote clients.</param>
 public void UpdateVisualization(VisProperties config, bool syncWithRemote = true)
 {
     if (Visualizations.TryGetValue(config.VisId, out AbstractView visualization))
     {
         visualization.UpdateView(config);
         if (syncWithRemote)
         {
             var message = new MessageUpdateVisualization(config);
             Services.NetworkManager().SendMessage(message.Pack());
         }
     }
 }
Пример #2
0
        /// <summary>
        /// Creates a new coordinate system.
        /// </summary>
        /// <param name="settings">The settings for the new coordinate system.</param>
        /// <returns>A <see cref="GameObject"/> with the coordinate system.</returns>
        public GameObject GenerateCoordinateSystemVis(VisProperties settings)
        {
            settings.VisId   = Guid.Empty;
            settings.VisType = VisType.CoordinateSystem3D;
            GameObject vis;
            var        coordinateSystem = Instantiate(CoordinateSystemPrefab);

            coordinateSystem.Init(settings);
            vis = coordinateSystem.gameObject;
            coordinateSystemVis = coordinateSystem;
            Transform worldAnchor = GameObject.FindGameObjectWithTag("VisRootAnchor").transform;

            vis.transform.SetParent(worldAnchor, false);
            return(vis);
        }
Пример #3
0
        /// <summary>
        /// Creates a new timeline control.
        /// </summary>
        /// <param name="settings">The settings for the new timeline control.</param>
        /// <returns>A <see cref="GameObject"/> with the timeline control.</returns>
        public GameObject CreateTimelineControl(VisProperties settings)
        {
            settings.VisId   = Guid.Empty;
            settings.VisType = VisType.TimelineControl;
            GameObject vis;
            var        timelineControl = Instantiate(TimelineControlPrefab);

            timelineControl.Init(settings);
            vis = timelineControl.gameObject;
            timelineController = timelineControl;
            Transform worldAnchor = GameObject.FindGameObjectWithTag("RootWorldAnchor").transform;

            vis.transform.SetParent(worldAnchor, false);
            return(vis);
        }
Пример #4
0
        /// <summary>
        /// Updates the session filter with the provided lists of sessions and conditions.
        /// </summary>
        /// <param name="sessions">The list of sessions.</param>
        /// <param name="conditions">The list of conditions.</param>
        public void UpdateSessionFilter(List <int> sessions, List <int> conditions)
        {
            foreach (var vis in Visualizations.Values)
            {
                vis.UpdateView(sessions, conditions);
            }

            if (!timelineController || timelineController.Disposed == true)
            {
                timelineController = null;
                var properties = new VisProperties(Guid.Empty, VisType.TimelineControl, -1)
                {
                    Conditions = new List <int>(conditions),
                    Sessions   = new List <int>(sessions)
                };
                CreateTimelineControl(properties);
            }
            else
            {
                timelineController.UpdateView(sessions, conditions);
            }

            if (!coordinateSystemVis || coordinateSystemVis.Disposed == true)
            {
                coordinateSystemVis = null;
                var properties = new VisProperties(Guid.Empty, VisType.CoordinateSystem3D, -1)
                {
                    Conditions = new List <int>(conditions),
                    Sessions   = new List <int>(sessions)
                };
                GenerateCoordinateSystemVis(properties);
            }
            else
            {
                coordinateSystemVis.UpdateView(sessions, conditions);
            }
        }
Пример #5
0
        /// <summary>
        /// Creates a visualization from a <see cref="VisProperties"/>.
        /// </summary>
        /// <param name="settings">The struct containing the settings for the visualization.</param>
        /// <param name="syncWithRemote">Indicates whether the visualization should also be created on other clients.</param>
        /// <returns>A <see cref="GameObject"/> with the visualization.</returns>
        public GameObject CreateVisualization(VisProperties settings, bool syncWithRemote = true)
        {
            try
            {
                if (Visualizations.ContainsKey(settings.VisId))
                {
                    throw new Exception("VisId " + settings.VisId + " has been used twice!");
                }

                // if the vis id is empty, create a new, non-colliding GUID
                if (settings.VisId == Guid.Empty)
                {
                    settings.VisId = Guid.NewGuid();

                    // This is extremely unlikely to ever happen
                    while (Visualizations.ContainsKey(settings.VisId))
                    {
                        Debug.LogWarning("GUID collision! Probably someone made a mistake. If not, you should start playing the lottery!");
                        settings.VisId = Guid.NewGuid();
                    }
                }

                // special case: timeline control view & coordinate system
                GameObject vis;
                if (settings.VisType == VisType.TimelineControl)
                {
                    var timelineControl = Instantiate(TimelineControlPrefab);
                    timelineControl.Init(settings);
                    vis = timelineControl.gameObject;
                    timelineController = timelineControl;
                }
                else if (settings.VisType == VisType.CoordinateSystem3D)
                {
                    var coordinateSystem = Instantiate(CoordinateSystemPrefab);
                    coordinateSystem.Init(settings);
                    vis = coordinateSystem.gameObject;
                    coordinateSystemVis = coordinateSystem;
                }

                // get correct prefab
                AbstractView visPrefab = null;
                foreach (var prefab in VisualizationPrefabs)
                {
                    if (prefab.VisType == settings.VisType)
                    {
                        visPrefab = prefab;
                        break;
                    }
                }

                if (visPrefab == null)
                {
                    throw new Exception("Attempt to spawn unknown visualization! Type: " + settings.VisType);
                }

                // instantiate prefab
                var visInstance = Instantiate(visPrefab);
                visInstance.Init(settings);
                vis = visInstance.gameObject;

                if (settings.AnchorId != -1 && ViewContainers.ContainsKey(settings.AnchorId))
                {
                    // anchor is available
                    ViewContainers[settings.AnchorId].AttachVis(vis.GetComponent <AbstractView>());
                }
                else if (settings.VisType == VisType.TimelineControl)
                {
                    // anchor not available, put at world anchor
                    Transform worldAnchor = GameObject.FindGameObjectWithTag("RootWorldAnchor").transform;
                    vis.transform.SetParent(worldAnchor, false);
                }
                else
                {
                    // anchor not available, put at world anchor
                    Transform worldAnchor = GameObject.FindGameObjectWithTag("VisRootAnchor").transform;
                    vis.transform.SetParent(worldAnchor, false);
                }

                Visualizations[settings.VisId] = vis.GetComponent <AbstractView>();

                // at this point, creation was successful; send message to the other clients if needed
                if (syncWithRemote)
                {
                    var message = new MessageCreateVisualization(settings);
                    Services.NetworkManager().SendMessage(message.Pack());
                }

                // send notification event that a new vis was created
                VisualizationCreatedEventBroadcast.Invoke(settings);

                return(vis);
            }
            catch (Exception e)
            {
                Debug.LogWarning("Creation of requested Visualization failed.");
                Debug.LogError(e.Message);
                Debug.LogError(e.StackTrace);
                return(new GameObject("Creation Failed"));
            }
        }