/// <summary> /// Initializes this instance. /// </summary> /// <param name="bulletHole">Bullet hole handling this instance.</param> /// <param name="gravity">Gravity.</param> /// <param name="initialVelocity">Initial velocity.</param> /// <param name="deleteY">Vertical level past below which this instance would destroy itself.</param> public void Initialize(BulletHole bulletHole, float gravity, Vector3 initialVelocity, float deleteY) { m_bulletHole = bulletHole; m_gravity = gravity; m_velocity = initialVelocity; m_deleteY = deleteY; UpdateRotation(); }
private void GenerateBarrier() { BulletHole bulletHole = bulletHoles[bulletHoles.Count - 1]; Vector3[] vertices = new Vector3[numberOfEdges * 2]; int[] triangles = new int[numberOfEdges * 6]; GameObject hole = new GameObject("Hole"); hole.transform.parent = transform; //hole.transform.rotation = transform.rotation; hole.transform.position = transform.position + bulletHole.Position; //Instantiate(, transform.position); MeshRenderer meshRenderer = hole.AddComponent <MeshRenderer>(); MeshFilter meshFilter = hole.AddComponent <MeshFilter>(); Mesh mesh = meshFilter.mesh; //Vector3 bulletHoleEdge = bulletHole.Position + bulletHole.Radius * transform.forward; int j = 0; for (int i = 0; i < 359; i += 360 / numberOfEdges) { Vector3 radiusPoint = Quaternion.AngleAxis(i, transform.up) * (bulletHole.Radius * raidusMod * transform.forward); vertices[j++] = -radiusPoint; vertices[j++] = -radiusPoint - transform.up * 0.1f; debugPos.Add(bulletHole.Position - radiusPoint); debugPos.Add(bulletHole.Position - radiusPoint - transform.up * 0.1f); } for (int i = 0; i < numberOfEdges; i++) { int[] tris; if (i == numberOfEdges - 1) { tris = CreateQuad(i * 2, i * 2 + 1, 0, 1); Debug.Log("d"); } else { tris = CreateQuad(i * 2, i * 2 + 1, i * 2 + 2, i * 2 + 3); } for (int k = 0; k < tris.Length; k++) { triangles[i * 6 + k] = tris[k]; } } mesh.vertices = vertices; mesh.triangles = triangles; mesh.RecalculateNormals(); meshRenderer.material = material; }
private void gridWrapper_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (canvasTarget.IsMouseOver) { Point mousePos = e.GetPosition(canvasTarget); BulletHole bh = new BulletHole(); bh.Width = bh.Height = 10; Canvas.SetLeft(bh, mousePos.X - bh.Width / 2); Canvas.SetTop(bh, mousePos.Y - bh.Height / 2); canvasTarget.Children.Add(bh); } }
/// <summary> /// Spawns a bullet hole. /// </summary> /// <returns>The bullet hole.</returns> private BulletHole SpawnBulletHole(Vector3 position) { GameObject bulletHoleObj = GameObject.Instantiate(m_bulletHoleResource) as GameObject; bulletHoleObj.transform.parent = Gameplay; bulletHoleObj.transform.position = position; BulletHole bulletHole = bulletHoleObj.AddComponentNoDupe <BulletHole>(); m_bulletHoles.Add(bulletHole); return(bulletHole); }
/// <summary> /// Spawns bullet holes. /// </summary> /// <param name="holeCount">Number of bullet holes to spawn.</param> private void SpawnBulletHoles(int holeCount) { while (m_bulletHoles.Count < holeCount) { // Randomize bullet hole position Vector2 holePos = new Vector2(Random.Range(m_holeSpawnAreaMin.x, m_holeSpawnAreaMax.x), Random.Range(m_holeSpawnAreaMin.y, m_holeSpawnAreaMax.y)); // Spawn the first few bullet holes outside the instruction text area if (m_bulletHoles.Count < (float)holeCount * 0.5f) { // If position is within the instruction text area, re-randomize a new position if (holePos.x > m_textAreaMin.x && holePos.x < m_textAreaMax.x && holePos.y > m_textAreaMin.y && holePos.y < m_textAreaMax.y) { continue; } } // Make sure there is enough space between holes bool isSpaced = true; float minDistSq = m_minDistBetweenHoles * m_minDistBetweenHoles; foreach (BulletHole hole in m_bulletHoles) { if ((hole.transform.position - (Vector3)holePos).sqrMagnitude < minDistSq) { isSpaced = false; break; } } // If not spaced enough from other holes, re-randomize a new position if (!isSpaced) { continue; } // Spawn a bullet hole BulletHole bulletHole = SpawnBulletHole(holePos); Vector3 bloodDir = Vector3.Normalize((Vector3)holePos - m_bloodSource.position); bulletHole.Initialize(this, m_bloodDropResource, m_initialBloodDropSpeed * bloodDir, m_bloodDropGravity, UICamera.ScreenMinWorld.y - 5.0f); // Start bullet hole hidden bulletHole.Hide(); } }
private void CreateBulletHole(Vector3 pos) { BulletHole bulletHole = new BulletHole(); Vector3 hitOffset = transform.InverseTransformPoint(pos); hitOffset = new Vector3(-hitOffset.x, -hitOffset.z, hitOffset.y) + new Vector3(0, 0, 1); bulletHole.Position = pos - transform.position; bulletHole.Radius = bulletInpactPrefab.transform.localScale.x; bulletHoles.Add(bulletHole); meshAroundAreaBorder.radius = bulletHoles[bulletHoles.Count - 1].Radius; if (!meshAroundAreaBorder.CheckIntersectionWithPoints((Vector2)bulletHoles[bulletHoles.Count - 1].Position, -1)) { Transform bullet = Instantiate(bulletInpactPrefab, renderTextureCamera.transform).transform; bullet.localPosition = hitOffset; meshAroundAreaBorder.points.Add(bulletHoles[bulletHoles.Count - 1].Position); meshAroundAreaBorder.CreateMeshBarrier(); } }
public void InitGame(uint cylinderSize, uint bulletPositon) { CurrentTriggerPosition = -1; if (bulletPositon > cylinderSize - 1) { throw new Exception("Somethings wrong the bulletPositon is higher than size of the cylinder"); } Cylinder = new BulletHole[cylinderSize]; // set the bulletholes in the cylinder for (int cylIndex = 0; cylIndex < cylinderSize - 1; cylIndex++) { if (cylIndex == bulletPositon) { Cylinder[cylIndex] = BulletHole.ContainsBullet; continue; } Cylinder[cylIndex] = BulletHole.Empty; } }
public void ReturnToPool(BulletHole bulletHole) { _bulletPool.Add(bulletHole); }