示例#1
0
    /// <summary>
    /// 动态创建可滑动的预设
    /// </summary>
    /// <param name="count"></param>
    /// <param name="head"></param>
    /// <param name="path"></param>
    protected void AutoCreateItems(int count, Transform head, string path)
    {
        for (int i = ButtonUis.Count - 1; i >= 0; i--)
        {
            GameObject.DestroyImmediate(ButtonUis.ElementAt(i).gameObject);
        }

        ButtonUis.Clear();
        int index = count / 6;

        if (count % 6 != 0)
        {
            index += 1;
        }
        for (int i = 0; i < index * 6; i++)
        {
            ResourceItem objUnit = ResourcesManager.Instance.loadImmediate(path, ResourceType.PREFAB);
            GameObject   obj     = GameObject.Instantiate(objUnit.Asset) as GameObject;
            obj.name                 = obj.name + (i + 1).ToString();
            obj.transform.parent     = head;
            obj.transform.localScale = Vector3.one;
            //obj.transform.localPosition = Vector3.zero;
            DbClickBotton click = obj.GetComponent <DbClickBotton>();
            click.AddListener(i, OnButtonClickFunc);
            click.AddListenerDb(i, OnButtolDbClickFunc);
            ButtonUis.Add(click);
            //click.transform.GetComponent<UIGrid>().Reposition() ;
        }
        UIGrid grid = head.GetComponentInChildren <UIGrid>();

        grid.enabled       = true;
        grid.repositionNow = true;
        grid.Reposition();
    }
示例#2
0
    protected override void SetSelectSpriteVisiable(int index, bool visiable)
    {
        if (ButtonUis.Count <= index || index < 0)
        {
            return;
        }
        UISprite sprite = ButtonUis.ElementAt(index).transform.Find("SpriteSelect").GetComponent <UISprite>();

        sprite.gameObject.SetActive(visiable);
    }
示例#3
0
 int GetIndexOfItem(GameObject obj)
 {
     for (int i = 0; i < 6; i++)
     {
         if (ButtonUis.ElementAt(i).gameObject == obj)
         {
             return(i);
         }
     }
     return(-1);
 }
示例#4
0
    void SetItemEnableByIndex(int index, bool enable)
    {
        if (index < 0 || index >= ButtonUis.Count)
        {
            return;
        }
        DbClickBotton click  = ButtonUis.ElementAt(index);
        UISprite      sprite = click.transform.Find("icon").GetComponent <UISprite>();
        UILabel       label  = click.transform.Find("Label").GetComponent <UILabel>();

        sprite.gameObject.SetActive(enable);
        label.gameObject.SetActive(enable);
    }
示例#5
0
 int CheckInBackPackage()
 {
     if (objMove == null)
     {
         return(-1);
     }
     if (UICamera.currentTouch.current == null)
     {
         return(-1);
     }
     for (int i = 0; i < ButtonUis.Count; i++)
     {
         if (ButtonUis.ElementAt(i).gameObject == UICamera.currentTouch.current)
         {
             return(i);
         }
     }
     return(-1);
 }
示例#6
0
    /// <summary>
    /// 刷新显示部分
    /// </summary>
    public override void OnShowItemInUserInterface()
    {
        for (int ct = 0; ct < UserItemBtnCount; ct++)
        {
            int           itemId = -1;
            DbClickBotton click  = ButtonUis.ElementAt(ct);
            UISprite      sprite = click.transform.Find("icon").GetComponent <UISprite>();
            localPlayer.UserGameItems.TryGetValue(ct, out itemId);
            int count = 0;
            localPlayer.UserGameItemsCount.TryGetValue(ct, out count);
            UILabel label = click.transform.Find("Label").GetComponent <UILabel>();
            if (count == 0 || !ConfigReader.ItemXmlInfoDict.ContainsKey(itemId))
            {
                sprite.gameObject.SetActive(false);
                label.gameObject.SetActive(false);
                label.text = "";
                click.GetComponent <UIObjDragEvent>().enabled = false;
                SetSelectSpriteVisiable(ct, false);
                continue;
            }
            click.GetComponent <UIObjDragEvent>().enabled = true;
            sprite.gameObject.SetActive(true);
            sprite.spriteName = ConfigReader.ItemXmlInfoDict[itemId].sIcon;


            if (ConfigReader.ItemXmlInfoDict[itemId].un8OverlapTimes >= 2 && count > 1)
            {
                label.gameObject.SetActive(true);
                label.text = count.ToString();
            }
            else
            {
                label.gameObject.SetActive(false);
                label.text = "";
            }
        }
    }