public static void CreateAsset(string path, byte[] data) { EffekseerResourcePath resourcePath = new EffekseerResourcePath(); if (!ReadResourcePath(data, ref resourcePath)) { return; } float defaultScale = 1.0f; string assetPath = Path.ChangeExtension(path, ".asset"); var asset = AssetDatabase.LoadAssetAtPath <EffekseerEffectAsset>(assetPath); if (asset != null) { defaultScale = asset.Scale; } string assetDir = assetPath.Substring(0, assetPath.LastIndexOf('/')); bool isNewAsset = false; if (asset == null) { isNewAsset = true; asset = CreateInstance <EffekseerEffectAsset>(); } asset.efkBytes = data; asset.textureResources = new EffekseerTextureResource[resourcePath.TexturePathList.Count]; for (int i = 0; i < resourcePath.TexturePathList.Count; i++) { asset.textureResources[i] = EffekseerTextureResource.LoadAsset(assetDir, resourcePath.TexturePathList[i]); if (asset.textureResources[i].texture == null) { Debug.LogWarning(string.Format("Failed to load {0}", resourcePath.TexturePathList[i])); } } asset.soundResources = new EffekseerSoundResource[resourcePath.SoundPathList.Count]; for (int i = 0; i < resourcePath.SoundPathList.Count; i++) { asset.soundResources[i] = EffekseerSoundResource.LoadAsset(assetDir, resourcePath.SoundPathList[i]); if (asset.soundResources[i].clip == null) { Debug.LogWarning(string.Format("Failed to load {0}", resourcePath.SoundPathList[i])); } } asset.modelResources = new EffekseerModelResource[resourcePath.ModelPathList.Count]; for (int i = 0; i < resourcePath.ModelPathList.Count; i++) { asset.modelResources[i] = EffekseerModelResource.LoadAsset(assetDir, resourcePath.ModelPathList[i]); if (asset.modelResources[i].asset == null) { Debug.LogWarning(string.Format("Failed to load {0}", resourcePath.ModelPathList[i])); } } asset.materialResources = new EffekseerMaterialResource[resourcePath.MaterialPathList.Count]; for (int i = 0; i < resourcePath.MaterialPathList.Count; i++) { asset.materialResources[i] = EffekseerMaterialResource.LoadAsset(assetDir, resourcePath.MaterialPathList[i]); if (asset.materialResources[i].asset == null) { Debug.LogWarning(string.Format("Failed to load {0}", resourcePath.MaterialPathList[i])); } } asset.curveResources = new EffekseerCurveResource[resourcePath.CurvePathList.Count]; for (int i = 0; i < resourcePath.CurvePathList.Count; i++) { asset.curveResources[i] = EffekseerCurveResource.LoadAsset(assetDir, resourcePath.CurvePathList[i]); if (asset.curveResources[i].asset == null) { Debug.LogWarning(string.Format("Failed to load {0}", resourcePath.CurvePathList[i])); } } asset.Scale = defaultScale; if (isNewAsset) { AssetDatabase.CreateAsset(asset, assetPath); } else { EditorUtility.SetDirty(asset); } AssetDatabase.Refresh(); }
public override void OnInspectorGUI() { var asset = target as EffekseerEffectAsset; if (asset == null) { return; } EditorGUILayout.LabelField("Data Size", asset.efkBytes.Length.ToString() + " bytes"); var scale = EditorGUILayout.FloatField("Scale", asset.Scale); scale = Math.Max(0, scale); if (asset.Scale != scale) { asset.Scale = scale; EditorUtility.SetDirty(asset); } textureVisible = EditorGUILayout.Foldout(textureVisible, "Texture Resources: " + asset.textureResources.Length); if (textureVisible) { EditorGUI.indentLevel++; foreach (var res in asset.textureResources) { if (EffekseerTextureResource.InspectorField(res)) { EditorUtility.SetDirty(asset); } } EditorGUI.indentLevel--; } soundVisible = EditorGUILayout.Foldout(soundVisible, "Sound Resources: " + asset.soundResources.Length); if (soundVisible) { EditorGUI.indentLevel++; foreach (var res in asset.soundResources) { if (EffekseerSoundResource.InspectorField(res)) { EditorUtility.SetDirty(asset); } } EditorGUI.indentLevel--; } modelVisible = EditorGUILayout.Foldout(modelVisible, "Model Resources: " + asset.modelResources.Length); if (modelVisible) { EditorGUI.indentLevel++; foreach (var res in asset.modelResources) { if (EffekseerModelResource.InspectorField(res)) { EditorUtility.SetDirty(asset); } } EditorGUI.indentLevel--; } if (asset.materialResources != null) { materialVisible = EditorGUILayout.Foldout(materialVisible, "Material Resources: " + asset.materialResources.Length); if (materialVisible) { EditorGUI.indentLevel++; foreach (var res in asset.materialResources) { if (EffekseerMaterialResource.InspectorField(res)) { EditorUtility.SetDirty(asset); } } EditorGUI.indentLevel--; } } if (asset.curveResources != null) { curveVisible = EditorGUILayout.Foldout(curveVisible, "Curve Resources: " + asset.curveResources.Length); if (curveVisible) { EditorGUI.indentLevel++; foreach (var res in asset.curveResources) { if (EffekseerCurveResource.InspectorField(res)) { EditorUtility.SetDirty(asset); } } EditorGUI.indentLevel--; } } }