コード例 #1
0
    public void DestroyEffect(GameObject go)
    {
        if (go == null)
        {
            //if (ShowLog)
            //{
            //    Debug.LogWarning("需要销毁的物体为空");
            //}
            return;
        }
        else
        {
            //if (ShowLog)
            //{
            //    Debug.Log("DestroyEffect:" + go.name);
            //}
        }
        GameObject inputGo = go;

        if (go.name == tempEffectBox)
        {
            if (go.transform.childCount > 0)
            {
                inputGo = go.transform.GetChild(0).gameObject;
            }
            //Debug.LogError("DestroyEffect+"+effectInSceneDic.Count);
        }
        GameObject toRemove  = null;
        GameObject toDestory = null;

        foreach (KeyValuePair <string, List <GameObject> > pair in effectInSceneDic)
        {
            foreach (GameObject goInDic in pair.Value)
            {
                if (inputGo == goInDic)
                {
                    if (poolDic.ContainsKey(pair.Key) && poolDic[pair.Key] != null)
                    {
                        if (poolDic[pair.Key].Count < MAX_COUNT_OFONE_EFFECT)
                        {
                            toRemove = inputGo;
                            SkillEffect se = inputGo.GetComponent <SkillEffect>();
                            se.DisableEffect();
                        }
                        else
                        {
                            toDestory = inputGo;
                        }
                    }
                    break;
                }
            }
            if (toRemove != null || toDestory != null)
            {
                break;
            }
        }

        if (toRemove != null)
        {
            AddEffectToPool(toRemove.name, inputGo);
        }

        if (toDestory != null)
        {
            effectInSceneDic[inputGo.name].Remove(toDestory);
            GameObject.Destroy(toDestory);
        }

        if (inputGo != go)
        {
            GameObject.Destroy(go);
        }
    }