// 用户自定义编辑颜色(添加颜色之后应该同步修改块儿的记录)(编辑颜色要判断颜色的个数是否过多和组合是否重复) public void SetEditColor(MagicColor pickedcolor) { operater.ColorDelete(mycolor); this.GetComponent <MeshRenderer> ().material.color = MyMapPrefab.ColorMap [pickedcolor]; mycolor = pickedcolor; operater.ColorAdd(); cube.SetColor(this.gameObject); }
// public void InitColor () // { // SingleBoxPiece[] mypieces = GetComponentsInChildren <SingleBoxPiece> (); // cubecolor.Clear (); // foreach (SingleBoxPiece p in mypieces) { // p.GetComponent <MeshRenderer> ().material.color = Color.gray; // cubecolor.Add (p.gameObject, MagicColor.None); // } // } public void SetColor(GameObject p) { if (operater == null) { operater = FindObjectOfType <MyMagicCube> (); } MagicColor curcolor = operater.Color; // print (operater.EditColorStore [curcolor]); if (curcolor != MagicColor.None && operater.EditColorStore [curcolor] > 7) { //print ("此颜色已经编辑完成" + curcolor + operater.EditColorStore [curcolor]); return; } if (cubecolor.ContainsKey(p) && cubecolor [p] == curcolor) { //print ("颜色相同"); return; } bool cansetcolor = true; if (editcolorfinished) { operater.ColorMapDelete(this); } MagicColor orignalcolor = MagicColor.None; // 如果字典里面有当前的物体,则为替换颜色,如果没有,则为添加颜色 if (cubecolor.ContainsKey(p)) { orignalcolor = cubecolor [p]; // 这些只是为了防止同一个块上出现两个相同的颜色和对面的颜色 foreach (GameObject g in cubecolor.Keys) { if (g != p) { if (!cubecolor [g].Equals(MagicColor.None)) { if (cubecolor [g] == curcolor) { cansetcolor = false; //print ("此块已经有相同颜色,请勿重复编辑"); break; } int index = (int)curcolor; if (index >= 3 && (int)cubecolor [g] == index - 3) { cansetcolor = false; //print ("颜色不匹配"); break; } else if (index < 3 && (int)cubecolor [g] == index + 3) { cansetcolor = false; //print ("颜色不匹配"); break; } } } } } else { cubecolor.Add(p, curcolor); //print ("添加新颜色"); } // 这里先假设将颜色附上去,如果不合适再去掉 if (cansetcolor) { cubecolor [p] = curcolor; } else { return; } // TODO: 判断是否完成当前cube的颜色设定,如果完成则保存到字典中,如果没有则等待完成 if ((cubestyle == CubeStyle.Edge && cubecolor.Count == 2) || (cubestyle == CubeStyle.Corner && cubecolor.Count == 3)) { editcolorfinished = true; } else { editcolorfinished = false; } if (editcolorfinished) { // foreach (GameObject g in cubecolor.Keys) { // editcolorfinished = true; // if (g.GetComponent <CubeFace> ().mycolor == MagicColor.None) { // editcolorfinished = false; // } // } if (cubecolor.ContainsValue(MagicColor.None)) { editcolorfinished = false; } } if (editcolorfinished) { //print ("当前块的颜色已经设置完成"); // TODO: 根据设定的颜色来标识当前cube,判断是否有重复 CubeMark mark = GetCubeMark(); if (operater.EditColorMap.ContainsValue(mark) && mark != CubeMark.None) { // print ("已经有这样的颜色块啦,请不要编辑错误了哦" + mark); cubecolor [p] = orignalcolor; } else { // print ("颜色编辑成功" + mark); operater.ColorDelete(orignalcolor); operater.ColorAdd(); operater.ColorMapAdd(this, mark); p.GetComponent <MeshRenderer> ().material.color = MyMapPrefab.ColorMap [curcolor]; } } else { // print ("当前块的颜色尚未设置完成"); operater.ColorDelete(orignalcolor); operater.ColorAdd(); p.GetComponent <MeshRenderer> ().material.color = MyMapPrefab.ColorMap [curcolor]; } }