Пример #1
0
        public LookupData(SimAssetBank bank)
        {
            if (bank == null)
            {
                throw new ArgumentNullException(nameof(bank));
            }

            SimAssetTechTypes = new NativeList <ViewTechType>(Allocator.Persistent);
            SimAssets         = new List <SimAsset>(bank._simAssets.Count);
            EditIdToRuntimeId = new Dictionary <string, SimAssetId>(bank._simAssets.Count);

            int count = bank._simAssets.Count;

            for (int i = 0; i < count; i++)
            {
                var asset = bank._simAssets[i];

                if (asset != null)
                {
                    int v = SimAssets.Count + 1;
                    if (v > ushort.MaxValue)
                    {
                        Log.Error($"Too many SimAssets! We are exceeding the maximal SimAssetId value of {ushort.MaxValue}.");
                        break;
                    }

                    SimAssetId assetId = new SimAssetId((ushort)v);

                    SimAssets.Add(asset);
                    EditIdToRuntimeId.Add(asset.Guid, assetId);
                    SimAssetTechTypes.Add(asset.ViewTechType);
                }
            }
        }
    public static void UpdateSimAssetIds()
    {
        SimAssetBank bank = AssetDatabaseX.LoadOrCreateScriptableObjectAsset <SimAssetBank>(ASSET_PATH);

        bank.EditorSimAssets.Clear();

        AssetDatabaseX.LoadPrefabAssetsWithComponentOnRoot <SimAsset>(out List <KeyValuePair <string, GameObject> > loadResult);
        foreach (KeyValuePair <string, GameObject> item in loadResult)
        {
            var prefab = item.Value.GetComponent <SimAsset>();

            ValidateSimAssetIdForPrefab(prefab);

            bank.EditorSimAssets.Add(prefab);
        }

        DebugEditor.LogAssetIntegrity($"[{nameof(SimAssetBankUpdater)}] Updated {typeof(SimAssetBank)}");

        EditorUtility.SetDirty(bank);
        AssetDatabase.SaveAssets();
    }
    static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
    {
        if (AssetPostprocessorUtility.ExitImportLoop(importedAssets, ASSET_PATH, ref s_importLoopCounter))
        {
            return;
        }

        SimAssetBank bank      = null;
        bool         saveAsset = false;

        importedAssets.Where((assetPath) => assetPath.EndsWith(".prefab"))
        .Select((assetPath) => AssetDatabase.LoadAssetAtPath <GameObject>(assetPath))
        .Where((gameObject) => gameObject.GetComponent <SimAsset>() != null)
        .Select((gameObject) => gameObject.GetComponent <SimAsset>())
        .ToList()
        .ForEach((SimAsset prefab) =>
        {
            if (bank == null)
            {
                bank = AssetDatabaseX.LoadOrCreateScriptableObjectAsset <SimAssetBank>(ASSET_PATH);
            }

            saveAsset |= ValidateSimAssetIdForPrefab(prefab);

            if (!bank.EditorSimAssets.Contains(prefab))
            {
                saveAsset = true;
                bank.EditorSimAssets.Add(prefab);

                DebugEditor.LogAssetIntegrity($"Added {prefab.gameObject.name} to {nameof(SimAssetBank)}.");
            }
        });

        if (saveAsset)
        {
            EditorUtility.SetDirty(bank);
            AssetDatabase.SaveAssets();
        }
    }