Exemplo n.º 1
0
        private void OnAimDeadEvent(AgeCalculator obj)
        {
            obj.OnDeadEvent -= OnAimDeadEvent;
            GameObject           aimSender = obj.gameObject;
            int                  groupId   = aimSender.GetComponent <AimController>().GroupId;
            List <AimController> nowAims   = GetAimById(groupId);

            if (nowAims != null)
            {
                AimController aim = aimSender.GetComponent <AimController>();
                if (aim.Delay)
                {
                    if (OnWeaponFireOnce != null)
                    {
                        OnWeaponFireOnce.Invoke(aim.Weapon, aim.Position);
                    }
                }

                nowAims.Remove(aim);
                Destroy(aimSender);

                if (nowAims.Count == 0)
                {
                    if (Aims.ContainsKey(groupId))
                    {
                        Aims.Remove(groupId);
                    }
                }
            }
            CheckIsStopAim();
        }
Exemplo n.º 2
0
        public int CreateAim(IWeapon weapon, Vector3 pos)
        {
            object[]             config = weapon.Config;
            WongWeaponController owner  = weapon.Owner;

            int   age           = (int)config[1];
            int   count         = (int)config[4];
            float seperateRange = (float)config[5];

            aimsId++;
            if (!Aims.ContainsKey(aimsId))
            {
                Aims.Add(aimsId, new List <AimController>());
            }

            for (int i = 0; i < count; ++i)
            {
                GameObject aim = Instantiate(Prefab);
                aim.SetActive(true);
                aim.transform.parent     = gameObject.transform;
                aim.transform.localScale = new Vector3(Scale, Scale, 1);

                Vector3 offset = new Vector3(UnityEngine.Random.Range(-1.0f, 1.0f) * seperateRange * Scale, UnityEngine.Random.Range(-1.0f, 1.0f) * seperateRange * Scale, 0);

                AimController aimController = aim.GetComponent <AimController>();
                aimController.Weapon   = weapon;
                aimController.Offset   = offset;
                aimController.Position = pos;
                aimController.GroupId  = aimsId;

                AgeCalculator ageCalculator = aim.GetComponent <AgeCalculator>();
                ageCalculator.DeadAge      = age;
                ageCalculator.OnDeadEvent += OnAimDeadEvent;
                Aims[aimsId].Add(aimController);

                if (OnCreateAim != null)
                {
                    OnCreateAim.Invoke(weapon, pos + offset);
                }

                if (!aimController.Delay)
                {
                    if (OnWeaponFireOnce != null)
                    {
                        OnWeaponFireOnce.Invoke(weapon, pos + offset);
                    }
                }
            }

            return(aimsId);
        }