public GameObject CreateMatchingMaterial(CollectBtnClick collectBtnClick, DropItem dropItem, DragItem dragitem)
    {
        GameObject objResource = Resources.Load("matching/" + collectBtnClick.material.ToString()) as GameObject;

        if (objResource == null)
        {
            return(null);
        }
        GameObject processBarObj = Instantiate(objResource, Vector3.zero, Quaternion.identity) as GameObject;
        // processBarObj.name = collectBtnClick.material.ToString();
        RectTransform rectans = processBarObj.GetComponent <RectTransform>();

        rectans.SetParent(this.GetComponent <RectTransform>());
        rectans.SetAsLastSibling();
        rectans.localScale       = Vector3.one;
        rectans.anchoredPosition = new Vector2(0, 0);
        // Destroy(processBarObj.gameObject, 1);
        //当动画播放完成,销毁刚才生成的对象
        //  dropItem.inUse = false;
        // 初始化数据
        // collectBtnClick.materialPanelIndex = 0;

        this.collectBtnClick = collectBtnClick;
        TextCountManager.Instance.UpdateTextCount(dragitem.gameObject);
        TextCountManager.Instance.UpdateCollectTextCount(dragitem.gameObject, dragitem.collectBtnClick);
        //数据配置,当拖放成功时进行数据配置
        dropItem.inUse = true;
        this.dropItem  = dropItem;
        //  CreateParts(collectBtnClick);
        return(objResource);
    }
    //更新采集按钮的文本数量
    public void UpdateCollectTextCount(GameObject obj, CollectBtnClick collectBtnClick)
    {
        Text txt          = obj.transform.GetChild(0).GetComponent <Text>();
        int  currentCount = Int32.Parse(txt.text);
        int  laterCount   = currentCount;

        collectBtnClick.currentCount = laterCount;
        collectBtnClick.tempCount    = currentCount;
    }
Example #3
0
 public void XYLMatchSwitch(string nam)
 {
     if (GameObject.Find("Canvas/BottomCollectBtns/CenterMaterialPart/" + "XY") != null)
     {
         this.dragItem = GameObject.Find("Canvas/BottomCollectBtns/CenterMaterialPart/" + "XY").GetComponent <DragItem>();
     }
     else
     {
         this.transform.GetChild(0).gameObject.SetActive(false);
         return;
     }
     this.XYClick = this.dragItem.collectBtnClick;
     //XYL单独处理
     if (nam.Equals("XY"))
     {
         this.XYClick.material           = Material.XY;
         this.XYClick.materialPanelIndex = 0;
         this.XYClick.factor             = 4;
     }
     if (nam.Equals("XYL"))
     {
         this.XYClick.material           = Material.XYL;
         this.XYClick.materialPanelIndex = 7;
         this.XYClick.factor             = 40;
         if (MatchingBarManager.Instance.partDictionary.ContainsKey(Material.XYL.ToString()))
         {
             GameObject temp;
             if (MatchingBarManager.Instance.partDictionary.TryGetValue(Material.XYL.ToString(), out temp))
             {
                 if (Int32.Parse(temp.transform.GetChild(0).GetComponent <Text>().text) >= 80)
                 {
                     Debug.Log("到达上限了,不要再加工了");
                     this.inUse = false;
                     this.XYClick.materialPanelIndex = 0;
                     if (tempXYLCollect != null)
                     {
                         this.tempXYLCollect.materialPanelIndex = 0;
                     }
                     this.transform.GetChild(0).gameObject.SetActive(false);
                     return;
                 }
             }
         }
     }
     if (TextCountManager.Instance.CheckPartTextCount(XYClick))
     {
         this.transform.GetChild(0).gameObject.SetActive(false);
         return;
     }
     this.GetComponent <MatchingBar>().CreateMatchingMaterial(XYClick, this, this.dragItem);
     this.transform.GetChild(0).gameObject.SetActive(false);
 }
Example #4
0
 void Start()
 {
     if (GameObject.Find("Canvas").transform != null)
     {
         GameObject temp = GameObject.Find("Canvas");
         this.canvasTrans = temp.transform;
     }
     this.canvasTrans = GameObject.Find("Canvas").transform;
     if (GameObject.Find("Canvas/BottomCollectBtns/BottomBtns/" + this.collectBtnClickName) != null)
     {
         this.collectBtnClick =
             GameObject.Find("Canvas/BottomCollectBtns/BottomBtns/" + this.collectBtnClickName).GetComponent <CollectBtnClick>();
     }
 }
    //更新部件文本的数量
    public void UpdatePartTextCount(GameObject obj, CollectBtnClick collectClick)
    {
        Text txt          = obj.transform.GetChild(0).GetComponent <Text>();
        int  currentCount = Int32.Parse(txt.text);

        if (currentCount >= 80)
        {
            // collectClick.materialPanelIndex = 0;
            return;
        }
        int laterCount = currentCount + collectClick.factor;

        txt.text = laterCount.ToString();
    }
    //判断部件栏是否达到最大值
    public bool CheckPartTextCount(CollectBtnClick collectBtnClick)
    {
        bool isOver = false;

        if (MatchingBarManager.Instance.partDictionary.ContainsKey(collectBtnClick.material.ToString()))
        {
            GameObject temp = null;
            MatchingBarManager.Instance.partDictionary.TryGetValue(collectBtnClick.material.ToString(), out temp);
            // TextCountManager.Instance.UpdatePartTextCount(temp, collectBtnClick);
            Text txt   = temp.transform.GetChild(0).GetComponent <Text>();
            int  count = Int32.Parse(txt.text);
            if (count >= 80)
            {
                isOver = true;
            }
        }
        return(isOver);
    }
    //生成加工部件,加工栏顶部的对象,部件栏
    public GameObject CreateParts(CollectBtnClick collectBtnClick)
    {
        //+ "(Clone)"
        if (MatchingBarManager.Instance.partDictionary.ContainsKey(collectBtnClick.material.ToString()))
        {
            GameObject temp = null;
            MatchingBarManager.Instance.partDictionary.TryGetValue(collectBtnClick.material.ToString(), out temp);
            TextCountManager.Instance.UpdatePartTextCount(temp, collectBtnClick);
            //  Debug.Log("有了");
            //这里开始对比订单和原料的要求
            OrderManager.Instance.CompareOrder();
            return(null);
        }
        GameObject objResouce = null;

        objResouce = Resources.Load("parts/" + collectBtnClick.material.ToString()) as GameObject;
        if (objResouce == null)
        {
            return(null);
        }
        Vector2 pos = new Vector2(collectBtnClick.materialPanelIndex * 121 + -396, 233);

        GameObject processBarObj = Instantiate(objResouce) as GameObject;

        //设置当前部件的名字
        processBarObj.name = collectBtnClick.material.ToString();
        RectTransform rectans     = processBarObj.GetComponent <RectTransform>();
        RectTransform parentTrans = GameObject.Find("Canvas/TopPart").GetComponent <RectTransform>();

        rectans.SetParent(parentTrans);
        rectans.SetAsLastSibling();
        rectans.anchoredPosition = pos;
        rectans.localScale       = Vector3.one;
        //Resources.UnloadAsset(objResouce);
        if (collectBtnClick.material == Material.XYL)
        {
            collectBtnClick.materialPanelIndex = 0;
        }
        TextCountManager.Instance.UpdatePartTextCount(processBarObj, collectBtnClick);
        MatchingBarManager.Instance.partDictionary.Add(processBarObj.gameObject.name, processBarObj);
        //从这里开始对比原料和订单的要求
        OrderManager.Instance.CompareOrder();
        return(objResouce);
    }