public Mesh GetShapeMesh(BlockShapeData shapeData) { if (!_shapes.TryGetValue(shapeData.ShapeType, out var mesh)) { var textureId = _shapeTextureProvider.GetTexture(shapeData); mesh = _meshBuilder.BuildMesh(shapeData.Sections, textureId); _shapes[shapeData.ShapeType] = mesh; } return(mesh); }
private Bounds ComputeBounds(BlockShapeData shapeData) { var minX = shapeData.Sections.Min(s => s.x) - 0.5f; var minY = shapeData.Sections.Min(s => s.y) - 0.5f; var minZ = shapeData.Sections.Min(s => s.z) - 0.5f; var maxX = shapeData.Sections.Max(s => s.x) + 0.5f; var maxY = shapeData.Sections.Max(s => s.y) + 0.5f; var maxZ = shapeData.Sections.Max(s => s.z) + 0.5f; var size = new Vector3(maxX - minX, maxY - minY, maxZ - minZ); var center = new Vector3(minX + maxX, minY + maxY, minZ + maxZ) / 2; return(new Bounds(center, size)); }
public void RecieveBlock(BlockData block) { Debug.Log(" hash " + block.Hash + " number " + block.Number + " oldNumber " + oldNumber); if (oldNumber == block.Number) { Debug.Log("Same Block Number!"); return; } oldNumber = block.Number; BlockShapeData data = new BlockShapeData(); data.block = block; // 変換 // ハッシュの先頭16文字取り出す string hashTopStr = block.Hash.Substring(2, 16); // 0xを無視する為に3文字目から開始 //ulong a = System.Convert.ToUInt64(hashTopStr, 16); ulong hashTop = ulong.Parse(hashTopStr, System.Globalization.NumberStyles.AllowHexSpecifier); uint topNum = (uint)(hashTop >> 32); uint bottomNum = (uint)(hashTop & 0xffffffff); data.shape.vertexCount = 3 + Mathf.FloorToInt(rand(topNum) * 6); // 3~8角形 data.shape.blurCount = 8 + Mathf.FloorToInt(rand(bottomNum) * 8); // 8~16 //Vector2 pos = Random.insideUnitCircle * Screen.height; //Vector2 pos = Random.insideUnitCircle * Camera.main.orthographicSize; Vector2 pos; if (blockShapeList.Count < 2) { // 最初 //float radius = Camera.main.orthographicSize; //float trackNum = 5; // 周回数 //float pi2 = 2f * Mathf.PI; //pos.x = Mathf.Cos(trackNum * pi2) * radius; //pos.y = Mathf.Sin(trackNum * pi2) * radius; pos = Random.insideUnitCircle * 0.1f; } else { // 3個め以降は一つ前から発生 Vector3 pos3d = blockShapeList[blockShapeList.Count - 1].shape.position; Vector3 diff = pos3d - blockShapeList[blockShapeList.Count - 2].shape.position; float len = diff.magnitude; Vector3 norm = Vector3.zero; if (len > 0) { norm = diff.normalized; } //pos.x = pos3d.x + norm.x * 0.1f; //pos.y = pos3d.z + norm.z * 0.1f; Vector2 randPos = Random.insideUnitCircle * 0.01f; pos.x = pos3d.x + norm.x * springLength * 0.125f + randPos.x; pos.y = pos3d.z + norm.y * springLength * 0.125f + randPos.y; //float rad = Mathf.Atan2(norm.y, norm.x) * Mathf.PI * 0.5f; //pos.x = pos3d.x + Mathf.Cos(rad) * 1f; //pos.y = pos3d.z + Mathf.Sin(rad) * 1f; } data.shape.id = idNumber++; data.shape.position.x = pos.x; data.shape.position.y = 0; data.shape.position.z = pos.y; data.shape.seq = 0; data.shape.number = (block.Number * 0.0000001f); //data.shape.number = bottomNum; // 仮 //data.shape.rotation = Quaternion.identity; // 角度 //data.shape.hashFloat = rand(bottomNum); Random.InitState((int)bottomNum); data.shape.hashFloat = Random.value; data.velocity = Vector3.zero; data.mass = Random.Range(massRange.x, massRange.y); bool isSpecial = false; double size = 0; for (int i = 0; i < block.Transactions.Count; i++) { size += block.Transactions[i].Value; particle.EmitParticle(data.shape.id, data.shape.position, (float)block.Transactions[i].Value); if (block.Transactions[i].To == specialTo) { isSpecial = true; } } //isSpecial = true; // test data.shape.size = Mathf.Clamp((float)(size / block.Transactions.Count), 0.25f, 0.5f); data.shape.isSpecial = isSpecial; if (isSpecial) { data.shape.size += 0.5f; // 大きくする data.shape.vertexCount = 16; // 16芒星 data.shape.blurCount = 6; } Debug.Log("hashTop " + hashTop + " Number " + data.shape.number + " pos " + data.shape.position + " vertexCount " + data.shape.vertexCount + " blurCount " + data.shape.blurCount + " size " + data.shape.size + " hashFloat " + data.shape.hashFloat + " TopNum " + topNum + " BottomNum " + bottomNum); blockShapeList.Add(data); Debug.Log("blockShapeList.Count " + blockShapeList.Count); if (blockShapeList.Count >= maxBlockNum) { // 最大数越えたら印刷して削除 RemoveBlock(); } }
private bool CheckAcceptableBlockState(Vector3Int position, Quaternion rotation, BlockShapeData shape) { if (!_levelPhysics.CheckShapeInsideLevelBounds(position, rotation, shape)) { return(false); } if (_levelPhysics.CheckOverlappingLevelBlocks(position, rotation, shape)) { return(false); } return(true); }
public bool CheckShapeInsideLevelBounds(Vector3Int position, Quaternion rotation, BlockShapeData shape) { return(_shapeUtil.IterateBlockSections(position, rotation, shape) .All(p => _levelModel.CheckInsideBounds(p))); }
public bool CheckOverlappingLevelBlocks(Vector3Int position, Quaternion rotation, BlockShapeData shape) { return(_shapeUtil.IterateBlockSections(position, rotation, shape) .Any(p => _levelModel.CheckHasBlock(p))); }