void OnEnable() { //Debug.Log("OnEnable"); if (!mCanvasExecutive) { mCanvasExecutive = GameObject.Find("Canvas General").GetComponent <CanvasExecutive>(); mSelect = transform.Find("Select").GetComponent <Button>(); mSelectImage = mSelect.transform.Find("SelectImage").gameObject; mWujiang = transform.Find("Wujiang").GetComponentInChildren <Text>(); mTongshuai = transform.Find("Tongshuai").GetComponentInChildren <Text>(); mWuli = transform.Find("Wuli").GetComponentInChildren <Text>(); mZhili = transform.Find("Zhili").GetComponentInChildren <Text>(); mZhengzhi = transform.Find("Zhengzhi").GetComponentInChildren <Text>(); mMeili = transform.Find("Meili").GetComponentInChildren <Text>(); mSelect.onClick.AddListener(delegate() { if (mIsSeclet) { // 之前已经选中那么现在不选中了 mIsSeclet = false; } else { // 之前没有选中那么现在选中 if (mCanvasExecutive.CanSelect()) { mIsSeclet = true; } else { return; } } mSelectImage.SetActive(mIsSeclet); mCanvasExecutive.SelectItem(mIsSeclet, mIndex); }); } }
void Start() { // 兵种 for (int i = 0; i < mArms.Length; i++) { int index = i; mArms[index].onClick.AddListener(delegate() { // 点击兵种自动显示出征的武将(由AI控制选择哪些武将) mWeapons[mWeaponIndex].GetComponent <Image>().sprite = mSprite01[mWeaponIndex]; mWeaponText[mWeaponIndex].text = 1000000 + ""; mWeaponIndex = index; mWeapons[mWeaponIndex].GetComponent <Image>().sprite = mSprite02[mWeaponIndex]; mWeaponText[mWeaponIndex].text = 1000000 - mCurrentSoldier + ""; List <WujiangBean> temp = Strategy.GetExpeditionGenerals(mCity.GetWujiangBeans()); WujiangBean[] wujiangs = new WujiangBean[3]; wujiangs[0] = temp[0]; wujiangs[1] = temp[1]; wujiangs[2] = temp[2]; SetGeneral(wujiangs); CanvasExecutive canvasExecutive = mCanvasExecutive.GetComponent <CanvasExecutive>(); // 设置本次选中的武将 canvasExecutive.SetSelectGeneral(wujiangs); }); } // 显示武将界面 mExecutiveBtn.GetComponent <Button>().onClick.AddListener(delegate() { CanvasExecutive canvasExecutive = mCanvasExecutive.GetComponent <CanvasExecutive>(); canvasExecutive.SetCity(mCity); canvasExecutive.Show(); }); // 确定、返回 mEnableBtn.GetComponent <Button>().onClick.AddListener(delegate() { this.gameObject.SetActive(false); GameObject canvasGameMenu = GameObject.Find("Canvas GameMenu"); if (canvasGameMenu != null) { canvasGameMenu.SetActive(false); } if (mChief != null) { // 出兵 GameObject wujiangGameObject = Instantiate(mWujiangPrefab); wujiangGameObject.transform.position = new Vector3(mCity.transform.position.x, 0.05f, mCity.transform.position.z); Wujiang wujiang = wujiangGameObject.GetComponent <Wujiang>(); wujiang.mAvatar.sprite = mChiefImg.sprite; wujiang.mHealth.text = mSliderText[0].text.Split('/')[0]; wujiang.mName.text = mChief.name; // 设置武将技能 wujiang.mArmType = (ArmType)mWeaponIndex; wujiang.mArmAbility = mArmAbility; wujiang.mSkills = new Skills(wujiang, new string[] { mSkillText[0].text, mSkillText[1].text, mSkillText[2].text }); WujiangBean[] wujiangBeans = new WujiangBean[3]; wujiangBeans[0] = mChief; wujiangBeans[1] = mJunior01; wujiangBeans[2] = mJunior02; wujiang.SetWujiangBeans(wujiangBeans); // 显示路径 Wujiang.SetCurrentWujiang(wujiang); wujiang.SetWujiangState(WujiangState.WujiangState_Prepare_Expedition); wujiang.SetCity(mCity); wujiang.ShowPath(); // 减少城池里面的武将 List <WujiangBean> allWujiangs = mCity.GetWujiangBeans(); for (int i = allWujiangs.Count - 1; i >= 0; i--) { for (int j = 0; j < wujiangBeans.Length; j++) { if (allWujiangs[i] == wujiangBeans[j]) { allWujiangs.Remove(allWujiangs[i]); break; } } } // 清零选中的武将 CanvasExecutive canvasExecutive = mCanvasExecutive.GetComponent <CanvasExecutive>(); canvasExecutive.ClearSelectWujiang(); } }); mCloseBtn.GetComponent <Button>().onClick.AddListener(delegate() { this.gameObject.SetActive(false); }); // 武器,默认第一个亮 mWeapons[mWeaponIndex].GetComponent <Image>().sprite = mSprite02[mWeaponIndex]; for (int i = 0; i < mWeapons.Length; i++) { int index = i; mWeapons[index].onClick.AddListener(delegate() { if (mWeaponIndex == index && mChief == null) { return; } else { mWeapons[mWeaponIndex].GetComponent <Image>().sprite = mSprite01[mWeaponIndex]; mWeaponText[mWeaponIndex].text = 1000000 + ""; mWeaponIndex = index; mWeapons[mWeaponIndex].GetComponent <Image>().sprite = mSprite02[mWeaponIndex]; mWeaponText[mWeaponIndex].text = 1000000 - mCurrentSoldier + ""; SetAbilitysValue(mChief, mJunior01, mJunior02); }; }); } // 滑动条 for (int i = 0; i < mSlider.Length; i++) { int index = i; mSlider[index].onValueChanged.AddListener(delegate(float value) { int max = 0; int current = 0; if (index == 0) { // 士兵 max = 20000; mCurrentSoldier = (int)(max * value); mWeaponText[mWeaponIndex].text = 1000000 - mCurrentSoldier + ""; } else if (index == 1) { max = 10000; int temp = (int)(max * value); } else if (index == 2) { max = 50000; mSliderDayText.text = (int)(200 * value) / 10 * 10 + "日"; } current = (int)(max * value); mSliderText[index].text = current + "/" + max; mTotalText[index].text = 1000000 - current + ""; }); } // Test //string PATH = Application.streamingAssetsPath + "/img/img"; //string url = PATH + BattleGameManager.msWujiangs[0].id + ".jpg"; //StartCoroutine(LoadImage(url, null)); }