mirror of
https://github.com/BlackMATov/unity-flash-tools.git
synced 2025-12-13 11:39:54 +07:00
Fix preview leaks in the Editor mode
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
###### Version 1.3.15
|
||||
* Fix preview leaks in the Editor mode
|
||||
|
||||
###### Version 1.3.14
|
||||
* Fix 2018.3.2f1 compilation
|
||||
|
||||
|
||||
@@ -11,7 +11,8 @@ using FTRuntime;
|
||||
namespace FTEditor.Editors {
|
||||
[CustomEditor(typeof(SwfClipAsset)), CanEditMultipleObjects]
|
||||
class SwfClipAssetEditor : Editor {
|
||||
List<SwfClipAsset> _clips = new List<SwfClipAsset>();
|
||||
List<SwfClipAsset> _clips = new List<SwfClipAsset>();
|
||||
SwfClipAssetPreview _preview = null;
|
||||
|
||||
static string GetClipPath(SwfClipAsset clip) {
|
||||
return clip
|
||||
@@ -159,11 +160,31 @@ namespace FTEditor.Editors {
|
||||
void DrawGUINotes() {
|
||||
EditorGUILayout.Separator();
|
||||
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.",
|
||||
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
|
||||
@@ -172,6 +193,12 @@ namespace FTEditor.Editors {
|
||||
|
||||
void OnEnable() {
|
||||
_clips = targets.OfType<SwfClipAsset>().ToList();
|
||||
SetupPreviews();
|
||||
}
|
||||
|
||||
void OnDisable() {
|
||||
ShutdownPreviews();
|
||||
_clips.Clear();
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI() {
|
||||
@@ -188,7 +215,23 @@ namespace FTEditor.Editors {
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,6 @@ using System.Linq;
|
||||
using FTRuntime;
|
||||
|
||||
namespace FTEditor.Editors {
|
||||
[CustomPreview(typeof(SwfClipAsset))]
|
||||
class SwfClipAssetPreview : ObjectPreview {
|
||||
int _sequence = 0;
|
||||
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 {
|
||||
get {
|
||||
var clip = target as SwfClipAsset;
|
||||
@@ -135,17 +125,17 @@ namespace FTEditor.Editors {
|
||||
//
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
public void SetCurrentSequence(string sequence_name) {
|
||||
public void SetSequence(string sequence_name) {
|
||||
var clip = target as SwfClipAsset;
|
||||
_sequence = clip && clip.Sequences != null
|
||||
? Mathf.Max(0, clip.Sequences.FindIndex(p => p.Name == sequence_name))
|
||||
: 0;
|
||||
}
|
||||
|
||||
public void Shutdown() {
|
||||
_matPropBlock.Clear();
|
||||
_previewUtils.Cleanup();
|
||||
}
|
||||
public void Shutdown() {
|
||||
_matPropBlock.Clear();
|
||||
_previewUtils.Cleanup();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
//
|
||||
@@ -168,27 +158,35 @@ namespace FTEditor.Editors {
|
||||
}
|
||||
|
||||
public override void OnPreviewSettings() {
|
||||
var any_multi_sequences = m_Targets
|
||||
.OfType<SwfClipAsset>()
|
||||
.Any(p => p.Sequences != null && p.Sequences.Count > 1);
|
||||
if ( any_multi_sequences && GUILayout.Button("<", EditorStyles.miniButton) ) {
|
||||
--_sequence;
|
||||
var clip = m_Targets.Length == 1
|
||||
? m_Targets[0] as SwfClipAsset
|
||||
: null;
|
||||
|
||||
if ( !clip || clip.Sequences == null ) {
|
||||
return;
|
||||
}
|
||||
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]);
|
||||
|
||||
if ( clip.Sequences.Count > 1 ) {
|
||||
if ( GUILayout.Button("<", EditorStyles.miniButton) ) {
|
||||
--_sequence;
|
||||
if ( _sequence < 0 ) {
|
||||
_sequence = clip.Sequences.Count - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
GUILayout.Label(label_text, EditorStyles.whiteLabel);
|
||||
if ( any_multi_sequences && GUILayout.Button(">", EditorStyles.miniButton) ) {
|
||||
++_sequence;
|
||||
|
||||
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;
|
||||
if ( _sequence >= clip.Sequences.Count ) {
|
||||
_sequence = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -131,37 +131,41 @@ namespace FTEditor.Editors {
|
||||
}
|
||||
|
||||
void SetupPreviews() {
|
||||
ShutdownPreviews();
|
||||
foreach ( var clip in _clips.Where(p => !!p.clip) ) {
|
||||
var preview = new SwfClipAssetPreview();
|
||||
preview.Initialize(new Object[]{clip.clip});
|
||||
_previews.Add(clip, preview);
|
||||
}
|
||||
ShutdownPreviews();
|
||||
_previews = targets
|
||||
.OfType<SwfClip>()
|
||||
.Where(p => p.clip)
|
||||
.ToDictionary(p => p, p => {
|
||||
var preview = new SwfClipAssetPreview();
|
||||
preview.Initialize(new Object[] { p.clip });
|
||||
return preview;
|
||||
});
|
||||
}
|
||||
|
||||
void ShutdownPreviews() {
|
||||
foreach ( var p in _previews ) {
|
||||
p.Value.Shutdown();
|
||||
}
|
||||
_previews.Clear();
|
||||
}
|
||||
void ShutdownPreviews() {
|
||||
foreach ( var p in _previews ) {
|
||||
p.Value.Shutdown();
|
||||
}
|
||||
_previews.Clear();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
//
|
||||
// Messages
|
||||
//
|
||||
// ---------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------
|
||||
//
|
||||
// Messages
|
||||
//
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
void OnEnable() {
|
||||
void OnEnable() {
|
||||
_clips = targets.OfType<SwfClip>().ToList();
|
||||
SetupPreviews();
|
||||
}
|
||||
|
||||
void OnDisable() {
|
||||
ShutdownPreviews();
|
||||
}
|
||||
void OnDisable() {
|
||||
ShutdownPreviews();
|
||||
_clips.Clear();
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI() {
|
||||
public override void OnInspectorGUI() {
|
||||
serializedObject.Update();
|
||||
DrawDefaultInspector();
|
||||
DrawSequence();
|
||||
@@ -173,11 +177,11 @@ namespace FTEditor.Editors {
|
||||
}
|
||||
|
||||
public override bool RequiresConstantRepaint() {
|
||||
return _previews.Count > 0;
|
||||
return _clips.Count > 0;
|
||||
}
|
||||
|
||||
public override bool HasPreviewGUI() {
|
||||
return _previews.Count > 0;
|
||||
return _clips.Count > 0;
|
||||
}
|
||||
|
||||
public override void OnPreviewGUI(Rect r, GUIStyle background) {
|
||||
@@ -185,7 +189,7 @@ namespace FTEditor.Editors {
|
||||
SwfClipAssetPreview preview;
|
||||
var clip = target as SwfClip;
|
||||
if ( _previews.TryGetValue(clip, out preview) ) {
|
||||
preview.SetCurrentSequence(clip.sequence);
|
||||
preview.SetSequence(clip.sequence);
|
||||
preview.DrawPreview(r);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user