Exemplo n.º 1
0
        /// <summary>
        /// Bind a Character PlayerGameItem to this component, the prefab of of the Character will be displayed,
        /// and the equipment will be equipped
        /// </summary>
        /// <param name="gameItem"></param>
        /// <param name="localisablePrefabType"></param>
        public virtual async Task BindCharacterPGI(PlayerGameItem gameItem, LocalisablePrefabType localisablePrefabType = LocalisablePrefabType.InGame)
        {
            if (gameItem == null || gameItem.GiType != typeof(Character).Name)
            {
                Debug.LogError("Only Character PlayerGameItem is allowed!");
                return;
            }
            PlayerGameItem = gameItem;

            await AttachCharacterPrefabById(gameItem.GiId, localisablePrefabType);


            var equipments = gameItem.Equipments;//new List<CharacterEquipment>(GameManager.Instance.Players.Selected.PlayerDto.CharacterEquipments[gameItem.Id]);

            if (equipments != null)
            {
                PopulateCharacterEquipments(equipments);
                Updated = false;
                if (!Updated)
                {
                    //If the equipment is already displayed, we need to manually trigger the equipment process
                    //Otherwise it will be called automatically in RunMethod
                    await EquipAssets();
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Instantiate the specified prefab for this GameObject, destroy the origin prefabs if any,
        /// so the new equipment can be equipped
        /// </summary>
        /// <param name="GiId"></param>
        /// <param name="contextModeType"></param>
        /// <param name="localisablePrefabType"></param>
        public async Task AttachCharacterPrefabById(string GiId, LocalisablePrefabType localisablePrefabType)
        {
            Context.ContextMode = ContextModeType.ByNumber;
            Context.Number      = GiId;
            PrefabType          = localisablePrefabType;

            //Clear the origin assets for new equipment
            _selectedPrefabInstance = null;
            //Detach the children
            transform.DetachChildren();
            foreach (var instance in _cachedPrefabInstances.Values)
            {
                GameObject.Destroy(instance);
            }
            _cachedPrefabInstances.Clear();
            await RunMethod(true);
        }
Exemplo n.º 3
0
 public void Apply(GameObject target, Slot slot, LocalisablePrefabType localisablePrefabType, bool instantiateInWorldSpace = false)
 {
     target = FindSlotTarget(target, slot) ?? target;
     if (ContentType == AddressableGameItemMeta.ContentType.Skin)
     {
         //Skin is texture
         foreach (var texture in _localisableTextures)
         {
             //TODO: Now compare the enum string, should find a better way
             if (Enum.GetName(typeof(LocalisableTextureType), texture.LocalisableTextureType) ==
                 Enum.GetName(typeof(LocalisablePrefabType), localisablePrefabType))
             {
                 TryToApplyTexture2DOnChildren(target, texture.LocalisableTexture.GetTexture().name,
                                               (Texture2D)texture.LocalisableTexture.GetTexture());
             }
         }
     }
     else
     {
         //Others are entity
         foreach (var prefab in _localisablePrefabs)
         {
             //If in supported slot
             if (SupportedSlots.Contains(Slot.All) || SupportedSlots.Contains(slot))
             {
                 //Matched prefab type
                 if (localisablePrefabType == prefab.LocalisablePrefabType)
                 {
                     GameObject resource;
                     //Prefab
                     if (target == null)
                     {
                         resource = Instantiate((GameObject)prefab.LocalisablePrefab.GetPrefab());
                     }
                     else
                     {
                         resource = Instantiate((GameObject)prefab.LocalisablePrefab.GetPrefab(), target.transform, instantiateInWorldSpace);
                     }
                 }
             }
         }
     }
 }