/// <summary>
 ///
 /// </summary>
 void InstanceFriend(FriendInfo[] friends)
 {
     for (int i = 0; i < friends.Length; i++)
     {
         GameObject    f    = Instantiate(FriendUIPrefab) as GameObject;
         bl_FriendInfo info = f.GetComponent <bl_FriendInfo>();
         info.GetInfo(friends[i]);
         cacheFriendsInfo.Add(info);
         f.name = friends[i].UserId;
         f.transform.SetParent(PanelList, false);
     }
 }
    /// <summary>
    ///
    /// </summary>
    public void UpdateFriendList(bool instance = false)
    {
        if (FriendManager == null)
        {
            FriendManager = FindObjectOfType <bl_FriendList>();
        }
        if (FriendManager.FriendList.Count <= 0 || PhotonNetwork.InRoom)
        {
            return;
        }

        FriendInfo[] friends = FriendManager.FriendList.ToArray();

        if (instance)
        {
            CleanCacheList();
            if (friends.Length > 0)
            {
                List <FriendInfo> OnlineFriends  = new List <FriendInfo>();
                List <FriendInfo> OfflineFriends = new List <FriendInfo>();

                for (int i = 0; i < friends.Length; i++)
                {
                    if (friends[i].UserId != "Null")
                    {
                        if (onlineFirst)
                        {
                            if (friends[i].IsOnline)
                            {
                                OnlineFriends.Add(friends[i]);
                            }
                            else
                            {
                                OfflineFriends.Add(friends[i]);
                            }
                        }
                        else
                        {
                            GameObject    f    = Instantiate(FriendUIPrefab) as GameObject;
                            bl_FriendInfo info = f.GetComponent <bl_FriendInfo>();
                            info.GetInfo(friends[i]);
                            f.name = friends[i].UserId;
                            cacheFriendsInfo.Add(info);

                            f.transform.SetParent(PanelList, false);
                        }
                    }
                }

                if (onlineFirst)
                {
                    if (OnlineFriends.Count > 0)
                    {
                        InstanceFriend(OnlineFriends.ToArray());
                    }
                    if (OfflineFriends.Count > 0)
                    {
                        InstanceFriend(OfflineFriends.ToArray());
                    }
                }
                ConnectFriendsText.text = OnlineFriends.Count.ToString();
            }
        }
        else//Just update list
        {
            for (int i = 0; i < cacheFriendsInfo.Count; i++)
            {
                if (cacheFriendsInfo[i] != null)
                {
                    cacheFriendsInfo[i].RefreshInfo(friends);
                }
                else
                {
                    cacheFriendsInfo.RemoveAt(i);
                }
            }
        }
        UpdateCount(friends);
    }