int GetColorValue(LightProjector projector) { bool isWithinCone = IsWithinCone(projector); bool isBlocked = IsBlockedByBlocker(projector); return((isWithinCone && !isBlocked) ? 1 : 0); }
bool IsBlockedByBlocker(LightProjector projector) { UnityEngine.Transform lightSphere = projector.transform.GetChild(1); if (!lightSphere.gameObject.activeSelf) { return(false); } Vector3 startPos = transform.position; Vector3 diff = lightSphere.position - startPos; Ray toProjector = new Ray(startPos, diff); float distance = diff.magnitude - 4; //Debug.DrawRay(toProjector.origin, toProjector.direction * distance); //Debug.DrawRay(projector.transform.position, projector.transform.right * distance); RaycastHit hitInfo; Physics.Raycast(toProjector, out hitInfo, distance); return(Physics.Raycast(toProjector, distance)); }
bool IsWithinCone(LightProjector projector) { Vector3 testPos = transform.position; Transform cone = projector.transform.GetChild(0); if (!cone.gameObject.activeSelf) { return(false); } Vector3 tipToCenterOfBaseWorld = -cone.up * (coneHeight * cone.localScale.y); Vector3 tipToEdgeOfBaseWorld = tipToCenterOfBaseWorld + cone.right * (coneRadius * cone.localScale.x); Vector3 tipToTestPointWorld = testPos - cone.position; // if (projector == green) { // Debug.DrawRay(cone.position, tipToCenterOfBaseWorld, Color.white); // Debug.DrawRay(cone.position, tipToEdgeOfBaseWorld, Color.blue); // // Debug.DrawRay(cone.position, tipToTestPointWorld, Color.red); // } float thresholdForWithinCone = Vector3.Dot(tipToCenterOfBaseWorld.normalized, tipToEdgeOfBaseWorld.normalized); float testValue = Vector3.Dot(tipToCenterOfBaseWorld.normalized, tipToTestPointWorld.normalized); return(testValue > thresholdForWithinCone); }
void Start() { projector = transform.parent.GetComponentInParent <ProjectorControls>().projector; }