Exemplo n.º 1
0
        public void LoadParcelScenesExecute(string scenePayload)
        {
            LoadParcelScenesMessage.UnityParcelScene scene;

            ProfilingEvents.OnMessageDecodeStart?.Invoke(MessagingTypes.SCENE_LOAD);
            scene = Utils.SafeFromJson <LoadParcelScenesMessage.UnityParcelScene>(scenePayload);
            ProfilingEvents.OnMessageDecodeEnds?.Invoke(MessagingTypes.SCENE_LOAD);

            if (scene == null || scene.id == null)
            {
                return;
            }

            var sceneToLoad = scene;


            DebugConfig debugConfig = DataStore.i.debugConfig;

#if UNITY_EDITOR
            if (debugConfig.soloScene && sceneToLoad.basePosition.ToString() != debugConfig.soloSceneCoords.ToString())
            {
                SendSceneReady(sceneToLoad.id);
                return;
            }
#endif

            ProfilingEvents.OnMessageProcessStart?.Invoke(MessagingTypes.SCENE_LOAD);

            IWorldState worldState = Environment.i.world.state;

            if (!worldState.loadedScenes.ContainsKey(sceneToLoad.id))
            {
                var newGameObject = new GameObject("New Scene");

                var newScene = newGameObject.AddComponent <ParcelScene>();
                newScene.SetData(sceneToLoad);

                if (debugConfig.isDebugMode)
                {
                    newScene.InitializeDebugPlane();
                }

                newScene.ownerController = this;
                worldState.loadedScenes.Add(sceneToLoad.id, newScene);
                worldState.scenesSortedByDistance.Add(newScene);

                sceneSortDirty = true;

                OnNewSceneAdded?.Invoke(newScene);

                Environment.i.messaging.manager.AddControllerIfNotExists(this, newScene.sceneData.id);

                if (VERBOSE)
                {
                    Debug.Log($"{Time.frameCount} : Load parcel scene {newScene.sceneData.basePosition}");
                }
            }

            ProfilingEvents.OnMessageProcessEnds?.Invoke(MessagingTypes.SCENE_LOAD);
        }
Exemplo n.º 2
0
        public bool ProcessMessage(QueuedSceneMessage_Scene msgObject, out CustomYieldInstruction yieldInstruction)
        {
            string sceneId = msgObject.sceneId;
            string method  = msgObject.method;

            yieldInstruction = null;

            IParcelScene scene;
            bool         res         = false;
            IWorldState  worldState  = Environment.i.world.state;
            DebugConfig  debugConfig = DataStore.i.debugConfig;

            if (worldState.loadedScenes.TryGetValue(sceneId, out scene))
            {
#if UNITY_EDITOR
                if (debugConfig.soloScene && scene is GlobalScene && debugConfig.ignoreGlobalScenes)
                {
                    return(false);
                }
#endif
                if (!scene.GetSceneTransform().gameObject.activeInHierarchy)
                {
                    return(true);
                }

#if UNITY_EDITOR
                OnMessageProcessInfoStart?.Invoke(sceneId, method);
#endif
                ProfilingEvents.OnMessageProcessStart?.Invoke(method);

                ProcessMessage(scene as ParcelScene, method, msgObject.payload, out yieldInstruction);

                ProfilingEvents.OnMessageProcessEnds?.Invoke(method);

#if UNITY_EDITOR
                OnMessageProcessInfoEnds?.Invoke(sceneId, method);
#endif

                res = true;
            }

            else
            {
                res = false;
            }

            sceneMessagesPool.Enqueue(msgObject);

            return(res);
        }
Exemplo n.º 3
0
        public void CreateUIScene(string json)
        {
#if UNITY_EDITOR
            DebugConfig debugConfig = DataStore.i.debugConfig;

            if (debugConfig.soloScene && debugConfig.ignoreGlobalScenes)
            {
                return;
            }
#endif
            CreateUISceneMessage uiScene = Utils.SafeFromJson <CreateUISceneMessage>(json);

            string uiSceneId = uiScene.id;

            IWorldState worldState = Environment.i.world.state;

            if (worldState.loadedScenes.ContainsKey(uiSceneId))
            {
                return;
            }

            var newGameObject = new GameObject("UI Scene - " + uiSceneId);

            var newScene = newGameObject.AddComponent <GlobalScene>();
            newScene.ownerController    = this;
            newScene.unloadWithDistance = false;
            newScene.isPersistent       = true;

            LoadParcelScenesMessage.UnityParcelScene data = new LoadParcelScenesMessage.UnityParcelScene
            {
                id           = uiSceneId,
                basePosition = new Vector2Int(0, 0),
                baseUrl      = uiScene.baseUrl
            };

            newScene.SetData(data);

            worldState.loadedScenes.Add(uiSceneId, newScene);
            OnNewSceneAdded?.Invoke(newScene);

            worldState.globalSceneId = uiSceneId;

            Environment.i.messaging.manager.AddControllerIfNotExists(this, worldState.globalSceneId, isGlobal: true);

            if (VERBOSE)
            {
                Debug.Log($"Creating UI scene {uiSceneId}");
            }
        }
Exemplo n.º 4
0
        public void CreateGlobalScene(string json)
        {
#if UNITY_EDITOR
            DebugConfig debugConfig = DataStore.i.debugConfig;

            if (debugConfig.soloScene && debugConfig.ignoreGlobalScenes)
            {
                return;
            }
#endif
            CreateGlobalSceneMessage globalScene = Utils.SafeFromJson <CreateGlobalSceneMessage>(json);

            string newGlobalSceneId = globalScene.id;

            IWorldState worldState = Environment.i.world.state;

            if (worldState.loadedScenes.ContainsKey(newGlobalSceneId))
            {
                return;
            }

            var newGameObject = new GameObject("Global Scene - " + newGlobalSceneId);

            var newScene = newGameObject.AddComponent <GlobalScene>();
            newScene.ownerController      = this;
            newScene.unloadWithDistance   = false;
            newScene.isPersistent         = true;
            newScene.sceneName            = globalScene.name;
            newScene.isPortableExperience = globalScene.isPortableExperience;

            LoadParcelScenesMessage.UnityParcelScene data = new LoadParcelScenesMessage.UnityParcelScene
            {
                id           = newGlobalSceneId,
                basePosition = new Vector2Int(0, 0),
                baseUrl      = globalScene.baseUrl,
                contents     = globalScene.contents
            };

            newScene.SetData(data);

            if (!string.IsNullOrEmpty(globalScene.icon))
            {
                newScene.iconUrl = newScene.contentProvider.GetContentsUrl(globalScene.icon);
            }

            worldState.loadedScenes.Add(newGlobalSceneId, newScene);
            OnNewSceneAdded?.Invoke(newScene);

            if (newScene.isPortableExperience)
            {
                OnNewPortableExperienceSceneAdded?.Invoke(newScene);
            }

            worldState.globalSceneIds.Add(newGlobalSceneId);

            Environment.i.messaging.manager.AddControllerIfNotExists(this, newGlobalSceneId, isGlobal: true);

            if (VERBOSE)
            {
                Debug.Log($"Creating Global scene {newGlobalSceneId}");
            }
        }