예제 #1
0
 public void Select(PortraitCircleView item)
 {
     if (item != null && Role.Instance.HeadId != item.ID)
     {
         if (item.isRelieve == 1)
         {
             Role.Instance.HeadId = item.ID;
             Portrait_img.sprite  = ResourceMgr.Instance.LoadSprite(item.ID);
             for (int i = 0; i < PortraitList.Count; i++)
             {
                 if (PortraitList[i].ID == item.ID)
                 {
                     PortraitList[i].Hint.SetActive(true);
                     PortraitList[i].SelectImag.SetActive(true);
                 }
                 else
                 {
                     PortraitList[i].Hint.SetActive(false);
                     PortraitList[i].SelectImag.SetActive(false);
                 }
             }
         }
         else
         {
             CanvasView.Instance.AddNotice("请解锁头像!");
         }
     }
 }
예제 #2
0
    /// <summary>
    /// 初始化头像
    /// </summary>
    public void Init()
    {
        Level_txt.text = Role.Instance.Level.ToString();
        Exp_txt.text   = Role.Instance.Exp.ToString();
        Name_txt.text  = Role.Instance.RoleName;
        if (ct == null)
        {
            HaveClear    = HaveClear_trf.GetComponent <GridLayoutGroup>();
            NotClear     = NotClears_trf.GetComponent <GridLayoutGroup>();
            HaveRect     = Have_trf as RectTransform;
            NotClearRect = NotClear_trf as RectTransform;
            Control      = Control_obj.transform as RectTransform;

            ct        = GameObject.Find("HeroParent").transform;
            grid      = Clear_trf.GetComponent <GridLayoutGroup>();
            Mask_rect = Mask_trf.transform as RectTransform;
            Clear     = Clear_trf.transform as RectTransform;
        }
        if (ct.childCount > 0)
        {
            for (int i = 0, length = ct.childCount; i < length; ++i)
            {
                Destroy(ct.GetChild(0).gameObject);
            }
        }
        GameObject heroGo = ResourceMgr.Instance.LoadResource(ID) as GameObject;

        if (heroGo == null)
        {
            return;
        }
        heroGo = Instantiate(heroGo, ct, false);
        Hreo   = heroGo.transform;
        heroGo.transform.localPosition = new Vector3(0, -1, 0);
        heroGo.transform.localScale    = new Vector3(2f, 2f, 2f);
        heroGo.SetLayer("Hero");
        EventListener.Get(RawImage_obj).BegineDragEvent = e =>
        {
            previousX = Input.mousePosition.x;
        };
        EventListener.Get(RawImage_obj).DragEvent = e =>
        {
            offset    = previousX - Input.mousePosition.x;
            previousX = Input.mousePosition.x;
            heroGo.transform.Rotate(Vector3.up, offset * Time.deltaTime, Space.Self);
        };


        Hreo.transform.localRotation = new Quaternion(0, 0, 0, 0);

        Portrait_img.sprite = ResourceMgr.Instance.LoadSprite(Role.Instance.HeadId);


        //头像
        allHero = HeroMgr.GetSingleton().Heros;
        if (allHero.Length > PortraitList.Count)
        {
            for (int idx = 0; idx < allHero.Length; idx++)
            {
                if (idx > PortraitList.Count)
                {
                    GameObject         majesty     = InitItemInfo(true, Clear_trf);
                    PortraitCircleView majestyview = majesty.GetComponent <PortraitCircleView>();
                    majestyview.Init();
                    if (idx > 10)
                    {
                        majestyview.Endow(allHero[idx].HeroId, false);
                    }
                    else
                    {
                        majestyview.Endow(allHero[idx].HeroId, true);
                    }
                    PortraitList.Add(majestyview);
                }
            }
        }

        SelectSort();
    }