Fix preview leaks in the Editor mode

This commit is contained in:
2019-03-22 05:53:14 +07:00
parent faca20e535
commit ca52ce93d2
6 changed files with 113 additions and 62 deletions

1
.gitignore vendored
View File

@@ -1,4 +1,5 @@
obj/* obj/*
Logs/*
Temp/* Temp/*
Library/* Library/*

View File

@@ -1,3 +1,6 @@
###### Version 1.3.15
* Fix preview leaks in the Editor mode
###### Version 1.3.14 ###### Version 1.3.14
* Fix 2018.3.2f1 compilation * Fix 2018.3.2f1 compilation

View File

@@ -12,6 +12,7 @@ namespace FTEditor.Editors {
[CustomEditor(typeof(SwfClipAsset)), CanEditMultipleObjects] [CustomEditor(typeof(SwfClipAsset)), CanEditMultipleObjects]
class SwfClipAssetEditor : Editor { class SwfClipAssetEditor : Editor {
List<SwfClipAsset> _clips = new List<SwfClipAsset>(); List<SwfClipAsset> _clips = new List<SwfClipAsset>();
SwfClipAssetPreview _preview = null;
static string GetClipPath(SwfClipAsset clip) { static string GetClipPath(SwfClipAsset clip) {
return clip return clip
@@ -159,11 +160,31 @@ namespace FTEditor.Editors {
void DrawGUINotes() { void DrawGUINotes() {
EditorGUILayout.Separator(); EditorGUILayout.Separator();
EditorGUILayout.HelpBox( EditorGUILayout.HelpBox(
"Masks and blends of animation may not be displayed correctly in preview window. " + "Masks and blends of animation may not be displayed correctly in the preview window. " +
"Instance animation to the scene, to see how it will look like the animation in the game.", "Instance animation to the scene, to see how it will look like the animation in the game.",
MessageType.Info); MessageType.Info);
} }
//
//
//
void SetupPreviews() {
ShutdownPreviews();
_preview = new SwfClipAssetPreview();
_preview.Initialize(targets
.OfType<SwfClipAsset>()
.Where(p => p)
.ToArray());
}
void ShutdownPreviews() {
if ( _preview != null ) {
_preview.Shutdown();
_preview = null;
}
}
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// //
// Messages // Messages
@@ -172,6 +193,12 @@ namespace FTEditor.Editors {
void OnEnable() { void OnEnable() {
_clips = targets.OfType<SwfClipAsset>().ToList(); _clips = targets.OfType<SwfClipAsset>().ToList();
SetupPreviews();
}
void OnDisable() {
ShutdownPreviews();
_clips.Clear();
} }
public override void OnInspectorGUI() { public override void OnInspectorGUI() {
@@ -188,7 +215,23 @@ namespace FTEditor.Editors {
} }
public override bool RequiresConstantRepaint() { public override bool RequiresConstantRepaint() {
return true; return _clips.Count > 0;
}
public override bool HasPreviewGUI() {
return _clips.Count > 0;
}
public override void OnPreviewSettings() {
if ( _preview != null ) {
_preview.OnPreviewSettings();
}
}
public override void OnPreviewGUI(Rect r, GUIStyle background) {
if ( _preview != null ) {
_preview.OnPreviewGUI(r, background);
}
} }
} }
} }

View File

@@ -6,7 +6,6 @@ using System.Linq;
using FTRuntime; using FTRuntime;
namespace FTEditor.Editors { namespace FTEditor.Editors {
[CustomPreview(typeof(SwfClipAsset))]
class SwfClipAssetPreview : ObjectPreview { class SwfClipAssetPreview : ObjectPreview {
int _sequence = 0; int _sequence = 0;
MaterialPropertyBlock _matPropBlock = null; MaterialPropertyBlock _matPropBlock = null;
@@ -33,15 +32,6 @@ namespace FTEditor.Editors {
} }
} }
int targetSequenceCount {
get {
var clip = target as SwfClipAsset;
return clip && clip.Sequences != null
? clip.Sequences.Count
: 0;
}
}
SwfClipAsset.Frame targetFrame { SwfClipAsset.Frame targetFrame {
get { get {
var clip = target as SwfClipAsset; var clip = target as SwfClipAsset;
@@ -135,7 +125,7 @@ namespace FTEditor.Editors {
// //
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
public void SetCurrentSequence(string sequence_name) { public void SetSequence(string sequence_name) {
var clip = target as SwfClipAsset; var clip = target as SwfClipAsset;
_sequence = clip && clip.Sequences != null _sequence = clip && clip.Sequences != null
? Mathf.Max(0, clip.Sequences.FindIndex(p => p.Name == sequence_name)) ? Mathf.Max(0, clip.Sequences.FindIndex(p => p.Name == sequence_name))
@@ -168,27 +158,35 @@ namespace FTEditor.Editors {
} }
public override void OnPreviewSettings() { public override void OnPreviewSettings() {
var any_multi_sequences = m_Targets var clip = m_Targets.Length == 1
.OfType<SwfClipAsset>() ? m_Targets[0] as SwfClipAsset
.Any(p => p.Sequences != null && p.Sequences.Count > 1); : null;
if ( any_multi_sequences && GUILayout.Button("<", EditorStyles.miniButton) ) {
if ( !clip || clip.Sequences == null ) {
return;
}
if ( clip.Sequences.Count > 1 ) {
if ( GUILayout.Button("<", EditorStyles.miniButton) ) {
--_sequence; --_sequence;
if ( _sequence < 0 ) {
_sequence = clip.Sequences.Count - 1;
} }
var sequence_names = m_Targets
.OfType<SwfClipAsset>()
.Select (p => GetSequenceForClip(p, _sequence))
.Where (p => p != null && !string.IsNullOrEmpty(p.Name))
.Select (p => p.Name)
.ToArray();
var label_text = string.Empty;
for ( int i = 0, e = sequence_names.Length; i < e; ++i ) {
label_text += string.Format(
i > 0 ? ", {0}" : "{0}",
sequence_names[i]);
} }
GUILayout.Label(label_text, EditorStyles.whiteLabel); }
if ( any_multi_sequences && GUILayout.Button(">", EditorStyles.miniButton) ) {
var sequence = GetSequenceForClip(clip, _sequence);
if ( sequence != null && !string.IsNullOrEmpty(sequence.Name) ) {
GUILayout.Label(sequence.Name, EditorStyles.whiteLabel);
}
if ( clip.Sequences.Count > 1 ) {
if ( GUILayout.Button(">", EditorStyles.miniButton) ) {
++_sequence; ++_sequence;
if ( _sequence >= clip.Sequences.Count ) {
_sequence = 0;
}
}
} }
} }

View File

@@ -132,11 +132,14 @@ namespace FTEditor.Editors {
void SetupPreviews() { void SetupPreviews() {
ShutdownPreviews(); ShutdownPreviews();
foreach ( var clip in _clips.Where(p => !!p.clip) ) { _previews = targets
.OfType<SwfClip>()
.Where(p => p.clip)
.ToDictionary(p => p, p => {
var preview = new SwfClipAssetPreview(); var preview = new SwfClipAssetPreview();
preview.Initialize(new Object[]{clip.clip}); preview.Initialize(new Object[] { p.clip });
_previews.Add(clip, preview); return preview;
} });
} }
void ShutdownPreviews() { void ShutdownPreviews() {
@@ -159,6 +162,7 @@ namespace FTEditor.Editors {
void OnDisable() { void OnDisable() {
ShutdownPreviews(); ShutdownPreviews();
_clips.Clear();
} }
public override void OnInspectorGUI() { public override void OnInspectorGUI() {
@@ -173,11 +177,11 @@ namespace FTEditor.Editors {
} }
public override bool RequiresConstantRepaint() { public override bool RequiresConstantRepaint() {
return _previews.Count > 0; return _clips.Count > 0;
} }
public override bool HasPreviewGUI() { public override bool HasPreviewGUI() {
return _previews.Count > 0; return _clips.Count > 0;
} }
public override void OnPreviewGUI(Rect r, GUIStyle background) { public override void OnPreviewGUI(Rect r, GUIStyle background) {
@@ -185,7 +189,7 @@ namespace FTEditor.Editors {
SwfClipAssetPreview preview; SwfClipAssetPreview preview;
var clip = target as SwfClip; var clip = target as SwfClip;
if ( _previews.TryGetValue(clip, out preview) ) { if ( _previews.TryGetValue(clip, out preview) ) {
preview.SetCurrentSequence(clip.sequence); preview.SetSequence(clip.sequence);
preview.DrawPreview(r); preview.DrawPreview(r);
} }
} }

View File

@@ -71,6 +71,8 @@ https://gist.github.com/talecrafter/111ea3345911bd238f4998b4d5a04bf3
UNITY_UV_STARTS_AT_TOP UNITY_UV_STARTS_AT_TOP
UNITY_HALF_TEXEL_OFFSET UNITY_HALF_TEXEL_OFFSET
** TODO Версия 1.3.15 ** TODO Версия 1.3.15
*** Баги
**** DONE Утечка превью в редакторе
*** Улучшения *** Улучшения
**** TODO Выводить в лог успешную конвертацию с контекстом **** TODO Выводить в лог успешную конвертацию с контекстом
**** TODO Триммить изображения из swf (adou.fla) **** TODO Триммить изображения из swf (adou.fla)