public void ReturnData() { for (int i = 0; i < gameObject.transform.childCount; i++) { Destroy(gameObject.transform.GetChild(i).gameObject); } float fSellWidthSize = 0; float fSellHeightSize = 0; fSellWidthSize = gameObject.transform.GetComponent <RectTransform>().rect.width * (gameObject.transform.GetComponent <RectTransform>().anchorMax.x - gameObject.transform.GetComponent <RectTransform>().anchorMin.x) / 12.0f - 2.0f; fSellHeightSize = gameObject.transform.GetComponent <RectTransform>().rect.height * (gameObject.transform.GetComponent <RectTransform>().anchorMax.y - gameObject.transform.GetComponent <RectTransform>().anchorMin.y) / 12.0f - 2.0f; m_lygContent = gameObject.GetComponent <GridLayoutGroup>(); m_lygContent.cellSize = new Vector2(fSellHeightSize, fSellHeightSize); GameObject goImage = new GameObject(); goImage.AddComponent <Image>(); goImage.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); int nIndex = 0; m_arTmpImage = new GameObject[12, 12]; for (int i = 0; i < 12; i++) { for (int j = 0; j < 12; j++) { m_arTmpImage[i, j] = Instantiate(goImage); m_arTmpImage[i, j].transform.SetParent(gameObject.transform); m_arTmpImage[i, j].transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); m_arTmpImage[i, j].GetComponent <Image>().color = intChangeColor(m_cLoadCustomMapData.getNodeColor(m_cLoadCustomMapData.getNode(i, j))); nIndex++; } nIndex++; } m_goStars = gameObject.transform.parent.GetChild(0).gameObject; int nDifficultyGame = (int)(m_cLoadCustomMapData.getDiffculty() + 3.0f - ((float)(m_cLoadCustomMapData.getStartResource()) / 1300.0f) - ((float)(m_cLoadCustomMapData.getStartCoinPrice()) / 800.0f)); for (int i = 0; i < nDifficultyGame; i++) { m_goStars.transform.GetChild(i).gameObject.SetActive(true); } }
// Use this for initialization void Start() { m_cLoadCustomMapData = GameObject.Find("LoadData").GetComponent <C_LOADCUSTOMMAPDATA>(); float fSellWidthSize = 0; float fSellHeightSize = 0; fSellWidthSize = gameObject.transform.parent.parent.parent.GetComponent <RectTransform>().rect.width * (gameObject.transform.parent.parent.GetComponent <RectTransform>().anchorMax.x - gameObject.transform.parent.parent.GetComponent <RectTransform>().anchorMin.x); fSellHeightSize = gameObject.transform.parent.parent.parent.GetComponent <RectTransform>().rect.height * (gameObject.transform.parent.parent.GetComponent <RectTransform>().anchorMax.y - gameObject.transform.parent.parent.GetComponent <RectTransform>().anchorMin.y) / 6.0f; m_lygContent = gameObject.GetComponent <GridLayoutGroup>(); PlayerManager = GameObject.Find("PlayerManager"); m_lygContent.cellSize = new Vector2(fSellWidthSize - m_lygContent.padding.left * 2.0f, fSellHeightSize); nMapCount = PlayerManager.GetComponent <ProductManager>().products.Count; //GameObject goButton = (GameObject)Resources.Load("ShopButton"); GameObject goButton = (GameObject)Resources.Load("btnShop"); GameObject goTmpButton; //for (int i = 0; i < nMapCount; i++) //{ // goTmpButton = Instantiate(goButton); // goTmpButton.transform.SetParent(gameObject.transform); // goTmpButton.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); // goTmpButton.AddComponent<C_SHOPMAINSELECT>().init(i); //} GameObject m_goStars; for (int i = 0; i < nMapCount; i++) { goTmpButton = Instantiate(goButton); goTmpButton.transform.SetParent(gameObject.transform); goTmpButton.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); goTmpButton.transform.GetChild(1).gameObject.AddComponent <C_SHOPMAINSELECT>().init(i); m_goStars = goTmpButton.transform.GetChild(0).gameObject; m_cLoadCustomMapData.settingButton(i); int nDifficultyGame = (int)(m_cLoadCustomMapData.getDiffculty() + 3.0f - ((float)(m_cLoadCustomMapData.getStartResource()) / 1300.0f) - ((float)(m_cLoadCustomMapData.getStartCoinPrice()) / 800.0f)); for (int j = 0; j < nDifficultyGame; j++) { m_goStars.transform.GetChild(j).gameObject.SetActive(true); } } gameObject.GetComponent <RectTransform>().sizeDelta = new Vector2(0.0f, fSellHeightSize * (float)nMapCount); }