예제 #1
0
    public void LoadResource(string name, string path, ResourceType type, IResourceLoadCallback callback)
    {
        ResourceInfo info = new ResourceInfo(name, path, type);

        if (m_AllLoadInfoDic.ContainsKey(info.m_RPath))
        {
            info = m_AllLoadInfoDic[info.m_RPath];
        }

        info.AddCallback(callback);

        LoadedObjectInfo oj = new LoadedObjectInfo(info.m_RType, info.m_RPath);

        if (m_LoadedObjects.Contains(oj))
        {
            for (int index = 0; index < m_LoadedObjects.Count; index++)
            {
                if (m_LoadedObjects[index].Equals(oj))
                {
                    GameObject go = GameObject.Instantiate(m_LoadedObjects[index].m_GameObject);
                    info.SetNoumenon(go);
                    break;
                }
            }
        }
        else
        {
            GameObject go = Resources.Load(info.m_RPath, typeof(GameObject)) as GameObject;
            if (go != null)
            {
                go.SetActive(false);
                m_LoadedObjects.Add(new LoadedObjectInfo(info.m_RType, info.m_RPath, go));
                info.SetNoumenon(GameObject.Instantiate(go));
            }
            else
            {
                Debug.LogWarning("the object is null." + info);
            }
        }

        m_AllLoadInfoDic.Remove(info.m_RPath);
    }