show clips for container asset in editor

This commit is contained in:
2016-09-10 15:04:35 +07:00
parent fd0fae1590
commit a5c9d21b66
4 changed files with 65 additions and 8 deletions

View File

@@ -145,7 +145,7 @@ Camera:
far clip plane: 1000
field of view: 60
orthographic: 1
orthographic size: 3
orthographic size: 5
m_Depth: 0
m_CullingMask:
serializedVersion: 2

View File

@@ -9,6 +9,7 @@ namespace FlashTools.Internal {
[CustomEditor(typeof(SwfAsset)), CanEditMultipleObjects]
public class SwfAssetEditor : Editor {
List<SwfAsset> _assets = new List<SwfAsset>();
bool _clipsFoldout = false;
bool _settingsFoldout = false;
//
@@ -28,6 +29,14 @@ namespace FlashTools.Internal {
: Path.ChangeExtension(asset_path, ".swf");
}
static SwfSettings _defaultSettingsCache = null;
static SwfSettings GetDefaultSettings() {
if ( !_defaultSettingsCache ) {
_defaultSettingsCache = SwfSettings.GetHolder();
}
return _defaultSettingsCache;
}
//
//
//
@@ -37,7 +46,7 @@ namespace FlashTools.Internal {
}
static void OverriddenSettingsToDefault(SwfAsset asset) {
asset.Overridden = SwfSettings.GetDefault();
asset.Overridden = GetDefaultSettings().Settings;
}
static void ApplyOverriddenSettings(SwfAsset asset) {
@@ -104,6 +113,48 @@ namespace FlashTools.Internal {
}
}
void DrawGUIDefaultSettings() {
SwfEditorUtils.DoWithEnabledGUI(false, () => {
EditorGUILayout.ObjectField(
"Default Settings",
GetDefaultSettings(),
typeof(SwfSettings),
false);
});
}
void DrawGUIClips() {
var asset = _assets.Count == 1 ? _assets.First() : null;
if ( asset && asset.Clips != null && asset.Clips.Count > 0 ) {
_clipsFoldout = EditorGUILayout.Foldout(_clipsFoldout, "Clips");
if ( _clipsFoldout ) {
SwfEditorUtils.DoWithEnabledGUI(false, () => {
var clip_count = Mathf.Min(asset.Data.Symbols.Count, asset.Clips.Count);
for ( var i = 0; i < clip_count; ++i ) {
EditorGUILayout.ObjectField(
asset.Data.Symbols[i].Name,
asset.Clips[i],
typeof(SwfClipAsset),
false);
}
});
DrawGUIClipsControls();
}
}
}
void DrawGUIClipsControls() {
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
{
if ( GUILayout.Button("Reimport all") ) {
RevertAllOverriddenSettings();
ApplyAllOverriddenSettings();
}
}
GUILayout.EndHorizontal();
}
void DrawGUISettings() {
_settingsFoldout = EditorGUILayout.Foldout(_settingsFoldout, "Settings");
if ( _settingsFoldout ) {
@@ -119,7 +170,7 @@ namespace FlashTools.Internal {
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
{
var default_settings = SwfSettings.GetDefault();
var default_settings = GetDefaultSettings().Settings;
SwfEditorUtils.DoWithEnabledGUI(
_assets.Any(p => !p.Overridden.CheckEquals(default_settings)), () => {
if ( GUILayout.Button("Default") ) {
@@ -147,6 +198,7 @@ namespace FlashTools.Internal {
void OnEnable() {
_assets = targets.OfType<SwfAsset>().ToList();
_clipsFoldout = false;
_settingsFoldout = true;
}
@@ -157,6 +209,8 @@ namespace FlashTools.Internal {
public override void OnInspectorGUI() {
serializedObject.Update();
DrawDefaultInspector();
DrawGUIDefaultSettings();
DrawGUIClips();
DrawGUISettings();
if ( GUI.changed ) {
serializedObject.ApplyModifiedProperties();

View File

@@ -137,18 +137,18 @@ namespace FlashTools.Internal {
// ---------------------------------------------------------------------
static void ConfigureClips(SwfAsset asset) {
asset.Clips.Clear();
foreach ( var symbol in asset.Data.Symbols ) {
ConfigureClip(asset, symbol);
}
}
static void ConfigureClip(SwfAsset asset, SwfSymbolData symbol) {
var clip_asset_path = Path.ChangeExtension(
AssetDatabase.GetAssetPath(asset),
symbol.Name + ".asset");
var clip_asset = SwfEditorUtils
.LoadOrCreateAsset<SwfClipAsset>(clip_asset_path);
var asset_path = AssetDatabase.GetAssetPath(asset);
var clip_asset_path = Path.ChangeExtension(asset_path, symbol.Name + ".asset");
var clip_asset = SwfEditorUtils.LoadOrCreateAsset<SwfClipAsset>(clip_asset_path);
clip_asset.Atlas = asset.Atlas;
clip_asset.Container = AssetDatabase.AssetPathToGUID(asset_path);
clip_asset.FrameRate = asset.Data.FrameRate;
clip_asset.Sequences = LoadClipSequences(asset, symbol);
ConfigureClipSubAssets(clip_asset);

View File

@@ -17,6 +17,8 @@ namespace FlashTools {
[SwfReadOnly]
public Texture2D Atlas;
[SwfAssetGUID(true)]
public string Container;
[SwfReadOnly]
public float FrameRate;
[HideInInspector]
@@ -25,6 +27,7 @@ namespace FlashTools {
#if UNITY_EDITOR
void Reset() {
Atlas = null;
Container = string.Empty;
FrameRate = 1.0f;
Sequences = new List<Sequence>();
}