private void SetImportMaterialsEnabled(bool?enabled) { string path = AssetDatabase.GetAssetPath(_asset); var importer = AssetImporter.GetAtPath(path); CustomAssetData data = CustomAssetData.Get(_asset) ?? new CustomAssetData(); data.importMaterialColors = enabled; CustomAssetData.Set(path, data); // if (enabled) { (importer as ModelImporter).materialImportMode = ModelImporterMaterialImportMode.None; } AssetDatabase.ImportAsset(path); OnImportMaterialsChangedEvent?.Invoke(); }
private void ApplyChangeToMeshes(string multipleWarning, MeshDataAction action) { // Dialogue popup warning var selectedIndices = _previewColorElement.GetSelectedIndices(); var colourSlotsCount = selectedIndices.Count; if (colourSlotsCount > 1) { if (!EditorUtility.DisplayDialog("Multiple mesh confirmation", $"You have {colourSlotsCount} colour slots selected. {multipleWarning}", "Yes", "No")) { return; } } var modelData = new Dictionary <GameObject, CustomAssetData>(); var meshColors = selectedIndices.Select(i => i >= _previewColorElement.ColourSlotCount ? _colourSlotsWithoutColours[i - _previewColorElement.ColourSlotCount] : _previewColours[i]); // Empty colour slots indexed from 0 after slot count exceeded foreach (var meshColor in meshColors) { var mesh = meshColor.mesh; var index = meshColor.materialIndex; var asset = _meshModelDictionary[meshColor.mesh]; if (!modelData.ContainsKey(asset)) { CustomAssetData data = CustomAssetData.Get(asset) ?? new CustomAssetData(); modelData.Add(asset, data); } modelData[asset] = action(mesh, index, modelData[asset]); } foreach (var data in modelData) { string path = AssetDatabase.GetAssetPath(data.Key); CustomAssetData.Set(data.Key, data.Value); AssetDatabase.ImportAsset(path); } _modelDataDictionary.Clear(); OnSelectionChanged(); }
private void ApplyChangeToModels(string multipleWarning, ModelDataAction action) { // Dialogue popup warning if (_selectedModels.Count > 1) { if (!EditorUtility.DisplayDialog("Multiple asset confirmation", $"You have {_selectedModels.Count} assets selected. {multipleWarning}", "Yes", "No")) { return; } } foreach (var model in _selectedModels) { string path = AssetDatabase.GetAssetPath(model); CustomAssetData data = CustomAssetData.Get(model) ?? new CustomAssetData(); data = action(model, data); CustomAssetData.Set(path, data); AssetDatabase.ImportAsset(path); } _modelDataDictionary.Clear(); OnSelectionChanged(); }