private void MoveOverEvent(UI_Control_ScrollFlow_Item t) { //上面参数框里MoveOverEvent(UI_Control_ScrollFlow_Item t) //t表示滑动后或者直接点选的对象 ,假如大家在做的时候 每个Item上有 //代码绑定 可以通过t.GetComponent<>()来查找 并操作。 Debug.Log("你要做的事情"); foreach (UI_Control_ScrollFlow_Item temp in UI_Control_ScrollFlow.instance.Items) { temp.gameObject.GetComponent <Image>().sprite = temp.GetComponent <UI_Control_ScrollFlow_Item>().Norimg; } t.GetComponent <Image>().sprite = t.GetComponent <UI_Control_ScrollFlow_Item>().Preimg; }
void Update() { if (_anim) { CurrentV = Time.deltaTime * _anim_speed * Vk; VT = Vtotal + CurrentV; if (Vk > 0 && VT >= AddV) { _anim = false; CurrentV = AddV - Vtotal; } if (Vk < 0 && VT <= AddV) { _anim = false; CurrentV = AddV - Vtotal; } //============== for (int i = 0; i < Items.Count; i++) { Items[i].Drag(CurrentV); if (Items[i].v - 0.5 < 0.05f) { Current = Items[i]; foreach (UI_Control_ScrollFlow_Item t in Items) { t.GetComponent <Image>().sprite = t.GetComponent <UI_Control_ScrollFlow_Item>().Norimg; } Current.GetComponent <Image>().sprite = Current.GetComponent <UI_Control_ScrollFlow_Item>().Preimg; } } Check(CurrentV); Vtotal = VT; if (!_anim) { if (MoveEnd != null) { MoveEnd(Current); } } } if (Input.GetKeyDown(KeyCode.Space)) { GenerateBtn(); } }
/// <summary> /// 产生对应的物体 /// </summary> /// <param name="count">产生数量</param> /// <param name="status">1表示城市 2表示县城</param> void SpwanAllGameobject(int count, int status) { if (count <= 0) { return; } for (int i = 0; i < count; i++) { if (status == 1) { GameObject go = Instantiate(Resources.Load <GameObject>("Lobby/City")); go.transform.localScale = Vector3.one; go.transform.localEulerAngles = Vector3.zero; go.transform.SetParent(Rect.transform); UI_Control_ScrollFlow_Item item = go.GetComponent <UI_Control_ScrollFlow_Item>(); if (item != null) { MahjongLobby_AH.Data.ParlorShowPanelData pspd = MahjongLobby_AH.GameData.Instance.ParlorShowPanelData; MahjongLobby_AH.Data.SelectAreaPanelData sapd = MahjongLobby_AH.GameData.Instance.SelectAreaPanelData; //更新该预置体的界面信息 item.GetComponent <Text>().text = pspd.listCityMessage[i].cityName; item.iCityId = Convert.ToInt32(pspd.listCityMessage[i].cityId); Items.Add(item); item.Init(this); item.Drag(StartValue + i * AddValue); if (item.v - 0.5 < 0.05f) { Current = Items[i]; } } } else { GameObject go = Instantiate(Resources.Load <GameObject>("Lobby/County")); go.transform.localScale = Vector3.one; go.transform.localEulerAngles = Vector3.zero; go.transform.SetParent(Rect.transform); UI_Control_ScrollFlow_Item item = go.GetComponent <UI_Control_ScrollFlow_Item>(); if (item != null) { MahjongLobby_AH.Data.SelectAreaPanelData sapd = MahjongLobby_AH.GameData.Instance.SelectAreaPanelData; MahjongLobby_AH.Data.ParlorShowPanelData pspd = MahjongLobby_AH.GameData.Instance.ParlorShowPanelData; //更新该预置体的界面信息 item.GetComponent <Text>().text = pspd.dicCountyMessage[sapd.iCityId][i].countyName; item.iCountyId = Convert.ToInt32(pspd.dicCountyMessage[sapd.iCityId][i].countyId); Items.Add(item); item.Init(this); item.Drag(StartValue + i * AddValue); if (item.v - 0.5 < 0.05f) { Current = Items[i]; } } } } }
public void OnPointerClick(PointerEventData eventData) { if (add_vect.sqrMagnitude <= 1) { UI_Control_ScrollFlow_Item script = eventData.pointerPressRaycast.gameObject.GetComponent <UI_Control_ScrollFlow_Item>(); if (script != null) { float k = script.v; k = 0.5f - k; AnimToEnd(k); //script.GetComponent<LSW_ScrollViewItem>().Selected(); Debug.Log(script.gameObject.transform.Find("Text").GetComponent <Text>().text); foreach (UI_Control_ScrollFlow_Item temp in Items) { temp.gameObject.GetComponent <Image>().sprite = temp.GetComponent <UI_Control_ScrollFlow_Item>().Norimg; } script.GetComponent <Image>().sprite = script.GetComponent <UI_Control_ScrollFlow_Item>().Preimg; } } }
/// <summary> /// 获取指定的更新物体 /// </summary> IEnumerator GetPointObject() { yield return(new WaitForSeconds(0.2f)); ParlorShowPanelData pspd = GameData.Instance.ParlorShowPanelData; SelectAreaPanelData sapd = GameData.Instance.SelectAreaPanelData; if (status == 1) { int CityCount = transform.GetComponentsInChildren <UI_Control_ScrollFlow_Item>().Length; UI_Control_ScrollFlow_Item[] cityItem = new UI_Control_ScrollFlow_Item[CityCount]; cityItem = transform.GetComponentsInChildren <UI_Control_ScrollFlow_Item>(); for (int i = 0; i < CityCount; i++) { float y = cityItem[i].sv; if (0.9 < y && y < 1) { pspd.temp_cc[0] = cityItem[i].iCityId; pspd.iCityId[pspd.iStatus_AreaSeeting - 1] = cityItem[i].iCityId; Debug.LogError("城市id:" + cityItem[i].iCityId); break; } } //更新玩家对应的县的玩家 UI_Control_ScrollFlow_Item[] temp = CountyMessage.transform.GetComponentsInChildren <UI_Control_ScrollFlow_Item>(); int count = 0; if (pspd.dicCountyMessage.ContainsKey(sapd.iCityId)) { count = pspd.dicCountyMessage[sapd.iCityId].Count; } CountyMessage.GetComponent <UI_Control_ScrollFlow>().Items.Clear(); if (temp.Length > count) { for (int i = 0; i < temp.Length; i++) { if (i < count) { //更新该预置体的界面信息 temp[i].GetComponent <Text>().text = pspd.dicCountyMessage[sapd.iCityId][i].countyName; temp[i].iCountyId = Convert.ToInt32(pspd.dicCountyMessage[sapd.iCityId][i].countyId); CountyMessage.GetComponent <UI_Control_ScrollFlow>().Items.Add(temp[i]); temp[i].Init_Num(); temp[i].Init(this); temp[i].Drag(StartValue + i * AddValue); if (temp[i].v - 0.5 < 0.05f) { CountyMessage.GetComponent <UI_Control_ScrollFlow>().Current = temp[i]; } } else { if (temp[i] != null) { Destroy(temp[i].gameObject); } } } } else { for (int i = 0; i < count; i++) { UI_Control_ScrollFlow_Item item = null; if (i < temp.Length) { item = temp[i].GetComponent <UI_Control_ScrollFlow_Item>(); item.Init_Num(); } else { GameObject go = Instantiate(Resources.Load <GameObject>("Lobby/County")); go.transform.localScale = Vector3.one; go.transform.localEulerAngles = Vector3.zero; go.transform.SetParent(CountyMessage.GetComponent <UI_Control_ScrollFlow>().Rect.transform); item = go.GetComponent <UI_Control_ScrollFlow_Item>(); } //更新该预置体的界面信息 item.GetComponent <Text>().text = pspd.dicCountyMessage[sapd.iCityId][i].countyName; item.iCountyId = Convert.ToInt32(pspd.dicCountyMessage[sapd.iCityId][i].countyId); CountyMessage.GetComponent <UI_Control_ScrollFlow>().Items.Add(item); item.Init(this); item.Drag(StartValue + i * AddValue); if (item.v - 0.5 < 0.05f) { CountyMessage.GetComponent <UI_Control_ScrollFlow>().Current = item; } } } CountyMessage.GetComponent <UI_Control_ScrollFlow>().Init(); CountyMessage.GetComponent <UI_Control_ScrollFlow>().Refresh(1); } if (status == 2) { int CountyCount = transform.GetComponentsInChildren <UI_Control_ScrollFlow_Item>().Length; UI_Control_ScrollFlow_Item[] countyItem = transform.GetComponentsInChildren <UI_Control_ScrollFlow_Item>(); for (int i = 0; i < CountyCount; i++) { float y = countyItem[i].sv; if (0.95f < y && y < 1.05f) { pspd.temp_cc[1] = countyItem[i].iCountyId; Debug.LogError("县城id:" + countyItem[i].iCountyId + ",名字:" + countyItem[i].GetComponent <Text>().text + ",位置:" + countyItem[i].transform.localPosition.y); break; } } } }