Example #1
0
        protected void DisplayPlayGameItems(Transform parent, PlayerGameItem item)
        {
            if (item != null)
            {
                //Get the position and rotation info for the GameItem
                var        position         = item.GetVector3Attr(PlayerGameItem.ATTRS_POSITION, Vector3.zero);
                var        rotationVariable = item.GetVector3Attr(PlayerGameItem.ATTRS_ROTATION, Vector3.zero);
                Quaternion rotation         = Quaternion.Euler(rotationVariable);

                GameObject gameObject = null;

                if (item.GiType == typeof(Level).Name)
                {
                    //Level
                    gameObject = Instantiate(LevelHolder,
                                             position, rotation, parent);
                }
                else if (item.GiType == typeof(Character).Name)
                {
                    //Create the character holder
                    gameObject = Instantiate(CharacterHolder,
                                             position, rotation, parent);
                    //Config the prefab
                    var holderComponent = gameObject.GetComponent <CharacterHolder>();
                    holderComponent.BindCharacterPGI(item, item.PrefabType);
                    if (item.IsPlayerCharacter())
                    {
                        //Link to the player's character holder
                        PlayerCharacterHolder = gameObject;
                    }
                }
                else if (item.GiType == typeof(AddressableGameItem).Name)
                {
                    AddressableGameItem gameItem = GameManager.Instance.AddressableGameItems.GetItem(item.GiId);
                    //Won't create GameObject for Skin (Texture).
                    if (gameItem.ContentType != Model.AddressableGameItemMeta.ContentType.Skin)
                    {
                        //AddressableGameItem
                        gameObject = Instantiate(AgiHolder,
                                                 position, rotation, parent);
                        //Config the prefab
                        var holderComponent = gameObject.GetComponent <AddressableGameItemHolder>();
                        holderComponent.Context.ContextMode = GameItems.ObjectModel.GameItemContext.ContextModeType.ByNumber;
                        holderComponent.Context.Number      = item.GiId;
                        holderComponent.PrefabType          = item.PrefabType;
                        holderComponent.PlayerGameItem      = item;
                    }
                }
                if (item.Children != null && gameObject != null)
                {
                    //Handle the children's display
                    foreach (var child in item.Children)
                    {
                        DisplayPlayGameItems(gameObject.transform, child);
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// Convert the equipments in the PlayerDto to the format this component can understand
        /// </summary>
        /// <param name="equipments"></param>
        //private void PopulateCharacterEquipments(List<GameItemEquipment> equipments)
        //{
        //    List<EquipmentInfo> equipmentInfos = new List<EquipmentInfo>();
        //    foreach (var equipment in equipments)
        //    {
        //        EquipmentInfo equipmentInfo = new EquipmentInfo();
        //        equipmentInfo.slot = equipment.EquipSlot;
        //        var gameItem = GameManager.Instance.PlayerGameItems.GetPlayerGameItemById(equipment.GameItemId);
        //        equipmentInfo.equipment = GameManager.Instance.GetIBaseGameItemManager(gameItem.GiType).BaseGetItem(gameItem.GiId);
        //        equipmentInfos.Add(equipmentInfo);
        //    }
        //    EquipmentInfos = equipmentInfos;
        //}

        /// <summary>
        /// Wear the equipable assets, put the resources to proper places in the GameObject tree
        /// </summary>
        /// <returns></returns>
        private async Task EquipAssets()
        {
            if (EquipmentInfos != null)
            {
                Updated = true;
                if (_selectedPrefabInstance != null)
                {
                    _selectedPrefabInstance.hideFlags = HideFlags.HideAndDontSave;
                }
                List <Task> tasks = new List <Task>();
                foreach (var equipmentInfo in EquipmentInfos)
                {
                    if (equipmentInfo.equipment.GetType() == typeof(AddressableGameItem))
                    {
                        AddressableGameItem agi = (AddressableGameItem)equipmentInfo.equipment;
                        agi.Apply(gameObject, equipmentInfo.slot, equipmentInfo.PrefabType);
                        //if (string.IsNullOrEmpty(agi.AddressableName) && string.IsNullOrEmpty(agi.AddressableLabel))
                        //{
                        //    //TODO: Should provide full info for the assets
                        //    //If not supplied the Addressable info, fallback to Package
                        //    tasks.Add(agi.Apply(gameObject, equipmentInfo.slot, null, agi.Package, true));
                        //}
                        //else
                        //{
                        //    tasks.Add(agi.Apply(gameObject, equipmentInfo.slot, new List<string> { agi.AddressableName }, agi.AddressableLabel, true));
                        //}
                    }
                }
                //await Task.WhenAll(tasks.ToArray());

                if (_selectedPrefabInstance != null)
                {
                    _selectedPrefabInstance.hideFlags = HideFlags.None;
                }
            }
        }