예제 #1
0
        void Start()
        {
            // Navigation manager
            NavigationManager.I.CurrentScene = AppScene.PlaySessionResult;

            // Calculate items to unlock count
            int itemsToUnlock = NavigationManager.I.CalculateUnlockItemCount();

            List <RewardPack> oldRewards = AppManager.I.Player.RewardsUnlocked.FindAll(ru => ru.PlaySessionId == AppManager.I.Player.CurrentJourneyPosition.ToString());
            int itemAlreadyUnlocked      = oldRewards.Count;

            for (int i = 0; i < itemsToUnlock - oldRewards.Count; i++)
            {
                // if necessary add one new random reward unlocked
                RewardPack newRewardToUnlock = RewardSystemManager.GetNextRewardPack()[0];
                oldRewards.Add(newRewardToUnlock);
                AppManager.I.Player.AddRewardUnlocked(newRewardToUnlock);
            }

            // Show UI result and unlock transform parent where show unlocked items
            GameObject[] objs = new GameObject[] { };
            objs = GameResultUI.ShowEndsessionResult(NavigationManager.I.UseEndSessionResults(), itemAlreadyUnlocked);

            for (int i = 0; i < objs.Length - oldRewards.Count; i++)
            {
                // if necessary add one new random reward not to be unlocked!
                oldRewards.Add(RewardSystemManager.GetNextRewardPack()[0]);
            }

            LogManager.I.LogPlaySessionScore(TeacherAI.I.journeyHelper.GetCurrentPlaySessionData().Id, objs.Length);
            // save max progression (internal check if necessary)
            NavigationManager.I.MaxJourneyPosistionProgress();

            // for any rewards mount them model on parent transform object (objs)
            for (int i = 0; i < oldRewards.Count && i < objs.Length; i++)
            {
                ModelsManager.MountModel(
                    oldRewards[i].ItemID,
                    objs[i].transform,
                    oldRewards[i].GetMaterialPair()
                    );
            }
        }
        /// <summary>
        /// Gets the reward items by rewardType (always 9 items, if not presente item in the return list is null).
        /// </summary>
        /// <param name="_rewardType">Type of the reward.</param>
        /// <param name="_parentsTransForModels">The parents trans for models.</param>
        /// <param name="_categoryRewardId">The category reward identifier.</param>
        /// <returns></returns>
        public static List <RewardItem> GetRewardItemsByRewardType(RewardTypes _rewardType, List <Transform> _parentsTransForModels, string _categoryRewardId = "")
        {
            List <RewardItem> returnList = new List <RewardItem>();

            /// TODO: logic
            /// - Load returnList by type and category checking unlocked and if exist active one
            switch (_rewardType)
            {
            case RewardTypes.reward:
                // Filter from unlocked elements (only items with this category and only one for itemID)
                foreach (var item in config.Rewards.FindAll(r => r.Category == _categoryRewardId))
                {
                    if (AppManager.I.Player.RewardsUnlocked.FindAll(ur => ur.GetRewardCategory() == _categoryRewardId).Exists(ur => ur.ItemID == item.ID))
                    {
                        returnList.Add(new RewardItem()
                        {
                            ID = item.ID, IsNew = false, IsSelected = AppManager.I.Player.CurrentAnturaCustomizations.Fornitures.Exists(f => f.ItemID == item.ID)
                        });
                    }
                    else
                    {
                        returnList.Add(null);
                    }
                }
                /// - Charge models
                for (int i = 0; i < returnList.Count; i++)
                {
                    if (returnList[i] != null)
                    {
                        ModelsManager.MountModel(returnList[i].ID, _parentsTransForModels[i]);
                    }
                }
                break;

            case RewardTypes.texture:
                // Filter from unlocked elements (only one for itemID)
                foreach (var item in config.RewardsTile)
                {
                    if (AppManager.I.Player.RewardsUnlocked.FindAll(ur => ur.Type == RewardTypes.texture).Exists(ur => ur.ItemID == item.ID))
                    {
                        returnList.Add(new RewardItem()
                        {
                            ID = item.ID, IsNew = false, IsSelected = AppManager.I.Player.CurrentAnturaCustomizations.TileTexture.ItemID == item.ID
                        });
                    }
                    else
                    {
                        returnList.Add(null);
                    }
                }
                /// - Charge texture
                for (int i = 0; i < returnList.Count; i++)
                {
                    if (returnList[i] != null)
                    {
                        string    texturePath  = "AnturaStuff/Textures_and_Materials/";
                        Texture2D inputTexture = Resources.Load <Texture2D>(texturePath + returnList[i].ID);
                        _parentsTransForModels[i].GetComponent <RawImage>().texture = inputTexture;
                    }
                }
                break;

            case RewardTypes.decal:
                // Filter from unlocked elements (only one for itemID)
                foreach (var item in config.RewardsDecal)
                {
                    if (AppManager.I.Player.RewardsUnlocked.FindAll(ur => ur.Type == RewardTypes.decal).Exists(ur => ur.ItemID == item.ID))
                    {
                        returnList.Add(new RewardItem()
                        {
                            ID = item.ID, IsNew = false, IsSelected = AppManager.I.Player.CurrentAnturaCustomizations.DecalTexture.ItemID == item.ID
                        });
                    }
                    else
                    {
                        returnList.Add(null);
                    }
                }
                /// - Charge texture
                for (int i = 0; i < returnList.Count; i++)
                {
                    if (returnList[i] != null)
                    {
                        string    texturePath  = "AnturaStuff/Textures_and_Materials/";
                        Texture2D inputTexture = Resources.Load <Texture2D>(texturePath + returnList[i].ID);
                        _parentsTransForModels[i].GetComponent <RawImage>().texture = inputTexture;
                    }
                }
                break;

            default:
                Debug.LogWarningFormat("Reward typology requested {0} not found", _rewardType);
                break;
            }

            //// add empty results
            //int emptyItemsCount = _parentsTransForModels.Count - returnList.Count;
            //for (int i = 0; i < emptyItemsCount; i++) {
            //    returnList.Add(null);
            //}
            return(returnList);
        }
        /// <summary>
        /// Loads the reward on model.
        /// </summary>
        /// <param name="_id">The identifier.</param>
        /// <returns></returns>
        public GameObject LoadRewardOnAntura(RewardPack _rewardPack)
        {
            Reward reward = RewardSystemManager.GetConfig().Rewards.Find(r => r.ID == _rewardPack.ItemID);

            if (reward == null)
            {
                Debug.LogFormat("Reward {0} not found!", _rewardPack.ItemID);
                return(null);
            }
            // Check if already charged reward of this category
            LoadedModel loadedModel = LoadedModels.Find(lm => lm.Reward.GetRewardCategory() == reward.Category);

            if (loadedModel != null)
            {
                Destroy(loadedModel.GO);
                LoadedModels.Remove(loadedModel);
            }

            // Load Model
            string     boneParent      = reward.BoneAttach;
            Transform  transformParent = transform;
            GameObject rewardModel     = null;

            switch (boneParent)
            {
            case "dog_head":
                transformParent = Dog_head;
                //if (Dog_head_pointer)
                //    Destroy(Dog_head_pointer.gameObject);
                //Dog_head_pointer = ModelsManager.MountModel(reward.ID, transformParent).transform;
                rewardModel = ModelsManager.MountModel(reward.ID, transformParent);
                break;

            case "dog_spine01":
                transformParent = Dog_spine01;
                //if (Dog_spine01_pointer)
                //    Destroy(Dog_spine01_pointer.gameObject);
                //Dog_spine01_pointer = ModelsManager.MountModel(reward.ID, transformParent).transform;
                rewardModel = ModelsManager.MountModel(reward.ID, transformParent);
                break;

            case "dog_jaw":
                transformParent = Dog_jaw;
                //if (Dog_jaw_pointer)
                //    Destroy(Dog_jaw_pointer.gameObject);
                //Dog_jaw_pointer = ModelsManager.MountModel(reward.ID, transformParent).transform;
                rewardModel = ModelsManager.MountModel(reward.ID, transformParent);
                break;

            case "dog_Tail4":
                transformParent = Dog_Tail3;
                //if (Dog_Tail3_pointer)
                //    Destroy(Dog_Tail3_pointer.gameObject);
                //Dog_Tail3_pointer = ModelsManager.MountModel(reward.ID, transformParent).transform;
                rewardModel = ModelsManager.MountModel(reward.ID, transformParent);
                break;

            case "dog_R_ear04":
                transformParent = Dog_R_ear04;
                //if (dog_R_ear04_pointer)
                //    Destroy(dog_R_ear04_pointer.gameObject);
                //dog_R_ear04_pointer = ModelsManager.MountModel(reward.ID, transformParent).transform;
                rewardModel = ModelsManager.MountModel(reward.ID, transformParent);
                break;

            case "dog_L_ear04":
                transformParent = Dog_L_ear04;
                //if (dog_L_ear04_pointer)
                //    Destroy(dog_L_ear04_pointer.gameObject);
                //dog_L_ear04_pointer = ModelsManager.MountModel(reward.ID, transformParent).transform;
                rewardModel = ModelsManager.MountModel(reward.ID, transformParent);
                break;

            default:
                break;
            }

            // Set materials
            ModelsManager.SwitchMaterial(rewardModel, _rewardPack.GetMaterialPair());

            // Save on LoadedModel List
            LoadedModels.Add(new LoadedModel()
            {
                Reward = _rewardPack, GO = rewardModel
            });
            return(rewardModel);
        }