private void Start() { //基础组件 BaseComponent baseComponent = GameEntry.GetComponent <BaseComponent>(); if (baseComponent == null) { Log.Fatal("[ResourceComponent.Start] Base component is invalid -> baseComponent == null."); return; } //事件组件 m_EventComponent = GameEntry.GetComponent <EventComponent>(); if (m_EventComponent == null) { Log.Fatal("[ResourceComponent.Start] Event component is invalid -> m_EventComponent == null."); return; } //资源管理器 ResourceManager = baseComponent.ResourceManager; if (ResourceManager == null) { Log.Fatal("[ResourceComponent.Start] Resource manager is invalid -> m_ResourceManager == null."); return; } //绑定事件 ResourceManager.ResourceUpdateStart += OnResourceUpdateStart; ResourceManager.ResourceUpdateChanged += OnResourceUpdateChanged; ResourceManager.ResourceUpdateSuccess += OnResourceUpdateSuccess; ResourceManager.ResourceUpdateFailure += OnResourceUpdateFailure; ResourceManager.SetReadOnlyPath(Application.streamingAssetsPath); //设置只读路径 if (m_ReadWritePathType == ReadWritePathType.TemporaryCache) { ResourceManager.SetReadWritePath(Application.temporaryCachePath); } else { if (m_ReadWritePathType == ReadWritePathType.Unspecified) { m_ReadWritePathType = ReadWritePathType.PersistentData; } ResourceManager.SetReadWritePath(Application.persistentDataPath); } #if UNITY_EDITOR m_IsEditorResourceMode = baseComponent.IsEditorResourceMode; if (m_IsEditorResourceMode) //编辑器模式直接返回即可 { return; } #endif SetResourceMode(m_ResourceMode); ResourceManager.SetDownloadManager(GameFrameworkEntry.GetModule <IDownloadManager>()); //设置下载管理器 ResourceManager.SetObjectPoolManager(GameFrameworkEntry.GetModule <IObjectPoolManager>()); //设置对象池管理器 ResourceManager.AssetAutoReleaseInterval = m_AssetAutoReleaseInterval; ResourceManager.AssetCapacity = m_AssetCapacity; ResourceManager.AssetExpireTime = m_AssetExpireTime; ResourceManager.AssetPriority = m_AssetPriority; ResourceManager.ResourceAutoReleaseInterval = m_ResourceAutoReleaseInterval; ResourceManager.ResourceCapacity = m_ResourceCapacity; ResourceManager.ResourceExpireTime = m_ResourceExpireTime; ResourceManager.ResourcePriority = m_ResourcePriority; if (m_ResourceMode == ResourceMode.Updatable) { ResourceManager.UpdatePrefixUri = m_UpdatePrefixUri; ResourceManager.UpdateFileCacheLength = m_UpdateFileCacheLength; ResourceManager.GenerateReadWriteListLength = m_GenerateReadWriteListLength; ResourceManager.UpdateRetryCount = m_UpdateRetryCount; } //资源辅助器 m_ResourceHelper = Helper.CreateHelper(m_ResourceHelperTypeName, m_CustomResourceHelper); if (m_ResourceHelper == null) { Log.Error("[ResourceComponent.Start] Can not create resource helper -> m_ResourceHelper == null."); return; } m_ResourceHelper.name = "Resource Helper"; Transform trans = m_ResourceHelper.transform; trans.SetParent(transform); transform.localScale = Vector3.one; ResourceManager.SetResourceHelper(m_ResourceHelper); if (m_InstanceRoot == null) { m_InstanceRoot = new GameObject("Load Resource Agent Instances").transform; m_InstanceRoot.SetParent(transform); m_InstanceRoot.localScale = Vector3.one; } for (int i = 0; i < m_LoadResourceAgentHelperCount; i++) { AddLoadResourceAgentHelper(i); } }