mirror of
https://github.com/BlackMATov/unity-flash-tools.git
synced 2025-12-15 12:29:49 +07:00
attribute drawers wip
This commit is contained in:
@@ -48,6 +48,8 @@
|
||||
<Compile Include="Assets\FlashTools\Scripts\Internal\Editor\SwfAnimationAssetEditor.cs" />
|
||||
<Compile Include="Assets\FlashTools\Scripts\Internal\Editor\SwfAnimationAssetPostprocessor.cs" />
|
||||
<Compile Include="Assets\FlashTools\Scripts\Internal\Editor\SwfAnimationEditor.cs" />
|
||||
<Compile Include="Assets\FlashTools\Scripts\Internal\Editor\SwfEditorTools\SwfPowerOfTwoIfDrawer.cs" />
|
||||
<Compile Include="Assets\FlashTools\Scripts\Internal\Editor\SwfEditorTools\SwfSortingLayerDrawer.cs" />
|
||||
<Compile Include="Assets\FlashTools\Scripts\Internal\Editor\SwfPostprocessor.cs" />
|
||||
<Compile Include="Assets\FlashTools\Scripts\Internal\Editor\SwfTools\SwfContext.cs" />
|
||||
<Compile Include="Assets\FlashTools\Scripts\Internal\Editor\SwfTools\SwfContextExecuter.cs" />
|
||||
|
||||
@@ -45,9 +45,11 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Assets\FlashTools\Scripts\Internal\SwfConverterSettings.cs" />
|
||||
<Compile Include="Assets\FlashTools\Scripts\Internal\SwfPowerOfTwoIfAttribute.cs" />
|
||||
<Compile Include="Assets\FlashTools\Scripts\Internal\SwfSortingLayerAttribute.cs" />
|
||||
<Compile Include="Assets\FlashTools\Scripts\SwfAnimation.cs" />
|
||||
<Compile Include="Assets\FlashTools\Scripts\SwfAnimationAsset.cs" />
|
||||
<Compile Include="Assets\FlashTools\Scripts\SwfConverterSettings.cs" />
|
||||
<None Include="Assets\FlashTools\Resources\Shaders\SwfDecrMask.shader" />
|
||||
<None Include="Assets\FlashTools\Resources\Shaders\SwfSimple.shader" />
|
||||
<None Include="Assets\FlashTools\Resources\Shaders\SwfIncrMask.shader" />
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ea1dd488b8903439b90ce209ff82574c
|
||||
timeCreated: 1471954996
|
||||
timeCreated: 1472013183
|
||||
licenseType: Free
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 92c4c08c8d0f648efa0a3f602e3e8710
|
||||
folderAsset: yes
|
||||
timeCreated: 1472012226
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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<int>();
|
||||
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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 115975934e0df4b05a62c112248e8964
|
||||
timeCreated: 1472013429
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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<GUIContent> GetAllSortingLayers() {
|
||||
var result = new List<GUIContent>();
|
||||
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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 75cfccb798f0a434492af628d750c4a4
|
||||
timeCreated: 1472012246
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d267119f922984b8b812889fd05d0c86
|
||||
timeCreated: 1472013332
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,6 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace FlashTools.Internal {
|
||||
public class SwfSortingLayerAttribute : PropertyAttribute {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a33d7ac8d525c4e8fbe3084eacab4f07
|
||||
timeCreated: 1472011819
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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<MeshRenderer>().sharedMaterials = full_groups.Select(p => p.Material).ToArray();
|
||||
var mesh_renderer = GetComponent<MeshRenderer>();
|
||||
mesh_renderer.sharedMaterials = full_groups.Select(p => p.Material).ToArray();
|
||||
mesh_renderer.sortingOrder = SortingOrder;
|
||||
mesh_renderer.sortingLayerName = SortingLayer;
|
||||
|
||||
var mesh_filter = GetComponent<MeshFilter>();
|
||||
if ( mesh_filter ) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using FlashTools.Internal;
|
||||
|
||||
namespace FlashTools {
|
||||
[System.Serializable]
|
||||
|
||||
@@ -41,3 +41,6 @@ TagManager:
|
||||
- name: Default
|
||||
uniqueID: 0
|
||||
locked: 0
|
||||
- name: jvjhv
|
||||
uniqueID: 811819031
|
||||
locked: 0
|
||||
|
||||
Reference in New Issue
Block a user