Пример #1
0
        /// <summary>
        /// Used for checking if the animal enables the action
        /// </summary>
        private void OnActionListener()
        {
            if (!oldAnimal)
            {
                return;                                            //Skip if there's no animal
            }
            StartCoroutine(OnActionDelay(ActionDelay, oldAnimal)); //Invoke the Event OnAction

            if (Align && AlingPoint)
            {
                IEnumerator ICo = null;

                Vector3 AlingPosition = AlingPoint.position;

                if (AlingPoint2)                //In case there's
                {
                    AlingPosition = MalbersTools.ClosestPointOnLine(AlingPoint.position, AlingPoint2.position, oldAnimal.transform.position);
                }

                if (AlignLookAt)
                {
                    ICo = MalbersTools.AlignLookAtTransform(oldAnimal.transform, AlingPoint, AlignTime, AlignCurve);                //Align Look At the Zone
                    StartCoroutine(ICo);
                }
                else
                {
                    if (AlignPos)
                    {
                        StartCoroutine(MalbersTools.AlignTransform_Position(oldAnimal.transform, AlingPosition, AlignTime, AlignCurve));
                    }
                    if (AlignRot)
                    {
                        StartCoroutine(MalbersTools.AlignTransform_Rotation(oldAnimal.transform, AlingPoint.rotation, AlignTime, AlignCurve));
                    }
                }
            }
            StartCoroutine(CheckForCollidersOff());
        }
Пример #2
0
        /// <summary>Aligns the Animal to the Align points of the Zone</summary>
        public virtual void AlignAnimal()
        {
            if (Align && AlingPoint && CurrentAnimal != null)
            {
                IEnumerator ICo = null;

                if (AlignLookAt)
                {
                    ICo = MalbersTools.AlignLookAtTransform(CurrentAnimal.transform, AlingPoint, AlignTime, AlignCurve);                //Align Look At the Zone
                    StartCoroutine(ICo);
                }
                else
                {
                    if (AlignPos)
                    {
                        Vector3 AlingPosition = AlingPoint.position;

                        if (AlingPoint2)                //In case there's a line ... move to the closest point between the two transforms
                        {
                            AlingPosition = MalbersTools.ClosestPointOnLine(AlingPoint.position, AlingPoint2.position, CurrentAnimal.transform.position);
                        }

                        if (DoubleSided)
                        {
                            Vector3 AlingPosOpposite = transform.InverseTransformPoint(AlingPosition);
                            AlingPosOpposite.z *= -1;
                            AlingPosOpposite    = transform.TransformPoint(AlingPosOpposite);

                            var Distance1 = Vector3.Distance(CurrentAnimal.transform.position, AlingPosition);
                            var Distance2 = Vector3.Distance(CurrentAnimal.transform.position, AlingPosOpposite);

                            if (Distance2 < Distance1)
                            {
                                StartCoroutine(MalbersTools.AlignTransform_Position(CurrentAnimal.transform, AlingPosOpposite, AlignTime, AlignCurve));
                            }
                            else
                            {
                                StartCoroutine(MalbersTools.AlignTransform_Position(CurrentAnimal.transform, AlingPosition, AlignTime, AlignCurve));
                            }
                        }
                        else
                        {
                            StartCoroutine(MalbersTools.AlignTransform_Position(CurrentAnimal.transform, AlingPosition, AlignTime, AlignCurve));
                        }
                    }
                    if (AlignRot)
                    {
                        Quaternion Side1     = AlingPoint.rotation;
                        Quaternion AnimalRot = CurrentAnimal.transform.rotation;

                        if (DoubleSided)
                        {
                            Quaternion Side2 = AlingPoint.rotation * Quaternion.Euler(0, 180, 0);

                            var Side1Angle = Quaternion.Angle(AnimalRot, Side1);
                            var Side2Angle = Quaternion.Angle(AnimalRot, Side2);

                            StartCoroutine(MalbersTools.AlignTransform_Rotation(CurrentAnimal.transform, Side1Angle < Side2Angle ? Side1 : Side2, AlignTime, AlignCurve));
                        }
                        else
                        {
                            StartCoroutine(MalbersTools.AlignTransform_Rotation(CurrentAnimal.transform, Side1, AlignTime, AlignCurve));
                        }
                    }
                }
            }
        }