//2-4个占4个格子的装饰 void addIsland4(GridBase grid, int index, Hashtable map) { List <int> cells = grid.getCells(index, editorCfg.pageSize); int count = NumEx.NextInt(2, 5); for (int i = 0; i <= count; i++) { int id = NumEx.NextBool() ? 2 : 3; occupyCells(grid, cells, id, 1, map); } }
public void resetPosition() { if (aStar != null) { int index = NumEx.NextInt(0, aStar.grid.NumberOfCells); transform.position = aStar.grid.GetCellCenter(index); } else { transform.position = new Vector3(NumEx.NextInt(-radius * 10, radius * 10) / 10.0f, 0, NumEx.NextInt(-radius * 10, radius * 10) / 10.0f); } Invoke("resetPosition", NumEx.NextInt(20, 80) / 10); }
void occupyCells(GridBase grid, List <int> cells, int id, int size, Hashtable map) { int count = 0; int i = NumEx.NextInt(0, cells.Count); int index = 0; while (true) { if (i >= cells.Count) { i = 0; } index = cells[i]; if (size > 1) { bool canAdd = true; List <int> _cells = grid.getCells(index, size); for (int j = 0; j < _cells.Count; j++) { if (_cells[j] < 0 || map[_cells[j]] != null) { canAdd = false; break; } } if (canAdd) { for (int j = 0; j < _cells.Count; j++) { map[_cells[j]] = 99; //占用 } map[index] = id; break; } } else { if (map[index] == null) { map[index] = id; break; } } i++; count++; if (count >= cells.Count) { break; } } }
/// <summary> /// Sets the action. /// </summary> /// <param name="actionValue">Action value.动作对应的value</param> /// <param name="callbackInfor">Callback infor. 是一个key:value的键值对 /// key:是0~100的整数,表示动作播放到百分之多少时执行回调, /// 而回调方法就是该key所对应的value /// </param> public void doSetActionWithCallback(string actionName, ArrayList progressCallbackInfor) { // if (currActionValue == actionValue) { // return; // } ////////////////////////////////////////////////////////////////// progressPoints.Clear(); progressCallback.Clear(); callbackMap.Clear(); if (progressCallbackInfor != null) { int count = progressCallbackInfor.Count; for (int i = 0; i < count; i++) { if (i % 2 == 0) { progressPoints.Add(NumEx.stringToInt(progressCallbackInfor [i].ToString()) / 100.0f); } else { progressCallback.Add(progressCallbackInfor [i]); } } progressCallbackInfor.Clear(); progressCallbackInfor = null; } ////////////////////////////////////////////////////////////////// PlayAnimation(actionName); if (progressPoints.Count > 0) { progressIndex = 0; isCheckProgress = true; // place the code after setAction, beacuse in setAction function ,set isCheckProgress = false; } else { isCheckProgress = false; } }
void showSpriteInfor() { if (currSelectSprite == null) { return; } Hashtable d = MapEx.getMap(currSelectSprite, "data"); int times = MapEx.getInt(currSelectSprite, "times"); string name = MapEx.getString(d, "name"); string path = MapEx.getString(d, "path"); int x = MapEx.getInt(d, "x"); int y = MapEx.getInt(d, "y"); int width = MapEx.getInt(d, "width"); int height = MapEx.getInt(d, "height"); int borderLeft = MapEx.getInt(d, "borderLeft"); int borderRight = MapEx.getInt(d, "borderRight"); int borderTop = MapEx.getInt(d, "borderTop"); int borderBottom = MapEx.getInt(d, "borderBottom"); int paddingLeft = MapEx.getInt(d, "paddingLeft"); int paddingRight = MapEx.getInt(d, "paddingRight"); int paddingTop = MapEx.getInt(d, "paddingTop"); int paddingBottom = MapEx.getInt(d, "paddingBottom"); Hashtable atlas = MapEx.getMap(currSelectSprite, "atlas"); string atlasStr = ""; foreach (DictionaryEntry item in atlas) { atlasStr = PStr.b().a(atlasStr).a(",").a(item.Key.ToString()).e(); } Texture tex = ECLEditorUtl.getObjectByPath(path) as Texture; Rect r = Rect.zero; if (tex != null) { float h = 0; float w = position.width - 160; float rate = w / tex.width; if (rate < 1) { h = tex.height * rate; } else { h = tex.height; } h = h > 200 ? h : 200; r = new Rect(0, 0, NumEx.getIntPart(w), NumEx.getIntPart(h)); GUI.DrawTexture(r, tex, ScaleMode.ScaleToFit); GUILayout.Space(r.height + r.y); //这句主要目的是为了可以滑动 } else { r = new Rect(0, 0, position.width - 160, 100); GUILayout.Space(r.height + r.y); //这句主要目的是为了可以滑动 } GUILayout.Space(10); ECLEditorUtl.BeginContents(); { EditorGUILayout.BeginHorizontal(); { EditorGUILayout.TextField("name", name); EditorGUILayout.IntField("times", times); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.IntField("x", x); EditorGUILayout.IntField("y", y); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.IntField("width", width); EditorGUILayout.IntField("height", height); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.IntField("borderLeft", borderLeft); EditorGUILayout.IntField("borderRight", borderRight); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.IntField("borderTop", borderTop); EditorGUILayout.IntField("borderBottom", borderBottom); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.IntField("paddingLeft", paddingLeft); EditorGUILayout.IntField("paddingRight", paddingRight); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.IntField("paddingTop", paddingTop); EditorGUILayout.IntField("paddingBottom", paddingBottom); } EditorGUILayout.EndHorizontal(); EditorGUILayout.TextField("path", path); EditorGUILayout.TextField("Atlas", atlasStr); } ECLEditorUtl.EndContents(); }
void showPackerView() { if (packTex != null) { //================= float h = 0; float w = position.width - 160; float rate = w / packTex.width; if (rate < 1) { h = packTex.height * rate; } else { h = packTex.height; } h = h > 512 ? h : 512; Rect r = new Rect(0, 0, NumEx.getIntPart(w), NumEx.getIntPart(h)); NGUIEditorTools.DrawTiledTexture(r, NGUIEditorTools.backdropTexture); if (isShowParckerTextureBg) { GUI.DrawTexture(r, _empty, ScaleMode.ScaleToFit, false); } GUI.DrawTexture(r, packTex, ScaleMode.ScaleToFit); GUILayout.Space(r.height + r.y); //这句主要目的是为了可以滑动 ECLEditorUtl.BeginContents(); { EditorGUILayout.BeginHorizontal(); { EditorGUILayout.IntField("width", packTex.width); EditorGUILayout.IntField("height", packTex.height); } EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Show/Hide Detail")) { showDeltail = !showDeltail; } if (showDeltail) { if (packSprites != null) { Hashtable m = null; Hashtable d = null; Rect _rect; for (int i = 0; i < packSprites.Count; i++) { _rect = packRects [i]; m = packSprites [i] as Hashtable; d = MapEx.getMap(m, "data"); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.LabelField(MapEx.getString(d, "name")); EditorGUILayout.LabelField(Mathf.RoundToInt(_rect.x) + "x" + Mathf.RoundToInt(_rect.y)); EditorGUILayout.LabelField(Mathf.RoundToInt(_rect.width) + "x" + Mathf.RoundToInt(_rect.height)); } EditorGUILayout.EndHorizontal(); } } } } ECLEditorUtl.EndContents(); } isShowParckerTextureBg = EditorGUILayout.ToggleLeft("Show Background", isShowParckerTextureBg); textureSize = (PackerTextureSize)EditorGUILayout.EnumPopup("", textureSize); isUseUnityPacking = EditorGUILayout.ToggleLeft("UnityPacking", isUseUnityPacking); sortSprite = (SortSprite)EditorGUILayout.EnumPopup("", sortSprite); GUILayout.Space(5); GUI.color = Color.yellow; if (GUILayout.Button("Review Pack Texture")) { if (!packTextures((int)textureSize, isUseUnityPacking)) { Debug.LogError("Some errors happened!"); } } GUI.color = Color.white; GUILayout.Space(10); ECLEditorUtl.BeginContents(); { packedName = EditorGUILayout.TextField("Packed Texture Name", string.IsNullOrEmpty(packedName) ? "Packed" + (int)packerSize : packedName); GUI.color = Color.red; removePublishRes = EditorGUILayout.ToggleLeft("Remove Publish AssetsBundle", removePublishRes); if (GUILayout.Button("Apply Pack Texture")) { applyPackTexture((int)textureSize, isUseUnityPacking); } GUI.color = Color.white; } ECLEditorUtl.EndContents(); }
void generateData() { if (editorCfg == null) { Debug.Log("Editor config is null"); return; } // 设置grid GridBase grid = new GridBase(); grid.init(Vector3.zero, editorCfg.size, editorCfg.size, 1); // 先把图的格式设置成RGBA32 Texture2D areaTex = editorCfg.oceanGidTexture; if (areaTex == null) { Debug.Log("oceanGid Texture is null"); return; } // 先取得大地图分区的数据 Color32[] colors = areaTex.GetPixels32(); Debug.Log("areaTex.width===" + areaTex.width); Debug.Log("colors.Length===" + colors.Length); // 区域块的index对应的val Hashtable areaMap = new Hashtable(); // 取得大地图与分区地图的比例,以例可以对换 int mapareaScale = editorCfg.size / areaTex.width; //地图分区块的网格 GridBase gridArea = new GridBase(); gridArea.init(Vector3.zero, areaTex.width, areaTex.width, mapareaScale); Color c; for (int i = 0; i < colors.Length - 1; i++) { c = colors[i]; int areaVal = 0; if (editorCfg.colors4MapArea.TryGetValue(c, out areaVal)) { areaMap[i] = areaVal; } else { Debug.LogError("get area val by color is nil!" + c + "==" + c * 255); } } //地图数据 Hashtable mapInfor = new Hashtable(); // 生成据点 int tmpSize = editorCfg.pageSize * 2; for (int i = tmpSize / 2; i < editorCfg.size; i += tmpSize) { for (int j = tmpSize / 2; j < editorCfg.size; j += tmpSize) { int index = grid.GetCellIndex(i, j); List <int> cells = grid.getCells(index, 5); int k = NumEx.NextInt(0, cells.Count); while (true) { if (k >= cells.Count) { k = 0; } if (mapInfor[(int)(cells[k])] == null) { mapInfor[(int)(cells[k])] = 1; break; } k++; } } } // 生成装饰 for (int i = editorCfg.pageSize / 2; i < editorCfg.size; i = i + editorCfg.pageSize) { for (int j = editorCfg.pageSize / 2; j < editorCfg.size; j = j + editorCfg.pageSize) { int index = grid.GetCellIndex(i, j); switch (NumEx.NextInt(0, 4)) { case 0: addIsland1(grid, index, mapInfor); break; case 1: addIsland2(grid, index, mapInfor); break; case 2: addIsland3(grid, index, mapInfor); break; default: addIsland4(grid, index, mapInfor); break; } } } //导出数据(会根据分区导出数据,这里会导出100份数据,方便加载) /* * 每个分区id对应一个文件,每个文件里存一个table,key是一屏的index,value是table2 * table2里的key是网格index,value是地块配置id */ string path = Application.dataPath + "/" + CLPathCfg.self.basePath + "/" + CLPathCfg.upgradeRes + "/priority/cfg/worldmap/maparea.cfg"; Directory.CreateDirectory(Path.GetDirectoryName(path)); MemoryStream ms = new MemoryStream(); B2OutputStream.writeObject(ms, areaMap); File.WriteAllBytes(path, ms.ToArray()); Debug.Log(path); for (int i = 0; i < areaTex.width; i++) { for (int j = 0; j < areaTex.width; j++) { int index = i * areaTex.width + j; Hashtable areaPageMap = new Hashtable(); List <int> pagesIndes = areaIndex2MapPageIndexs(grid, gridArea, index, mapareaScale); for (int p = 0; p < pagesIndes.Count; p++) { int center = pagesIndes[p]; List <int> cells = grid.getCells(center, editorCfg.pageSize); Hashtable map = new Hashtable(); for (int k = 0; k < cells.Count; k++) { if (mapInfor[cells[k]] != null) { map[cells[k]] = mapInfor[cells[k]]; } } areaPageMap[center] = map; } path = Application.dataPath + "/" + CLPathCfg.self.basePath + "/" + CLPathCfg.upgradeRes + "/priority/cfg/worldmap/" + index + ".cfg"; Directory.CreateDirectory(Path.GetDirectoryName(path)); ms = new MemoryStream(); B2OutputStream.writeObject(ms, areaPageMap); File.WriteAllBytes(path, ms.ToArray()); } } Debug.Log("total===" + mapInfor.Count); }
public void Recenter() { if (mScrollView == null) { mScrollView = NGUITools.FindInParents <UIScrollView>(gameObject); if (mScrollView == null) { Debug.LogWarning(GetType() + " requires " + typeof(UIScrollView) + " on a parent object in order to work", this); enabled = false; return; } else { if (mScrollView) { mScrollView.centerOnChild = this; mScrollView.onDragFinished += OnDragFinished; } if (mScrollView.horizontalScrollBar != null) { mScrollView.horizontalScrollBar.onDragFinished += OnDragFinished; } if (mScrollView.verticalScrollBar != null) { mScrollView.verticalScrollBar.onDragFinished += OnDragFinished; } } } if (mScrollView.panel == null) { return; } Transform trans = transform; if (trans.childCount == 0) { return; } // Calculate the panel's center in world coordinates Vector3[] corners = mScrollView.panel.worldCorners; Vector3 panelCenter = (corners[2] + corners[0]) * 0.5f; // Offset this value by the momentum Vector3 momentum = mScrollView.currentMomentum * mScrollView.momentumAmount; Vector3 moveDelta = NGUIMath.SpringDampen(ref momentum, 9f, 2f); Vector3 pickingPoint = panelCenter - moveDelta * 0.01f; // Magic number based on what "feels right" float min = float.MaxValue; Transform closest = null; int index = 0; int ignoredIndex = 0; // Determine the closest child for (int i = 0, imax = trans.childCount, ii = 0; i < imax; ++i) { Transform t = trans.GetChild(i); if (!t.gameObject.activeInHierarchy) { continue; } float sqrDist = Vector3.SqrMagnitude(t.position - pickingPoint); if (sqrDist < min) { min = sqrDist; closest = t; index = i; ignoredIndex = ii; } ++ii; } // If we have a touch in progress and the next page threshold set if (nextPageThreshold > 0f && UICamera.currentTouch != null) { // If we're still on the same object if (mCenteredObject != null && mCenteredObject.transform == trans.GetChild(index)) { Vector3 totalDelta = UICamera.currentTouch.totalDelta; totalDelta = transform.rotation * totalDelta; float delta = 0f; switch (mScrollView.movement) { case UIScrollView.Movement.Horizontal: { delta = totalDelta.x; break; } case UIScrollView.Movement.Vertical: { delta = totalDelta.y; break; } default: { delta = totalDelta.magnitude; break; } } if (Mathf.Abs(delta) > nextPageThreshold) { UIGrid grid = GetComponent <UIGrid>(); CLUILoopGrid loopGrid = GetComponent <CLUILoopGrid>(); // add by chenbin if (loopGrid == null) { if (grid != null && grid.sorting != UIGrid.Sorting.None) { List <Transform> list = grid.GetChildList(); if (delta > nextPageThreshold) { // Next page if (ignoredIndex > 0) { closest = list [ignoredIndex - 1]; } else { closest = (GetComponent <UIWrapContent> () == null) ? list [0] : list [list.Count - 1]; } } else if (delta < -nextPageThreshold) { // Previous page if (ignoredIndex < list.Count - 1) { closest = list [ignoredIndex + 1]; } else { closest = (GetComponent <UIWrapContent> () == null) ? list [list.Count - 1] : list [0]; } } } else { Debug.LogWarning("Next Page Threshold requires a sorted UIGrid in order to work properly", this); } #region add by chenbin } else { int _index = NumEx.stringToInt(closest.name); if (delta > nextPageThreshold) { // Next page if (_index > 0) { _index--; closest = trans.Find(NumEx.nStrForLen(_index, 6)); } } else if (delta < -nextPageThreshold) { // Previous page if (_index < loopGrid.list.Count - 1) { _index++; closest = trans.Find(NumEx.nStrForLen(_index, 6)); } } } #endregion } } } CenterOn(closest, panelCenter); }
// Use this for initialization void Start() { Invoke("resetPosition", NumEx.NextInt(10, 50) / 10); }