コード例 #1
0
        /// <summary>
        /// 卸载资源
        /// </summary>
        /// <param name="asset"></param>
        public void UnloadAssetAsync(UnityEngine.Object asset)
        {
            MDebug.Assert(asset != null, LOG_TAG, "asset != null");
            MDebug.Assert(m_AssetToAssetHandlerMap.ContainsKey(asset), LOG_TAG, "m_AssetToAssetHandlerMap.ContainsKey(asset)");

            if (asset == null || !m_AssetToAssetHandlerMap.ContainsKey(asset))
            {
                return;
            }
            AssetHandler assetHandler = m_AssetToAssetHandlerMap[asset];

            if (assetHandler == null)
            {
                MDebug.Log(LOG_TAG, $"UnloadAssetAsync({assetHandler.GetAssetKey()})");

                AssetAction assetAction = assetHandler.RemoveReference();
                switch (assetAction)
                {
                case AssetAction.Unload:
                    AddAssetActionRequest(assetHandler.GetAssetIndex(), AssetAction.Unload);
                    break;

                default:
                    MDebug.Log(LOG_TAG, "unload failed !");
                    break;
                }
            }
        }
コード例 #2
0
            public bool TryExecuteAction(AssetAction assetAction)
            {
                switch (assetAction)
                {
                case AssetAction.Load:
                    return(TryLoadAsset());

                case AssetAction.Unload:
                    return(TryUnloadAsset());

                case AssetAction.LoadedCallback:
                    try
                    {
                        m_OnAssetLoaded?.Invoke(m_AssetKey, m_Asset);
                    }
                    catch (Exception e)
                    {
                        MDebug.LogError(LOG_TAG, "LoadedCallBack Error \n\n" + e.ToString());
                    }
                    finally
                    {
                        m_OnAssetLoaded = null;
                    }
                    return(true);

                default:
                    MDebug.Assert(false, LOG_TAG, "Not support AssetAction: " + assetAction);
                    return(false);
                }
            }
コード例 #3
0
    private void OnGUI()
    {
        m_AssetObject = EditorGUILayout.ObjectField("Asset Object", m_AssetObject, typeof(Object), false);

        if (GUILayout.Button("Show Asset Path"))
        {
            if (m_AssetObject != null)
            {
                //Va nous donner le chemin d'acces a partir de 'Assets/...'
                string assetPath = AssetDatabase.GetAssetPath(m_AssetObject);
                string extension = Path.GetExtension(assetPath);
                // GUID est un ID (identifiant) généré automatiquement par unity lors de son importation et ne changera jamais.
                //tres utile quand on veut une référence sur un asset même si ce dernier se fais déplace/renommer
                Debug.Log(assetPath + " | " + extension + " | " + AssetDatabase.AssetPathToGUID(assetPath));
            }
        }
        m_AssetAction = (AssetAction)EditorGUILayout.EnumPopup("Action", m_AssetAction);
        ShowActionParameters();
        EditorGUI.BeginDisabledGroup(m_AssetObject == null);
        if (GUILayout.Button(m_AssetAction.ToString() + " asset"))
        {
            string assetPath = AssetDatabase.GetAssetPath(m_AssetObject);
            bool   needSave  = false;
            switch (m_AssetAction)
            {
            case AssetAction.Copy:
            case AssetAction.Move:
                //TODO Prochain cours!!!
                break;

            case AssetAction.Rename:
                if (!string.IsNullOrEmpty(m_Rename))
                {
                    // permet de renommer un string si aucune erreur, renboit string vide
                    string renameMessage = AssetDatabase.RenameAsset(assetPath, m_Rename);
                    needSave = string.IsNullOrEmpty(renameMessage);
                }
                break;

            case AssetAction.Open:
                //Permet d'ouvrir un asset delon le type de l'objet. unity se charge de l'ouvrir selon le bon programme
                AssetDatabase.OpenAsset(m_AssetObject);
                break;
            }
            if (needSave)
            {
                //Rafraici l'assetDatabase pour etre sur que tout est a jour
                AssetDatabase.Refresh();
                //Sauvegarde tous les changements dans l'assetdatabase
                AssetDatabase.SaveAssets();
            }
        }
        EditorGUI.EndDisabledGroup();
    }
コード例 #4
0
        /// <summary>
        /// 异步加载资源
        /// </summary>
        /// <param name="assetKey"></param>
        /// <param name="callback"></param>
        public void LoadAssetAsync(AssetKey assetKey, Action <AssetKey, UnityEngine.Object> callback)
        {
            MDebug.Log(LOG_TAG, $"LoadAssetAsync({assetKey})");
            MDebug.Assert(callback != null, LOG_TAG, "callback != null");

            int assetIndex = (int)assetKey;

            AssetHandler assetHandler = m_AssetHandlers[assetIndex];

            if (assetHandler == null)
            {
                assetHandler = m_AssetHandlerPool.Alloc();
                assetHandler.SetAssetKey(assetKey);
                m_AssetHandlers[assetIndex] = assetHandler;
            }

            AssetAction assetAction = assetHandler.AddReference(callback);

            switch (assetAction)
            {
            case AssetAction.RequestLoadBundle:
                int   bundleIndex            = m_AssetInfos[assetIndex].BundleIndex;
                int[] dependencyBundleIndexs = m_BundleInfos[bundleIndex].DependencyBundleIndexs;
                for (int iBundle = 0; iBundle < dependencyBundleIndexs.Length; iBundle++)
                {
                    int iterDependencyBundleIndex = dependencyBundleIndexs[iBundle];
                    LoadBundleForLoadAsset(iterDependencyBundleIndex, assetIndex);
                }
                LoadBundleForLoadAsset(bundleIndex, assetIndex);

                //全部依赖Bundle加载完成?

                if (assetHandler.GetRemainLoadBundleCount() == 0)
                {
                    AddAssetActionRequest(assetIndex, AssetAction.Load);
                }
                break;

            case AssetAction.Load:
            case AssetAction.LoadedCallback:
                AddAssetActionRequest(assetIndex, assetAction);
                break;

            case AssetAction.Null:
                // Nothing To Do
                break;

            default:
                MDebug.Assert(false, LOG_TAG, "Asset Not Support AssetAction: " + assetAction);
                break;
            }
        }
コード例 #5
0
    private void ShowActions()
    {
        EditorGUILayout.BeginVertical(GUI.skin.box);
        EditorGUILayout.LabelField("Action", EditorStyles.centeredGreyMiniLabel);
        //Sert à montrer en liste déroulante/dropdown un enum
        m_Action = (AssetAction)EditorGUILayout.EnumPopup("Action", m_Action);
        //Sert à montrer en liste déroulante/dropdown un string à partir d'un array de string
        int index = ArrayUtility.IndexOf(m_PopupExample, m_Animal);

        index = EditorGUILayout.Popup("Animal", index, m_PopupExample);
        if (index != -1)
        {
            m_Animal = m_PopupExample[index];
        }
        ShowParameters();
        ShowActionButton();
        EditorGUILayout.EndVertical();
    }
コード例 #6
0
    private void ShowActions()
    {
        EditorGUILayout.BeginVertical(GUI.skin.box);                               // crée une box comme style
        EditorGUILayout.LabelField("Actions", EditorStyles.centeredGreyMiniLabel); // Regroupe en rectangle clean

        // Liste déroulante (EnumPopup). On doit le caster en type de notre Enum pour le créer.
        m_Actions = (AssetAction)EditorGUILayout.EnumPopup("Actions ", m_Actions);

        // Pour un array de string: On peut utiliser Popup à partir d'un string[]
        int index = ArrayUtility.IndexOf(m_PopupExample, m_Animal);

        index = EditorGUILayout.Popup("Animals", index, m_PopupExample);
        if (index != -1)
        {
            m_Animal = m_PopupExample[index];
        }

        ShowParameters();
        ShowActionButton();

        EditorGUILayout.EndVertical();
    }
コード例 #7
0
        private void AddActions()
        {
            if (!_context.AssetActions.Any())
            {
                _logger.LogInformation("Add asset actions");
                var buy = new AssetAction()
                {
                    Name = SeedFinanceData.BUY_ACTION
                };

                var sell = new AssetAction()
                {
                    Name = SeedFinanceData.SELL_ACTION
                };

                _context.AssetActions.AddRange(buy, sell);
                _context.SaveChanges();
                _logger.LogInformation("Added asset actions successfully");
            }

            if (!_context.CurrencyActions.Any())
            {
                _logger.LogInformation("Add currency actions");
                var refill = new CurrencyAction()
                {
                    Name = SeedFinanceData.REFILL_ACTION
                };

                var withdrawal = new CurrencyAction()
                {
                    Name = SeedFinanceData.WITHDRAWAL_ACTION
                };

                _context.CurrencyActions.AddRange(refill, withdrawal);
                _context.SaveChanges();
                _logger.LogInformation("Added currency actions successfully");
            }
        }
コード例 #8
0
 private void AddAssetActionRequest(AssetKey assetKey, AssetAction assetAction)
 {
     AddAssetActionRequest((int)assetKey, assetAction);
 }
コード例 #9
0
 /// <summary>
 /// 资源操作请求,统一在LateUpdate中处理
 /// </summary>
 /// <param name="assetIndex"></param>
 /// <param name="assetAction"></param>
 private void AddAssetActionRequest(int assetIndex, AssetAction assetAction)
 {
     m_AssetActionRequests.Enqueue(new AssetActionRequest(assetIndex, assetAction));
 }
コード例 #10
0
 public AssetActionRequest(int assetIndex, AssetAction assetAction)
 {
     AssetIndex  = assetIndex;
     AssetAction = assetAction;
 }