private void OnEnable() { m_AsepriteObjects = new CAsepriteObject[targets.Length]; for (int i = 0; i < targets.Length; i++) { AssetImporter tImporter = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(targets[i])); if (tImporter == null) { continue; } JSONNode tData = JSON.Parse(tImporter.userData); if (tData == null) { tData = new JSONObject(); } JSONNode tID = tData["assetID"]; if (tID != null) { m_AsepriteObjects[i] = CAsepritePostProcesor.GetAssetByID <CAsepriteObject>(tID.Value); if (m_AsepriteObjects[i] == null) { m_AsepriteObjects[i] = CAsepritePostProcesor.FindAsepriteObject(targets[i]); } //Debug.Log(tID.Value); } if (m_AsepriteObjects[i] != null) { tID.Value = CAsepritePostProcesor.GetIDByAsset(m_AsepriteObjects[i]); tImporter.userData = tData.ToString(); } } }
public override void OnInspectorGUI() { int tNotImported = 0; foreach (CAsepriteObject tObj in m_AsepriteObjects) { if (tObj == null) { tNotImported++; } } if (tNotImported > 0) { GUILayout.Label("No imported asset found for " + tNotImported + " file" + (tNotImported > 1 ? "s" : "")); if (GUILayout.Button(ButtonContentImport, GUILayout.MaxHeight(60))) { for (int i = 0; i < targets.Length; i++) { if (m_AsepriteObjects[i] == null) { Object tTarget = targets[i]; string tPath = AssetDatabase.GetAssetPath(tTarget); m_AsepriteObjects[i] = CAsepriteObjectEditor.CreateAsset(tPath); m_AsepriteObjects[i].asepriteAsset = tTarget; CAsepriteObjectEditor.Import(tPath, m_AsepriteObjects[i]); AssetImporter tImporter = AssetImporter.GetAtPath(tPath); JSONNode tData = JSON.Parse(tImporter.userData); if (tData == null) { tData = new JSONObject(); } tData["assetID"] = CAsepritePostProcesor.GetIDByAsset(m_AsepriteObjects[i]); tImporter.userData = tData.ToString(); EditorUtility.SetDirty(tTarget); EditorUtility.SetDirty(m_AsepriteObjects[i]); AssetDatabase.WriteImportSettingsIfDirty(tPath); } } } } else { if (GUILayout.Button("Select imported asset", GUILayout.MaxHeight(60))) { for (int i = 0; i < targets.Length; i++) { m_AsepriteObjects[i].asepriteAsset = targets[i]; EditorUtility.SetDirty(m_AsepriteObjects[i]); } Selection.objects = m_AsepriteObjects; } } }
public override void OnInspectorGUI() { int assetLost = 0; for (int i = 0; i < m_AssetTargets.Length; i++) { if (m_AssetTargets[i].asepriteAsset == null) { var asset = CAsepritePostProcesor.FindAsepriteAsset( m_AssetTargets[i]); if (asset != null) { m_AssetTargets[i].asepriteAsset = asset; EditorUtility.SetDirty(m_AssetTargets[i]); } else { assetLost++; } } } if (assetLost > 0) { GUILayout.Label((assetLost > 1 ? "These objects" : "This object") + " lost connection to " + (assetLost > 1 ? "their assets" : "its asset")); if (m_AssetTargets.Length > 1) { GUILayout.Label("Select " + (assetLost > 1 ? "one" : "it") + " to fix it"); for (int i = 0; i < m_AssetTargets.Length; i++) { if (m_AssetTargets[i].asepriteAsset == null) { if (GUILayout.Button(m_AssetTargets[i].name)) { Selection.activeObject = m_AssetTargets[i]; } } } } else { GUILayout.Label("Select the correct asset to fix it"); var obj = EditorGUILayout.ObjectField(null, typeof(Object), false); if (obj != null) { string path = AssetDatabase.GetAssetPath(obj); if (path.ToLower().EndsWith(".ase")) { m_AssetTargets[0].asepriteAsset = obj; } } } return; } GUILayout.Label("Assets", EditorStyles.boldLabel); GUILayout.BeginVertical(CAsepriteGUIData.Box); ShowProperty(m_TargetTexture, CAsepriteGUIData.TargetTexture); ShowProperty(m_TargetAtlas, CAsepriteGUIData.TargetAtlas); GUILayout.EndVertical(); // Configuration GUILayout.Label("Configuration", EditorStyles.boldLabel); GUILayout.BeginVertical(CAsepriteGUIData.Box); ShowProperty(m_UseTags, CAsepriteGUIData.UseTags); ShowProperty(m_LoopAnim, CAsepriteGUIData.LoopAnim); ShowProperty(m_UseConfig, CAsepriteGUIData.UseConfig); ShowProperty(m_Border, CAsepriteGUIData.Border); ShowProperty(m_UseChild, CAsepriteGUIData.UseChild); // Alignment EditorGUI.showMixedValue = m_Alignment.mixed; EditorGUI.BeginChangeCheck(); m_Alignment.value = (SpriteAlignment)EditorGUILayout.EnumPopup( CAsepriteGUIData.Alignment, m_Alignment.value); if (EditorGUI.EndChangeCheck()) { m_Alignment.dirty = true; m_Alignment.mixed = false; } // Pivot EditorGUI.BeginDisabledGroup(m_Alignment.value != SpriteAlignment.Custom || m_Alignment.mixed); EditorGUI.showMixedValue = m_Pivot.mixed; EditorGUI.BeginChangeCheck(); m_Pivot.value = EditorGUILayout.Vector2Field( CAsepriteGUIData.Pivot, m_Pivot.value); if (EditorGUI.EndChangeCheck()) { m_Pivot.dirty = true; m_Pivot.mixed = false; } EditorGUI.EndDisabledGroup(); // Anim type EditorGUI.showMixedValue = m_AnimType.mixed; EditorGUI.BeginChangeCheck(); m_AnimType.value = (AnimationType)EditorGUILayout.EnumPopup( CAsepriteGUIData.AnimType, m_AnimType.value); if (EditorGUI.EndChangeCheck()) { m_AnimType.dirty = true; m_AnimType.mixed = false; } EditorGUI.showMixedValue = false; GUILayout.EndVertical(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button(ButtonContentPrefab, GUILayout.MaxHeight(64))) { foreach (CAsepriteObject tObj in m_AssetTargets) { CAsepriteWindow.CreatePrefab(tObj); } } if (GUILayout.Button(ButtonContentSettings, GUILayout.MaxHeight(64))) { CAsepriteWindow.ShowWindow(); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); EditorGUI.BeginDisabledGroup(!IsDirty); if (GUILayout.Button("Revert")) { RevertChanges(); } if (GUILayout.Button("Apply")) { ApplyChanges(); } EditorGUI.EndDisabledGroup(); GUILayout.EndHorizontal(); }