コード例 #1
0
        public void SetState(IO sender, int?value)
        {
            if (value > 0)
            {
                LevelHigh?.Invoke(sender, null);
            }
            else
            {
                LevelLow?.Invoke(sender, null);
            }
            if (value != GetState())
            {
                OnEdge?.Invoke(sender, new StateEventArgs(value));
            }

            _state = value;
        }
コード例 #2
0
        private Vector3 GetGroundOrient(Vector3 wdir)
        {
            if (wdir.magnitude <= 0)
            {
                return(Vector3.zero);
            }

            var        pos = _collider.transform.position;
            RaycastHit rayhit;

            UnityEngine.Physics.Raycast(pos + Vector3.up, -_collider.transform.up, out rayhit, 2f, _movementMask);

            if (rayhit.collider == null)
            {
                return(Vector3.zero);
            }

            var distance = CheckBounds(rayhit);

            if (distance < 0.2f)
            {
                if (!UnityEngine.Physics.Raycast(
                        pos + Vector3.up,
                        (_collider.transform.forward - _collider.transform.up).normalized,
                        2f,
                        _movementMask
                        ))
                {
                    OnEdge?.Invoke();
                }
            }

            var rot = Quaternion.AngleAxis(90, _collider.transform.up) * wdir;

            var cross = Vector3.Cross(rot, rayhit.normal);

            _stepAngle = Vector3.Angle(cross, Vector3.down);

            return(cross);
        }