예제 #1
0
    static public void LoadPrefabWithInstanceNOCoroutine(string iFilename, AsyncLoadingPrefabComplete iCallback = null, string iObjname = "Load Prefab", bool iIsFromResources = true)
    {
        GameObject   _Loader = new GameObject(iObjname);
        PrefabLoader _Script = _Loader.AddComponent <PrefabLoader>();

        if (_Script)
        {
            _Script.LoadPrfab(iFilename, iCallback, true, iIsFromResources);
        }
    }
예제 #2
0
    /*
     * 載入Prefab
     * @parameter 1. 檔名. 2. 資料夾或路徑. 3. Callback函式. 4. 物件名稱,用來辨識
     */
    static public void LoadPrefab(string iFilename, AsyncLoadingPrefabComplete iCallback = null, string iObjname = "Load Prefab", bool iIsFromResources = true)
    {
        GameObject   _Loader = new GameObject(iObjname);
        PrefabLoader _Script = _Loader.AddComponent <PrefabLoader>();

        if (_Script != null)
        {
            _Script.LoadPrfabByAsync(iFilename, iCallback, false, iIsFromResources);
        }
    }
예제 #3
0
    protected void LoadPrfab(string iName, AsyncLoadingPrefabComplete iCallback, bool iIsInstance, bool iIsFromResources)
    {
        m_FilePath    = iName;
        m_IsCompelete = false;
        m_IsInstance  = iIsInstance;

        if (iCallback != null)
        {
            m_PrefabLoadingCB = iCallback;
        }

        if (iIsFromResources)
        {
            GameObject _Obj = CoreTools.LoadResource <GameObject>(m_FilePath, "");

            if (_Obj != null)
            {
                GameObject _TempObj = _Obj;

                if (m_IsInstance)
                {
                    _TempObj = Instantiate(_Obj, Vector3.zero, Quaternion.identity) as GameObject;
                }

                if (m_PrefabLoadingCB != null)
                {
                    m_PrefabLoadingCB(_TempObj);
                }

                _TempObj = null;
            }
            else
            {
                if (m_PrefabLoadingCB != null)
                {
                    m_PrefabLoadingCB(_Obj);
                }
            }

            _Obj = null;
            Resources.UnloadUnusedAssets();
            m_IsCompelete = true;
        }
        else
        {
        }
    }
예제 #4
0
    /*
     * 建立一個Coroutine來載入檔案並設定變數
     * @parameter 1. 檔名. 2. 資料夾或路徑. 3. Callback函式. 4. 是否直接實體化
     */
    protected void LoadPrfabByAsync(string iName, AsyncLoadingPrefabComplete iCallback, bool iIsInstance, bool iIsFromResources)
    {
        m_FilePath    = iName;
        m_IsCompelete = false;
        m_IsInstance  = iIsInstance;

        if (iCallback != null)
        {
            m_PrefabLoadingCB = iCallback;
        }

        if (iIsFromResources)
        {
            StartCoroutine(LoadPrefabAsync());
        }
        else
        {
        }
    }