//创建基本方块 private void createCubeCell(out GameObject ret,WorldObjectCombineController.WORLD_OBJECT_COMPONENT compData) { ret = (GameObject)Instantiate (prefCubeCell); ret.transform.localPosition = new Vector3 (compData.posX,compData.posY,compData.posZ); CubeCell cell = ret.GetComponent<CubeCell> (); Material top = matController.getMat (compData.topFaceName); top.SetVector("_UV01",uvController.getBlocksUVByName (compData.topFaceName)); Material bottom = matController.getMat (compData.bottomFaceName); bottom.SetVector("_UV01",uvController.getBlocksUVByName(compData.bottomFaceName)); Material front = matController.getMat (compData.frontFaceName); front.SetVector("_UV01",uvController.getBlocksUVByName(compData.frontFaceName)); Material back = matController.getMat (compData.backFaceName); back.SetVector("_UV01",uvController.getBlocksUVByName(compData.backFaceName)); Material left = matController.getMat (compData.leftFaceName); left.SetVector("_UV01",uvController.getBlocksUVByName(compData.leftFaceName)); Material right = matController.getMat (compData.rightFaceName); right.SetVector("_UV01",uvController.getBlocksUVByName(compData.rightFaceName)); cell.setFaceMats (top,bottom,left,right,front,back); cell.setInitRotation (compData.rotationX,compData.rotationY,compData.rotationZ); cell.setInitScale (compData.scaleX,compData.scaleY,compData.scaleZ); }
//获取边界 上下前后左右 private OBJ_BOUNDARY getBoundary(WorldObjectCombineController.WORLD_OBJECT _data) { OBJ_BOUNDARY ret; ret.left = 0; ret.right = 0; ret.bottom = 0; ret.top = 0; ret.front = 0; ret.back = 0; for (int i = 0; i < _data.componentCount; i++) { var comData = _data.components[i]; //计算边界 ret.left = Mathf.Min(ret.left,comData.posX); ret.right = Mathf.Max(ret.right,comData.posX); ret.top = Mathf.Max(ret.top,comData.posY); ret.bottom = Mathf.Min(ret.bottom,comData.posY); ret.front = Mathf.Max(ret.front,comData.posZ); ret.back = Mathf.Min(ret.back,comData.posZ); } return ret; }
void Awake() { m_dicObjTransByIndex = new Dictionary<int, Dictionary<int, Dictionary<int, Transform>>> (); m_dicObjIndex = new Dictionary<Transform, List<Vector3>> (); trans = GetComponent<Transform>(); matController = new MatHandler (cubeTex); uvController = new UVController (); objectCombineController = new WorldObjectCombineController (); }