public override void SetInput(int sourceID, LaserHit hit) { if (!beamIOMap.ContainsKey(sourceID)) { GameObject newBeam = new GameObject(); newBeam.AddComponent <LaserBeam>(); beamIOMap.Add(sourceID, newBeam.GetComponent <LaserBeam>()); } beamIOMap[sourceID].isBeamOn = true; beamIOMap[sourceID].beamStartPos = hit.hitPosition; beamIOMap[sourceID].beamDir = Vector3.Reflect(hit.inDirection, hit.hitNormal); beamIOMap[sourceID].SetColor(hit.lightColor); }
void OnTriggerEnter2D(Collider2D collider) { if (!this._isAlive) { return; } var cache = LaserHit.GetCache(Type); var key = collider.gameObject; if (cache.ContainsKey(key)) { AudioHandler.Play(LASER_HIT_SFX); cache [key].Hit(gameObject, collider); this.Explode(); } }
private void Awake() { // setup defaults mOutputHit = new LaserHit(); mColor = Color.black; mID = gameObject.GetInstanceID(); // setup laserbeam object laserBeamObject = GameObject.CreatePrimitive(PrimitiveType.Cylinder); Destroy(laserBeamObject.GetComponent <CapsuleCollider>()); // no collider! laserBeamObject.transform.Rotate(90, 0, 0); laserMaterial = new Material(Shader.Find("Standard")); // setup material laserMaterial.EnableKeyword("_EMISSION"); laserBeamObject.GetComponent <Renderer>().receiveShadows = false; // dont cast and receive shadows laserBeamObject.GetComponent <Renderer>().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; laserBeamObject.GetComponent <Renderer>().material = laserMaterial; // turn off by default laserBeamObject.SetActive(false); isBeamOn = false; }
/// <summary> /// Returns arrays to send out through messaging /// </summary> /// <param name="largeUDiff"></param> /// <param name="largeSigDiff"></param> /// <param name="pijDiff"></param> /// <param name="colIdx"></param> /// <param name="rowIdx"></param> public void GetArraysToSend(out List <Index> indexList, out List <float> heightList, out List <float> covList, out List <float> pijSumList, out List <float> laserHit) { int index = 0; if (indicesDictionary == null) { indexList = new List <Index>(); heightList = new List <float>(); covList = new List <float>(); pijSumList = new List <float>(); laserHit = new List <float>(); return; } else { indexList = new List <Index>(indicesDictionary.Count); heightList = new List <float>(indicesDictionary.Count); covList = new List <float>(indicesDictionary.Count); pijSumList = new List <float>(indicesDictionary.Count); laserHit = new List <float>(indicesDictionary.Count); } lock (locker) { foreach (KeyValuePair <Index, int> pair in indicesDictionary) { indexList.Add(pair.Key); heightList.Add((float)uhatGM.GetCellByIdxUnsafe(pair.Key.Col, pair.Key.Row)); //heightList.Add((float)thresholdedHeightMap.GetCellByIdxUnsafe(pair.Key.Col, pair.Key.Row)); covList.Add((float)sigSqrGM.GetCellByIdxUnsafe(pair.Key.Col, pair.Key.Row)); pijSumList.Add((float)pij_sum.GetCellByIdxUnsafe(pair.Key.Col, pair.Key.Row)); laserHit.Add((float)LaserHit.GetCellByIdxUnsafe(pair.Key.Col, pair.Key.Row)); indexMap.SetCellByIdx(pair.Key.Col, pair.Key.Row, 0.0); // reset the index map } indicesDictionary.Clear(); } }
public virtual void SetInput(int sourceID, LaserHit hit) { }
void AddHit(LaserHit hit) { hits[hitSize++] = hit; }
public LaserTurret() { hits = new LaserHit[max]; }
private void UpdateBeam() { int count = 0; float remainingDistance = maxDistance; Vector3 direction = transform.forward; Vector3 position = transform.position; laserHits.Clear(); List <Vector3> points = new List <Vector3>(); points.Add(position); while (count < maxBounces && remainingDistance > 0) { RaycastHit hit; if (Physics.Raycast(position, direction, out hit, remainingDistance)) { position = hit.point; direction = Vector3.Reflect(direction, hit.normal); bool shouldBounce = false; LaserHit laserHit = new LaserHit(); laserHit.position = position; laserHit.normal = direction; Collider collider = hit.collider; laserHit.hitObject = collider.gameObject; ISurface surface = collider.GetComponent <ISurface>(); laserHit.surface = surface; if (surface != null) { switch (surface.surfaceType) { case SurfaceType.Mirror: shouldBounce = true; break; case SurfaceType.Goal: hit.collider.GetComponent <BeamGoal>().GetHit(); break; } laserHit.didBounce = true; } else { laserHit.didBounce = false; } remainingDistance -= hit.distance; count += 1; laserHits.Add(laserHit); points.Add(laserHit.position); if (!shouldBounce) { break; } } else { points.Add(position + direction * remainingDistance); // break; } } line.positionCount = points.Count; line.SetPositions(points.ToArray()); }