public void ArcReactorReflection(ArcReactorHitInfo2D hit) { mirrorHit = true; temperature = Mathf.Clamp01(temperature + heatRate * Time.deltaTime); if (!partSystem.activeSelf) partSystem.SetActive(true); if (!partSystem.GetComponent<ParticleSystem>().enableEmission) partSystem.GetComponent<ParticleSystem>().enableEmission = true; partSystem.transform.position = hit.raycastHit.point; Vector2 point = hit.raycastHit.point + hit.raycastHit.normal; partSystem.transform.LookAt(new Vector3(point.x,point.y,transform.position.z)); }
public void ArcReactorReflection(ArcReactorHitInfo2D hit) { mirrorHit = true; temperature = Mathf.Clamp01(temperature + heatRate * Time.deltaTime); if (!partSystemObj.activeSelf) { partSystemObj.SetActive(true); } if (!emission.enabled) { emission.enabled = true; } partSystemObj.transform.position = hit.raycastHit.point; Vector2 point = hit.raycastHit.point + hit.raycastHit.normal; partSystemObj.transform.LookAt(new Vector3(point.x, point.y, transform.position.z)); }
// Update is called once per frame void LateUpdate() { for (int x = 0; x < rays.Count; x++) { if (rays[x].arc == null || rays[x].arc.currentlyInPool) { destrArr.Add(rays[x]); } else { rays[x].distance = Mathf.Clamp(rays[x].distance + PropagationSpeed * Time.deltaTime, 0, Distance); Vector3 endPos = Vector3.zero; switch (reflectionSettings.reflections) { case ReflectSettings.no_reflections: if (startBehaviour == RayTransformBehaivour.follow_raycast) { if (hit = (Physics2D.Raycast(Get2DVect(transform.position), Get2DVect(-transform.forward), rays[x].distance, layers.value))) { if (SendMessageToHitObjects) { ArcReactorHitInfo2D arcHit = new ArcReactorHitInfo2D(); arcHit.launcher = this; arcHit.rayInfo = rays[x]; arcHit.raycastHit = hit; hit.transform.gameObject.SendMessage("ArcReactorHit", arcHit, SendMessageOptions.DontRequireReceiver); } if (SendMessageToTouchedObjects) { RaycastHit2D[] hits; hits = Physics2D.RaycastAll(Get2DVect(transform.position), Get2DVect(-transform.forward), Vector3.Distance(transform.position, hit.point), touchLayers); foreach (RaycastHit2D touchHit in hits) { ArcReactorHitInfo2D arcHit = new ArcReactorHitInfo2D(); arcHit.launcher = this; arcHit.rayInfo = rays[x]; arcHit.raycastHit = touchHit; touchHit.transform.gameObject.SendMessage("ArcReactorTouch", arcHit, SendMessageOptions.DontRequireReceiver); } } rays[x].startObject = hit.transform.gameObject; rays[x].shape[0].position = transform.position + (transform.position - Get3DVect(hit.point, transform.position.z)).normalized * (float)((transform.position - Get3DVect(hit.point, transform.position.z)).magnitude - 0.05); } else { if (SendMessageToTouchedObjects) { RaycastHit2D[] hits; hits = Physics2D.RaycastAll(transform.position, -transform.forward, rays[x].distance, touchLayers); foreach (RaycastHit2D touchHit in hits) { ArcReactorHitInfo2D arcHit = new ArcReactorHitInfo2D(); arcHit.launcher = this; arcHit.rayInfo = rays[x]; arcHit.raycastHit = touchHit; touchHit.transform.gameObject.SendMessage("ArcReactorTouch", arcHit, SendMessageOptions.DontRequireReceiver); } } rays[x].startObject = null; rays[x].shape[0].position = transform.position - transform.forward * rays[x].distance; } } if (endBehaviour == RayTransformBehaivour.follow_raycast) { if (hit = (Physics2D.Raycast(transform.position, transform.forward, rays[x].distance, layers.value))) { if (SendMessageToHitObjects) { ArcReactorHitInfo2D arcHit = new ArcReactorHitInfo2D(); arcHit.launcher = this; arcHit.rayInfo = rays[x]; arcHit.raycastHit = hit; hit.transform.gameObject.SendMessage("ArcReactorHit", arcHit, SendMessageOptions.DontRequireReceiver); } if (SendMessageToTouchedObjects) { RaycastHit2D[] hits; hits = Physics2D.RaycastAll(transform.position, transform.forward, Vector3.Distance(transform.position, hit.point), touchLayers); foreach (RaycastHit2D touchHit in hits) { ArcReactorHitInfo2D arcHit = new ArcReactorHitInfo2D(); arcHit.launcher = this; arcHit.rayInfo = rays[x]; arcHit.raycastHit = touchHit; touchHit.transform.gameObject.SendMessage("ArcReactorTouch", arcHit, SendMessageOptions.DontRequireReceiver); } } rays[x].endObject = hit.transform.gameObject; endPos = transform.position + (Get3DVect(hit.point, transform.position.z) - transform.position).normalized * (float)((Get3DVect(hit.point, transform.position.z) - transform.position).magnitude - 0.05); //endPos = hit.point; } else { if (SendMessageToTouchedObjects) { RaycastHit2D[] hits; hits = Physics2D.RaycastAll(transform.position, transform.forward, rays[x].distance, touchLayers); foreach (RaycastHit2D touchHit in hits) { ArcReactorHitInfo2D arcHit = new ArcReactorHitInfo2D(); arcHit.launcher = this; arcHit.rayInfo = rays[x]; arcHit.raycastHit = touchHit; touchHit.transform.gameObject.SendMessage("ArcReactorTouch", arcHit, SendMessageOptions.DontRequireReceiver); } } rays[x].endObject = null; endPos = transform.position + transform.forward * rays[x].distance; } } else { endPos = rays[x].shape[rays[x].shape.Length - 1].position; } /* * switch (rayInertiaSettings.type) * { * case InertiaMethod.none: * rays[x].shape[rays[x].shape.Length-1].position = endPos; * break; * case InertiaMethod.linespeed: * int transformCount = rays[x].shape.Length; * Vector3 targetPos; * for (int i = 1; i < transformCount; i++) * { * targetPos = Vector3.Lerp(rays[x].shape[0].position,endPos,(float)i/(transformCount-1)); * rays[x].shape[i].position = Vector3.MoveTowards(rays[x].shape[i].position,targetPos, * rayInertiaSettings.speed * rayInertiaSettings.snapbackForceCurve.Evaluate(Vector3.Distance(rays[x].shape[i].position,targetPos) / rayInertiaSettings.maxSnapBackDistance) * Time.deltaTime); * } * break; * } */ break; case ReflectSettings.reflect_by_layer: case ReflectSettings.reflect_specified_objects: int posNum; GameObject obj; if (startBehaviour == RayTransformBehaivour.follow_raycast) { posArrayLen = 0; FillPosArray(transform.position, -transform.forward, rays[x].distance, rays[x]); for (int i = 0; i < posArrayLen; i++) { positions[i] = posArray[i]; } posNum = posArrayLen; } else { posNum = 1; positions[0] = rays[x].shape[0].position; } if (endBehaviour == RayTransformBehaivour.follow_raycast) { posArrayLen = 0; FillPosArray(transform.position, transform.forward, rays[x].distance, rays[x]); for (int i = 0; i < posArrayLen; i++) { positions[posNum + i] = posArray[i]; } posNum += posArrayLen; } else { positions[posNum] = rays[x].shape[rays[x].shape.Length - 1].position; posNum++; } if (rays[x].shape.Length == posNum) { } if (rays[x].shape.Length > posNum) { for (int i = posNum - 1; i < rays[x].shape.Length - 1; i++) { GameObject.Destroy(rays[x].shape[i].gameObject); } rays[x].shape[posNum - 1] = rays[x].shape[rays[x].shape.Length - 1]; Array.Resize(ref rays[x].shape, posNum); } if (rays[x].shape.Length < posNum) { int oldSize = rays[x].shape.Length; Array.Resize(ref rays[x].shape, posNum); rays[x].shape[rays[x].shape.Length - 1] = rays[x].shape[oldSize - 1]; for (int i = oldSize - 1; i < posNum - 1; i++) { obj = new GameObject("RayPoint" + (i + 1).ToString()); obj.transform.parent = globalSpaceTransform; rays[x].shape[i] = obj.transform; } } for (int i = 0; i < posNum; i++) { rays[x].shape[i].position = positions[i]; } rays[x].arc.shapeTransforms = rays[x].shape; break; } } } for (int x = 0; x < destrArr.Count; x++) { foreach (Transform tr in destrArr[x].shape) { GameObject.Destroy(tr.gameObject); } rays.RemoveAt(x); } if (destrArr.Count > 0) { destrArr.Clear(); } }
protected void FillPosArray(Vector3 position, Vector3 direction, float maxDistance, RayInfo rayInfo) { RaycastHit2D hit = new RaycastHit2D(); if (hit = (Physics2D.Raycast(Get2DVect(position), Get2DVect(direction), maxDistance, layers.value | reflectionSettings.reflectLayers.value))) { if (SendMessageToHitObjects) { ArcReactorHitInfo2D arcHit = new ArcReactorHitInfo2D(); arcHit.launcher = this; arcHit.rayInfo = rayInfo; arcHit.raycastHit = hit; hit.transform.gameObject.SendMessage("ArcReactorHit", arcHit, SendMessageOptions.DontRequireReceiver); } posArray[posArrayLen] = hit.point; posArrayLen++; if (SendMessageToTouchedObjects) { RaycastHit2D[] hits; hits = Physics2D.RaycastAll(Get2DVect(position), Get2DVect(direction), Vector2.Distance(Get2DVect(position), hit.point), touchLayers); foreach (RaycastHit2D touchHit in hits) { ArcReactorHitInfo2D arcHit = new ArcReactorHitInfo2D(); arcHit.launcher = this; arcHit.rayInfo = rayInfo; arcHit.raycastHit = touchHit; touchHit.transform.gameObject.SendMessage("ArcReactorTouch", arcHit, SendMessageOptions.DontRequireReceiver); } } if ((reflectionSettings.reflections == ReflectSettings.reflect_by_layer || CheckReflectObject(hit.transform)) && (reflectionSettings.reflectLayers.value & 1 << hit.transform.gameObject.layer) > 0) { if (reflectionSettings.sendMessageToReflectors) { ArcReactorHitInfo2D arcHit = new ArcReactorHitInfo2D(); arcHit.launcher = this; arcHit.rayInfo = rayInfo; arcHit.raycastHit = hit; hit.transform.gameObject.SendMessage("ArcReactorReflection", arcHit, SendMessageOptions.DontRequireReceiver); } FillPosArray(hit.point + hit.normal * reflectionSettings.thickness, Vector3.Reflect(direction, hit.normal), maxDistance - Vector3.Distance(position, hit.point), rayInfo); } } else { if (SendMessageToTouchedObjects) { RaycastHit2D[] hits; hits = Physics2D.RaycastAll(Get2DVect(position), Get2DVect(direction), maxDistance, touchLayers); foreach (RaycastHit2D touchHit in hits) { ArcReactorHitInfo2D arcHit = new ArcReactorHitInfo2D(); arcHit.launcher = this; arcHit.rayInfo = rayInfo; arcHit.raycastHit = touchHit; touchHit.transform.gameObject.SendMessage("ArcReactorTouch", arcHit, SendMessageOptions.DontRequireReceiver); } } posArray[posArrayLen] = position + direction.normalized * maxDistance; posArrayLen++; } }
// Update is called once per frame void LateUpdate () { for (int x = 0; x < rays.Count; x++) { if (rays[x].arc == null) { destrArr.Add(rays[x]); } else { rays[x].distance = Mathf.Clamp(rays[x].distance + PropagationSpeed * Time.deltaTime,0,Distance); Vector3 endPos = Vector3.zero; switch (reflectionSettings.reflections) { case ReflectSettings.no_reflections: if (startBehaviour == RayTransformBehaivour.follow_raycast) { if (hit = (Physics2D.Raycast(Get2DVect(transform.position),Get2DVect(-transform.forward),rays[x].distance,layers.value))) { if (SendMessageToHitObjects) { ArcReactorHitInfo2D arcHit = new ArcReactorHitInfo2D(); arcHit.launcher = this; arcHit.rayInfo = rays[x]; arcHit.raycastHit = hit; hit.transform.gameObject.SendMessage("ArcReactorHit",arcHit,SendMessageOptions.DontRequireReceiver); } if (SendMessageToTouchedObjects) { RaycastHit2D[] hits; hits = Physics2D.RaycastAll(Get2DVect(transform.position),Get2DVect(-transform.forward), Vector3.Distance(transform.position,hit.point), touchLayers); foreach (RaycastHit2D touchHit in hits) { ArcReactorHitInfo2D arcHit = new ArcReactorHitInfo2D(); arcHit.launcher = this; arcHit.rayInfo = rays[x]; arcHit.raycastHit = touchHit; touchHit.transform.gameObject.SendMessage("ArcReactorTouch",arcHit,SendMessageOptions.DontRequireReceiver); } } rays[x].startObject = hit.transform.gameObject; rays[x].shape[0].position = transform.position + (transform.position - Get3DVect(hit.point,transform.position.z)).normalized * (float)((transform.position - Get3DVect(hit.point,transform.position.z)).magnitude - 0.05); } else { if (SendMessageToTouchedObjects) { RaycastHit2D[] hits; hits = Physics2D.RaycastAll(transform.position,-transform.forward, rays[x].distance, touchLayers); foreach (RaycastHit2D touchHit in hits) { ArcReactorHitInfo2D arcHit = new ArcReactorHitInfo2D(); arcHit.launcher = this; arcHit.rayInfo = rays[x]; arcHit.raycastHit = touchHit; touchHit.transform.gameObject.SendMessage("ArcReactorTouch",arcHit,SendMessageOptions.DontRequireReceiver); } } rays[x].startObject = null; rays[x].shape[0].position = transform.position - transform.forward * rays[x].distance; } } if (endBehaviour == RayTransformBehaivour.follow_raycast) { if (hit = (Physics2D.Raycast(transform.position,transform.forward,rays[x].distance,layers.value))) { if (SendMessageToHitObjects) { ArcReactorHitInfo2D arcHit = new ArcReactorHitInfo2D(); arcHit.launcher = this; arcHit.rayInfo = rays[x]; arcHit.raycastHit = hit; hit.transform.gameObject.SendMessage("ArcReactorHit",arcHit,SendMessageOptions.DontRequireReceiver); } if (SendMessageToTouchedObjects) { RaycastHit2D[] hits; hits = Physics2D.RaycastAll(transform.position,transform.forward, Vector3.Distance(transform.position,hit.point), touchLayers); foreach (RaycastHit2D touchHit in hits) { ArcReactorHitInfo2D arcHit = new ArcReactorHitInfo2D(); arcHit.launcher = this; arcHit.rayInfo = rays[x]; arcHit.raycastHit = touchHit; touchHit.transform.gameObject.SendMessage("ArcReactorTouch",arcHit,SendMessageOptions.DontRequireReceiver); } } rays[x].endObject = hit.transform.gameObject; endPos = transform.position + (Get3DVect(hit.point,transform.position.z) - transform.position).normalized * (float)((Get3DVect(hit.point,transform.position.z) - transform.position).magnitude - 0.05); //endPos = hit.point; } else { if (SendMessageToTouchedObjects) { RaycastHit2D[] hits; hits = Physics2D.RaycastAll(transform.position,transform.forward, rays[x].distance, touchLayers); foreach (RaycastHit2D touchHit in hits) { ArcReactorHitInfo2D arcHit = new ArcReactorHitInfo2D(); arcHit.launcher = this; arcHit.rayInfo = rays[x]; arcHit.raycastHit = touchHit; touchHit.transform.gameObject.SendMessage("ArcReactorTouch",arcHit,SendMessageOptions.DontRequireReceiver); } } rays[x].endObject = null; endPos = transform.position + transform.forward * rays[x].distance; } } else { endPos = rays[x].shape[rays[x].shape.Length-1].position; } switch (rayInertiaSettings.type) { case InertiaMethod.none: rays[x].shape[rays[x].shape.Length-1].position = endPos; break; case InertiaMethod.linespeed: int transformCount = rays[x].shape.Length; Vector3 targetPos; for (int i = 1; i < transformCount; i++) { targetPos = Vector3.Lerp(rays[x].shape[0].position,endPos,(float)i/(transformCount-1)); rays[x].shape[i].position = Vector3.MoveTowards(rays[x].shape[i].position,targetPos, rayInertiaSettings.speed * rayInertiaSettings.snapbackForceCurve.Evaluate(Vector3.Distance(rays[x].shape[i].position,targetPos) / rayInertiaSettings.maxSnapBackDistance) * Time.deltaTime); } break; } break; case ReflectSettings.reflect_by_layer: case ReflectSettings.reflect_specified_objects: int posNum; GameObject obj; if (startBehaviour == RayTransformBehaivour.follow_raycast) { posArrayLen = 0; FillPosArray(transform.position,-transform.forward,rays[x].distance,rays[x]); for (int i = 0; i < posArrayLen; i++) { positions[i] = posArray[i]; } posNum = posArrayLen; } else { posNum = 1; positions[0] = rays[x].shape[0].position; } if (endBehaviour == RayTransformBehaivour.follow_raycast) { posArrayLen = 0; FillPosArray(transform.position,transform.forward,rays[x].distance,rays[x]); for (int i = 0; i < posArrayLen; i++) { positions[posNum + i] = posArray[i]; } posNum += posArrayLen; } else { positions[posNum] = rays[x].shape[rays[x].shape.Length-1].position; posNum++; } if (rays[x].shape.Length == posNum) { } if (rays[x].shape.Length > posNum) { for (int i = posNum-1; i < rays[x].shape.Length-1; i++) GameObject.Destroy(rays[x].shape[i].gameObject); rays[x].shape[posNum-1] = rays[x].shape[rays[x].shape.Length-1]; Array.Resize(ref rays[x].shape,posNum); } if (rays[x].shape.Length < posNum) { int oldSize = rays[x].shape.Length; Array.Resize(ref rays[x].shape, posNum); rays[x].shape[rays[x].shape.Length-1] = rays[x].shape[oldSize-1]; for (int i = oldSize-1; i < posNum-1; i++) { obj = new GameObject("RayPoint" + (i+1).ToString()); obj.transform.parent = globalSpaceTransform; rays[x].shape[i] = obj.transform; } } for (int i = 0; i < posNum; i++) rays[x].shape[i].position = positions[i]; rays[x].arc.shapeTransforms = rays[x].shape; break; } } } for (int x = 0; x < destrArr.Count; x++) { foreach (Transform tr in destrArr[x].shape) GameObject.Destroy(tr.gameObject); rays.RemoveAt(x); } if (destrArr.Count > 0) destrArr.Clear(); }
protected void FillPosArray(Vector3 position, Vector3 direction, float maxDistance,RayInfo rayInfo) { RaycastHit2D hit = new RaycastHit2D(); if (hit = (Physics2D.Raycast(Get2DVect(position),Get2DVect(direction),maxDistance,layers.value | reflectionSettings.reflectLayers.value))) { if (SendMessageToHitObjects) { ArcReactorHitInfo2D arcHit = new ArcReactorHitInfo2D(); arcHit.launcher = this; arcHit.rayInfo = rayInfo; arcHit.raycastHit = hit; hit.transform.gameObject.SendMessage("ArcReactorHit",arcHit,SendMessageOptions.DontRequireReceiver); } posArray[posArrayLen] = hit.point; posArrayLen++; if (SendMessageToTouchedObjects) { RaycastHit2D[] hits; hits = Physics2D.RaycastAll(Get2DVect(position), Get2DVect(direction), Vector2.Distance(Get2DVect(position),hit.point), touchLayers); foreach (RaycastHit2D touchHit in hits) { ArcReactorHitInfo2D arcHit = new ArcReactorHitInfo2D(); arcHit.launcher = this; arcHit.rayInfo = rayInfo; arcHit.raycastHit = touchHit; touchHit.transform.gameObject.SendMessage("ArcReactorTouch",arcHit,SendMessageOptions.DontRequireReceiver); } } if ((reflectionSettings.reflections == ReflectSettings.reflect_by_layer || CheckReflectObject(hit.transform)) && (reflectionSettings.reflectLayers.value & 1 << hit.transform.gameObject.layer) > 0) { if (reflectionSettings.sendMessageToReflectors) { ArcReactorHitInfo2D arcHit = new ArcReactorHitInfo2D(); arcHit.launcher = this; arcHit.rayInfo = rayInfo; arcHit.raycastHit = hit; hit.transform.gameObject.SendMessage("ArcReactorReflection",arcHit,SendMessageOptions.DontRequireReceiver); } FillPosArray(hit.point + hit.normal * reflectionSettings.thickness,Vector3.Reflect(direction, hit.normal), maxDistance - Vector3.Distance(position,hit.point),rayInfo ); } } else { if (SendMessageToTouchedObjects) { RaycastHit2D[] hits; hits = Physics2D.RaycastAll(Get2DVect(position), Get2DVect(direction), maxDistance, touchLayers); foreach (RaycastHit2D touchHit in hits) { ArcReactorHitInfo2D arcHit = new ArcReactorHitInfo2D(); arcHit.launcher = this; arcHit.rayInfo = rayInfo; arcHit.raycastHit = touchHit; touchHit.transform.gameObject.SendMessage("ArcReactorTouch",arcHit,SendMessageOptions.DontRequireReceiver); } } posArray[posArrayLen] = position + direction.normalized * maxDistance; posArrayLen++; } }
public void ArcReactorHit(ArcReactorHitInfo2D hit) { manager.TargetHit(); Destroy(gameObject); }