コード例 #1
0
        GameObject InstantiateInner(GameObject _prefab, Vector3 _pos, Quaternion _qua)
        {
            if (!dic_PoolList.ContainsKey(_prefab))
            {
                Debug.LogError("풀링에 없음 _name[" + _prefab.name + "]");
                return(null);
            }
            //ArgumentNullException: Argument cannot be null.
            //Parameter name: key
            //System.Collections.Generic.Dictionary`2[UnityEngine.GameObject, PoolManager7.PoolManager + GameObjectData].ContainsKey(UnityEngine.GameObject key)(at / Users / builduser / buildslave / mono / build / mcs /class/corlib/System.Collections.Generic/Dictionary.cs:458)
            //PoolManager7.PoolManager.InstantiateInner(UnityEngine.GameObject _prefab, Vector3 _pos, Quaternion _qua) (at Assets/PoolManager/PoolManager7_CircleUI/PoolManager.cs:160)
            //PoolManager7.PoolManager.Instantiate(UnityEngine.GameObject _go, Vector3 _pos, Quaternion _qua) (at Assets/PoolManager/PoolManager7_CircleUI/PoolManager.cs:152)
            //CoinEat.MouseClick.Spawn_GameObject(Int32 _idx) (at Assets/CoinEat/MouseClick.cs:44)
            //CoinEat.MouseClick.Update() (at Assets/CoinEat/MouseClick.cs:16)


            GameObject        _rtn      = null;
            GameObjectData    _dataList = dic_PoolList [_prefab];
            List <GameObject> _list     = _dataList.list;

            //Debug.Log(12);
            if (!_list [_dataList.front].activeInHierarchy)
            {
                //Debug.Log(13);
                //Not use gameobject > return data
                _rtn = _list [_dataList.front];
                //Debug.Log ("used > f");
                _rtn.transform.position = _pos;                 //순서가 중요.
                _rtn.transform.rotation = _qua;
                _rtn.SetActive(true);
                //Debug.Log ("used > t");

                _dataList.NextFront();
                //_dataList.front++;
                //if (_dataList.front >= _dataList.max)
                //{
                //	_dataList.front = 0;
                //}
            }
            else if (willGrow)
            {
                //Debug.Log(14);
                int _idx = CheckAccessTime(_dataList, _list);
                if (_idx != -1)
                {
                    //Debug.Log (" > Enmpy find ");
                    //재검색... 빈곳 찾기....
                    _dataList.front = _idx;

                    _rtn = _list [_dataList.front];
                    //Debug.Log ("used > f");
                    _rtn.transform.position = _pos;                     //순서가 중요.
                    _rtn.transform.rotation = _qua;
                    _rtn.SetActive(true);
                    //Debug.Log ("used > t");

                    _dataList.NextFront();
                    //_dataList.front++;
                    //if (_dataList.front >= _dataList.max) {
                    //	_dataList.front = 0;
                    //}
                }
                else
                {
                    //Debug.Log(16);
                    //not found the pooling gameobject and create gameobject
                    //GameObject _goTemp = Instantiate (_prefab, _pos, _qua) as GameObject;
                    //이상하게 위치 잡고 생성하면 오류나고 이렇게 해야만 한다...

                    //이것도 안된다. ㅠㅠ.
                    //Debug.Log ("create2 > .");
                    //GameObject _goTemp = Instantiate ((GameObject)_prefab, _pos, _qua) as GameObject;             //유니티 자체가 멈춰버린다. ㅠㅠ
                    //GameObject _goTemp = Instantiate (_prefab, _pos, _qua) as GameObject;                         //유니티 자체가 멈춰버린다. ㅠㅠ
                    GameObject _goTemp = (Instantiate(_prefab.transform, _pos, _qua) as Transform).gameObject;                          //된다. ㅠㅠ.
                    //Debug.Log ("create2 > I");
                    //Debug.Log("create2 > I" + _goTemp.transform.position + ":" + _pos);

                    //생성후(Awake, OnEnable) => 위치 음... 문제
                    //1. Instantiate    ->  Awake()
                    //				        OnEnable() -> 충돌, 체크 할 수 있다....
                    //						*위치가 반영되었다고 생각했는데... > 순서 꼬임...
                    //2. pos, qut		->  이제 위치 반영...
                    //GameObject _goTemp = Instantiate (_prefab);
                    //_goTemp.transform.position = _pos;
                    //_goTemp.transform.rotation = _qua;
                    //Debug.Log ("create2 > I");
                    Transform _parent = transform;
                    bool      _bUI    = false;
                    FindGameObjectInfoToParent(_prefab, ref _parent, ref _bUI);

                    _goTemp.transform.SetParent(_parent);
                    if (_bUI)
                    {
                        _goTemp.transform.localScale = Vector3.one;
                    }
                    _list.Insert(_dataList.front, _goTemp);
                    _goTemp.name += _dataList.max.ToString();
                    _rtn          = _goTemp;
                    if (!_goTemp.activeInHierarchy)
                    {
                        _goTemp.SetActive(true);
                        //Debug.Log(_goTemp.name + ":" + _goTemp.activeInHierarchy);
                    }

                    //Debug.Log ("add front:" + _dataList.front);

                    _dataList.max++;
                    _dataList.front++;
                    if (_dataList.front >= _dataList.max)
                    {
                        _dataList.front = 0;
                    }
                    //Debug.Log ("info front:" + _dataList.front + " max:" + _dataList.max);
                }
            }
            else
            {
                Debug.LogWarning(" 성장이 아닌데 여유가 없다 > 논리 오류");
            }
            //Debug.Log(191);
            //Debug.Log(192);

            return(_rtn);
        }