예제 #1
0
    public void ReleaseGo(string path, GameObject go, EPoolObjectType type)
    {
        if (string.IsNullOrEmpty(path) || go == null)
        {
            return;
        }
        if (mObjectsPool == null)
        {
            mObjectsPool = new GameObject("PoolManager");
            mObjectsPool.transform.localPosition = new Vector3(0, -10000, 0);
        }
        go.transform.parent = mObjectsPool.transform;
        PoolInfo poolInfo = null;

        if (!mPoolDict.TryGetValue(path, out poolInfo))
        {
            poolInfo = new PoolInfo();
            mPoolDict.Add(path, poolInfo);
        }
        XPoolObj obj = new XPoolObj();

        obj.type       = type;
        obj.name       = path;
        obj.gameObject = go;
        DisablePoolGameObject(go, obj);
        poolInfo.quene.Enqueue(obj);
    }
예제 #2
0
    private List <GameObject> mDestroyPoolGameObjects = new List <GameObject>();//删除队列

    private bool TryGetObject(PoolInfo poolInfo, ref XPoolObj obj)
    {
        if (poolInfo.quene.Count > 0)
        {
            obj = poolInfo.quene.Dequeue();
            return(true);
        }
        return(false);
    }
예제 #3
0
    public GameObject GetGo(string path)
    {
        if (string.IsNullOrEmpty(path))
        {
            return(null);
        }
        PoolInfo poolInfo = null;
        XPoolObj obj      = null;

        if (mPoolDict.ContainsKey(path))
        {
            poolInfo = mPoolDict[path];
            if (TryGetObject(poolInfo, ref obj))
            {
                EnablePoolGameObject(obj.gameObject, obj);
                return(obj.gameObject);
            }
        }
        return(ZTResource.Instance.Instantiate(path));
    }
예제 #4
0
파일: ZTPool.cs 프로젝트: 977567460/Escapes
    public GameObject GetGo(string path)
    {
        if (string.IsNullOrEmpty(path))
        {
            return(null);
        }
        PoolInfo poolInfo = null;
        XPoolObj obj      = null;

        if (mPoolDict.ContainsKey(path))
        {
            poolInfo = mPoolDict[path];
            if (TryGetObject(poolInfo, ref obj))
            {
                EnablePoolGameObject(obj.gameObject, obj);
                return(obj.gameObject);
            }
        }
        GameObject go = LoadResource.Instance.Instantiate(path);

        go.transform.parent = this.gameObject.transform;
        return(go);
    }
예제 #5
0
 public void DisablePoolGameObject(GameObject go, XPoolObj info)
 {
     go.SetActive(false);
 }
예제 #6
0
 public void EnablePoolGameObject(GameObject go, XPoolObj obj)
 {
     go.SetActive(true);
     go.transform.parent = null;
 }