diff --git a/Assembly-CSharp-Editor.csproj b/Assembly-CSharp-Editor.csproj index 2b34368..2acc11f 100644 --- a/Assembly-CSharp-Editor.csproj +++ b/Assembly-CSharp-Editor.csproj @@ -48,6 +48,8 @@ + + diff --git a/Assembly-CSharp.csproj b/Assembly-CSharp.csproj index b170016..a5a7cbb 100644 --- a/Assembly-CSharp.csproj +++ b/Assembly-CSharp.csproj @@ -45,9 +45,11 @@ + + + - diff --git a/Assets/FlashTools/Resources/SwfConverterSettings.asset.meta b/Assets/FlashTools/Resources/SwfConverterSettings.asset.meta index 0d539a2..34f7f50 100644 --- a/Assets/FlashTools/Resources/SwfConverterSettings.asset.meta +++ b/Assets/FlashTools/Resources/SwfConverterSettings.asset.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 guid: ea1dd488b8903439b90ce209ff82574c -timeCreated: 1471954996 +timeCreated: 1472013183 licenseType: Free NativeFormatImporter: userData: diff --git a/Assets/FlashTools/Scripts/Internal/Editor/SwfAnimationAssetEditor.cs b/Assets/FlashTools/Scripts/Internal/Editor/SwfAnimationAssetEditor.cs index e356112..4d96d82 100644 --- a/Assets/FlashTools/Scripts/Internal/Editor/SwfAnimationAssetEditor.cs +++ b/Assets/FlashTools/Scripts/Internal/Editor/SwfAnimationAssetEditor.cs @@ -117,23 +117,14 @@ namespace FlashTools.Internal { void DrawGUISettings() { GUI.enabled = false; + EditorGUILayout.PropertyField(serializedObject.FindProperty("m_Script")); EditorGUILayout.PropertyField(serializedObject.FindProperty("Atlas")); GUI.enabled = true; _settingsFoldout = EditorGUILayout.Foldout(_settingsFoldout, "Settings"); if ( _settingsFoldout ) { var it = serializedObject.FindProperty("Overridden"); while ( it.NextVisible(true) ) { - if ( it.name == "MaxAtlasSize" && _asset.Overridden.AtlasPowerOfTwo ) { - if ( !Mathf.IsPowerOfTwo(it.intValue) ) { - it.intValue = Mathf.ClosestPowerOfTwo(it.intValue); - serializedObject.ApplyModifiedProperties(); - } - var values = new int[] {32, 64, 128, 256, 512, 1024, 2048, 4096, 8192}; - var names = values.Select(p => new GUIContent(p.ToString())).ToArray(); - EditorGUILayout.IntPopup(it, names, values); - } else { - EditorGUILayout.PropertyField(it); - } + EditorGUILayout.PropertyField(it); } DrawGUISettingsControls(); } @@ -141,6 +132,7 @@ namespace FlashTools.Internal { void DrawGUISettingsControls() { GUILayout.BeginHorizontal(); + GUILayout.FlexibleSpace(); { var default_settings = SwfConverterSettings.GetDefaultSettings(); GUI.enabled = !_asset.Overridden.CheckEquals(default_settings); diff --git a/Assets/FlashTools/Scripts/Internal/Editor/SwfAnimationEditor.cs b/Assets/FlashTools/Scripts/Internal/Editor/SwfAnimationEditor.cs index c8c9912..315ff62 100644 --- a/Assets/FlashTools/Scripts/Internal/Editor/SwfAnimationEditor.cs +++ b/Assets/FlashTools/Scripts/Internal/Editor/SwfAnimationEditor.cs @@ -1,5 +1,6 @@ using UnityEngine; using UnityEditor; +using System.Collections.Generic; namespace FlashTools.Internal { [CustomEditor(typeof(SwfAnimation))] @@ -12,6 +13,7 @@ namespace FlashTools.Internal { public override void OnInspectorGUI() { DrawDefaultInspector(); + if ( _animation.Asset && _animation.frameCount > 1 ) { var new_current_frame = EditorGUILayout.IntSlider( "Frame", _animation.currentFrame, diff --git a/Assets/FlashTools/Scripts/Internal/Editor/SwfEditorTools.meta b/Assets/FlashTools/Scripts/Internal/Editor/SwfEditorTools.meta new file mode 100644 index 0000000..405a777 --- /dev/null +++ b/Assets/FlashTools/Scripts/Internal/Editor/SwfEditorTools.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 92c4c08c8d0f648efa0a3f602e3e8710 +folderAsset: yes +timeCreated: 1472012226 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/FlashTools/Scripts/Internal/Editor/SwfEditorTools/SwfPowerOfTwoIfDrawer.cs b/Assets/FlashTools/Scripts/Internal/Editor/SwfEditorTools/SwfPowerOfTwoIfDrawer.cs new file mode 100644 index 0000000..866dc3e --- /dev/null +++ b/Assets/FlashTools/Scripts/Internal/Editor/SwfEditorTools/SwfPowerOfTwoIfDrawer.cs @@ -0,0 +1,60 @@ +using UnityEngine; +using UnityEditor; +using System.Linq; +using System.Collections.Generic; + +namespace FlashTools.Internal.SwfEditorTools { + [CustomPropertyDrawer(typeof(SwfPowerOfTwoIfAttribute))] + public class SwfPowerOfTwoIfDrawer : PropertyDrawer { + + SerializedProperty FindBoolProperty(SerializedProperty property, string bool_prop) { + var prop = property.Copy(); + while ( prop.NextVisible(false) ) { + if ( prop.propertyType == SerializedPropertyType.Boolean && prop.name == bool_prop ) { + return prop; + } + } + return null; + } + + void PropertyToPowerOfTwo(SerializedProperty property) { + if ( property.propertyType == SerializedPropertyType.Integer ) { + if ( !Mathf.IsPowerOfTwo(property.intValue) ) { + property.intValue = Mathf.ClosestPowerOfTwo(property.intValue); + property.serializedObject.ApplyModifiedProperties(); + } + } + } + + int[] GenPowerOfTwoValues(int min, int max) { + var values = new List(); + if ( !Mathf.IsPowerOfTwo(min) ) { + min = Mathf.NextPowerOfTwo(min); + } + while ( min <= max ) { + values.Add(min); + min = Mathf.NextPowerOfTwo(min + 1); + } + return values.ToArray(); + } + + public override void OnGUI( + Rect position, SerializedProperty property, GUIContent label) + { + if ( property.propertyType == SerializedPropertyType.Integer ) { + var attr = attribute as SwfPowerOfTwoIfAttribute; + var bool_prop = FindBoolProperty(property, attr.BoolProp); + if ( bool_prop != null && bool_prop.boolValue ) { + PropertyToPowerOfTwo(property); + var values = GenPowerOfTwoValues(attr.Min, attr.Max); + var vnames = values.Select(p => new GUIContent(p.ToString())).ToArray(); + EditorGUI.IntPopup(position, property, vnames, values, label); + } else { + EditorGUI.PropertyField(position, property, label); + } + } else { + EditorGUI.LabelField(position, label.text, "Use SwfPowerOfTwoIf with integer attribute."); + } + } + } +} \ No newline at end of file diff --git a/Assets/FlashTools/Scripts/Internal/Editor/SwfEditorTools/SwfPowerOfTwoIfDrawer.cs.meta b/Assets/FlashTools/Scripts/Internal/Editor/SwfEditorTools/SwfPowerOfTwoIfDrawer.cs.meta new file mode 100644 index 0000000..3f04e3d --- /dev/null +++ b/Assets/FlashTools/Scripts/Internal/Editor/SwfEditorTools/SwfPowerOfTwoIfDrawer.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 115975934e0df4b05a62c112248e8964 +timeCreated: 1472013429 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/FlashTools/Scripts/Internal/Editor/SwfEditorTools/SwfSortingLayerDrawer.cs b/Assets/FlashTools/Scripts/Internal/Editor/SwfEditorTools/SwfSortingLayerDrawer.cs new file mode 100644 index 0000000..7860b71 --- /dev/null +++ b/Assets/FlashTools/Scripts/Internal/Editor/SwfEditorTools/SwfSortingLayerDrawer.cs @@ -0,0 +1,43 @@ +using UnityEngine; +using UnityEditor; +using System.Linq; +using System.Collections.Generic; + +namespace FlashTools.Internal.SwfEditorTools { + [CustomPropertyDrawer(typeof(SwfSortingLayerAttribute))] + public class SwfSortingLayerDrawer : PropertyDrawer { + + List GetAllSortingLayers() { + var result = new List(); + var tag_manager_so = new SerializedObject( + AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/TagManager.asset")[0]); + var layers = tag_manager_so.FindProperty("m_SortingLayers"); + if ( layers != null && layers.isArray ) { + for ( var i = 0; i < layers.arraySize; ++i ) { + var layer_prop = layers.GetArrayElementAtIndex(i); + var layer_name_prop = layer_prop.FindPropertyRelative("name"); + if ( !string.IsNullOrEmpty(layer_name_prop.stringValue) ) { + result.Add(new GUIContent(layer_name_prop.stringValue)); + } + } + } + return result; + } + + public override void OnGUI( + Rect position, SerializedProperty property, GUIContent label) + { + var all_sorting_layers = GetAllSortingLayers(); + if ( property.propertyType == SerializedPropertyType.String ) { + var new_sorting_layer = EditorGUI.Popup( + position, + label, + all_sorting_layers.FindIndex(p => p.text == property.stringValue), + all_sorting_layers.ToArray()); + property.stringValue = all_sorting_layers[new_sorting_layer].text; + } else { + EditorGUI.LabelField(position, label.text, "Use SwfSortingLayer with string attribute."); + } + } + } +} \ No newline at end of file diff --git a/Assets/FlashTools/Scripts/Internal/Editor/SwfEditorTools/SwfSortingLayerDrawer.cs.meta b/Assets/FlashTools/Scripts/Internal/Editor/SwfEditorTools/SwfSortingLayerDrawer.cs.meta new file mode 100644 index 0000000..79edfd9 --- /dev/null +++ b/Assets/FlashTools/Scripts/Internal/Editor/SwfEditorTools/SwfSortingLayerDrawer.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 75cfccb798f0a434492af628d750c4a4 +timeCreated: 1472012246 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/FlashTools/Scripts/SwfConverterSettings.cs b/Assets/FlashTools/Scripts/Internal/SwfConverterSettings.cs similarity index 96% rename from Assets/FlashTools/Scripts/SwfConverterSettings.cs rename to Assets/FlashTools/Scripts/Internal/SwfConverterSettings.cs index 2f4bb32..54fc229 100644 --- a/Assets/FlashTools/Scripts/SwfConverterSettings.cs +++ b/Assets/FlashTools/Scripts/Internal/SwfConverterSettings.cs @@ -5,7 +5,7 @@ using UnityEditor; using System.IO; #endif -namespace FlashTools { +namespace FlashTools.Internal { public class SwfConverterSettings : ScriptableObject { public enum SwfAtlasFilter { Point, @@ -22,6 +22,7 @@ namespace FlashTools { [System.Serializable] public struct Settings { + [SwfPowerOfTwoIfAttribute("AtlasPowerOfTwo", 32, 8192)] public int MaxAtlasSize; public int AtlasPadding; public int PixelsPerUnit; diff --git a/Assets/FlashTools/Scripts/SwfConverterSettings.cs.meta b/Assets/FlashTools/Scripts/Internal/SwfConverterSettings.cs.meta similarity index 100% rename from Assets/FlashTools/Scripts/SwfConverterSettings.cs.meta rename to Assets/FlashTools/Scripts/Internal/SwfConverterSettings.cs.meta diff --git a/Assets/FlashTools/Scripts/Internal/SwfPowerOfTwoIfAttribute.cs b/Assets/FlashTools/Scripts/Internal/SwfPowerOfTwoIfAttribute.cs new file mode 100644 index 0000000..b92543e --- /dev/null +++ b/Assets/FlashTools/Scripts/Internal/SwfPowerOfTwoIfAttribute.cs @@ -0,0 +1,14 @@ +using UnityEngine; + +namespace FlashTools.Internal { + public class SwfPowerOfTwoIfAttribute : PropertyAttribute { + public string BoolProp; + public int Min; + public int Max; + public SwfPowerOfTwoIfAttribute(string bool_prop, int min, int max) { + BoolProp = bool_prop; + Min = min; + Max = max; + } + } +} \ No newline at end of file diff --git a/Assets/FlashTools/Scripts/Internal/SwfPowerOfTwoIfAttribute.cs.meta b/Assets/FlashTools/Scripts/Internal/SwfPowerOfTwoIfAttribute.cs.meta new file mode 100644 index 0000000..acee22f --- /dev/null +++ b/Assets/FlashTools/Scripts/Internal/SwfPowerOfTwoIfAttribute.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: d267119f922984b8b812889fd05d0c86 +timeCreated: 1472013332 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/FlashTools/Scripts/Internal/SwfSortingLayerAttribute.cs b/Assets/FlashTools/Scripts/Internal/SwfSortingLayerAttribute.cs new file mode 100644 index 0000000..9c54173 --- /dev/null +++ b/Assets/FlashTools/Scripts/Internal/SwfSortingLayerAttribute.cs @@ -0,0 +1,6 @@ +using UnityEngine; + +namespace FlashTools.Internal { + public class SwfSortingLayerAttribute : PropertyAttribute { + } +} \ No newline at end of file diff --git a/Assets/FlashTools/Scripts/Internal/SwfSortingLayerAttribute.cs.meta b/Assets/FlashTools/Scripts/Internal/SwfSortingLayerAttribute.cs.meta new file mode 100644 index 0000000..b6d3292 --- /dev/null +++ b/Assets/FlashTools/Scripts/Internal/SwfSortingLayerAttribute.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: a33d7ac8d525c4e8fbe3084eacab4f07 +timeCreated: 1472011819 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/FlashTools/Scripts/SwfAnimation.cs b/Assets/FlashTools/Scripts/SwfAnimation.cs index bb668a1..1a6572b 100644 --- a/Assets/FlashTools/Scripts/SwfAnimation.cs +++ b/Assets/FlashTools/Scripts/SwfAnimation.cs @@ -1,6 +1,7 @@ using UnityEngine; using System.Linq; using System.Collections.Generic; +using FlashTools.Internal; #if UNITY_EDITOR using UnityEditor; @@ -10,8 +11,12 @@ namespace FlashTools { [ExecuteInEditMode] [RequireComponent(typeof(MeshFilter), typeof(MeshRenderer))] public class SwfAnimation : MonoBehaviour { - public SwfAnimationAsset Asset = null; - public int GroupCount = 0; + public SwfAnimationAsset Asset = null; + public int GroupCount = 0; + + public int SortingOrder = 0; + [SwfSortingLayer] + public string SortingLayer = "Default"; int _current_frame = 0; float _frame_timer = 0.0f; @@ -176,7 +181,10 @@ namespace FlashTools { } } - GetComponent().sharedMaterials = full_groups.Select(p => p.Material).ToArray(); + var mesh_renderer = GetComponent(); + mesh_renderer.sharedMaterials = full_groups.Select(p => p.Material).ToArray(); + mesh_renderer.sortingOrder = SortingOrder; + mesh_renderer.sortingLayerName = SortingLayer; var mesh_filter = GetComponent(); if ( mesh_filter ) { diff --git a/Assets/FlashTools/Scripts/SwfAnimationAsset.cs b/Assets/FlashTools/Scripts/SwfAnimationAsset.cs index 0e73917..2d930b1 100644 --- a/Assets/FlashTools/Scripts/SwfAnimationAsset.cs +++ b/Assets/FlashTools/Scripts/SwfAnimationAsset.cs @@ -1,5 +1,6 @@ using UnityEngine; using System.Collections.Generic; +using FlashTools.Internal; namespace FlashTools { [System.Serializable] diff --git a/ProjectSettings/TagManager.asset b/ProjectSettings/TagManager.asset index 1c92a78..c5dade8 100644 --- a/ProjectSettings/TagManager.asset +++ b/ProjectSettings/TagManager.asset @@ -41,3 +41,6 @@ TagManager: - name: Default uniqueID: 0 locked: 0 + - name: jvjhv + uniqueID: 811819031 + locked: 0