예제 #1
0
        public bool TestLOSAll(out ModuleDeployableReflector targetReflector)
        {
            targetReflector = null;
            LayerMask mask = 1 << LayerMask.NameToLayer("Default");

            // Cast the ray!
            RaycastHit[] hits = Physics.RaycastAll(RaycastStartPoint + RaycastDirection.normalized * RayDistance, -RaycastDirection, RayDistance, mask, QueryTriggerInteraction.Collide);

            if (hits.Length > 0)
            {
                //Debug.Log(String.Format("[NearFutureExploration] [ModuleAntennaFeed]: Num Hits {0}", hits.Length));

                float      maxDist = 0f;
                RaycastHit minHit  = hits[0];

                for (int i = 0; i < hits.Length; i++)
                {
                    //Debug.Log(String.Format("[NearFutureExploration] [ModuleAntennaFeed]: Hit {0} with distance {1}", hits[i].collider, hits[i].distance));
                    if (hits[i].rigidbody == part.Rigidbody)
                    {
                    }
                    else
                    {
                        if (hits[i].distance > maxDist)
                        {
                            minHit  = hits[i];
                            maxDist = hits[i].distance;
                        }
                    }
                }

                targetReflector = minHit.collider.gameObject.GetComponentInParent <ModuleDeployableReflector>();
                //Debug.Log(String.Format("[NearFutureExploration] [ModuleAntennaFeed]: Chose {0}", minHit.collider));
                if (targetReflector != null)
                {
                    for (int i = 0; i < targetReflector.dishColliders.Count; i++)
                    {
                        if (minHit.collider == targetReflector.dishColliders[i] && targetReflector.deployState == ModuleDeployablePart.DeployState.EXTENDED)
                        {
                            if (lineRenderable)
                            {
                                renderedLine.SetVisibility(true);
                            }
                            renderedLine.AdjustSize(RayDistance - minHit.distance);
                            renderedLine.SetColor(goodColor);
                            return(true);
                        }
                    }
                }
                if (lineRenderable)
                {
                    renderedLine.SetVisibility(true);
                }
                if (minHit.rigidbody == part.Rigidbody)
                {
                    renderedLine.AdjustSize(30f);
                }
                else
                {
                    renderedLine.AdjustSize(RayDistance - minHit.distance);
                }
                renderedLine.SetColor(badColor);
                return(false);
            }
            else
            {
                if (lineRenderable)
                {
                    renderedLine.SetVisibility(true);
                }
                renderedLine.AdjustSize(30f);
                renderedLine.SetColor(badColor);
            }
            return(false);
        }