Пример #1
0
    void OnTriggerEnter(Collider other)
    {
        if (!ActorTargetManager.IsTrigger(other))
        {
            return;
        }
        try
        {
            if (m_info.m_isNeedRemove)
            {
                return;
            }
            Transform targetObj = other.transform;
            while (null != targetObj && targetObj.name != "body")
            {
                targetObj = targetObj.parent;
            }
            if (null == targetObj)
            {
                return;
            }
            ActorProp actorProp = targetObj.parent.GetComponent <ActorProp>();
            if (null == actorProp)
            {
                Debug.LogWarning("trigger return, actorProp get failed");
                return;
            }
            Actor target = actorProp.ActorLogicObj;
            if (target == null || target.IsDead)
            {
                return;
            }
            if (m_info.m_itemInfo.IsOnlyForChosenTarget)
            {     //只对选中目标生效
                if (target != m_info.m_dstActor)
                { //不是选中目标
                    return;
                }
            }
            if (m_info.m_bouncyTargetIDList != null)
            {     //反弹中
                if (target != m_info.m_dstActor)
                { //不是选中目标
                    return;
                }
            }
            SkillResultInfo info = GameTable.SkillResultTableAsset.Lookup(m_info.m_itemInfo.Item_ResultID);
            if (info == null)
            {
                //Debug.LogWarning("trigger return, SkillResultInfo is null, result id is " + m_info.m_itemInfo.Item_ResultID);
                return;
            }
            switch ((ENResultTargetType)info.ResultTargetType)
            {
            case ENResultTargetType.enEnemySingle:
            case ENResultTargetType.enEnemyAll:
            {        //作用于enemy
                if (!ActorTargetManager.IsEnemy(m_info.m_actorCamp, m_info.m_actorType, target))
                {
                    return;
                }
            }
            break;

            case ENResultTargetType.enFriendlySingle:
            case ENResultTargetType.enFriendlyAll:
            {        //作用于friendly
                if (!ActorTargetManager.IsFriendly(m_info.m_actorCamp, m_info.m_actorType, target))
                {
                    return;
                }
            }
            break;

            case ENResultTargetType.enEveryone:
                break;

            case ENResultTargetType.enSelf:
                if (m_info.m_actorType != target.Type)
                {
                    return;
                }
                break;

            case ENResultTargetType.enFriendlyAllAndSelf:
            case ENResultTargetType.enFriendlySingleAndSelf:
            {
                if (!ActorTargetManager.IsFriendly(m_info.m_actorCamp, m_info.m_actorType, target) && m_info.m_actorType != target.Type)
                {
                    return;
                }
            }
            break;

            default:
                return;
            }
            if (m_targetIDList.Contains(target.ID))
            {
                if (!m_info.m_itemInfo.IsMultiResult)
                {//不对目标多次生效
                    return;
                }
            }
            else
            {
                m_targetIDList.Add(target.ID);
            }

            GlobalEnvironment.Singleton.IsInCallbackOrTrigger = true;

            IResult r = BattleFactory.Singleton.CreateResult(ENResult.Skill, m_info.m_srcActor.ID, target.ID,
                                                             m_info.m_itemInfo.Item_ResultID, m_info.m_skillID);
            if (r != null)
            {
                target.SetBlastPos(m_info.m_itemObj.transform.position, m_info.m_itemObj.transform.forward);
                r.ResultExpr(null);
                BattleFactory.Singleton.GetBattleContext().CreateResultControl().DispatchResult(r);
            }
            if (m_info.m_itemInfo.IsRemoveAfterResult)
            {
                m_info.m_isNeedRemove = true;
            }

            //播放击中声音
            if (!string.IsNullOrEmpty(info.SoundList))
            {
                string[] param = info.SoundList.Split(new char[1] {
                    ','
                });
                string sound = param[0];
                if (!string.IsNullOrEmpty(sound))
                {
#if UNITY_IPHONE || UNITY_ANDRIOD
#else
                    AudioClip aClip = PoolManager.Singleton.LoadSound(sound);
                    if (aClip != null)
                    {
                        AudioSource.PlayClipAtPoint(aClip, gameObject.transform.position);
                    }
#endif
                }
                else
                {
                    Debug.LogWarning("sound string is null");
                }
            }
            RemoteAttackManager.Singleton.StartBouncy(m_info, target.MainPos);
        }
        catch (Exception e)
        {
            Debug.LogError("Error On OnTriggerEnter" + e.Message + ",,,,Stack:" + e.StackTrace.ToString());
        }
        GlobalEnvironment.Singleton.IsInCallbackOrTrigger = false;
    }