public static void CreateCardList() { GameObject cardList = GameObject.Find("CardList"); int index = 0; foreach (MusicData md in mdata) { GameObject cardSelectItem = new GameObject("CardWheelItem" + string.Format("{0}", index)); CardSelectItem temp = cardSelectItem.AddComponent <CardSelectItem>(); temp.state = false; cardSelectItem.transform.parent = cardList.transform; GameObject textContent = new GameObject(); textContent.transform.parent = cardSelectItem.transform; Text textContentText = textContent.AddComponent <Text>(); textContentText.text = LanguageManager.UTF8String(md.packname + "-" + md.NO); textContentText.font = (Font)Resources.Load("chaoshijicufanghei"); textContentText.alignment = TextAnchor.UpperCenter; textContentText.color = Color.white; textContentText.transform.localPosition = new Vector3(0f, -1.6f, -10f); textContentText.fontSize = 24; textContent.GetComponent <RectTransform>().sizeDelta = new Vector2(160, 100); textContent.GetComponent <RectTransform>().localScale = new Vector3(0.01f, 0.01f, 0.01f); temp.rImage = cardSelectItem.AddComponent <RawImage>(); byte[] bytes = FileManager.ReadBytesWWW(FileManager.GetThumbnailPath(md.image)); //创建Texture Texture2D texture = new Texture2D(0, 0); texture.LoadImage(bytes); int area = texture.width * texture.height; float max_area = 6.75f * 10.5f * 0.035f; float ratio = (float)(System.Math.Sqrt(max_area * 1.0f / area)); temp.rImage.texture = texture; temp.rImage.GetComponent <RectTransform>().sizeDelta = new Vector2(texture.width * ratio, texture.height * ratio); temp.m_Button = cardSelectItem.AddComponent <Button>(); temp.m_Button.targetGraphic = temp.rImage; temp.m_Button.onClick.RemoveAllListeners(); temp.m_Button.onClick.AddListener(temp.ButtonOnClickEvent); ColorBlock cb = new ColorBlock(); cb = temp.m_Button.colors; cb.normalColor = new Color(255 / 255f, 255 / 255f, 255 / 255f, 255 / 255f); cb.highlightedColor = new Color(0 / 255f, 255 / 255f, 255 / 255f, 225 / 255f); cb.pressedColor = new Color(255 / 255f, 255 / 255f, 255 / 255f, 255 / 255f); cb.selectedColor = new Color(255 / 255f, 255 / 255f, 255 / 255f, 255 / 255f); cb.fadeDuration = 0.4f; temp.m_Button.colors = cb; temp.index = index; index++; } }
public static void RemoveAllCardOfFolder(string foldername) { for (int i = 0; i < mdata.Count; i++) { if (mdata[i].packname == foldername) { CardSelectItem card_item = GameObject.Find("CardWheelItem" + string.Format("{0}", i)).GetComponent <CardSelectItem>(); if (card_item.state) { card_item.ButtonOnClickEvent(); } } } }