//初始化所有三个hex方体总入口 void initHexs() { //初始化三个hex方体展示的位置,并把定位的三个hex隐藏 GameObject[] LoadFirstHex = new GameObject[HEX_COUNT_ARRAY]; for (int i = 0; i < HEX_COUNT_ARRAY; i++) { LoadFirstHex[i] = GameObject.Find("LoadFirstHex" + (i + 1)); if (LoadFirstHex[i] != null) { LoadHexPosition[i] = LoadFirstHex[i].transform.position; LoadFirstHex[i].GetComponent <Renderer>().enabled = false; } } //随机选择颜色,但是不能喝上一次颜色相同 int randomIndex; do { randomIndex = Random.Range(0, HexPrefabs.Length); } while (mPriviousColor == randomIndex); mPriviousColor = randomIndex; //随机选hex方体邢专 for (int i = 0; i < HEX_COUNT_ARRAY; i++) { int index = Random.Range(0, AllHexArray.Length); HexArray[i] = AllHexArray[index]; } for (int i = 0; i < HEX_COUNT_ARRAY; i++) { mHexObjectsArray[i] = new HexObjectsArray(); mHexObjectsArray[i].initPrefabs(LoadHexPosition[i], HexPrefabs[randomIndex], mHexColliderSizeSmall, HexArray[i]); //执行加载新的hex方体的动画 foreach (GameObject hex in mHexObjectsArray[i].mHexObject) { hex.transform.localScale = new Vector3(0.01f, 0.01f, 0.01f); } GameObject.Find("BackgroundScript").GetComponent <LoadHexAnimation>().animationLoadHexSB(mHexObjectsArray[i].mHexObject, LoadHexAnimation.ANIMATION_SMALL_BIG); } }
//初始化所有三个hex方体总入口 void initHexs() { //初始化三个hex方体展示的位置,并把定位的三个hex隐藏 GameObject[] LoadFirstHex = new GameObject[HEX_COUNT_ARRAY]; for (int i = 0; i < HEX_COUNT_ARRAY; i++) { LoadFirstHex[i] = GameObject.Find("LoadFirstHex" + (i + 1)); if (LoadFirstHex[i] != null) { LoadHexPosition[i] = LoadFirstHex[i].transform.position; LoadFirstHex[i].GetComponent<Renderer>().enabled = false; } } //随机选择颜色,但是不能喝上一次颜色相同 int randomIndex; do { randomIndex = Random.Range(0, HexPrefabs.Length); } while (mPriviousColor == randomIndex); mPriviousColor = randomIndex; //随机选hex方体邢专 for (int i = 0; i < HEX_COUNT_ARRAY; i++) { int index = Random.Range(0, AllHexArray.Length); HexArray[i] = AllHexArray[index]; } for (int i = 0; i < HEX_COUNT_ARRAY; i++) { mHexObjectsArray[i] = new HexObjectsArray(); mHexObjectsArray[i].initPrefabs(LoadHexPosition[i], HexPrefabs[randomIndex], mHexColliderSizeSmall, HexArray[i]); //执行加载新的hex方体的动画 foreach (GameObject hex in mHexObjectsArray[i].mHexObject) { hex.transform.localScale = new Vector3(0.01f, 0.01f, 0.01f); } GameObject.Find("BackgroundScript").GetComponent<LoadHexAnimation>().animationLoadHexSB(mHexObjectsArray[i].mHexObject, LoadHexAnimation.ANIMATION_SMALL_BIG); } }
void Start() { HexObject = GameObject.Find("RedHexObject"); float r = HexObject.gameObject.GetComponent <CircleCollider2D>().bounds.size.x; float d = Mathf.Sqrt(3.0f) / 2.0f * r; LeftUp = LeftUp * r; RightUp = RightUp * r; Left = Left * d; Right = Right * d; for (int j = 0; j < 3; j++) { Vector2 originPosition = new Vector2((j - 1) * 3 * r, 0); mHexObjectsArray[j] = new HexObjectsArray(); mHexObjectsArray[j].mHexObject[0] = (GameObject)Instantiate(RedHex, originPosition, RedHex.transform.rotation); Vector2 offsetPosition = new Vector2(0, 0); for (int i = 1; i < 4; i++) { mHexObjectsArray[j].mHexObject[i] = (GameObject)Instantiate(RedHex, originPosition, RedHex.transform.rotation); if (HexArray[j, i] == 1) { mHexObjectsArray[j].mHexObject[i] = (GameObject)Instantiate(RedHex, originPosition, RedHex.transform.rotation); mHexObjectsArray[j].mHexObject[i].transform.position = originPosition + offsetPosition + Left; offsetPosition += Left; //mHexObjectsArray[j].mHexObject[i].tag = ""+j; } if (HexArray[0, i] == 2) { mHexObjectsArray[j].mHexObject[i] = (GameObject)Instantiate(RedHex, originPosition, RedHex.transform.rotation); mHexObjectsArray[j].mHexObject[i].transform.position = originPosition + offsetPosition + Right; offsetPosition += Right; //mHexObjectsArray[j].mHexObject[i].tag = "" + j; } if (HexArray[0, i] == 3) { mHexObjectsArray[j].mHexObject[i] = (GameObject)Instantiate(RedHex, originPosition, RedHex.transform.rotation); mHexObjectsArray[j].mHexObject[i].transform.position = originPosition + offsetPosition + LeftUp; offsetPosition += LeftUp; //mHexObjectsArray[j].mHexObject[i].tag = "" + j; } if (HexArray[0, i] == 4) { mHexObjectsArray[j].mHexObject[i] = (GameObject)Instantiate(RedHex, originPosition, RedHex.transform.rotation); mHexObjectsArray[j].mHexObject[i].transform.position = originPosition + offsetPosition + RightUp; offsetPosition += RightUp; //mHexObjectsArray[j].mHexObject[i].tag = "" + j; } if (HexArray[0, i] == 5) { mHexObjectsArray[j].mHexObject[i] = (GameObject)Instantiate(RedHex, originPosition, RedHex.transform.rotation); mHexObjectsArray[j].mHexObject[i].transform.position = originPosition + offsetPosition + LeftDown; offsetPosition += LeftDown; //mHexObjectsArray[j].mHexObject[i].tag = "" + j; } if (HexArray[0, i] == 6) { mHexObjectsArray[j].mHexObject[i] = (GameObject)Instantiate(RedHex, originPosition, RedHex.transform.rotation); mHexObjectsArray[j].mHexObject[i].transform.position = originPosition + offsetPosition + RightDown; offsetPosition += RightDown; //mHexObjectsArray[j].mHexObject[i].tag = "" + j; } } } //Vector2 position = new Vector2(0, 0); //GameObject obj = (GameObject)Instantiate(RedHex, position, RedHex.transform.rotation); //GameObject obj2 = (GameObject)Instantiate(RedHex, position, RedHex.transform.rotation); //obj2.transform.position = position + Right; //GameObject obj3 = (GameObject)Instantiate(RedHex, position, RedHex.transform.rotation); //obj3.transform.position = position + Right + RightUp; //GameObject obj4 = (GameObject)Instantiate(RedHex, position, RedHex.transform.rotation); //obj4.transform.position = position + Right + RightUp + LeftUp; }
void Start() { HexObject = GameObject.Find("RedHexObject"); float r = HexObject.gameObject.GetComponent<CircleCollider2D>().bounds.size.x; float d = Mathf.Sqrt(3.0f) / 2.0f * r; LeftUp = LeftUp * r; RightUp = RightUp * r; Left = Left * d; Right = Right * d; for (int j = 0; j < 3; j++) { Vector2 originPosition = new Vector2((j - 1) * 3 * r, 0); mHexObjectsArray[j] = new HexObjectsArray(); mHexObjectsArray[j].mHexObject[0] = (GameObject)Instantiate(RedHex, originPosition, RedHex.transform.rotation); Vector2 offsetPosition = new Vector2(0, 0); for (int i = 1; i < 4; i++) { mHexObjectsArray[j].mHexObject[i] = (GameObject)Instantiate(RedHex, originPosition, RedHex.transform.rotation); if (HexArray[j, i] == 1) { mHexObjectsArray[j].mHexObject[i] = (GameObject)Instantiate(RedHex, originPosition, RedHex.transform.rotation); mHexObjectsArray[j].mHexObject[i].transform.position = originPosition + offsetPosition + Left; offsetPosition += Left; //mHexObjectsArray[j].mHexObject[i].tag = ""+j; } if (HexArray[0, i] == 2) { mHexObjectsArray[j].mHexObject[i] = (GameObject)Instantiate(RedHex, originPosition, RedHex.transform.rotation); mHexObjectsArray[j].mHexObject[i].transform.position = originPosition + offsetPosition + Right; offsetPosition += Right; //mHexObjectsArray[j].mHexObject[i].tag = "" + j; } if (HexArray[0, i] == 3) { mHexObjectsArray[j].mHexObject[i] = (GameObject)Instantiate(RedHex, originPosition, RedHex.transform.rotation); mHexObjectsArray[j].mHexObject[i].transform.position = originPosition + offsetPosition + LeftUp; offsetPosition += LeftUp; //mHexObjectsArray[j].mHexObject[i].tag = "" + j; } if (HexArray[0, i] == 4) { mHexObjectsArray[j].mHexObject[i] = (GameObject)Instantiate(RedHex, originPosition, RedHex.transform.rotation); mHexObjectsArray[j].mHexObject[i].transform.position = originPosition + offsetPosition + RightUp; offsetPosition += RightUp; //mHexObjectsArray[j].mHexObject[i].tag = "" + j; } if (HexArray[0, i] == 5) { mHexObjectsArray[j].mHexObject[i] = (GameObject)Instantiate(RedHex, originPosition, RedHex.transform.rotation); mHexObjectsArray[j].mHexObject[i].transform.position = originPosition + offsetPosition + LeftDown; offsetPosition += LeftDown; //mHexObjectsArray[j].mHexObject[i].tag = "" + j; } if (HexArray[0, i] == 6) { mHexObjectsArray[j].mHexObject[i] = (GameObject)Instantiate(RedHex, originPosition, RedHex.transform.rotation); mHexObjectsArray[j].mHexObject[i].transform.position = originPosition + offsetPosition + RightDown; offsetPosition += RightDown; //mHexObjectsArray[j].mHexObject[i].tag = "" + j; } } } //Vector2 position = new Vector2(0, 0); //GameObject obj = (GameObject)Instantiate(RedHex, position, RedHex.transform.rotation); //GameObject obj2 = (GameObject)Instantiate(RedHex, position, RedHex.transform.rotation); //obj2.transform.position = position + Right; //GameObject obj3 = (GameObject)Instantiate(RedHex, position, RedHex.transform.rotation); //obj3.transform.position = position + Right + RightUp; //GameObject obj4 = (GameObject)Instantiate(RedHex, position, RedHex.transform.rotation); //obj4.transform.position = position + Right + RightUp + LeftUp; }