コード例 #1
0
 private void OnTriggerExit2D(Collider2D collider)
 {
     if (this.CurrentEntity == null)
     {
         Destroy(this);
     }
     if (this.CurrentEntity.GetComponentFlag().HasFlag(OperatorIds.TRIGGER2D))
     {
         if (this.CurrentEntity.GetValue <TriggerCallBack>(Trigger2DComponentVariable.exitCallBack) == null)
         {
             return;
         }
         int count = triggerList.Count;
         for (int i = 0; i < count; i++)
         {
             Trigger2DModel item = triggerList[i];
             if (item.CurrentCollider.gameObject == collider.gameObject)
             {
                 item.TriggerState = TriggerEnum.Exit;
                 this.CurrentEntity.SetValue(Trigger2DComponentVariable.isPhysical, true);
             }
         }
     }
     else
     {
         Destroy(this);
     }
 }
コード例 #2
0
ファイル: Trigger2DSystem.cs プロジェクト: zhejimanyu/TSFrame
        public void Execute(List <Entity> entitys)
        {
            foreach (Entity entity in entitys)
            {
                GameObject obj = entity.GetValue <GameObject>(GameObjectComponentVariable.value);
                if (obj == null)
                {
                    continue;
                }
                List <Trigger2DModel> triggerList = entity.GetValue <List <Trigger2DModel> >(Trigger2DComponentVariable.triggerList);
                Trigger2DCallBack     enter       = entity.GetValue <Trigger2DCallBack>(Trigger2DComponentVariable.enterCallBack);
                Trigger2DCallBack     stay        = entity.GetValue <Trigger2DCallBack>(Trigger2DComponentVariable.stayCallBack);
                Trigger2DCallBack     exit        = entity.GetValue <Trigger2DCallBack>(Trigger2DComponentVariable.exitCallBack);

                int  count    = triggerList.Count;
                bool isChange = false;
                bool isRemove = false;
                for (int i = 0; i < count; i++)
                {
                    Trigger2DModel item = triggerList[i];
                    switch (item.TriggerState)
                    {
                    case TriggerEnum.Enter:
                        if (enter != null)
                        {
                            Invoke(enter, entity, item.CurrentCollider);
                        }
                        if (stay != null)
                        {
                            item.TriggerState = TriggerEnum.Stay;
                            isChange          = true;
                        }
                        if (item.TriggerState == TriggerEnum.Enter)
                        {
                            item.TriggerState = TriggerEnum.None;
                            isRemove          = true;
                        }
                        break;

                    case TriggerEnum.Stay:
                        if (stay != null)
                        {
                            Invoke(stay, entity, item.CurrentCollider);
                            isChange = true;
                        }
                        break;

                    case TriggerEnum.Exit:
                        if (exit != null)
                        {
                            Invoke(exit, entity, item.CurrentCollider);
                            item.TriggerState = TriggerEnum.None;
                            isRemove          = true;
                        }
                        break;

                    case TriggerEnum.None:
                    default:
                        break;
                    }
                }
                if (isChange)
                {
                    entity.SetValue(Trigger2DComponentVariable.isPhysical, true);
                }
                if (isRemove)
                {
                    triggerList.RemoveAll(a => a.TriggerState == TriggerEnum.None);
                }
            }
        }