mirror of
https://github.com/BlackMATov/unity-flash-tools.git
synced 2026-03-22 12:55:32 +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 ) {
|
||||
|
||||
@@ -6,9 +6,11 @@ namespace FlashTools {
|
||||
[RequireComponent(typeof(MeshFilter), typeof(MeshRenderer))]
|
||||
public class SwfAnimation : MonoBehaviour {
|
||||
|
||||
MeshFilter _meshFilter = null;
|
||||
MeshRenderer _meshRenderer = null;
|
||||
MaterialPropertyBlock _matPropBlock = null;
|
||||
MeshFilter _meshFilter = null;
|
||||
MeshRenderer _meshRenderer = null;
|
||||
|
||||
SwfAnimationAsset.Sequence _curSequence = null;
|
||||
MaterialPropertyBlock _curPropBlock = null;
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
//
|
||||
@@ -48,6 +50,16 @@ namespace FlashTools {
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField][HideInInspector]
|
||||
string _sequence = "Default";
|
||||
public string sequence {
|
||||
get { return _sequence; }
|
||||
set {
|
||||
_sequence = value;
|
||||
ChangeSequence();
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField][HideInInspector]
|
||||
int _currentFrame = 0;
|
||||
public int currentFrame {
|
||||
@@ -60,8 +72,8 @@ namespace FlashTools {
|
||||
|
||||
public int frameCount {
|
||||
get {
|
||||
return asset && asset.Data != null && asset.Data.Frames != null
|
||||
? asset.Data.Frames.Count
|
||||
return _curSequence != null && _curSequence.Frames != null
|
||||
? _curSequence.Frames.Count
|
||||
: 0;
|
||||
}
|
||||
}
|
||||
@@ -112,6 +124,7 @@ namespace FlashTools {
|
||||
|
||||
public void UpdateAllProperties() {
|
||||
asset = _asset;
|
||||
sequence = _sequence;
|
||||
currentFrame = _currentFrame;
|
||||
sortingLayer = _sortingLayer;
|
||||
sortingOrder = _sortingOrder;
|
||||
@@ -121,8 +134,31 @@ namespace FlashTools {
|
||||
if ( _meshRenderer ) {
|
||||
_meshRenderer.enabled = !!asset;
|
||||
}
|
||||
UpdateMaterialPropertyBlock();
|
||||
UpdateCurrentMesh();
|
||||
UpdatePropertyBlock();
|
||||
ChangeSequence();
|
||||
}
|
||||
|
||||
void ChangeSequence() {
|
||||
_curSequence = null;
|
||||
if ( asset && asset.Sequences != null ) {
|
||||
for ( int i = 0, e = asset.Sequences.Count; i < e; ++i ) {
|
||||
var asset_sequence = asset.Sequences[i];
|
||||
if ( asset_sequence != null && asset_sequence.Name == sequence ) {
|
||||
_curSequence = asset_sequence;
|
||||
}
|
||||
}
|
||||
if ( _curSequence == null ) {
|
||||
for ( int i = 0, e = asset.Sequences.Count; i < e; ++i ) {
|
||||
var asset_sequence = asset.Sequences[i];
|
||||
if ( asset_sequence != null ) {
|
||||
_sequence = asset_sequence.Name;
|
||||
_curSequence = asset_sequence;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ChangeCurrentFrame();
|
||||
}
|
||||
|
||||
void ChangeCurrentFrame() {
|
||||
@@ -139,17 +175,17 @@ namespace FlashTools {
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateMaterialPropertyBlock() {
|
||||
void UpdatePropertyBlock() {
|
||||
if ( _meshRenderer ) {
|
||||
if ( _matPropBlock == null ) {
|
||||
_matPropBlock = new MaterialPropertyBlock();
|
||||
if ( _curPropBlock == null ) {
|
||||
_curPropBlock = new MaterialPropertyBlock();
|
||||
}
|
||||
_meshRenderer.GetPropertyBlock(_matPropBlock);
|
||||
_meshRenderer.GetPropertyBlock(_curPropBlock);
|
||||
var atlas = asset && asset.Atlas ? asset.Atlas : null;
|
||||
if ( atlas ) {
|
||||
_matPropBlock.SetTexture("_MainTex", atlas);
|
||||
_curPropBlock.SetTexture("_MainTex", atlas);
|
||||
}
|
||||
_meshRenderer.SetPropertyBlock(_matPropBlock);
|
||||
_meshRenderer.SetPropertyBlock(_curPropBlock);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,9 +198,10 @@ namespace FlashTools {
|
||||
}
|
||||
|
||||
SwfAnimationAsset.Frame GetCurrentBakedFrame() {
|
||||
return currentFrame >= 0 && currentFrame < frameCount
|
||||
? asset.Frames[currentFrame]
|
||||
: SwfAnimationAsset.Frame.identity;
|
||||
var frames = _curSequence != null ? _curSequence.Frames : null;
|
||||
return frames != null && currentFrame >= 0 && currentFrame < frames.Count
|
||||
? frames[currentFrame]
|
||||
: new SwfAnimationAsset.Frame();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
@@ -176,7 +213,8 @@ namespace FlashTools {
|
||||
void Awake() {
|
||||
_meshFilter = GetComponent<MeshFilter>();
|
||||
_meshRenderer = GetComponent<MeshRenderer>();
|
||||
_matPropBlock = new MaterialPropertyBlock();
|
||||
_curSequence = null;
|
||||
_curPropBlock = null;
|
||||
UpdateAllProperties();
|
||||
}
|
||||
|
||||
|
||||
@@ -73,19 +73,17 @@ namespace FlashTools {
|
||||
public class SwfAnimationAsset : ScriptableObject {
|
||||
[System.Serializable]
|
||||
public class Frame {
|
||||
public Mesh Mesh;
|
||||
public Material[] Materials;
|
||||
public static Frame identity {
|
||||
get {
|
||||
return new Frame{
|
||||
Mesh = new Mesh(),
|
||||
Materials = new Material[0]};
|
||||
}
|
||||
}
|
||||
public Mesh Mesh = new Mesh();
|
||||
public Material[] Materials = new Material[0];
|
||||
}
|
||||
[System.Serializable]
|
||||
public class Sequence {
|
||||
public string Name = string.Empty;
|
||||
public List<Frame> Frames = new List<Frame>();
|
||||
}
|
||||
public SwfAnimationData Data;
|
||||
public Texture2D Atlas;
|
||||
public List<Frame> Frames;
|
||||
public List<Sequence> Sequences;
|
||||
public SwfSettings Settings;
|
||||
public SwfSettings Overridden;
|
||||
|
||||
@@ -93,7 +91,7 @@ namespace FlashTools {
|
||||
void Reset() {
|
||||
Data = new SwfAnimationData();
|
||||
Atlas = null;
|
||||
Frames = new List<Frame>();
|
||||
Sequences = new List<Sequence>();
|
||||
Settings = SwfConverterSettings.GetDefaultSettings();
|
||||
Overridden = SwfConverterSettings.GetDefaultSettings();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user