Esempio n. 1
0
        void Update()
        {
            if (!player)
            {
                player = OpenMMO.PlayerAccount.localPlayer;
            }
            if (player != null)
            {
                TargetingSystem targetingSystem = player.GetComponent <TargetingSystem>(); //GET TARGETING SYSTEM
                if (targetingSystem != null)
                {
                    target = targetingSystem.currentTarget;                          //GET CURRENT TARGET
                }
                if (target != null)
                {
                    panel.SetActive(true);
                }
                else
                {
                    panel.SetActive(false); return;
                }                                                                                       //ACTIVATE IF THERE IS A TARGET

                if (panel.activeSelf)
                {
                    targetImage.sprite = target.icon; //IMAGE
                    targetLabel.text   = target.name; //NAME
                }
            }
            else
            {
                panel.SetActive(false);
            }
        }
Esempio n. 2
0
        //GET NEAREST TARGET
        private Targetable GetNearestTarget(Transform[] targetList)
        {
            Targetable nearestTarget = null;

            if (targetList != null && targetList.Length > 0)
            {
                foreach (Transform hit in targetList)
                {
                    Targetable targ = hit.GetComponent <Targetable>();
                    //if (targ == null) targ = hit.transform.GetComponentInChildren<Targetable>();

                    if (targ != null)
                    {
                        float distance = Vector3.Distance(transform.position, targ.position);
                        if (distance <= distanceToTarget)
                        {
                            distanceToTarget = distance;
                            nearestTarget    = targ;
                        }
                    }
                }
            }

            return(nearestTarget);
        }
Esempio n. 3
0
        //FIND NEXT TARGET
        public void FindNextTarget(Transform location, float range, out Targetable nextTarget)
        {
            Transform[] targets = fetch.Targets(location, range);

            /*
             #region DEBUG
             #if UNITY_EDITOR && DEBUG
             * if (targets != null && targets.Length > 0)
             * {
             *  System.Text.StringBuilder log = new System.Text.StringBuilder("<color=green>TARGETS FOUND</color>");
             *
             *  foreach (Transform t in targets)
             *  {
             *      log.Append("\n" + t.name.ToString());
             *  }
             *
             *  Debug.Log(log.ToString());
             * }
             * else
             * {
             *  Debug.Log("<color=red>NO TARGETS FOUND</color>");
             * }
             #endif
             #endregion
             */

            Targetable targ = GetNearestTarget(targets);

            if (targ != null)
            {
                previousTarget = currentTarget; //SET PREVIOUS TARGET
                nextTarget     = targ;
            }
            else
            {
                nextTarget = currentTarget;
            }
        }
Esempio n. 4
0
        //LATE UPDATE
        private void LateUpdate()
        {
            if (!gameObject.activeInHierarchy)
            {
                return;
            }

            //AUTOTARGET
            if (autoTarget)
            {
                autoTarget     = false;
                findNextTarget = true;
                //FindNextTarget(transform, targetingRange, out currentTarget);
                return;
            }

            if (findNextTarget) //SELECT NEXT TARGET
            {
                findNextTarget = false;
                Targetable nextTarget;
                FindNextTarget(transform, targetingRange, out nextTarget);

                if (currentTarget != nextTarget && distanceToTarget <= targetingRange)
                {
                    currentTarget = nextTarget;
                }

                return;
            }
            else if (findLastTarget) //SELECT LAST TARGET
            {
                findLastTarget = false;
                Targetable lastTarget;
                FindLastTarget(transform.position, targetingRange, out lastTarget);

                if (currentTarget != lastTarget && distanceToTarget <= targetingRange)
                {
                    currentTarget = lastTarget;
                }
                return;
            }
            else if (currentTarget != null)
            {
                //VERIFY RANGE
                if (verifyRange)
                {
                    verifyRange = false;
                    if (Vector3.Distance(currentTarget.position, transform.position) > targetingRange * RANGE_VERIFICATION_TOLERENCE)
                    {
                        CancelTarget();
                        return;
                    }
                }
                //VERIFY VITALS
                if (verifyVitals)
                {
                    verifyVitals = false;
                    if (!currentTarget.IsAlive)
                    {
                        CancelTarget();
                        return;
                    }
                }
            }
        }
Esempio n. 5
0
 //FIND LAST TARGET
 public void FindLastTarget(Vector3 location, float range, out Targetable nextTarget)
 {
     nextTarget     = previousTarget;
     previousTarget = currentTarget;
 }
Esempio n. 6
0
 //CANCEL TARGET
 public void CancelTarget()
 {
     previousTarget   = currentTarget;                     //SET PREVIOUS TARGET
     currentTarget    = null;                              //REMOVE CURRENT TARGET
     distanceToTarget = DEFAULT_MAXIMIZED_TARGET_DISTANCE; //RESET TARGET DISTANCE
 }