//===================================================== public void OnOutfitSelected(int Index) { // Move into 'buy?' overlay mode // Only allow outfits to be selected on bought fairies FairyData CurFairy = GameDataManager.Instance.GetFairyData((eFairy)m_CurrentFairyIndex); if (CurFairy != null) { List <ClothingItemData> CurClothingList = ClothingItemsManager.GetClothingItems((eFairy)m_CurrentFairyIndex); m_BuyOutfit = CurClothingList[Index]; // If we own this outfit just wear it, otherwise show the 'buy' overlay if (CurFairy.OutfitOwned(m_BuyOutfit.id)) { // Twirl anim bool bDoTwirl = false; if (CurFairy.Outfit != m_BuyOutfit.id) { bDoTwirl = true; } // Wear CurFairy.Outfit = m_BuyOutfit.id; m_bBuyOutfitActive = false; UpdateSelectedFairy(); GameDataManager.Instance.SaveGameData(); // Analytics event Dictionary <string, object> EventDictionary = new Dictionary <string, object>(); EventDictionary["outfitID"] = m_BuyOutfit.id; Analytics.CustomEvent("WearOutfit", EventDictionary); if (bDoTwirl) { m_InspectOufitTimer = UnityEngine.Random.Range(3.0f, 6.0f); m_CurrentFairyObj.GetComponent <Animator>().SetTrigger("IsChangingOutfit"); } } else { // Buy - show preview of outfit UpdateSelectedFairy(m_BuyOutfit.id); m_bBuyOutfitActive = true; } } else { // Fairy not owned, allow outfits to be tested anyway List <ClothingItemData> CurClothingList = ClothingItemsManager.GetClothingItems((eFairy)m_CurrentFairyIndex); m_BuyOutfit = CurClothingList[Index]; UpdateSelectedFairy(m_BuyOutfit.id); } }
//===================================================== public void Update() { if (m_bSwiping) { Vector3 WorldPos = m_GUI2DCamera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 1.0f)); WorldPos *= 800.0f; float SwipingDeltaX = WorldPos.x - m_SwipingStartX; m_SwipingAccel = (WorldPos - m_LastWorldPos[3]).x; for (int MIdx = 3; MIdx > 0; MIdx--) { m_LastWorldPos[MIdx] = m_LastWorldPos[MIdx - 1]; } m_LastWorldPos[0] = WorldPos; m_DestinationItemIndex = m_SwipingStartItemIndex - (SwipingDeltaX * 0.0079f); List <ClothingItemData> CurClothingList = ClothingItemsManager.GetClothingItems(m_CurrentFairy); int MaxItems = CurClothingList.Count; float MinSwipePos = (float)-2.0f; float MaxSwipePos = (float)(MaxItems - 4); if (MaxSwipePos < 0.0f) { MaxSwipePos = 0.0f; } //MinSwipePos -= 0.4f; MaxSwipePos += 0.4f; if (m_DestinationItemIndex < MinSwipePos) { m_DestinationItemIndex = MinSwipePos; } if (m_DestinationItemIndex > MaxSwipePos) { m_DestinationItemIndex = MaxSwipePos; } if (Input.GetMouseButtonUp(0)) { m_bSwiping = false; //m_DestinationItemIndex = (float)((int)(m_DestinationItemIndex + 0.5f)); m_SwipingAccel = Mathf.Clamp(m_SwipingAccel, -25.0f, 25.0f); } } else { // Not swiping Vector3 WorldPos = m_GUI2DCamera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 1.0f)); WorldPos *= 800.0f; for (int MIdx = 3; MIdx > 0; MIdx--) { m_LastWorldPos[MIdx] = WorldPos; } m_SwipingStartX = WorldPos.x; m_SwipingStartItemIndex = m_DestinationItemIndex; //Debug.Log( WorldPos ); if (Input.GetMouseButtonDown(0)) { if ((WorldPos.y > 1004.0f) && (WorldPos.y < 1345.0f)) { if ((WorldPos.x > -497.0f) && (WorldPos.x < 314.0f)) { m_bSwiping = true; m_SwipingAccel = 0.0f; } } } else { //m_DestinationItemIndex -= m_SwipingAccel * Time.deltaTime * 0.35f; m_SwipingAccel *= 0.92f; } } PreHelpers.DeltaTend(ref m_CurrentItemIndex, m_DestinationItemIndex, 7.5f, Time.deltaTime); // Update renderer if (RackRenderer.instance != null) { RackRenderer.instance.m_CurItem = m_CurrentItemIndex; } }
//===================================================== public void Update() { // Render if page has changed bool bUpdateResources = false; // Position the rack with the correct offset float Offset = m_CurItem % 1.0f; Offset *= m_RackSpacing; this.transform.localPosition = new Vector3(-Offset + m_RackBasePosition.x, m_RackBasePosition.y, m_RackBasePosition.z); // Load the correct sprites for each piece of clothing into the render slots we have int ItemOffset = (int)m_CurItem; if (ItemOffset != m_LastItemOffsetRendered) { //Debug.Log("RES"); bUpdateResources = true; } m_LastItemOffsetRendered = ItemOffset; List <ClothingItemData> CurClothingList = ClothingItemsManager.GetClothingItems(m_CurrentFairy); int MaxItems = CurClothingList.Count; for (int Idx = 0; Idx < 8; Idx++) { // Valid outfit? int OutfitIndex = Idx + ItemOffset; bool bValidOutfit = false; ClothingItemData CurOutfit = null; if (OutfitIndex < 0) { bValidOutfit = false; } else { if (OutfitIndex < MaxItems) { CurOutfit = CurClothingList[OutfitIndex]; if (CurOutfit == null) { bValidOutfit = false; } else { bValidOutfit = true; } } } if (bValidOutfit) { m_RackItems[Idx].SetActive(true); // Update sprite for this outfit UnityEngine.SpriteRenderer RenderOutfitImage = m_RackItems[Idx].GetComponent(typeof(UnityEngine.SpriteRenderer)) as UnityEngine.SpriteRenderer; CurOutfit.currentRotation += Time.deltaTime * 1.4f; if (bUpdateResources) { string Filename = "Clothing/GUITextures/" + CurOutfit.guiTexture2D; Sprite RenderSprite = (Sprite)Resources.Load(Filename, typeof(Sprite)); RenderOutfitImage.sprite = RenderSprite; RenderOutfitImage.enabled = true; } float outfitRotation = Mathf.Sin(CurOutfit.currentRotation) * 7.0f; m_RackItems[Idx].transform.eulerAngles = new Vector3(0.0f, 344.0f + outfitRotation, 0.0f); } else { m_RackItems[Idx].SetActive(false); } } }
//===================================================== void UpdateSelectedFairy(string PreviewOutfitID = null) { if (m_CurrentFairyObj != null) { GameObject.Destroy(m_CurrentFairyObj); m_CurrentFairyObj = null; } string path = "Fairies/"; switch ((eFairy)m_CurrentFairyIndex) { case eFairy.BLOOM: path += "Bloom/Prefabs/"; break; case eFairy.STELLA: path += "Stella/Prefabs/"; break; case eFairy.FLORA: path += "Flora/Prefabs/"; break; case eFairy.MUSA: path += "Musa/Prefabs/"; break; case eFairy.TECNA: path += "Tecna/Prefabs/"; break; case eFairy.AISHA: path += "Aisha/Prefabs/"; break; } // Fairy owned? eFairy CurFairyType = (eFairy)m_CurrentFairyIndex; RackScroller.instance.SetCurrentFairy(CurFairyType); RackRenderer.instance.SetCurrentFairy(CurFairyType); RackRenderer.instance.MarkDirty(); FairyData CurFairy = GameDataManager.Instance.GetFairyData(CurFairyType); if (CurFairy == null) { // Not owned, show default outfit (unless we have an override) string DefaultItem = ClothingItemsManager.GetClothingDefaultItem((eFairy)m_CurrentFairyIndex); if (PreviewOutfitID != null) { DefaultItem = PreviewOutfitID; } if (!String.IsNullOrEmpty(DefaultItem)) { path += ClothingItemsManager.GetClothingItem(DefaultItem).prefabName; } } else { // Owned, show current outfit string CurrentOutfit = CurFairy.Outfit; if (PreviewOutfitID != null) { CurrentOutfit = PreviewOutfitID; } if (!String.IsNullOrEmpty(CurrentOutfit)) { ClothingItemData itemData = ClothingItemsManager.GetClothingItem(CurrentOutfit); if (itemData == null) { // Not owned, show default outfit (unless we have an override) string DefaultItem = ClothingItemsManager.GetClothingDefaultItem((eFairy)m_CurrentFairyIndex); if (PreviewOutfitID != null) { DefaultItem = PreviewOutfitID; } if (!String.IsNullOrEmpty(DefaultItem)) { path += ClothingItemsManager.GetClothingItem(DefaultItem).prefabName; } } else { path += itemData.prefabName; } } } // Load prefab GameObject prefab = Resources.Load(path.ToString()) as GameObject; if (prefab == null) { } if (prefab != null) { m_CurrentFairyObj = Instantiate(prefab) as GameObject; m_CurrentFairyObj.transform.parent = m_FairyPosition.transform; m_CurrentFairyObj.transform.localPosition = new Vector3(0.0f, 0.0f, 0.0f); m_CurrentFairyObj.transform.localEulerAngles = new Vector3(0.0f, 0.0f, 0.0f); } }
//===================================================== void LoadLiveUpdate() { string DocPath = PreHelpers.GetFileFolderPath(); string FilePath = DocPath + "wfs2.zip"; if (System.IO.File.Exists(FilePath) == false) { return; } // Read file FileStream fs = null; try { fs = new FileStream(FilePath, FileMode.Open); } catch { Debug.Log("GameData file open exception: " + FilePath); } if (fs != null) { try { // Read zip file ZipFile zf = new ZipFile(fs); int numFiles = 0; if (zf.TestArchive(true) == false) { Debug.Log("Zip file failed integrity check!"); zf.IsStreamOwner = false; zf.Close(); fs.Close(); } else { foreach (ZipEntry zipEntry in zf) { // Ignore directories if (!zipEntry.IsFile) { continue; } String entryFileName = zipEntry.Name; // Skip .DS_Store files if (entryFileName.Contains("DS_Store")) { continue; } Debug.Log("Unpacking zip file entry: " + entryFileName); byte[] buffer = new byte[4096]; // 4K is optimum Stream zipStream = zf.GetInputStream(zipEntry); // Manipulate the output filename here as desired. string fullZipToPath = PreHelpers.GetFileFolderPath() + Path.GetFileName(entryFileName); // Unzip file in buffered chunks. This is just as fast as unpacking to a buffer the full size // of the file, but does not waste memory. // The "using" will close the stream even if an exception occurs. using (FileStream streamWriter = System.IO.File.Create(fullZipToPath)) { StreamUtils.Copy(zipStream, streamWriter, buffer); } numFiles++; } zf.IsStreamOwner = false; zf.Close(); fs.Close(); // If we've unpacked the local files (at least 13) then start using local spreadsheets data Debug.Log("Zip updated with " + numFiles + " files (needs 13)"); if (numFiles >= 13) { PlayerPrefs.SetInt(PreHelpers.GetLiveDataVersionString(), 1); } // Reload managers TextManager.Reload(); SettingsManager.Reload(); TradingCardItemsManager.Reload(); ClothingItemsManager.Reload(); FairyItemsManager.Reload(); WildMagicItemsManager.Reload(); NPCItemsManager.Reload(); } } catch { Debug.Log("Zip file error!"); } // Remove zip file Debug.Log("Removing zip file"); System.IO.File.Delete(FilePath); } }