[unity] Add initialFlip fields for SkeletonGraphic.

This commit is contained in:
pharan 2017-05-24 20:49:26 +08:00
parent f62b6b2326
commit 8cb99365cd
2 changed files with 54 additions and 31 deletions

View File

@ -38,11 +38,12 @@ namespace Spine.Unity.Editor {
[CustomEditor(typeof(SkeletonGraphic))] [CustomEditor(typeof(SkeletonGraphic))]
[CanEditMultipleObjects] [CanEditMultipleObjects]
public class SkeletonGraphicInspector : UnityEditor.Editor { public class SkeletonGraphicInspector : UnityEditor.Editor {
SerializedProperty material_, color_; SerializedProperty material, color;
SerializedProperty skeletonDataAsset_, initialSkinName_; SerializedProperty skeletonDataAsset, initialSkinName;
SerializedProperty startingAnimation_, startingLoop_, timeScale_, freeze_, unscaledTime_, tintBlack_; SerializedProperty startingAnimation, startingLoop, timeScale, freeze, unscaledTime, tintBlack;
SerializedProperty meshGeneratorSettings_; SerializedProperty initialFlipX, initialFlipY;
SerializedProperty raycastTarget_; SerializedProperty meshGeneratorSettings;
SerializedProperty raycastTarget;
SkeletonGraphic thisSkeletonGraphic; SkeletonGraphic thisSkeletonGraphic;
@ -51,32 +52,34 @@ namespace Spine.Unity.Editor {
thisSkeletonGraphic = target as SkeletonGraphic; thisSkeletonGraphic = target as SkeletonGraphic;
// MaskableGraphic // MaskableGraphic
material_ = so.FindProperty("m_Material"); material = so.FindProperty("m_Material");
color_ = so.FindProperty("m_Color"); color = so.FindProperty("m_Color");
raycastTarget_ = so.FindProperty("m_RaycastTarget"); raycastTarget = so.FindProperty("m_RaycastTarget");
// SkeletonRenderer // SkeletonRenderer
skeletonDataAsset_ = so.FindProperty("skeletonDataAsset"); skeletonDataAsset = so.FindProperty("skeletonDataAsset");
initialSkinName_ = so.FindProperty("initialSkinName"); initialSkinName = so.FindProperty("initialSkinName");
//tintBlack_ = so.FindProperty("tintBlack");
initialFlipX = so.FindProperty("initialFlipX");
initialFlipY = so.FindProperty("initialFlipY");
// SkeletonAnimation // SkeletonAnimation
startingAnimation_ = so.FindProperty("startingAnimation"); startingAnimation = so.FindProperty("startingAnimation");
startingLoop_ = so.FindProperty("startingLoop"); startingLoop = so.FindProperty("startingLoop");
timeScale_ = so.FindProperty("timeScale"); timeScale = so.FindProperty("timeScale");
unscaledTime_ = so.FindProperty("unscaledTime"); unscaledTime = so.FindProperty("unscaledTime");
freeze_ = so.FindProperty("freeze"); freeze = so.FindProperty("freeze");
meshGeneratorSettings_ = so.FindProperty("meshGenerator").FindPropertyRelative("settings"); meshGeneratorSettings = so.FindProperty("meshGenerator").FindPropertyRelative("settings");
meshGeneratorSettings_.isExpanded = SkeletonRendererInspector.advancedFoldout; meshGeneratorSettings.isExpanded = SkeletonRendererInspector.advancedFoldout;
} }
public override void OnInspectorGUI () { public override void OnInspectorGUI () {
EditorGUI.BeginChangeCheck(); EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(skeletonDataAsset_); EditorGUILayout.PropertyField(skeletonDataAsset);
EditorGUILayout.PropertyField(material_); EditorGUILayout.PropertyField(material);
EditorGUILayout.PropertyField(color_); EditorGUILayout.PropertyField(color);
if (thisSkeletonGraphic.skeletonDataAsset == null) { if (thisSkeletonGraphic.skeletonDataAsset == null) {
EditorGUILayout.HelpBox("You need to assign a SkeletonDataAsset first.", MessageType.Info); EditorGUILayout.HelpBox("You need to assign a SkeletonDataAsset first.", MessageType.Info);
@ -85,23 +88,33 @@ namespace Spine.Unity.Editor {
return; return;
} }
using (new SpineInspectorUtility.BoxScope()) { using (new SpineInspectorUtility.BoxScope()) {
EditorGUILayout.PropertyField(meshGeneratorSettings_, SpineInspectorUtility.TempContent("Advanced..."), includeChildren: true); EditorGUILayout.PropertyField(meshGeneratorSettings, SpineInspectorUtility.TempContent("Advanced..."), includeChildren: true);
SkeletonRendererInspector.advancedFoldout = meshGeneratorSettings_.isExpanded; SkeletonRendererInspector.advancedFoldout = meshGeneratorSettings.isExpanded;
} }
EditorGUILayout.Space(); EditorGUILayout.Space();
EditorGUILayout.PropertyField(initialSkinName_); EditorGUILayout.PropertyField(initialSkinName);
{
var rect = GUILayoutUtility.GetRect(EditorGUIUtility.currentViewWidth, EditorGUIUtility.singleLineHeight);
EditorGUI.PrefixLabel(rect, SpineInspectorUtility.TempContent("Initial Flip"));
rect.x += EditorGUIUtility.labelWidth;
rect.width = 30f;
initialFlipX.boolValue = EditorGUI.ToggleLeft(rect, SpineInspectorUtility.TempContent("X", tooltip:"initialFlipX"), initialFlipX.boolValue);
rect.x += 35f;
initialFlipY.boolValue = EditorGUI.ToggleLeft(rect, SpineInspectorUtility.TempContent("Y", tooltip:"initialFlipY"), initialFlipY.boolValue);
}
EditorGUILayout.Space(); EditorGUILayout.Space();
EditorGUILayout.LabelField("Animation", EditorStyles.boldLabel); EditorGUILayout.LabelField("Animation", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(startingAnimation_); EditorGUILayout.PropertyField(startingAnimation);
EditorGUILayout.PropertyField(startingLoop_); EditorGUILayout.PropertyField(startingLoop);
EditorGUILayout.PropertyField(timeScale_); EditorGUILayout.PropertyField(timeScale);
EditorGUILayout.PropertyField(unscaledTime_, SpineInspectorUtility.TempContent(unscaledTime_.displayName, tooltip: "If checked, this will use Time.unscaledDeltaTime to make this update independent of game Time.timeScale. Instance SkeletonGraphic.timeScale will still be applied.")); EditorGUILayout.PropertyField(unscaledTime, SpineInspectorUtility.TempContent(unscaledTime.displayName, tooltip: "If checked, this will use Time.unscaledDeltaTime to make this update independent of game Time.timeScale. Instance SkeletonGraphic.timeScale will still be applied."));
EditorGUILayout.Space(); EditorGUILayout.Space();
EditorGUILayout.PropertyField(freeze_); EditorGUILayout.PropertyField(freeze);
EditorGUILayout.Space(); EditorGUILayout.Space();
EditorGUILayout.LabelField("UI", EditorStyles.boldLabel); EditorGUILayout.LabelField("UI", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(raycastTarget_); EditorGUILayout.PropertyField(raycastTarget);
bool wasChanged = EditorGUI.EndChangeCheck(); bool wasChanged = EditorGUI.EndChangeCheck();

View File

@ -43,6 +43,7 @@ namespace Spine.Unity {
[SpineSkin(dataField:"skeletonDataAsset")] [SpineSkin(dataField:"skeletonDataAsset")]
public string initialSkinName = "default"; public string initialSkinName = "default";
public bool initialFlipX, initialFlipY;
[SpineAnimation(dataField:"skeletonDataAsset")] [SpineAnimation(dataField:"skeletonDataAsset")]
public string startingAnimation; public string startingAnimation;
@ -79,6 +80,11 @@ namespace Spine.Unity {
} }
if (!Application.isPlaying) {
skeleton.flipX = this.initialFlipX;
skeleton.flipY = this.initialFlipY;
}
skeleton.SetToSetupPose(); skeleton.SetToSetupPose();
if (!string.IsNullOrEmpty(startingAnimation)) if (!string.IsNullOrEmpty(startingAnimation))
skeleton.PoseWithAnimation(startingAnimation, 0f, false); skeleton.PoseWithAnimation(startingAnimation, 0f, false);
@ -212,7 +218,11 @@ namespace Spine.Unity {
return; return;
} }
this.skeleton = new Skeleton(skeletonData); this.skeleton = new Skeleton(skeletonData) {
flipX = this.initialFlipX,
flipY = this.initialFlipY
};
meshBuffers = new DoubleBuffered<MeshRendererBuffers.SmartMesh>(); meshBuffers = new DoubleBuffered<MeshRendererBuffers.SmartMesh>();
// Set the initial Skin and Animation // Set the initial Skin and Animation