Ejemplo n.º 1
0
        private RealtimeViewComponentsModel CreateChildViewsModel(Dictionary <int, RealtimeView> childViewMap)
        {
            // Create models for all views
            Dictionary <int, IModel> childViewModelMap = new Dictionary <int, IModel>();

            foreach (KeyValuePair <int, RealtimeView> pair in childViewMap)
            {
                int          viewID = pair.Key;
                RealtimeView view   = pair.Value;

                if (view == null)
                {
                    // Note: Deprecated view IDs will have a null view property. This is normal and they can be safely ignored.
                    continue;
                }

                // Create model
                RealtimeViewModel viewModel = view._CreateChildViewModel();
                if (viewModel == null)
                {
                    Debug.LogError("Model supplied by child RealtimeView is null. Skipping view: (" + viewID + ":" + view + ")", view);
                    continue;
                }

                // Set model
                childViewModelMap[viewID] = viewModel;
            }

            // Create RealtimeViewComponentsModel
            RealtimeViewComponentsModel childViewsModel = new RealtimeViewComponentsModel(childViewModelMap);

            return(childViewsModel);
        }
Ejemplo n.º 2
0
        public RealtimeViewModel _CreateRootSceneViewModel()
        {
            if (!isRootSceneView)
            {
                Debug.LogError("RealtimeView: Asked to create root scene view model for view that's not a root scene view. This is a bug!");
            }

            // Create components model
            Dictionary <int, Tuple <Component, MethodInfo, PropertyInfo, PropertyInfo> > componentMap = CreateComponentMap();
            RealtimeViewComponentsModel componentsModel = CreateComponentsModel(componentMap);

            // Create child views model
            Dictionary <int, RealtimeView> childViewsMap   = CreateChildViewMap();
            RealtimeViewComponentsModel    childViewsModel = CreateChildViewsModel(childViewsMap);

            // Ownership / lifetime flags
            int  ownerID       = _sceneViewOwnedByCreatingClient ? _realtime.clientID : -1;
            uint lifetimeFlags = 0;

            if (_sceneViewPreventOwnershipTakeover)
            {
                lifetimeFlags |= (uint)MetaModel.LifetimeFlags.PreventOwnershipTakeover;
            }

            if (_sceneViewDestroyWhenOwnerOrLastClientLeaves)
            {
                lifetimeFlags |= (uint)MetaModel.LifetimeFlags.DestroyWhenOwnerOrLastClientLeaves;
            }

            // Create RealtimeViewModel
            RealtimeViewModel viewModel = new RealtimeViewModel(_sceneViewUUID, ownerID, lifetimeFlags, componentsModel, childViewsModel);

            return(viewModel);
        }
Ejemplo n.º 3
0
 private void PrefabViewModelAddedToSet(RealtimeSet <RealtimeViewModel> set, RealtimeViewModel model, bool remote)
 {
     if (prefabRealtimeViewModelAdded != null)
     {
         prefabRealtimeViewModelAdded(this, model, remote);
     }
 }
Ejemplo n.º 4
0
 public void AddPrefabRealtimeViewModel(RealtimeViewModel prefabViewModel)
 {
     if (!_prefabViewModels.Add(prefabViewModel))
     {
         UnityEngine.Debug.LogError("RealtimeViewModel already exists in Datastore! This is a bug!");
         return;
     }
 }
Ejemplo n.º 5
0
 public bool AddSceneRealtimeViewModel(RealtimeViewModel viewModel)
 {
     if (viewModel.sceneViewUUID.Length == 0)
     {
         UnityEngine.Debug.LogError("Scene RealtimeView is missing a UUID. This is a bug!");
         return(false);
     }
     if (!_sceneViewModels.Add(viewModel))
     {
         UnityEngine.Debug.LogError("RealtimeViewModel already exists in Datastore! This is a bug!");
         return(false);
     }
     return(true);
 }
Ejemplo n.º 6
0
        public RealtimeViewModel _CreateChildViewModel()
        {
            if (!isChildView)
            {
                Debug.LogError("RealtimeView: Asked to create child view model for view that's not a child view. This is a bug!");
            }

            // Create components model
            Dictionary <int, Tuple <Component, MethodInfo, PropertyInfo, PropertyInfo> > componentMap = CreateComponentMap();
            RealtimeViewComponentsModel componentsModel = CreateComponentsModel(componentMap);

            // Create child views model
            Dictionary <int, RealtimeView> childViewsMap   = CreateChildViewMap();
            RealtimeViewComponentsModel    childViewsModel = CreateChildViewsModel(childViewsMap);

            // Create RealtimeViewModel
            RealtimeViewModel viewModel = new RealtimeViewModel(componentsModel, childViewsModel);

            return(viewModel);
        }
Ejemplo n.º 7
0
        public RealtimeViewModel _CreateRootPrefabViewModel(string prefabName, int ownerID, uint lifetimeFlags)
        {
            if (!isRootPrefabView)
            {
                Debug.LogError("RealtimeView: Asked to create root prefab view model for view that's not on the root of a prefab. This is a bug!");
            }

            // Create components model
            Dictionary <int, Tuple <Component, MethodInfo, PropertyInfo, PropertyInfo> > componentMap = CreateComponentMap();
            RealtimeViewComponentsModel componentsModel = CreateComponentsModel(componentMap);

            // Create child views model
            Dictionary <int, RealtimeView> childViewsMap   = CreateChildViewMap();
            RealtimeViewComponentsModel    childViewsModel = CreateChildViewsModel(childViewsMap);

            // Create RealtimeViewModel
            RealtimeViewModel viewModel = new RealtimeViewModel(prefabName, ownerID, lifetimeFlags, componentsModel, childViewsModel);

            return(viewModel);
        }
Ejemplo n.º 8
0
        private void SetModel(RealtimeViewModel model)
        {
            if (model == _model)
            {
                return;
            }

            if (_model != null)
            {
                _model._SetRealtimeView(null);
            }

            _model = model;

            if (_model != null)
            {
                _model._SetRealtimeView(this);

                Dictionary <int, Tuple <Component, MethodInfo, PropertyInfo, PropertyInfo> > componentMap = CreateComponentMap();

                // Create components model if needed (can happen if RealtimeViewModel existed in the datastore but hasn't been linked to a RealtimeView yet)
                RealtimeViewComponentsModel componentsModel = _model.componentsModel;
                if (_model.componentsModel == null)
                {
                    componentsModel = CreateComponentsModel(componentMap);
                    _model.SetComponentsModelAndDeserializeCachedModelsIfNeeded(componentsModel);
                }

                // Loop through components and assign models
                foreach (KeyValuePair <int, Tuple <Component, MethodInfo, PropertyInfo, PropertyInfo> > pair in componentMap)
                {
                    int          componentID          = pair.Key;
                    Component    component            = pair.Value.First;
                    MethodInfo   createModelMethod    = pair.Value.Second;
                    PropertyInfo modelProperty        = pair.Value.Third;
                    PropertyInfo realtimeViewProperty = pair.Value.Fourth;

                    IModel componentModel = componentsModel[componentID];
                    if (componentModel == null)
                    {
                        Debug.LogError("RealtimeView is attempting to connect a component to its model, but cannot find model for component: (" + componentID + ":" + component + "). This is a bug!", component);
                        continue;
                    }

                    // Set realtime view reference on object if it supports it
                    if (realtimeViewProperty != null)
                    {
                        realtimeViewProperty.SetValue(component, this, null);
                    }

                    // Set model on component
                    modelProperty.SetValue(component, componentModel, null);
                }

                Dictionary <int, RealtimeView> childViewMap = CreateChildViewMap();

                // Create child views model if needed (can happen if RealtimeViewModel existed in the datastore but hasn't been linked to a RealtimeView yet)
                RealtimeViewComponentsModel childViewsModel = _model.childViewsModel;
                if (childViewsModel == null)
                {
                    childViewsModel = CreateChildViewsModel(childViewMap);
                    _model.SetChildViewsModelAndDeserializeCachedModelsIfNeeded(childViewsModel);
                }

                // Loop through child views and assign models
                foreach (KeyValuePair <int, RealtimeView> pair in childViewMap)
                {
                    int          viewID = pair.Key;
                    RealtimeView view   = pair.Value;

                    RealtimeViewModel viewModel = childViewsModel[viewID] as RealtimeViewModel;
                    if (viewModel == null)
                    {
                        Debug.LogError("RealtimeView attempting to connect child view to its models, but cannot find model for view: (" + viewID + ":" + view + "). This is a bug!", view);
                        continue;
                    }

                    // Set realtime instance and model
                    view._SetRealtime(_realtime);
                    view.model = viewModel;
                }
            }
        }
Ejemplo n.º 9
0
 public bool RemovePrefabRealtimeViewModel(RealtimeViewModel model)
 {
     return(_prefabViewModels.Remove(model));
 }