Exemplo n.º 1
0
        public virtual void FireProyectile(RaycastHit AimRay)
        {
            float percent = Random.Range(0, 1);

            Vector3 AimDirection = (AimRay.point - transform.position).normalized;

            if (C_ReduceAmmoAfterShoot != null)
            {
                StopCoroutine(C_ReduceAmmoAfterShoot);
            }
            C_ReduceAmmoAfterShoot = ReduceAmmoAfterShoot();
            StartCoroutine(C_ReduceAmmoAfterShoot);

            OnFire.Invoke(AimDirection);

            if (AimRay.transform)                                                                                       //If the AIM Ray hit something
            {
                var interactable = AimRay.transform.GetComponent <IInteractable>();
                interactable?.Interact();

                AffectStat.Value = Random.Range(MinDamage, MaxDamage);
                AffectStat.ModifyStat(AimRay.transform.GetComponentInParent <Stats>());

                Damager.SetDamage(AimRay.normal, AimRay.transform, transform);

                if (AimRay.rigidbody)                                                                                          //If the thing we hit has a rigidbody
                {
                    AimRay.rigidbody.AddForceAtPosition(AimDirection * Mathf.Lerp(MinForce, MaxForce, percent), AimRay.point); //Apply the force to it
                }

                BulletHole(AimRay);

                OnHit.Invoke(AimRay.transform);  //Invoke OnHitSomething Event
            }
        }
Exemplo n.º 2
0
        // Called when this component is attached in editor
        private void Initialize()
        {
            raycast2DManager = GetComponent <Raycast2DManager>();
            // Start drag
            raycast2DManager.OnRaycast2DMouseDown_left.AddListener((RaycastHit2D pHit) => {
                if (pHit.transform == null || !interactable)
                {
                    return;
                }



                // pHit.transform exists, so we start dragging it
                if (raycast2DManager.Logs)
                {
                    Debug.Log("Started dragging: " + pHit.transform.name);
                }
                mDragged            = pHit.transform;
                mIndexAsChildBuffer = mDragged.GetSiblingIndex();
                mDragged.transform.SetAsLastSibling();
                mDraggedInitialPos = mDragged.transform.position;
                mMouseInitialPos   = raycast2DManager.raycastCamera.ScreenToWorldPoint(Input.mousePosition);
                OnDragStart.Invoke(mDragged);
            });
        }
Exemplo n.º 3
0
        public virtual void FireProyectile(RaycastHit AimRay)
        {
            float percent = Random.Range(0, 1);

            Vector3 AimDirection = (AimRay.point - transform.position).normalized;

            ReduceAmmo(1);

            OnFire.Invoke(AimDirection);

            DamageValues PistolDamage =
                new DamageValues(AimRay.normal, Mathf.Lerp(MinDamage, MaxDamage, percent));                                    //Set the Direction and Damage value

            if (AimRay.transform)                                                                                              //If the AIM Ray hit something
            {
                AimRay.transform.root.SendMessage("getDamaged", PistolDamage, SendMessageOptions.DontRequireReceiver);         //Send to the thing that we hit the Damage Values

                if (AimRay.rigidbody)                                                                                          //If the thing we hit has a rigidbody
                {
                    AimRay.rigidbody.AddForceAtPosition(AimDirection * Mathf.Lerp(MinForce, MaxForce, percent), AimRay.point); //Apply the force to it
                }
                BulletHole(AimRay);

                OnHit.Invoke(AimRay.transform);  //Invoke OnHitSomething Event
            }
        }
Exemplo n.º 4
0
    IEnumerator task()
    {
        yield return(new WaitForSeconds(wait));

        onComplete.Invoke(transform);
        running = false;
    }
Exemplo n.º 5
0
        /// <summary>Change mesh to the Next/Before</summary>
        public virtual void ChangeMesh(bool next = true)
        {
            if (next)
            {
                Current++;
            }
            else
            {
                Current--;
            }

            if (Current >= meshes.Length)
            {
                Current = 0;
            }
            if (Current < 0)
            {
                Current = meshes.Length - 1;
            }

            foreach (var item in meshes)
            {
                if (item)
                {
                    item.gameObject.SetActive(false);
                }
            }

            if (meshes[Current])
            {
                meshes[Current].gameObject.SetActive(true);
                OnActiveMesh.Invoke(meshes[Current]);
            }
        }
Exemplo n.º 6
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.transform.tag == triggerTag)
     {
         functionEvent.Invoke(other.transform);
     }
 }
Exemplo n.º 7
0
        public void OnGroundClick(BaseEventData data)
        {
            PointerEventData pData = (PointerEventData)data;
            NavMeshHit       hit;

            if (NavMesh.SamplePosition(pData.pointerCurrentRaycast.worldPosition, out hit, navMeshSampleDistance, NavMesh.AllAreas))
            {
                destinationPosition = hit.position;
            }
            else
            {
                destinationPosition = pData.pointerCurrentRaycast.worldPosition;
            }

            if (PointUI)
            {
                Instantiate(PointUI, destinationPosition, Quaternion.FromToRotation(PointUI.transform.up, pData.pointerCurrentRaycast.worldNormal));
            }

            interactables = Physics.OverlapSphere(destinationPosition, radius);

            foreach (var inter in interactables)
            {
                if (inter.GetComponent <IDestination>() != null)
                {
                    OnInteractableClick.Invoke(inter.transform.root); //Invoke only the first interactable found
                    return;
                }
            }

            OnPointClick.Invoke(destinationPosition);
        }
Exemplo n.º 8
0
        protected override void InvokeEvents()
        {
            base.InvokeEvents();
            var obj = (GameObject)Instantiate(prefab, _position, Quaternion.identity);

            _instantiatedObjectEvent.Invoke(obj);
            _instantiatedTransformEvent.Invoke(obj.transform);
        }
Exemplo n.º 9
0
 void OnTriggerExit2D(Collider2D col)
 {
     if (IsInLayerMask(col))
     {
         Invoke("InvokedTriggerExit", DelayOnExit);
         OnTriggerExitTransformEvent.Invoke(col.transform);
     }
 }
Exemplo n.º 10
0
 public virtual void OnEventInvoked(Transform value)
 {
     ResponseTransform.Invoke(value);
     if (!value)
     {
         ResponseNull.Invoke();
     }
 }
Exemplo n.º 11
0
 public void TakeDamage(int damage)
 {
     currenthealth -= damage;
     if (currenthealth <= 0)
     {
         onDeathTransform.Invoke(myTransform);
         onDeath.Invoke();
     }
 }
        #pragma warning restore 0649

        public void Input(int index)
        {
            if (index < 0 || index >= transforms.Length)
            {
                return;
            }

            Output.Invoke(transforms[index]);
        }
        void Update()
        {
            result = process.GetFirstOrNull();

            if (result || outputResultIfNull)
            {
                output.Invoke(result);
            }
        }
Exemplo n.º 14
0
 void OnTriggerEnter2D(Collider2D col)
 {
     if (IsInLayerMask(col))
     {
         //Debug.Log("OnTriggerEnter");
         OnTriggerEnterEvent.Invoke();
         OnTriggerEnterTransformEvent.Invoke(col.transform);
     }
 }
Exemplo n.º 15
0
    /// <summary>
    /// Trigger event
    /// </summary>
    /// <param name="eventName"></param>
    /// <param name="t"></param>
    public static void TriggerEvent(string eventName, Transform t)
    {
        TransformEvent thisEvent = null;

        if (instance.eventDictionary.TryGetValue(eventName, out thisEvent))
        {
            thisEvent.Invoke(t);
        }
    }
Exemplo n.º 16
0
        public static void TriggerEvent(GlobalEvents eventName, Transform transform)
        {
            TransformEvent thisEvent = null;

            if (transformEventDictionary.TryGetValue(eventName, out thisEvent))
            {
                thisEvent.Invoke(transform);
            }
        }
Exemplo n.º 17
0
 public void TakeDamage(int damage)
 {
     myTransform.gameObject.GetComponent <AudioSource>().PlayOneShot(onDamageSound);
     currenthealth -= damage;
     if (currenthealth <= 0)
     {
         onDeathTransform.Invoke(myTransform);
         onDeath.Invoke();
     }
 }
Exemplo n.º 18
0
    public static void SafeInvoke(this TransformEvent e, Transform target)
    {
        if (e == null)
        {
            Debug.Log("Event is empty, Invoke aborted");
            return;
        }

        e.Invoke(target);
    }
Exemplo n.º 19
0
        /// <summary>
        /// Updates the Agents using he animation root motion
        /// </summary>
        protected virtual void UpdateAgent()
        {
            Vector3 Direction = Vector3.zero;                               //Reset the Direction (THIS IS THE DIRECTION VECTOR SENT TO THE ANIMAL)

            //Store the remaining distance -- but if navMeshAgent is still looking for a path Keep Moving
            RemainingDistance = Agent.remainingDistance;
            // RemainingDistance = Agent.remainingDistance <=0 ? float.PositiveInfinity : Agent.remainingDistance;


            if (Agent.pathPending || Mathf.Abs(RemainingDistance) <= 0.1f)
            {
                RemainingDistance = float.PositiveInfinity;
                agent.SetDestination(targetPosition);
            }

            //  if (RemainingDistance == 0) RemainingDistance = float.PositiveInfinity;

            if (RemainingDistance > StoppingDistance)                   //if haven't arrived yet to our destination
            {
                Direction = Agent.desiredVelocity.normalized;
                OnAction  = false;
            }
            else  //if we get to our destination
            {
                OnTargetPositionArrived.Invoke(targetPosition);
                if (target)
                {
                    OnTargetArrived.Invoke(target);
                }

                targetPosition  = NullVector;                               //Clean the TargetPosition
                agent.isStopped = true;


                if (isActionZone && !OnAction)                           //If the Target is an Action Zone Start the Action
                {
                    OnAction      = true;
                    animal.Action = true;                               //Activate the Action on the Animal
                }
                else if (isWayPoint)                                    //If the Next Target is a Waypoint
                {
                    SetTarget(isWayPoint ? isWayPoint.NextTarget.transform : null);
                }
            }

            animal.Move(Direction);                                     //Set the Movement to the Animal

            if (AutoSpeed)
            {
                AutomaticSpeed();                                       //Set Automatic Speeds
            }
            CheckOffMeshLinks();                                        //Jump/Fall behaviour
        }
Exemplo n.º 20
0
 public void FindClosest(List <Transform> targets)
 {
     if (targets.Count == 0)
     {
         OnClearTarget.Invoke();
     }
     else
     {
         var target = VectorMath.GetClosest(targets, transform.position);
         OnSetTarget.Invoke(target);
     }
 }
Exemplo n.º 21
0
        /// <summary> Updates the Agents using he animation root motion </summary>
        protected virtual void UpdateAgent()
        {
            if (Agent.pathPending)
            {
                return;
            }                                  //Means is still calculating the path to go



            RemainingDistance = Agent.remainingDistance;               //Store the remaining distance -- but if navMeshAgent is still looking for a path Keep Moving

            if (RemainingDistance < StoppingDistance)                  //if We Arrive to the Destination
            {
                OnTargetPositionArrived.Invoke(TargetPosition);        //Invoke the Event On Target Position Arrived

                if (target)
                {
                    OnTargetArrived.Invoke(target);                     //Invoke the Event On Target Arrived
                    if (IsWayPoint)
                    {
                        IsWayPoint.TargetArrived(this);                 //Send that the Animal has Arrived
                    }
                }

                TargetPosition = NullVector;                            //Reset the TargetPosition

                agent.isStopped = true;                                 //Stop the Agent

                // Debug.Log("Arrive_Destination");

                Arrive_Destination();
            }
            else
            {
                //  Debug.Log("Moving");
                animal.Move(Agent.desiredVelocity);                                     //Set the Movement to the Animal


                if (IsGrounded)
                {
                    if (walkDistance > RemainingDistance)
                    {
                        animal.CurrentSpeedIndex = 1;
                    }
                    else
                    {
                        animal.CurrentSpeedIndex = defaultGroundIndex;
                    }
                }

                CheckOffMeshLinks();                                        //Jump/Fall behaviour
            }
        }
Exemplo n.º 22
0
 void OnTriggerExit(Collider target)
 {
     for (int i = 0; i < ReactsToTags.Length; i++)
     {
         if (target.CompareTag(ReactsToTags[i]))
         {
             OnTriggeredExit.Invoke();
             OnTransformTriggeredExit.Invoke(target.transform);
             break;
         }
     }
 }
Exemplo n.º 23
0
 public void Die()
 {
     HP     = 0f;
     Lives -= 1;
     OnDied.Invoke(transform);
     if (Lives > 0)
     {
         Rebirth();
     }
     else
     {
         OnElimination.Invoke();
     }
 }
 void OnTriggerEnter(Collider otherCollider)
 {
     if (otherCollider.transform.tag.Equals("Marker"))
     {
         if (m_Selected.GetPersistentEventCount() >= 0)
         {
             m_Selected.Invoke(otherCollider.transform);
         }
         else
         {
             print("Collided with virtual hand, no attached script for handling");
         }
     }
 }
Exemplo n.º 25
0
        /// <summary>
        /// Creates an event handler that can handle losing a given target. The event handler will
        /// fire the targetChanged event if the lost target was the <see cref="CurrentTarget"/>. If
        /// losing this target means that there are no tracked targets, then the <see
        /// cref="onAllTargetsLost"/> event is fired. Finally, Vuforia's Persistent Extended Tracking
        /// is reset, if it was active.
        /// </summary>
        /// <returns>The loser.</returns>
        /// <param name="target">Target.</param>
        private UnityAction TargetLoser(AbstractTrackableFoundEventHandler target)
        {
            return(() =>
            {
                onTargetLost?.Invoke(target.transform);

                if (!HasTargets && hadAnyTargets)
                {
                    hadAnyTargets = HasTargets;
                    if (!done)
                    {
                        Invoke(nameof(OnAllTargetsLost), 1);
                    }
                }
            });
        }
Exemplo n.º 26
0
 void OnTriggerEnter(Collider target)
 {
     if (currentCooldown <= 0f)
     {
         for (int i = 0; i < ReactsToTags.Length; i++)
         {
             if (target.CompareTag(ReactsToTags[i]))
             {
                 OnTriggered.Invoke();
                 OnTransformTriggered.Invoke(target.transform);
                 currentCooldown = TriggerCooldown;
                 break;
             }
         }
     }
 }
Exemplo n.º 27
0
        private void OnTriggerStay2D(Collider2D col)
        {
            if (foundTarget)
            {
                return;
            }

            // If gameobject is on targeted layer
            if ((1 << col.gameObject.layer & _targetMask) != 0)
            {
                // If no obstacles were hit when trying to "see" the target, we can see it!
                if (!Physics2D.Linecast(transform.position, col.transform.position, _obstacleMask).collider)
                {
                    foundTarget = true;
                    OnTargetFound.Invoke(col.transform);
                }
            }
        }
Exemplo n.º 28
0
        /// <summary>
        /// Updates the Agents using he animation root motion
        /// </summary>
        protected virtual void UpdateAgent()
        {
            var Direction = Vector3.zero;                               //Reset the Direction (THIS IS THE DIRECTION VECTOR SENT TO THE ANIMAL)

            RemainingDistance = Agent.remainingDistance;                //Store the remaining distance -- but if navMeshAgent is still looking for a path Keep Moving
            //RemainingDistance = Agent.remainingDistance <=0 ? float.PositiveInfinity : Agent.remainingDistance;

            if (Agent.pathPending || Mathf.Abs(RemainingDistance) <= 0.1f)      //In Case the remaining Distance is wrong
            {
                RemainingDistance = float.PositiveInfinity;
                UpdateTargetTransform();
            }

            if (RemainingDistance > StoppingDistance)                   //if haven't arrived yet to our destination
            {
                Direction     = Agent.desiredVelocity;
                DoingAnAction = false;
            }
            else  //if we get to our destination
            {
                OnTargetPositionArrived.Invoke(targetPosition);         //Invoke the Event On Target Position Arrived
                if (target)
                {
                    OnTargetArrived.Invoke(target);                 //Invoke the Event On Target Arrived
                    if (isWayPoint)
                    {
                        isWayPoint.TargetArrived(this);             //Send that the Animal has Arrived
                    }
                }

                targetPosition  = NullVector;                           //Reset the TargetPosition
                agent.isStopped = true;                                 //Stop the Agent

                CheckNextTarget();
            }

            animal.Move(Direction);                                     //Set the Movement to the Animal

            if (AutoSpeed)
            {
                AutomaticSpeed();                                       //Set Automatic Speeds
            }
            CheckOffMeshLinks();                                        //Jump/Fall behaviour
        }
Exemplo n.º 29
0
        // Drag update and release detection
        void Update()
        {
            if (interactable == false)
            {
                mDragged = null; return;
            }
            if (mDragged != null)
            {
                // Mouse position
                Vector3 lDraggedPos = raycast2DManager.raycastCamera.ScreenToWorldPoint(Input.mousePosition);
                lDraggedPos.z = dragZValue;

                // Mouse Offset
                Vector3 lMouseOffset = Vector3.zero;
                if (!centerObject)
                {
                    lMouseOffset = mDraggedInitialPos - mMouseInitialPos;
                }

                // Final assignation
                mDragged.transform.position = lDraggedPos + lMouseOffset;

                // Detect if the mouse was released and end dragging if true
                if (Input.GetKeyUp(KeyCode.Mouse0))
                {
                    if (returnToPosition)
                    {
                        mDragged.transform.position = mDraggedInitialPos;
                    }
                    if (setAsLastSibbling)
                    {
                        mDragged.SetSiblingIndex(mIndexAsChildBuffer);
                    }
                    OnDragEnd.Invoke(mDragged);
                    if (raycast2DManager.Logs)
                    {
                        Debug.Log("Stopped dragging: " + mDragged.name);
                    }
                    mDragged = null;
                }
            }
        }
Exemplo n.º 30
0
    private void CheckForTarget()
    {
        if (runningToAttacker)
        {
            return;
        }

        Transform oldTarget = target;

        if (target != null)
        {
            if (target.gameObject.layer == (int)Layer.Dead || (target.position - transform.position).sqrMagnitude > sightRange * sightRange)
            {
                target = null;
            }
        }

        Collider[] colliders = Physics.OverlapSphere(transform.position, sightRange, layersToTarget).Where(col => col.gameObject != gameObject).ToArray();
        if (colliders.Length > 0)
        {
            float    distance    = float.MaxValue;
            Collider finalTarget = null;
            foreach (var col in colliders)
            {
                float currentDistance = (col.transform.position - transform.position).sqrMagnitude;
                if (currentDistance < distance)
                {
                    distance    = currentDistance;
                    finalTarget = col;
                }
            }

            target = finalTarget.transform;
        }

        if (target != oldTarget)
        {
            onTargetChanged?.Invoke(target);
        }
    }