Example #1
0
        public void Initialize(IGameSettingsManager gameSettingsManager, CinemachineVirtualCamera mainCamera)
        {
            _gameSettingsManager = gameSettingsManager;
            var gameConfig = _gameSettingsManager.GameConfig;

            _player      = Object.Instantiate(gameConfig.PlayerPrefab).GetComponent <IActor>();
            _mazeCreator = new MazeCreator(_gameSettingsManager.GameConfig);
            _player.Initialize(this);

            _mainCamera        = mainCamera;
            _mainCamera.Follow = _player.Transform;

            var fpvCamera = _player.Abilities.Find(ability => ability is AbilityFPV) as AbilityFPV;

            if (fpvCamera != null)
            {
                _fpvCamera = fpvCamera.FpvCamera;
            }

            if (_player == null || !gameConfig.MazeLevelsConfigList.Any())
            {
                return;
            }

            StartLevel(0);
        }
Example #2
0
        /// <summary>
        ///		Called after the client changes scenes
        /// </summary>
        internal static void OnClientSceneChanged()
        {
            Object.Instantiate(netManager.gameMangerPrefab);
            Logger.Info("The scene has been loaded to {Scene}", TCScenesManager.GetActiveScene().scene);

            DisplayMotdAndOrCreatePlayer().Forget();
        }
Example #3
0
        internal UnityObject CreateInstance()
        {
            UnityObject asset = GetAsset();

            if (asset != null)
            {
                UnityObject instance = UnityObject.Instantiate(asset);
                bool        isAdded  = false;
                for (int i = 0; i < instanceRefs.Count; i++)
                {
                    if (!instanceRefs[i].TryGetTarget(out var _))
                    {
                        isAdded = true;
                        instanceRefs[i].SetTarget(instance);
                        break;
                    }
                }
                if (!isAdded)
                {
                    instanceRefs.Add(new WeakReference <UnityObject>(instance));
                }
                return(instance);
            }
            return(null);
        }
Example #4
0
        public InfrastructureView Cteate(Infrastructure element)
        {
            var prefab = _infrastructureViews[element];
            var view   = Object.Instantiate(prefab);

            return(view);
        }
Example #5
0
        private static async UniTaskVoid DisplayMotdAndOrCreatePlayer()
        {
            await UniTask.WaitUntil(() => clientReceivedConfig);

            //If the server has an MOTD, display it before creating a player object
            if (netManager.serverConfig.motdMode != Server.ServerMOTDMode.Disabled && ClientMotdMode != ClientMOTDMode.Disable)
            {
                if (netManager.serverConfig.motdMode == Server.ServerMOTDMode.WebOnly && ClientMotdMode == ClientMOTDMode.TextOnly)
                {
                    RequestPlayerObject();
                    return;
                }

                try
                {
                    MOTDUI motdUILogic = Object.Instantiate(netManager.motdUIPrefab).GetComponent <MOTDUI>();
                    motdUILogic.Setup(netManager.serverConfig, RequestPlayerObject);
                    return;
                }
                catch (InvalidMOTDSettings ex)
                {
                    Logger.Error(ex, "Something was wrong with the server's MOTD settings!");
                    netManager.StopHost();
                    return;
                }
            }

            RequestPlayerObject();
        }
Example #6
0
 public ItemSystem(Item data, IEntitySystem owner)
 {
     Owner       = owner;
     Data        = U.Instantiate(data);
     defaultData = data;
     Index       = (owner as PlayerSystem).ItemsCount;
 }
Example #7
0
        private void SpawnPlayerCharacter(UserHandler userHandler)
        {
            // Спавним игрока
            var playerEntity = Object.Instantiate(Session.PlayerEntityPrefab);

            playerEntity.gameObject.transform.position = SpawnPoint.SpawnPoints.Random().transform.position;
            playerEntity.owner = userHandler.UserConnection.User;
            playerEntity.team  = TeamType.Chaos;
            NetworkFactory.SpawnForAll(playerEntity.gameObject, userHandler.UserConnection);

            // Спавн контроллера
            var playerController = Object.Instantiate(Session.PlayerController);

            playerController.gameObject.name = $"PC [{playerEntity.owner.id}]";
            NetworkFactory.SpawnForConnection(playerController.gameObject, userHandler.UserConnection);
            playerController.SetPlayerEntity(playerEntity);
            playerController.playerEntityId = playerEntity.netId;

            userHandler.RelatedPlayerEntity = playerEntity;
            userHandler.AddGameObject(playerEntity.gameObject);
            userHandler.AddGameObject(playerController.gameObject);

            Session.AddPlayerEntity(playerEntity);
            OnPlayerEntitySpawned(playerEntity);
        }
Example #8
0
        private static void OnReceivedServerConfig(NetworkConnection conn, ServerConfig config)
        {
            //Server has sent config twice in the same scene session? Probs a modified server
            if (clientHasPlayer)
            {
                Logger.Error("The server has sent it's config twice in the same scene session!");
                return;
            }

            //Set the game name
            netManager.serverConfig = config;

            ClientMotdMode = GameSettings.MultiplayerSettings.MOTDMode;

            //If the server has an MOTD, display it before creating a player object
            if (config.motdMode != Server.ServerMOTDMode.Disabled && ClientMotdMode != ClientMOTDMode.Disable)
            {
                try
                {
                    MOTDUI motdUILogic = Object.Instantiate(netManager.motdUIPrefab).GetComponent <MOTDUI>();
                    motdUILogic.Setup(config, () => RequestPlayerObject(conn));
                    return;
                }
                catch (InvalidMOTDSettings ex)
                {
                    Logger.Error(ex, "Something was wrong with the server's MOTD settings!");
                    netManager.StopHost();
                    return;
                }
            }

            RequestPlayerObject(conn);
        }
Example #9
0
        private void CreateFollowedField()
        {
            var levelRecord = ScriptableUtils.GetCurrentLevelRecord();

            _followedField = Object.Instantiate(levelRecord.Field);
            _followedField.SetPlayer(_player);
        }
        public T Execute <T>(Instantiable def) where T : GameCollision
        {
            var collision = Object.Instantiate(def.GetPrefab()).GetComponent <T>();

            AddCollision(collision);
            return(collision);
        }
Example #11
0
        protected override object _Spawn()
        {
            Object clone = Object.Instantiate(prefab);

            clone.name = prefab.name;
            return(clone);
        }
 public void SpawnPlayer()
 {
     _playerActor = Object.Instantiate(_playerConfig.GetActor());
     _playerActor.Init(_tickManager.Processor, _cameraManager.GameCamera);
     _playerActor.GetData <SpellData>().Add(_spellManager.GetDefaultSpell());
     _cameraManager.SetCameraTarget(_playerActor);
 }
        private TUnityObject CreateNew()
        {
            var newUnityObject = Object.Instantiate(_template);

            _created?.Invoke(newUnityObject);
            return(newUnityObject);
        }
Example #14
0
 /// <summary>
 /// 实例化资源
 /// </summary>
 /// <param name="address"></param>
 /// <param name="asset"></param>
 /// <returns></returns>
 protected internal override UnityObject InstantiateAsset(string address, UnityObject asset)
 {
     if (asset != null)
     {
         return(UnityObject.Instantiate(asset));
     }
     return(null);
 }
Example #15
0
 protected override T GetInstantiateObjectEx <T>()
 {
     if (AssetObject == null || !CanInstantiate())
     {
         return(null);
     }
     return(UnityObject.Instantiate(AssetObject) as T);
 }
Example #16
0
 /// <summary> Creates an object by instaniating th
 /// <see cref="AbstractPool{T}.Create" />
 /// </summary>
 /// <exception cref="InvalidOperationException"> the source prefab has been destroyed </exception>
 protected override T Create()
 {
     if (!_source)
     {
         throw new InvalidOperationException();
     }
     return(Object.Instantiate(_source));
 }
Example #17
0
 protected internal override UnityObject GetInstance(UnityObject uObj)
 {
     if (uObj != null)
     {
         return(UnityObject.Instantiate(uObj));
     }
     return(null);
 }
Example #18
0
        public override T GetInstantiateObject <T>()
        {
            T t = null;

            if (AssetObject != null && CanInstantiate())
            {
                t = Object.Instantiate(AssetObject) as T;
            }
            return(t);
        }
        protected override T GetInstantiateObjectEx <T>()
        {
            T t = null;

            if (AssetObject != null && CanInstantiate())
            {
                t = UnityObject.Instantiate(AssetObject) as T;
            }
            return(t);
        }
Example #20
0
        protected internal override UnityObject GetInstance(UnityObject uObj)
        {
            if (uObj != null)
            {
                UnityObject instance = UnityObject.Instantiate(uObj);
                AddInstance(instance);

                return(instance);
            }
            return(null);
        }
        void IInitializable.Initialize()
        {
            var initializer = UnityObject.Instantiate(_settings.InitializerPrefab);

            if (initializer.gameObject.GetComponent <CriAtom>() == null)
            {
                var atom = initializer.gameObject.AddComponent <CriAtom>();
                atom.dontDestroyOnLoad = initializer.dontDestroyOnLoad;
                atom.acfFile           = initializer.atomConfig.acfFileName;
            }
        }
Example #22
0
 protected internal override UnityObject GetInstance()
 {
     if (uObject != null)
     {
         return(UnityObject.Instantiate(uObject));
     }
     else
     {
         DebugLog.Error(AssetConst.LOGGER_NAME, "State is not finished or object is null");
         return(null);
     }
 }
        public override void Deserialize(NetworkReader reader)
        {
            ImageTargetIndex = reader.ReadInt32();
            StepOrder        = reader.ReadUInt32();

            var application = Object.FindObjectOfType <Base.Application>();

            Data = Object.Instantiate(application.Prefabs.StepModelPrefab);
            var data = new MemoryStream(reader.ReadBytes(reader.Length - 8));

            Data.Deserialize(new BinaryReader(data));
        }
Example #24
0
        static void ProcessAlembicStreamPlayerAssets(AlembicStreamPlayer streamPlayer, string streamingAssetsPath)
        {
            streamPlayer.StreamDescriptor = Object.Instantiate(streamPlayer.StreamDescriptor);// make a copy
            var srcPath = streamPlayer.StreamDescriptor.PathToAbc;

            // Avoid name collisions by hashing the full path
            var hashedFilename = HashSha1(srcPath) + ".abc";
            var dstPath        = Path.Combine(streamingAssetsPath, hashedFilename);

            AlembicBuildPostProcess.FilesToCopy.Add(new KeyValuePair <string, string>(srcPath, dstPath));

            streamPlayer.StreamDescriptor.PathToAbc = hashedFilename;
        }
Example #25
0
        public static void Build()
        {
            var holderPrefab = ResourceProvider.GetResource <CataloguePanel>(CatalogueItemsHolderPath);

            _cataloguePanel = Object.Instantiate(holderPrefab, UiController.Instance.MainCanvas.transform);
            _itemPrefab     = ResourceProvider.GetResource <CatalogueItem>(CatalogueItemPath);

            var products = GetProductsFromAsset();

            products.ForEach(CreateItem);
            UiController.Instance.Catalogue = _cataloguePanel;
            _cataloguePanel.gameObject.SetActive(false);
        }
Example #26
0
        // Create an instance of the blueprint and return it
        private T NewObject(T blueprint)
        {
            if (CreateFunction != null)
            {
                return(CreateFunction(blueprint));
            }

            if (blueprint == null || !(blueprint is Object))
            {
                return(null);
            }

            return(Object.Instantiate(blueprint as Object) as T);
        }
Example #27
0
        public void Initialize(PopupInputMenu menu)
        {
            if (Menu != null)
            {
                return;
            }
            var parent     = menu.transform.parent.gameObject;
            var parentCopy = Object.Instantiate(parent);

            parentCopy.AddComponent <DontDestroyOnLoad>();
            _inputMenu = parentCopy.transform.GetComponentInChildren <PopupInputMenu>(true);
            Object.Destroy(_inputMenu.GetValue <Text>("_labelText").GetComponent <LocalizedText>());
            Initialize((Menu)_inputMenu);
        }
Example #28
0
        public async Task <Widget> CreateInstance(IUIStack manager, string name, UIMessage message)
        {
            var loader = Her.Resolve <IViewLoader>();
            var prefab = await loader.LoadView(name);

            if (prefab == null)
            {
                throw new Exception($"Load view: {name} failed");
            }

            var instance = Object.Instantiate(prefab).GetComponent <Widget>();

            instance.SetManagerInfo(name, manager, message);
            return(instance);
        }
Example #29
0
        public T GetObject()
        {
            T tile;

            if (Pool.Count > 0)
            {
                tile = Pool.Pop();
                tile.gameObject.SetActive(true);
            }
            else
            {
                tile = Object.Instantiate(ObjPrefab);
            }
            tile.ResetToDefault();
            return(tile);
        }
        private static BlueprintScriptableObject PatchBlueprint(string assetId, BlueprintScriptableObject blueprint)
        {
            if (blueprintRegex == null)
            {
                // Catastrophic failure - assume we're downgrading.
                Downgrade = true;
                return(blueprint);
            }

            var match = blueprintRegex.Match(assetId);

            if (!match.Success)
            {
                return(blueprint);
            }

            if (!enabled)
            {
                Downgrade = true;
                return(blueprint);
            }

            if (blueprint.AssetGuid.Length == VanillaAssetIdLength)
            {
                // We have the original blueprint - clone it so we can make modifications which won't affect the original.
                blueprint = Object.Instantiate(blueprint);
            }

            // Patch the blueprint
            var newAssetId = patchBlueprint(blueprint, match);

            if (newAssetId != null)
            {
                // Insert patched blueprint into ResourcesLibrary under the new GUID.
                Main.Accessors.SetBlueprintScriptableObjectAssetGuid(blueprint, newAssetId);
                if (ResourcesLibrary.LibraryObject.BlueprintsByAssetId != null)
                {
                    ResourcesLibrary.LibraryObject.BlueprintsByAssetId[newAssetId] = blueprint;
                }
                ResourcesLibrary.LibraryObject.GetAllBlueprints().Add(blueprint);
                // Also record the custom GUID so we can clean it up if the mod is later disabled.
                CustomBlueprintIDs.Add(newAssetId);
            }

            return(blueprint);
        }