public int Bump(Tilemap map, Vector3Int pos, Vector3 offset, float duration, System.Action <int> onFin) { if (map == null || !map.HasTile(pos) || duration < 0.02f || offset.sqrMagnitude < 0.001f ) { return(-1); } var cmd = GetCMD <BumpCmd>(map, pos, duration, onFin); var tran = map.GetTransformMatrix(pos); cmd.startPos = tran.GetColumn(3); cmd.offset = offset; TilemapUtilties.UnlockFlag(map, pos, TileFlags.LockTransform); if (!enabled) { enabled = true; } return(cmd.GUID); }
/// <summary> /// 隐藏所有地块与小件 /// </summary> /// <param name="mapSize">地图尺寸</param> public void HideAll(int mapSize) { if (groundTilemap == null || miscBodyCache == null) { return; } activeCell.Clear(); for (int y = -mapSize; y < mapSize; y++) { for (int x = -mapSize; x < mapSize; x++) { Vector3Int pos = new Vector3Int(x, y, 0); TilemapUtilties.SetTileColor(groundTilemap, pos, Color.clear); } } foreach (var item in miscBodyCache) { if (item.Value != null && item.Value.Count > 0) { foreach (var m in item.Value) { m.SetActive(false); } } } }
public int Color(Tilemap map, Vector3Int pos, Color col, float duration, System.Action <int> onFin) { if (map == null || !map.HasTile(pos) || duration < 0.02f ) { return(-1); } var cmd = GetCMD <ColorCmd>(map, pos, duration, onFin); cmd.startColor = map.GetColor(pos); cmd.endColor = col; TilemapUtilties.UnlockFlag(map, pos, TileFlags.LockColor); if (!enabled) { enabled = true; } return(cmd.GUID); }
public int MoveTo(Tilemap map, Vector3Int pos, Vector3 end, float duration, System.Action <int> onFin) { if (map == null || !map.HasTile(pos) || duration < 0.02f ) { return(-1); } var cmd = GetCMD <MoveToCmd>(map, pos, duration, onFin); var tran = map.GetTransformMatrix(pos); cmd.startPos = tran.GetColumn(3); cmd.endPos = new Vector4(end.x, end.y, end.z, cmd.startPos.w); TilemapUtilties.UnlockFlag(map, pos, TileFlags.LockTransform); if (!enabled) { enabled = true; } return(cmd.GUID); }
/// <summary> /// 更新迷雾,激活隐藏的地块, /// </summary> public void UpdateTilemap() { if (groundTilemap == null) { return; } /* * foreach (var p in visiableZone.allPositionsWithin) * { * if (!groundTilemap.HasTile(p)) * { * continue; * } * if (!activeCell.Contains(p)) * { * activeCell.Add(p); * } * } */ foreach (var visZone in visiableZoneList) { foreach (var p in visZone.Value.allPositionsWithin) { if (!groundTilemap.HasTile(p)) { continue; } if (!activeCell.Contains(p)) { activeCell.Add(p); } } } foreach (var p in activeCell) { var color = groundTilemap.GetColor(p); if (color.a < 0.1f) { //激活动画 TilemapUtilties.SetTileOffset(groundTilemap, p, Vector3.up * -0.3f); TileTweener.Instance.MoveTo(groundTilemap, p, Vector3.zero, 0.2f, OnTweenFin); } /* * var tileCol = nearZone.Contains(p) ? Color.white : Color.gray; * var count = nearZone.Contains(p) ? 1 : - 1; */ Color tileCol = Color.gray; int count = -1; foreach (var a in nearZoneList) { if (a.Value.Contains(p)) { tileCol = Color.white; } if (a.Value.Contains(p)) { count = 1; } } //更新地块颜色 TileTweener.Instance.Color(groundTilemap, p, tileCol, 0.2f, OnTweenFin); //更新小件 if (miscBodyCache == null || miscBodyCache.Count < 1) { continue; } List <GameObject> miscList = null; if (!miscBodyCache.TryGetValue(p, out miscList)) { continue; } if (miscList != null && miscList.Count < 1) { continue; } foreach (var item in miscList) { if (!item.activeSelf) { //active anim item.SetActive(true); var endScale = item.transform.localScale; item.transform.localScale = Vector3.zero; item.transform.DOScale(endScale, 0.2f).SetEase(Ease.OutBounce).SetDelay(0.2f); /* var sps = item.GetComponentsInChildren<SpriteRenderer>(); * if (sps != null && sps.Length > 0) * { * foreach (var sp in sps) * { * sp.color = tileCol; * } * }*/ } else { /* var sps = item.GetComponentsInChildren<SpriteRenderer>(); * if (sps != null && sps.Length > 0) * { * foreach (var sp in sps) * { * sp.DOColor(tileCol, 0.2f); * } * }*/ } //小件颜色引用计数 MiscData tempData; if (!miscDataDic.TryGetValue(item, out tempData)) { continue; } tempData.count = count == 1 ? tempData.maxCount : tempData.count + count; miscDataDic[item] = tempData; } } //更新小件颜色 Dictionary <GameObject, MiscData> .Enumerator enumerator = miscDataDic.GetEnumerator(); for (int i = 0; i < miscDataDic.Count; i++) { enumerator.MoveNext(); var key = enumerator.Current.Key; var color = enumerator.Current.Value.count > 0 ? Color.white : Color.gray; var sps = enumerator.Current.Value.go.GetComponentsInChildren <SpriteRenderer>(); if (sps != null && sps.Length > 0) { foreach (var sp in sps) { sp.DOColor(color, 0.2f); } } } //小件虚化,减小alpha List <GameObject> miscBodyList = null; foreach (var pos in allCurPos) { if (miscBodyCache.TryGetValue(pos.Value, out miscBodyList)) { var tileCol = new Color(1, 1, 1, 0.7f); foreach (var item in miscBodyList) { var sps = item.GetComponentsInChildren <SpriteRenderer>(); if (sps != null && sps.Length > 0) { foreach (var sp in sps) { sp.DOColor(tileCol, 0.2f); } } } } } }