Esempio n. 1
0
        void HandleSelecting()
        {
            Plane plane = new Plane(trs.forward, centerOptionRange.bounds.center);
            float hitDistance;
            Ray   ray = new Ray(selectorTrs.position, selectorTrs.forward);

            if (plane.Raycast(ray, out hitDistance))
            {
                Vector3          hitPoint         = ray.GetPoint(hitDistance);
                List <Transform> optionTransforms = new List <Transform>();
                for (int i = 0; i < options.Length; i++)
                {
                    Option option = options[i];
                    optionTransforms.Add(option.trs);
                }
                optionTransforms.Add(centerOption.trs);
                Transform closestOptionTrs = TransformExtensions.GetClosestTransform_3D(optionTransforms.ToArray(), hitPoint);
                for (int i = 0; i < optionTransforms.Count - 1; i++)
                {
                    Transform optionTrs = optionTransforms[i];
                    if (closestOptionTrs == optionTrs)
                    {
                        Select(options[i]);
                        return;
                    }
                }
                Select(centerOption);
                //  int optionIndex = 0;
                //  for (float angle = 0; angle < 360; angle += 360f / options.Length)
                //  {
                //      Option option = options[optionIndex];
                //      if (Vector3.Angle(trs.rotation * (selectorTrs.position - centerOptionRange.bounds.center), trs.rotation * VectorExtensions.FromFacingAngle(angle)) <= 360f / options.Length / 2)
                //          Select (option);
                //      optionIndex ++;
                //  }
                // }
            }
            // List<Transform> optionTransforms = new List<Transform>();
            // for (int i = 0; i < options.Length; i ++)
            // {
            //  Option option = options[i];
            //  optionTransforms.Add(option.trs);
            // }
            // optionTransforms.Add(centerOption.trs);
            // Transform closestOptionTrs = selectorTrs.GetClosestTransform_3D(optionTransforms.ToArray());
            // for (int i = 0; i < optionTransforms.Count; i ++)
            // {
            //  Transform optionTrs = optionTransforms[i];
            //  if (closestOptionTrs == optionTrs)
            //  {
            //      Select (options[i]);
            //      return;
            //  }
            // }
            // Select (centerOption);
        }