Пример #1
0
        public void AddTurk(Transform _transform, Camera _camera, HaloHit direction, AirValveController _valveController, string _serialPort)
        {
            Turk turk = new Turk(_transform, _camera, direction, _valveController, _serialPort);

            turks.Add(turk);
            Debug.Log("Add a turk: " + _transform.name);
        }
Пример #2
0
        public Turk GetNearestTurk(Vector3 position)
        {
            Turk  nearestTurk     = null;
            float nearestDistance = float.MaxValue;

            float distance;

            if (turks.Count > 0)
            {
                foreach (Turk t in turks)
                {
                    distance = Vector3.Distance(t.transform.position, position);
                    if (distance < nearestDistance)
                    {
                        nearestDistance = distance;
                        nearestTurk     = t;
                    }
                }
            }

            return(nearestTurk);
        }
Пример #3
0
        // Update is called once per frame
        void Update()
        {
            if ((jpSignal != null) && (jpSignal.trans != null))
            {
                //Update the position of the hit point.
                transform.DOMove(jpSignal.trans.position, 0.5f);

                // Update the time text.
                if (timeText != null)
                {
                    float t = jpSignal.enableTime - Time.time;
                    timeText.text = t.ToString("0");
                }

                // Scale the point.
                Turk newNearestTurk = tm.GetNearestTurk(transform.position);
                if (newNearestTurk != null)
                {
                    // Register the halo hiter.
                    if (nearestTurk != newNearestTurk)
                    {
                        // Release old ui hiter.
                        if (nearestTurk != null)
                        {
                            nearestTurk.ReleaseHitPoint(this);
                        }

                        // Register new ui hiter.
                        nearestTurk = newNearestTurk;
                        nearestTurk.RegisterHitPoint(this);
                    }

                    // Update the lookat canvas.
                    if (lookatCanvas != null)
                    {
                        lookatCanvas.transform.DOLookAt(nearestTurk.transform.position, 0.5f);
                    }

                    Vector3 head_forward     = nearestTurk.camera.transform.forward;
                    Vector3 head_position    = nearestTurk.camera.transform.position;
                    Vector3 target_position  = transform.position;
                    Vector3 target_direction = target_position - head_position;

                    // Show the halo
                    float angle = Vector3.Angle(target_direction, head_forward);
                    if (angle > angleThreshold)
                    {
                        float sphere_radius = Vector3.Distance(target_position, head_position);

                        // Adjust the halo size.
                        Vector3    head_forward_on_surface = head_position + head_forward * sphere_radius;
                        Vector3    normal = Vector3.Cross(head_forward, target_direction);
                        GameObject head_on_surface_obj = new GameObject();
                        head_on_surface_obj.transform.position = head_forward_on_surface;
                        head_on_surface_obj.transform.RotateAround(head_position, normal, angleThreshold);

                        // The radius need multiple two.
                        float halo_Sphere_radius = Vector3.Distance(target_position, head_on_surface_obj.transform.position) * 2;

                        // Keep the jet size.
                        float minScale = jpSignal.GetShowScale();
                        if (halo_Sphere_radius < minScale)
                        {
                            halo_Sphere_radius = minScale;
                        }

                        // Set HaloSphere
                        scaleObject.transform.DOMove(target_position, 0.5f);
                        scaleObject.transform.DOScale(new Vector3(halo_Sphere_radius, halo_Sphere_radius, halo_Sphere_radius), 0.5f);

                        // Check raying a target or raying a obstacle.
                        //Debug.DrawRay(head_position, target_direction * hitDistanceRate, Color.yellow);
                        RaycastHit hit;
                        if (Physics.Raycast(head_position, target_direction, out hit, sphere_radius * hitDistanceRate, checkLayer))
                        {
                            if (rayHaventObstacleMat != null)
                            {
                                render.material = rayHaventObstacleMat;
                            }
                        }
                        else
                        {
                            if (rayToTargetMat != null)
                            {
                                render.material = rayToTargetMat;
                            }
                        }

                        // Show the obejct.
                        if (showOrHideObject != null)
                        {
                            showOrHideObject.SetActive(true);
                        }

                        Destroy(head_on_surface_obj);
                    }
                }//end scale the hit point.
            }
        }