public void UpdateObject(ObjectDto objectDto)
        {
            GameEntity entityObject = GameStateData.GetEntity(objectDto.InstanceId);

            entityObject.name.Value = objectDto.Name;
            OnUpdateObject?.Invoke(entityObject, objectDto);
        }
Exemplo n.º 2
0
        private static void LoadAssemby(string dllPath, string dllName, ref byte[] byteData,
                                        ref Dictionary <string, Type> typesInDll)
        {
            if (!Directory.Exists(dllPath))
            {
                Directory.CreateDirectory(dllPath);
            }

            string dllFileName = dllPath + "/" + dllName;

            File.WriteAllBytes(dllFileName, byteData);
            Assembly assembly = Assembly.Load(byteData);

            GameStateData.AddAssembly(assembly.ManifestModule.Name, dllFileName);

            foreach (Type exportedType in assembly.GetExportedTypes())
            {
                Debug.Log(exportedType + " is loaded!");

                if (exportedType.FullName != null)
                {
                    typesInDll.Add(exportedType.FullName, exportedType);
                }
            }
        }
Exemplo n.º 3
0
        public static void ReloadLocationObjects()
        {
            _logger.Info($"Reloading location objects for world location {WorldData.WorldLocationId}");
            ParentManager.Instance.ParentCommand = ParentCommand.None;
            GameStateData.ClearObjects();
            WorldData.ObjectsAreChanged = false;
            WorldLocation location      = WorldData.WorldStructure.WorldLocations.GetWorldLocation(WorldData.WorldLocationId);
            LogicInstance logicInstance = new LogicInstance(WorldData.WorldLocationId);

            GameStateData.RefreshLogic(logicInstance, WorldData.LogicCode);
            CreateSpawnEntities(location.WorldLocationObjects, WorldData.WorldLocationId);
            WorldDataListener.Instance.ReadyToGetNewMessages();
        }
Exemplo n.º 4
0
        public static void LoadLocationObjects(int newWorldLocationId, int oldWorldLocationId)
        {
            _logger.Info($"Loading location objects for world location {newWorldLocationId}");
            ParentManager.Instance.ParentCommand = ParentCommand.None;

            GameStateData.ClearObjects();
            WorldData.ObjectsAreChanged = false;
            WorldLocation location      = WorldData.WorldStructure.WorldLocations.GetWorldLocation(newWorldLocationId);
            LogicInstance logicInstance = new LogicInstance(newWorldLocationId);

            GameStateData.RefreshLogic(logicInstance, WorldData.LogicCode);
            CreateSpawnEntities(location.WorldLocationObjects, newWorldLocationId);
        }
Exemplo n.º 5
0
        /// <summary>
        ///     Initialize object in platform
        /// </summary>
        /// <param name="idObject">Object type id. Used for save.</param>
        /// <param name="spawnInitParams">Parameters for spawn</param>
        /// <param name="spawnedGameObject">Game object for init</param>
        public static void InitObject(int idObject, SpawnInitParams spawnInitParams, GameObject spawnedGameObject, Config config)
        {
            //var photonView = AddPhoton(spawnedGameObject, spawnInitParams.spawnAsset.IdPhoton);
            GameObject gameObjectLink = spawnedGameObject;
            int        idLocation     = spawnInitParams.IdLocation;
            int        idServer       = spawnInitParams.IdServer;
            int        idInstance     = spawnInitParams.IdInstance;
            string     name           = spawnInitParams.Name;
            var        parentId       = spawnInitParams.ParentId;

            ObjectController parent = null;

            if (parentId != null)
            {
                parent = GameStateData.GetObjectInLocation(parentId.Value);
            }

            WrappersCollection wrappersCollection = null;

            if (idLocation != 0)
            {
                wrappersCollection = GameStateData.GetWrapperCollection();
            }

            InitObjectParams initObjectParams = new InitObjectParams
            {
                Id                 = idInstance,
                IdObject           = idObject,
                IdLocation         = idLocation,
                IdServer           = idServer,
                Asset              = gameObjectLink,
                Name               = name,
                RootGameObject     = spawnedGameObject,
                WrappersCollection = wrappersCollection,
                Parent             = parent,
                Config             = config
            };

            var newController = new ObjectController(initObjectParams);

            ObjectControllerCreated?.Invoke(newController);
        }
Exemplo n.º 6
0
        private static void CreatePrefabEntity(IResponse response, ref GameEntity counter, PrefabObject o, Sprite icon = null)
        {
            ResponseAsset responseAsset = (ResponseAsset)response;
            Object        unityObject   = responseAsset.Asset;
            PrefabObject  serverObject  = (PrefabObject)responseAsset.UserData[0];
            GameEntity    entity        = Contexts.sharedInstance.game.CreateEntity();

            entity.AddServerObject(serverObject);
            GameStateData.AddPrefabGameObject(serverObject.Id, responseAsset.Asset, o);
            GameStateData.AddObjectIcon(serverObject.Id, icon);

            if (o.Embedded)
            {
                GameStateData.AddToEmbeddedList(serverObject.Id);
            }

            AddCastComponent(unityObject, entity);
            entity.AddIcon(icon);
            counter.loadObjectsCounter.PrefabsLoaded++;
            LogManager.GetCurrentClassLogger().Info(o.Config.i18n.en + " is loaded");
        }
        public void LoadWorldConfiguration(int worldConfigurationId, out int worldLocationId)
        {
            _logger.Info($"Loading world configuration {worldConfigurationId}...");
            GameStateData.ClearObjects();
            worldLocationId = 0;

            foreach (WorldConfiguration worldConfiguration in WorldData.WorldStructure.WorldConfigurations)
            {
                if (worldConfiguration.Id != worldConfigurationId)
                {
                    continue;
                }

                worldLocationId = GetStartLocation(worldConfigurationId);
            }

            if (worldLocationId == 0)
            {
                _logger.Error($"World configuration id = {worldConfigurationId} not found!");
            }

            int newWorldLocationId = worldLocationId;
            int oldWorldLocationId = WorldData.WorldLocationId;

            WorldData.Update(WorldData.WorldId, newWorldLocationId, worldConfigurationId);

            WorldData.OnLoadObjects    = null;
            WorldData.ObjectsAreLoaded = false;

            WorldData.OnLoadObjects = delegate
            {
                WorldData.OnLoadLocation = delegate
                {
                    Helper.LoadLocationObjects(newWorldLocationId, oldWorldLocationId);
                    WorldData.OnLoadObjects = null;
                };
            };
        }
        private IEnumerator StopLogicAndLoadSceneCoroutine(int newWorldLocationId, int oldWorldLocationId)
        {
            GameStateData.ClearLogic();

            yield return(new WaitForEndOfFrame());

            GameStateData.ClearObjects();

            if (newWorldLocationId == oldWorldLocationId)
            {
                //Hide everything

                Helper.LoadLocationObjects(newWorldLocationId, oldWorldLocationId);

                LoadWorldDescriptor();

                yield return(new WaitForSeconds(1.0f));

                yield break;
            }

            Debug.Log("Loading loading Scene");

            AsyncOperation loadLoading = SceneManager.LoadSceneAsync("Loading", LoadSceneMode.Additive);

            while (!loadLoading.isDone)
            {
                yield return(null);
            }

            Debug.Log("Unloading old Scene");
            //Hide everything
            // GameStateData.ClearObjects();

            AsyncOperation unloadSceneOperation = SceneManager.UnloadSceneAsync(SceneManager.GetSceneAt(0));

            while (!unloadSceneOperation.isDone)
            {
                yield return(null);
            }

            Resources.UnloadUnusedAssets();

            Debug.Log("Preparing everything");

            GameObjects.Instance.PlayerRig.GetComponentInChildren <VRTK_SDKSetup>().actualBoundaries.transform.position = Vector3.zero;

            WorldData.Update(WorldData.WorldId, newWorldLocationId, WorldData.WorldConfigurationId);
            WorldData.OnLoadObjects    = null;
            WorldData.ObjectsAreLoaded = false;
            Debug.Log("WorldDataListener.StopLogicAndLoadSceneCoroutine()");

            WorldData.OnLoadObjects = delegate
            {
                WorldData.OnLoadLocation = delegate
                {
                    Helper.LoadLocationObjects(newWorldLocationId, oldWorldLocationId);
                };
            };

            int locationId = WorldData.WorldStructure.WorldLocations.GetWorldLocation(newWorldLocationId).LocationId;

            SceneLoaderSystem
                sceneLoader =
                new SceneLoaderSystem(Contexts.sharedInstance,
                                      null,
                                      locationId);

            sceneLoader.Initialize();



            yield return(true);
        }