Пример #1
0
    public void PrepareGameObject(string prefabFullPath, enResourceType resourceType, int amount)
    {
        string key = CFileManager.EraseExtension(prefabFullPath).ToLower();
        Queue <CPooledGameObjectScript> queue = null;

        if (!this.m_pooledGameObjectMap.TryGetValue(key, out queue))
        {
            queue = new Queue <CPooledGameObjectScript>();
            this.m_pooledGameObjectMap.Add(key, queue);
        }
        if (queue.Count < amount)
        {
            amount -= queue.Count;
            for (int i = 0; i < amount; i++)
            {
                CPooledGameObjectScript item = this.CreateGameObject(prefabFullPath, Vector3.zero, Quaternion.identity, false, resourceType, key);
                DebugHelper.Assert(item != null);
                if (item != null)
                {
                    queue.Enqueue(item);
                    item.gameObject.transform.SetParent(this.m_poolRoot.transform, true);
                    item.gameObject.SetActive(false);
                }
            }
        }
    }
    public void PrepareGameObject(string prefabFullPath, enResourceType resourceType, int amount, bool assertNull = true)
    {
        string text = CFileManager.EraseExtension(prefabFullPath);
        Queue <CPooledGameObjectScript> queue = null;

        if (!this.m_pooledGameObjectMap.TryGetValue(text.JavaHashCodeIgnoreCase(), out queue))
        {
            queue = new Queue <CPooledGameObjectScript>();
            this.m_pooledGameObjectMap.Add(text.JavaHashCodeIgnoreCase(), queue);
        }
        if (queue.get_Count() >= amount)
        {
            return;
        }
        amount -= queue.get_Count();
        for (int i = 0; i < amount; i++)
        {
            CPooledGameObjectScript cPooledGameObjectScript = this.CreateGameObject(prefabFullPath, Vector3.zero, Quaternion.identity, false, resourceType, text);
            if (assertNull)
            {
                DebugHelper.Assert(cPooledGameObjectScript != null, "Failed Create Game object from \"{0}\"", new object[]
                {
                    prefabFullPath
                });
            }
            if (cPooledGameObjectScript != null)
            {
                queue.Enqueue(cPooledGameObjectScript);
                cPooledGameObjectScript.gameObject.transform.SetParent(this.m_poolRoot.transform, true);
                cPooledGameObjectScript.OnPrepare();
            }
        }
    }
Пример #3
0
    public CResource GetResource(string fullPathInResources, System.Type resourceContentType, enResourceType resourceType, bool needCached = false, bool unloadBelongedAssetBundleAfterLoaded = false)
    {
        if (string.IsNullOrEmpty(fullPathInResources))
        {
            return(new CResource(string.Empty, string.Empty, null, resourceType, unloadBelongedAssetBundleAfterLoaded));
        }
        string    key      = CFileManager.EraseExtension(fullPathInResources).ToLower();
        CResource resource = null;

        if (this.m_cachedResourceMap.TryGetValue(key, out resource))
        {
            if (resource.m_resourceType != resourceType)
            {
                resource.m_resourceType = resourceType;
            }
            return(resource);
        }
        resource = new CResource(key, fullPathInResources, resourceContentType, resourceType, unloadBelongedAssetBundleAfterLoaded);
        this.LoadResource(resource);
        if (needCached)
        {
            this.m_cachedResourceMap.Add(key, resource);
        }
        return(resource);
    }
Пример #4
0
 public void Load()
 {
     if (this.m_isAbandon)
     {
         this.m_state = enResourceState.Unload;
     }
     else
     {
         if (this.m_contentType == null)
         {
             this.m_content = Resources.Load(CFileManager.EraseExtension(this.m_fullPathInResources));
         }
         else
         {
             this.m_content = Resources.Load(CFileManager.EraseExtension(this.m_fullPathInResources), this.m_contentType);
         }
         this.m_state = enResourceState.Loaded;
         if ((this.m_content != null) && (this.m_content.GetType() == typeof(TextAsset)))
         {
             CBinaryObject obj2 = ScriptableObject.CreateInstance <CBinaryObject>();
             obj2.m_data    = (this.m_content as TextAsset).bytes;
             this.m_content = obj2;
         }
     }
 }
Пример #5
0
    public bool CheckCachedResource(string fullPathInResources)
    {
        string    key      = CFileManager.EraseExtension(fullPathInResources).ToLower();
        CResource resource = null;

        return(this.m_cachedResourceMap.TryGetValue(key, out resource));
    }
Пример #6
0
 public CResourcePackerInfo GetResourceBelongedPackerInfo(string fullPathInResources)
 {
     if (!string.IsNullOrEmpty(fullPathInResources) && (this.m_resourcePackerInfoSet != null))
     {
         return(this.m_resourcePackerInfoSet.GetResourceBelongedPackerInfo(CFileManager.EraseExtension(fullPathInResources).ToLower()));
     }
     return(null);
 }
Пример #7
0
 public void AddRefPrefab(string prefabName, bool isParticle)
 {
     prefabName = CFileManager.EraseExtension(prefabName);
     if (!this.prefabDict.ContainsKey(prefabName))
     {
         this.prefabDict.Add(prefabName, isParticle);
     }
 }
Пример #8
0
        public void RemoveCachedResource(string fullPathInResources)
        {
            //int key = CFileManager.EraseExtension(fullPathInResources).JavaHashCodeIgnoreCase();
            int key = CFileManager.EraseExtension(fullPathInResources).GetHashCode();

            CResource resource = null;

            if (m_cachedResourceMap.TryGetValue(key, out resource))
            {
                resource.Unload();
                m_cachedResourceMap.Remove(key);
            }
        }
Пример #9
0
 public CResource(string key, string fullPathInResources, System.Type contentType, enResourceType resourceType, bool unloadBelongedAssetBundleAfterLoaded)
 {
     this.m_key = key;
     this.m_fullPathInResources = fullPathInResources;
     this.m_fullPathInResourcesWithoutExtension = CFileManager.EraseExtension(this.m_fullPathInResources);
     this.m_name         = CFileManager.EraseExtension(CFileManager.GetFullName(fullPathInResources));
     this.m_resourceType = resourceType;
     this.m_state        = enResourceState.Unload;
     this.m_contentType  = contentType;
     this.m_unloadBelongedAssetBundleAfterLoaded = unloadBelongedAssetBundleAfterLoaded;
     this.m_content   = null;
     this.m_isAbandon = false;
 }
Пример #10
0
    private GameObject GetGameObject(string prefabFullPath, Vector3 pos, Quaternion rot, bool useRotation, enResourceType resourceType, out bool isInit)
    {
        string key = CFileManager.EraseExtension(prefabFullPath).ToLower();
        Queue <CPooledGameObjectScript> queue = null;

        if (!this.m_pooledGameObjectMap.TryGetValue(key, out queue))
        {
            queue = new Queue <CPooledGameObjectScript>();
            this.m_pooledGameObjectMap.Add(key, queue);
        }
        CPooledGameObjectScript script = null;

        while (queue.Count > 0)
        {
            script = queue.Dequeue();
            if ((script != null) && (script.gameObject != null))
            {
                script.gameObject.transform.SetParent(null, true);
                script.gameObject.transform.position   = pos;
                script.gameObject.transform.rotation   = rot;
                script.gameObject.transform.localScale = script.m_defaultScale;
                break;
            }
            script = null;
        }
        if (script == null)
        {
            script = this.CreateGameObject(prefabFullPath, pos, rot, useRotation, resourceType, key);
        }
        if (script == null)
        {
            isInit = false;
            return(null);
        }
        isInit = script.m_isInit;
        script.gameObject.SetActive(true);
        this.HandlePooledMonoBehaviour(script.m_pooledMonoBehaviours, enPooledMonoBehaviourAction.Get);
        return(script.gameObject);
    }
    private GameObject GetGameObject(string prefabFullPath, Vector3 pos, Quaternion rot, bool useRotation, enResourceType resourceType, out bool isInit)
    {
        string text = CFileManager.EraseExtension(prefabFullPath);
        Queue <CPooledGameObjectScript> queue = null;

        if (!this.m_pooledGameObjectMap.TryGetValue(text.JavaHashCodeIgnoreCase(), out queue))
        {
            queue = new Queue <CPooledGameObjectScript>();
            this.m_pooledGameObjectMap.Add(text.JavaHashCodeIgnoreCase(), queue);
        }
        CPooledGameObjectScript cPooledGameObjectScript = null;

        while (queue.get_Count() > 0)
        {
            cPooledGameObjectScript = queue.Dequeue();
            if (cPooledGameObjectScript != null && cPooledGameObjectScript.gameObject != null)
            {
                cPooledGameObjectScript.gameObject.transform.SetParent(null, true);
                cPooledGameObjectScript.gameObject.transform.position   = pos;
                cPooledGameObjectScript.gameObject.transform.rotation   = rot;
                cPooledGameObjectScript.gameObject.transform.localScale = cPooledGameObjectScript.m_defaultScale;
                break;
            }
            cPooledGameObjectScript = null;
        }
        if (cPooledGameObjectScript == null)
        {
            cPooledGameObjectScript = this.CreateGameObject(prefabFullPath, pos, rot, useRotation, resourceType, text);
        }
        if (cPooledGameObjectScript == null)
        {
            isInit = false;
            return(null);
        }
        isInit = cPooledGameObjectScript.m_isInit;
        cPooledGameObjectScript.OnGet();
        return(cPooledGameObjectScript.gameObject);
    }
Пример #12
0
        public static CResource GetResource(string fullPathInResources, Type resourceContentType, enResourceType resourceType, bool needCached = false, bool unloadBelongedAssetBundleAfterLoaded = false)
        {
            if (string.IsNullOrEmpty(fullPathInResources))
            {
                return(new CResource(0, string.Empty, null, resourceType, unloadBelongedAssetBundleAfterLoaded));
            }
            string s = CFileManager.EraseExtension(fullPathInResources);

            //int key = s.JavaHashCodeIgnoreCase();
            int key = s.GetHashCode();

            CResource resource = null;

            if (m_cachedResourceMap.TryGetValue(key, out resource))
            {
                if (resource.m_resourceType != resourceType)
                {
                    resource.m_resourceType = resourceType;
                }
                return(resource);
            }
            resource = new CResource(key, fullPathInResources, resourceContentType, resourceType, unloadBelongedAssetBundleAfterLoaded);
            try
            {
                LoadResource(resource);
            }
            catch (Exception exception)
            {
                object[] inParameters = new object[] { s };
                //DebugHelper.Assert(false, "Failed Load Resource {0}", inParameters);
                throw exception;
            }
            if (needCached)
            {
                m_cachedResourceMap.Add(key, resource);
            }
            return(resource);
        }
Пример #13
0
 private T LoadResource <T>(string path) where T : UnityEngine.Object
 {
     path = CFileManager.EraseExtension(path);
     return(Singleton <CResourceManager> .GetInstance().GetResource(path, typeof(T), enResourceType.BattleScene, true, false).m_content as T);
 }
Пример #14
0
 private string GetFormName(string formPath)
 {
     return(CFileManager.EraseExtension(CFileManager.GetFullName(formPath)));
 }