mirror of
https://github.com/BlackMATov/unity-flash-tools.git
synced 2026-04-29 23:43:09 +07:00
+ sequences
This commit is contained in:
@@ -167,11 +167,11 @@ namespace FlashTools.Internal {
|
||||
var atlas_prop = SwfEditorUtils.GetPropertyByName(serializedObject, "Atlas");
|
||||
EditorGUILayout.PropertyField(atlas_prop, true);
|
||||
|
||||
var frames_prop = SwfEditorUtils.GetPropertyByName(serializedObject, "Frames");
|
||||
if ( frames_prop.isArray ) {
|
||||
var sequences_prop = SwfEditorUtils.GetPropertyByName(serializedObject, "Sequences");
|
||||
if ( sequences_prop.isArray ) {
|
||||
SwfEditorUtils.DoWithMixedValue(
|
||||
frames_prop.hasMultipleDifferentValues, () => {
|
||||
EditorGUILayout.IntField("Frame count", frames_prop.arraySize);
|
||||
sequences_prop.hasMultipleDifferentValues, () => {
|
||||
EditorGUILayout.IntField("Sequence count", sequences_prop.arraySize);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -151,15 +151,22 @@ namespace FlashTools.Internal {
|
||||
|
||||
static void ConfigureBakedFrames(string asset_path, SwfAnimationAsset asset) {
|
||||
RemoveAllSubAssets(asset_path);
|
||||
var baked_frames = new List<SwfAnimationAsset.Frame>();
|
||||
if ( asset && asset.Atlas && asset.Data != null && asset.Data.Frames.Count > 0 ) {
|
||||
var sequences = new List<SwfAnimationAsset.Sequence>();
|
||||
if ( IsValidAssetForFrame(asset) ) {
|
||||
for ( var i = 0; i < asset.Data.Frames.Count; ++i ) {
|
||||
var frame = asset.Data.Frames[i];
|
||||
var frame = asset.Data.Frames[i];
|
||||
var baked_frame = BakeFrameFromAnimationFrame(asset, frame);
|
||||
baked_frames.Add(baked_frame);
|
||||
if ( !string.IsNullOrEmpty(frame.Name) &&
|
||||
(sequences.Count < 1 || sequences.Last().Name != frame.Name) )
|
||||
{
|
||||
sequences.Add(new SwfAnimationAsset.Sequence{Name = frame.Name});
|
||||
} else if ( sequences.Count < 1 ) {
|
||||
sequences.Add(new SwfAnimationAsset.Sequence{Name = "Default"});
|
||||
}
|
||||
sequences.Last().Frames.Add(baked_frame);
|
||||
}
|
||||
}
|
||||
asset.Frames = baked_frames;
|
||||
asset.Sequences = sequences;
|
||||
}
|
||||
|
||||
static void RemoveAllSubAssets(string asset_path) {
|
||||
@@ -172,6 +179,12 @@ namespace FlashTools.Internal {
|
||||
}
|
||||
}
|
||||
|
||||
static bool IsValidAssetForFrame(SwfAnimationAsset asset) {
|
||||
return
|
||||
asset && asset.Atlas &&
|
||||
asset.Data != null && asset.Data.Frames != null;
|
||||
}
|
||||
|
||||
static SwfAnimationAsset.Frame BakeFrameFromAnimationFrame(
|
||||
SwfAnimationAsset asset, SwfAnimationFrameData frame)
|
||||
{
|
||||
|
||||
@@ -28,7 +28,8 @@ namespace FlashTools.Internal {
|
||||
|
||||
string GetAnimationsFrameCountStr() {
|
||||
return _animations.Aggregate(string.Empty, (acc, anim) => {
|
||||
var frame_count_str = anim.frameCount.ToString();
|
||||
var frame_count = anim.frameCount > 0 ? anim.frameCount - 1 : 0;
|
||||
var frame_count_str = frame_count.ToString();
|
||||
return string.IsNullOrEmpty(acc)
|
||||
? frame_count_str
|
||||
: (acc != frame_count_str ? "--" : acc);
|
||||
@@ -37,13 +38,61 @@ namespace FlashTools.Internal {
|
||||
|
||||
string GetAnimationsCurrentFrameStr() {
|
||||
return _animations.Aggregate(string.Empty, (acc, anim) => {
|
||||
var current_frame_str = anim.currentFrame.ToString();
|
||||
var current_frame = anim.currentFrame;
|
||||
var current_frame_str = current_frame.ToString();
|
||||
return string.IsNullOrEmpty(acc)
|
||||
? current_frame_str
|
||||
: (acc != current_frame_str ? "--" : acc);
|
||||
});
|
||||
}
|
||||
|
||||
bool IsAllAnimationsHasOneAsset() {
|
||||
foreach ( var animation in _animations ) {
|
||||
if ( !animation.asset ) {
|
||||
return false;
|
||||
}
|
||||
if ( animation.asset != _animations.First().asset ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
List<string> GetAllSequences(bool include_empty) {
|
||||
var seq_set = new HashSet<string>(_animations
|
||||
.Where(p => p.asset)
|
||||
.SelectMany(p => p.asset.Sequences)
|
||||
.Select(p => p.Name));
|
||||
if ( include_empty ) {
|
||||
seq_set.Add(string.Empty);
|
||||
}
|
||||
return seq_set.ToList();
|
||||
}
|
||||
|
||||
void DrawSequence() {
|
||||
if ( IsAllAnimationsHasOneAsset() ) {
|
||||
var sequence_prop = SwfEditorUtils.GetPropertyByName(serializedObject, "_sequence");
|
||||
SwfEditorUtils.DoWithMixedValue(
|
||||
sequence_prop.hasMultipleDifferentValues, () => {
|
||||
var all_sequences = GetAllSequences(true);
|
||||
var sequence_index = EditorGUILayout.Popup(
|
||||
"Sequence",
|
||||
sequence_prop.hasMultipleDifferentValues
|
||||
? all_sequences.FindIndex(p => string.IsNullOrEmpty(p))
|
||||
: all_sequences.FindIndex(p => p == sequence_prop.stringValue),
|
||||
all_sequences.ToArray());
|
||||
var new_sequence = all_sequences[sequence_index];
|
||||
if ( !string.IsNullOrEmpty(new_sequence) ) {
|
||||
if ( sequence_prop.hasMultipleDifferentValues ) {
|
||||
sequence_prop.stringValue = string.Empty;
|
||||
}
|
||||
sequence_prop.stringValue = new_sequence;
|
||||
sequence_prop.serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void DrawCurrentFrame() {
|
||||
var min_frame_count = GetMinAnimationsFrameCount();
|
||||
if ( min_frame_count > 0 ) {
|
||||
@@ -51,7 +100,7 @@ namespace FlashTools.Internal {
|
||||
SwfEditorUtils.GetPropertyByName(serializedObject, "_currentFrame"),
|
||||
0,
|
||||
min_frame_count - 1,
|
||||
"Frame");
|
||||
"Current frame");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,6 +144,7 @@ namespace FlashTools.Internal {
|
||||
public override void OnInspectorGUI() {
|
||||
serializedObject.Update();
|
||||
DrawDefaultInspector();
|
||||
DrawSequence();
|
||||
DrawCurrentFrame();
|
||||
DrawAnimationControls();
|
||||
if ( GUI.changed ) {
|
||||
|
||||
Reference in New Issue
Block a user