public void UpdateStars(LoadLevelButton button) { if (mySprite == null) { mySprite = GetComponent <UISprite>(); } if (button.levelIdx > LoadLevelButton.lastUnlockedLevel) { mySprite.enabled = false; return; } int count = UserManagerCloud.Instance.GetStarsForLevel(button.levelIdx); mySprite.enabled = count > 0; if (count == 1) { mySprite.spriteName = "star_map_01"; } else if (count == 2) { mySprite.spriteName = "star_map_02"; } else if (count == 3) { mySprite.spriteName = "star_map_03"; } }
public void UpdateStars(LoadLevelButton button) { if (mySprite == null) { mySprite = GetComponent<UISprite>(); } if (button.levelIdx > LoadLevelButton.lastUnlockedLevel) { mySprite.enabled = false; return; } int count = UserManagerCloud.Instance.GetStarsForLevel(button.levelIdx); mySprite.enabled = count > 0; if (count == 1) { mySprite.spriteName = "star_map_01"; } else if (count == 2) { mySprite.spriteName = "star_map_02"; } else if (count == 3) { mySprite.spriteName = "star_map_03"; } }
void GetCustomLevels() { if (levelButtons.Count > 0) { foreach (GameObject go in levelButtons) { Destroy(go); } levelButtons.Clear(); } if (Directory.Exists(customLevelsDirectory)) { customLevelsFiles = Directory.GetFiles(customLevelsDirectory); } foreach (string file in customLevelsFiles) { GameObject go = Instantiate(customLevelButtonPrefab, buttonsContainer); LoadLevelButton llb = go.GetComponent <LoadLevelButton>(); string levelName = file.Remove(0, file.LastIndexOf("/") + 1); llb.Setup(levelName, file); levelButtons.Add(go); } }
public void RegisterButton(LoadLevelButton button, int levelIndex) { if (levelButtons[levelIndex * 2] == null) { levelButtons[levelIndex * 2] = button; } else { levelButtons[levelIndex * 2 + 1] = button; } }
public void UpdateButtonStatus() { if (UserManagerCloud.Instance == null) { return; } //lastUnlockedLevel = User.CurrentUser.LastFinishedLvl == maxLevels ? User.CurrentUser.LastFinishedLvl : User.CurrentUser.LastFinishedLvl + 1; UserCloud currentUser = UserManagerCloud.Instance.CurrentUser; lastUnlockedLevel = currentUser.LastFinishedLvl == maxLevels ? currentUser.LastFinishedLvl : currentUser.LastFinishedLvl + 1; if (stars != null) { stars.UpdateStars(this); } if (levelIdx == maxLevels + 1 && maxLevels == lastUnlockedLevel && UserManagerCloud.Instance.GetScoreForLevel(lastUnlockedLevel) > 0) { SetButtonActive(true); //gameObject.SetActive(true); return; } else if (levelIdx > lastUnlockedLevel) { //wenming modify 如果级别关卡大于上次解锁的关卡,则不显示 SetButtonActive(false); // gameObject.SetActive(false); //TODO TALIN: DECOMMENT THIS return; } SetButtonActive(true); // gameObject.SetActive(true); //TODO TALIN: AND THIS! if (Match3BoardRenderer.levelIdx == levelIdx) { CompanionsManager.Instance.UpdateCenterButtonPosition(transform.localPosition); } if (levelIdx == lastUnlockedLevel) { lastButton = this; // Debug.Log("LAST UNLOCKED BUTTON: " + name + " " + transform.parent.name); CompanionsManager.Instance.UpdateAvatarPosition(transform.localPosition, userAvatarPos); if (newUnlockedLevel || Match3BoardRenderer.levelIdx == 0) { CompanionsManager.Instance.UpdateCenterButtonPosition(transform.localPosition); } } else if (newUnlockedLevel && levelIdx == lastUnlockedLevel - 1) { CompanionsManager.Instance.UpdateOldAvatarPosition(transform.localPosition, userAvatarPos); } }
public void UpdateFriendNameInMap() { Dictionary <int, FriendData> dataDict = HighScoreModel.Instance.getLevelFriendDict(); for (int i = 0; i < LoadLevelButton.maxLevels; i++) { if (!dataDict.ContainsKey(i + 1)) { continue; } FriendData data = dataDict[i + 1]; string buttonName = (i + 1).ToString() + " Level Button"; if (i + 1 < 10) { buttonName = "0" + buttonName; } Debug.Log("Level = " + (i + 1).ToString()); Debug.Log("buttonName = " + buttonName); GameObject buttonObj = GameObject.Find("Map Panel Portrait/Contents/" + buttonName); if (buttonObj != null) { /* * GameObject boardObj = buttonObj.transform.Find("NameBoard").gameObject; * boardObj.transform.localScale = new Vector3(155, 56, 1); * * GameObject labelObj = buttonObj.transform.Find("NameLabel").gameObject; * labelObj.transform.localScale = new Vector3(24, 24, 1); * * UILabel labelCom = labelObj.GetComponent<UILabel>(); * labelCom.text = data.userName.ToString(); */ //buttonObj.SendMessage("AddFriendNameLabel", LoadLevelButton buttonCom = buttonObj.GetComponent <LoadLevelButton>(); buttonCom.AddFriendNameLabel(data.userName.ToString()); } } }
public void UpdateOldAvatarPosition(Vector3 pos, LoadLevelButton.AvatarPos avatarPos) { avatarOldPosition = pos + GetPositionOnButton(avatarPos); }
public void UpdateAvatarPosition(Vector3 pos, LoadLevelButton.AvatarPos avatarPos) { avatarPosition = pos + GetPositionOnButton(avatarPos); avatarScale = avatarPos == LoadLevelButton.AvatarPos.Right ? new Vector3(-1f, 1f, 1f) : Vector3.one; }
// void Start() // { // if (UserManager.Instance != null) { // UserManager.Instance.GetFacebookFriends(true, FriendsReceived/*(args) => { // friendsArgs = args; // }*/); // // StartCoroutine(CheckFriendsReceived()); // } // } // UserFriendsDelegateEventArgs friendsArgs = null; // IEnumerator CheckFriendsReceived() // { // Debug.Log("Start checking friends received"); // while (friendsArgs == null) { // yield return null; // } // Debug.Log("Friends received, calling function"); // FriendsReceived(friendsArgs); // friendsArgs = null; // } // void FriendsReceived(UserFriendsDelegateEventArgs args) // { // foreach (LoadLevelButton button in levelButtons) { // if (button != null && button.friend != null) { // Destroy(button.friend.gameObject); // button.friend = null; // } // } //#if UNITY_EDITOR // CreateFriendAvatar(null); //#endif // // if (args.FriendsList == null || args.FriendsList.Count == 0) { // return; // } // // foreach (User user in args.FriendsList) { // CreateFriendAvatar(user); // } // } // // void CreateFriendAvatar(User friend) // { // LoadLevelButton button1 = null; // LoadLevelButton button2 = null; // //#if UNITY_EDITOR // button1 = levelButtons[18 * 2]; // button2 = levelButtons[18 * 2 + 1]; //#else // Debug.Log("Creating friend avatar: " + friend.FBName + " level: " + friend.LastFinishedLvl); // // if (friend.LastFinishedLvl < LoadLevelButton.maxLevels) { // button1 = levelButtons[(friend.LastFinishedLvl + 1) * 2]; //last unlocked level is +1 // button2 = levelButtons[(friend.LastFinishedLvl + 1) * 2 + 1]; // } // else if (friend.LastFinishedLvl == LoadLevelButton.maxLevels) { // button1 = levelButtons[friend.LastFinishedLvl * 2]; //all levels finished so last unlocked level is the last finished level // button2 = levelButtons[friend.LastFinishedLvl * 2 + 1]; // } //#endif // // if (button1 != null && button1.friend == null) { // SetFriendAvatar(button1, friend); // SetFriendAvatar(button2, friend); // } // } // // void SetFriendAvatar(LoadLevelButton button, User friend) // { // GameObject friendAvatarObj = GameObject.Instantiate(friendAvatarPrefab) as GameObject; // Transform friendTransform = friendAvatarObj.transform; // friendTransform.parent = button.transform; // friendTransform.localPosition = GetPositionOnButton(button.friendAvatarPos); // friendTransform.localScale = Vector3.one; // // button.friend = friendAvatarObj.GetComponent<FriendAvatar>(); // button.friend.friend = friend; // button.friend.Refresh(); // } Vector3 GetPositionOnButton(LoadLevelButton.AvatarPos avatarPos) { if (avatarPos == LoadLevelButton.AvatarPos.Left) { return new Vector3(-73f, 0f, -2f); } else if (avatarPos == LoadLevelButton.AvatarPos.Right) { return new Vector3(73f, 0f, -2f); } else if (avatarPos == LoadLevelButton.AvatarPos.Top) { return new Vector3(0f, 57f, -2f); } else if (avatarPos == LoadLevelButton.AvatarPos.Bottom) { return new Vector3(0f, -50f, -2f); } return Vector3.zero; }