コード例 #1
0
        void Update()
        {
            if (!IsRunning)
            {
                return;
            }

            // Adjust the cast by the tilt value.
            Quaternion adjustmentQuaternion = Quaternion.AngleAxis(_tilt, _source.right);
            Vector3    castVector           = adjustmentQuaternion * _source.forward;

            if (Physics.Raycast(_source.position, castVector, out _surfaceHit, _maxDistance, _hitLayers))
            {
                // Set the initial values.
                Position = _surfaceHit.point;
                UpdateAdjustedPosition();
                Surface    = GetSurfaceType(_surfaceHit.normal);
                _fitStatus = GetFitType(Surface);

                // Obtain a "perfect" normal since meshed surfaces are not smooth.
                _normal = GetPerfectNormal(Surface, _surfaceHit.normal);

                ValidateCorners(_surfaceHit);

                ValidateVolume();
            }
            else
            {
                _fitStatus = FitType.NoSurface;
                Surface    = SurfaceType.Unknown;
                _normal    = Vector3.zero;

                Position = _source.position + (castVector * _maxDistance);
                Rotation = Quaternion.LookRotation(-_source.forward);
            }

            // Event Notification
            if (Fit != _fitStatus)
            {
                Fit = _fitStatus;
                if (OnPlacementEvent != null)
                {
                    OnPlacementEvent.Invoke(_fitStatus);
                }
            }
        }