예제 #1
0
        async Task <GameObject> LoadPlayerGameObject(PlayerConfig config, Transform transform)
        {
            var pallete = config.Selection.GetPallete();
            var prefab  = await pallete.Prefab.LoadAssetAsync <GameObject>().Task;

            var player = GameObject.Instantiate(prefab, transform.position, Quaternion.identity);

#if UNITY_EDITOR
            player.name = $"Player {config.PlayerID + 1} ({prefab.name})";
#endif
            var playerComponent = ObjectUtil.GetOrAddComponent <Player>(player);
            playerComponent.PlayerID = config.PlayerID;
            return(player);
        }
예제 #2
0
        Entity ToPlayerEntity(PlayerConfig playerConfig, GameObject player)
        {
            var settings = new GameObjectConversionSettings(World,
                                                            GameObjectConversionUtility.ConversionFlags.AssignName,
                                                            _blobAssetStore);
            var entity = GameObjectConversionUtility.ConvertGameObjectHierarchy(player, settings);

            EntityManager.AddComponentData(entity, playerConfig);
            EntityManager.AddComponentData(entity, new PlayerComponent {
                RNG    = new Unity.Mathematics.Random((uint)(Config.RandomSeed ^ (1 << playerConfig.PlayerID))),
                Stocks = (int)Config.Stocks,
                Damage = playerConfig.DefaultDamage,
            });
            Debug.Log($"Player {playerConfig.PlayerID} spawned!");

            foreach (var component in player.GetComponentsInChildren <IConvertGameObjectToEntity>())
            {
                UnityEngine.Object.Destroy((Component)component);
            }

            return(entity);
        }