Exemplo n.º 1
0
        public void UpdateState(OpenDirection open)
        {
            Angles rot = open switch
            {
                OpenDirection.Back => RotationBack,
                OpenDirection.Front => RotationFront,
                _ => RotationClosed
            };

            if (Speed <= 0)
            {
                Speed = 0.1f;
            }

            var dfference = (Rotation.Angles() - rot).Normal;
            var distance  = dfference.Length;
            var seconds   = distance / Speed;

            _ = DoMove(Rotation.From(rot), seconds, open);
        }

        int movement = 0;

        async Task DoMove(Rotation target, float timeToTake, OpenDirection open)
        {
            var startPos = Rotation;
            int moveid   = ++movement;

            for (float f = 0; f < 1;)
            {
                await Task.NextPhysicsFrame();

                if (moveid != movement)
                {
                    return;
                }

                var eased = Easing.EaseOut(f);

                var newPos = Rotation.Lerp(startPos, target, eased);
                SetPositionAndUpdateVelocity(newPos);
                f += Time.Delta / timeToTake;
            }

            if (open != OpenDirection.Closed && TimeBeforeReset >= 0)
            {
                await Task.DelaySeconds(TimeBeforeReset);

                if (moveid != movement)
                {
                    return;
                }

                EnableAllCollisions = true;
                // Toggle();
            }
        }
Exemplo n.º 2
0
        void OnDrawGizmos()
        {
            if (!doorHinge)
            {
                return;
            }

            if (previousOpenDirection != openDirection)
            {
                previousOpenDirection = openDirection;

                if (openDirection == OpenDirection.Up)
                {
                    doorHinge.localPosition    = new Vector3(0.25f, 3.45f, 0);
                    doorHinge.localEulerAngles = Vector3.zero;
                }
                else if (openDirection == OpenDirection.Down)
                {
                    doorHinge.localPosition    = new Vector3(0.25f, -0.05f, 0);
                    doorHinge.localEulerAngles = new Vector3(180, 0, 0);
                }
                else if (openDirection == OpenDirection.Right)
                {
                    doorHinge.localPosition    = new Vector3(0.25f, 1.725f, 1);
                    doorHinge.localEulerAngles = new Vector3(90, 0, 0);
                }
                else if (openDirection == OpenDirection.Left)
                {
                    doorHinge.localPosition    = new Vector3(0.25f, 1.725f, -1);
                    doorHinge.localEulerAngles = new Vector3(-90, 0, 0);
                }
            }

            //Draw Gizmos
            Gizmos.color = Color.green;

            for (int i = 0; i < arrowGizmoPoints.Length; i++)
            {
                if (i == arrowGizmoPoints.Length - 1)
                {
                    Gizmos.DrawLine(doorHinge.TransformPoint(arrowGizmoPoints[0]), doorHinge.TransformPoint(arrowGizmoPoints[arrowGizmoPoints.Length - 1]));
                }
                else
                {
                    Gizmos.DrawLine(doorHinge.TransformPoint(arrowGizmoPoints[i]), doorHinge.TransformPoint(arrowGizmoPoints[i + 1]));
                }
            }

            // Convert the local coordinate values into world
            // coordinates for the matrix transformation.
            Gizmos.matrix = transform.localToWorldMatrix;
            Gizmos.color  = Selection.activeGameObject != gameObject ? mainColor : selectedColor;
            Gizmos.DrawCube(Vector3.zero, mainGizmoDimensions);
        }
Exemplo n.º 3
0
 public DoorOpened(string name, Gender gender, OpenDirection direction)
 {
     Name      = name;
     Gender    = gender;
     Direction = direction;
 }
Exemplo n.º 4
0
 public DoorOpened(string name, Gender gender, OpenDirection direction)
 {
     Name = name;
      Gender = gender;
      Direction = direction;
 }