mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
65982c7eca
@ -581,7 +581,7 @@ namespace Spine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
float[] frames = this.frames;
|
float[] frames = this.frames;
|
||||||
if (time < frames[0]) {
|
if (time < frames[0]) { // Time is before first frame.
|
||||||
if (setupPose) {
|
if (setupPose) {
|
||||||
attachmentName = slot.data.attachmentName;
|
attachmentName = slot.data.attachmentName;
|
||||||
slot.Attachment = attachmentName == null ? null : skeleton.GetAttachment(slotIndex, attachmentName);
|
slot.Attachment = attachmentName == null ? null : skeleton.GetAttachment(slotIndex, attachmentName);
|
||||||
|
|||||||
@ -228,7 +228,7 @@ namespace Spine {
|
|||||||
if (rotateTimeline != null) {
|
if (rotateTimeline != null) {
|
||||||
ApplyRotateTimeline(rotateTimeline, skeleton, animationTime, alpha, setupPose, timelinesRotation, i << 1, firstFrame);
|
ApplyRotateTimeline(rotateTimeline, skeleton, animationTime, alpha, setupPose, timelinesRotation, i << 1, firstFrame);
|
||||||
} else {
|
} else {
|
||||||
if (setupPose) {
|
if (!setupPose) {
|
||||||
if (!attachments && timeline is AttachmentTimeline) continue;
|
if (!attachments && timeline is AttachmentTimeline) continue;
|
||||||
if (!drawOrder && timeline is DrawOrderTimeline) continue;
|
if (!drawOrder && timeline is DrawOrderTimeline) continue;
|
||||||
}
|
}
|
||||||
@ -236,7 +236,7 @@ namespace Spine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QueueEvents(entry, animationTime);
|
QueueEvents(from, animationTime);
|
||||||
from.nextAnimationLast = animationTime;
|
from.nextAnimationLast = animationTime;
|
||||||
from.nextTrackLast = from.trackTime;
|
from.nextTrackLast = from.trackTime;
|
||||||
|
|
||||||
|
|||||||
@ -82,7 +82,7 @@ namespace Spine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (updateAabb) {
|
if (updateAabb) {
|
||||||
aabbCompute();
|
AabbCompute();
|
||||||
} else {
|
} else {
|
||||||
minX = int.MinValue;
|
minX = int.MinValue;
|
||||||
minY = int.MinValue;
|
minY = int.MinValue;
|
||||||
@ -91,7 +91,7 @@ namespace Spine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void aabbCompute () {
|
private void AabbCompute () {
|
||||||
float minX = int.MaxValue, minY = int.MaxValue, maxX = int.MinValue, maxY = int.MinValue;
|
float minX = int.MaxValue, minY = int.MaxValue, maxX = int.MinValue, maxY = int.MinValue;
|
||||||
ExposedList<Polygon> polygons = Polygons;
|
ExposedList<Polygon> polygons = Polygons;
|
||||||
for (int i = 0, n = polygons.Count; i < n; i++) {
|
for (int i = 0, n = polygons.Count; i < n; i++) {
|
||||||
@ -204,7 +204,7 @@ namespace Spine {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Polygon getPolygon (BoundingBoxAttachment attachment) {
|
public Polygon GetPolygon (BoundingBoxAttachment attachment) {
|
||||||
int index = BoundingBoxes.IndexOf(attachment);
|
int index = BoundingBoxes.IndexOf(attachment);
|
||||||
return index == -1 ? null : Polygons.Items[index];
|
return index == -1 ? null : Polygons.Items[index];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -263,12 +263,12 @@ namespace Spine.Unity.Editor {
|
|||||||
if (isBakingExpanded) {
|
if (isBakingExpanded) {
|
||||||
EditorGUI.indentLevel++;
|
EditorGUI.indentLevel++;
|
||||||
const string BakingWarningMessage =
|
const string BakingWarningMessage =
|
||||||
"WARNING!" +
|
// "WARNING!" +
|
||||||
"\nBaking is NOT the same as SkeletonAnimator!" +
|
// "\nBaking is NOT the same as SkeletonAnimator!" +
|
||||||
|
// "\n\n" +
|
||||||
|
"The main use of Baking is to export Spine projects to be used without the Spine Runtime (ie: for sale on the Asset Store, or background objects that are animated only with a wind noise generator)" +
|
||||||
|
|
||||||
"\n\nThe main use of Baking is to export Spine projects to be used without the Spine Runtime (ie: for sale on the Asset Store, or background objects that are animated only with a wind noise generator)" +
|
"\n\nBaking does not support the following:" +
|
||||||
|
|
||||||
"\n\nBaking also does not support the following:" +
|
|
||||||
"\n\tDisabled transform inheritance" +
|
"\n\tDisabled transform inheritance" +
|
||||||
"\n\tShear" +
|
"\n\tShear" +
|
||||||
"\n\tColor Keys" +
|
"\n\tColor Keys" +
|
||||||
@ -277,7 +277,7 @@ namespace Spine.Unity.Editor {
|
|||||||
|
|
||||||
"\n\nCurves are sampled at 60fps and are not realtime." +
|
"\n\nCurves are sampled at 60fps and are not realtime." +
|
||||||
"\nPlease read SkeletonBaker.cs comments for full details.";
|
"\nPlease read SkeletonBaker.cs comments for full details.";
|
||||||
EditorGUILayout.HelpBox(BakingWarningMessage, MessageType.Warning, true);
|
EditorGUILayout.HelpBox(BakingWarningMessage, MessageType.Info, true);
|
||||||
|
|
||||||
EditorGUI.indentLevel++;
|
EditorGUI.indentLevel++;
|
||||||
bakeAnimations = EditorGUILayout.Toggle("Bake Animations", bakeAnimations);
|
bakeAnimations = EditorGUILayout.Toggle("Bake Animations", bakeAnimations);
|
||||||
|
|||||||
@ -28,6 +28,8 @@
|
|||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
|
#pragma warning disable 0219
|
||||||
|
|
||||||
// Contributed by: Mitch Thompson
|
// Contributed by: Mitch Thompson
|
||||||
|
|
||||||
#define SPINE_SKELETONANIMATOR
|
#define SPINE_SKELETONANIMATOR
|
||||||
|
|||||||
@ -32,6 +32,8 @@ using System;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
|
|
||||||
|
using SpineInspectorUtility = Spine.Unity.Editor.SpineInspectorUtility;
|
||||||
|
|
||||||
public class SpineSpriteShaderGUI : ShaderGUI {
|
public class SpineSpriteShaderGUI : ShaderGUI {
|
||||||
static readonly string kShaderVertexLit = "Spine/Sprite/Vertex Lit";
|
static readonly string kShaderVertexLit = "Spine/Sprite/Vertex Lit";
|
||||||
static readonly string kShaderPixelLit = "Spine/Sprite/Pixel Lit";
|
static readonly string kShaderPixelLit = "Spine/Sprite/Pixel Lit";
|
||||||
@ -90,9 +92,10 @@ public class SpineSpriteShaderGUI : ShaderGUI {
|
|||||||
//Blend texture
|
//Blend texture
|
||||||
MaterialProperty _blendTexture = null;
|
MaterialProperty _blendTexture = null;
|
||||||
MaterialProperty _blendTextureLerp = null;
|
MaterialProperty _blendTextureLerp = null;
|
||||||
|
|
||||||
bool _firstTimeApply = true;
|
bool _firstTimeApply = true;
|
||||||
eLightMode _lightMode;
|
eLightMode _lightMode;
|
||||||
|
static bool showAdvanced = false;
|
||||||
|
|
||||||
#region ShaderGUI
|
#region ShaderGUI
|
||||||
public override void OnGUI (MaterialEditor materialEditor, MaterialProperty[] properties) {
|
public override void OnGUI (MaterialEditor materialEditor, MaterialProperty[] properties) {
|
||||||
@ -119,14 +122,14 @@ public class SpineSpriteShaderGUI : ShaderGUI {
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Virtual Interface
|
#region Virtual Interface
|
||||||
protected virtual void FindProperties(MaterialProperty[] props) {
|
protected virtual void FindProperties (MaterialProperty[] props) {
|
||||||
_mainTexture = FindProperty("_MainTex", props);
|
_mainTexture = FindProperty("_MainTex", props);
|
||||||
_color = FindProperty("_Color", props);
|
_color = FindProperty("_Color", props);
|
||||||
_blendMode = FindProperty("_BlendMode", props);
|
_blendMode = FindProperty("_BlendMode", props);
|
||||||
|
|
||||||
_emissionMap = FindProperty("_EmissionMap", props, false);
|
_emissionMap = FindProperty("_EmissionMap", props, false);
|
||||||
_emissionColor = FindProperty("_EmissionColor", props, false);
|
_emissionColor = FindProperty("_EmissionColor", props, false);
|
||||||
_emissionPower = FindProperty("_EmissionPower", props, false);
|
_emissionPower = FindProperty("_EmissionPower", props, false);
|
||||||
|
|
||||||
_writeToDepth = FindProperty("_ZWrite", props);
|
_writeToDepth = FindProperty("_ZWrite", props);
|
||||||
_depthAlphaCutoff = FindProperty("_Cutoff", props);
|
_depthAlphaCutoff = FindProperty("_Cutoff", props);
|
||||||
@ -149,259 +152,204 @@ public class SpineSpriteShaderGUI : ShaderGUI {
|
|||||||
_rimColor = FindProperty("_RimColor", props, false);
|
_rimColor = FindProperty("_RimColor", props, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void ShaderPropertiesGUI(Material material) {
|
protected virtual void ShaderPropertiesGUI (Material material) {
|
||||||
// Use default labelWidth
|
using (new EditorGUILayout.HorizontalScope()) {
|
||||||
EditorGUIUtility.labelWidth = 0f;
|
GUILayout.FlexibleSpace();
|
||||||
|
var showAdvancedLabel = new GUIContent("Show Advanced", "Show extra options under all sections. This only affects the inspector. The Material's resulting shader is still compiled/optimized based on what features you actually use and don't use.");
|
||||||
|
float lw = GUI.skin.toggle.CalcSize(showAdvancedLabel).x;
|
||||||
|
|
||||||
|
EditorGUIUtility.labelWidth = lw;
|
||||||
|
showAdvanced = EditorGUILayout.Toggle(showAdvancedLabel, showAdvanced);
|
||||||
|
EditorGUIUtility.labelWidth = 0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
EditorGUILayout.Space();
|
||||||
|
|
||||||
// Detect any changes to the material
|
|
||||||
EditorGUI.BeginChangeCheck();
|
EditorGUI.BeginChangeCheck();
|
||||||
{
|
{
|
||||||
//GUILayout.Label("Rendering", EditorStyles.boldLabel);
|
LightingModePopup();
|
||||||
{
|
BlendModePopup();
|
||||||
RenderModes(material);
|
|
||||||
|
if (showAdvanced) {
|
||||||
|
EditorGUILayout.Space();
|
||||||
|
EditorGUI.BeginChangeCheck();
|
||||||
|
int renderQueue = EditorGUILayout.IntSlider("Renderer Queue Offset", (int)_renderQueue.floatValue, 0, 49);
|
||||||
|
if (EditorGUI.EndChangeCheck()) material.SetInt("_RenderQueue", renderQueue);
|
||||||
|
|
||||||
|
EditorGUI.BeginChangeCheck();
|
||||||
|
eCulling culling = (eCulling)Mathf.RoundToInt(_culling.floatValue);
|
||||||
|
culling = (eCulling)EditorGUILayout.EnumPopup("Culling", culling);
|
||||||
|
if (EditorGUI.EndChangeCheck()) material.SetInt("_Cull", (int)culling);
|
||||||
|
|
||||||
|
EditorGUI.BeginChangeCheck();
|
||||||
|
bool fog = EditorGUILayout.Toggle("Use fog", material.IsKeywordEnabled("_FOG"));
|
||||||
|
if (EditorGUI.EndChangeCheck()) SetKeyword(material, "_FOG", fog);
|
||||||
}
|
}
|
||||||
|
|
||||||
GUILayout.Label("Main Maps", EditorStyles.boldLabel);
|
using (new SpineInspectorUtility.BoxScope())
|
||||||
{
|
RenderTextureProperties("Main Maps", material);
|
||||||
RenderTextureProperties(material);
|
|
||||||
}
|
|
||||||
|
|
||||||
GUILayout.Label("Depth", EditorStyles.boldLabel);
|
if (showAdvanced) {
|
||||||
{
|
using (new SpineInspectorUtility.BoxScope()) {
|
||||||
RenderDepthProperties(material);
|
Heading("Depth and Cast Shadow");
|
||||||
}
|
EditorGUI.BeginChangeCheck();
|
||||||
|
bool writeTodepth = EditorGUILayout.Toggle(new GUIContent("Write to Depth", "Write to Depth Buffer by clipping alpha."), _writeToDepth.floatValue != 0.0f);
|
||||||
|
if (EditorGUI.EndChangeCheck())
|
||||||
|
material.SetInt("_ZWrite", writeTodepth ? 1 : 0);
|
||||||
|
|
||||||
if (_fixedNormal != null)
|
if (writeTodepth)
|
||||||
{
|
_materialEditor.RangeProperty(_depthAlphaCutoff, "Depth Alpha Cutoff");
|
||||||
GUILayout.Label("Normals", EditorStyles.boldLabel);
|
|
||||||
RenderNormalsProperties(material);
|
|
||||||
}
|
|
||||||
|
|
||||||
GUILayout.Label("Shadows", EditorStyles.boldLabel);
|
EditorGUILayout.Space();
|
||||||
{
|
|
||||||
RenderShadowsProperties(material);
|
|
||||||
}
|
|
||||||
|
|
||||||
GUILayout.Label("Color Adjustment", EditorStyles.boldLabel);
|
_materialEditor.RangeProperty(_shadowAlphaCutoff, "Shadow Alpha Cutoff");
|
||||||
{
|
}
|
||||||
RenderColorProperties(material);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_emissionMap != null && _emissionColor != null)
|
if (_fixedNormal != null) {
|
||||||
{
|
using (new SpineInspectorUtility.BoxScope()) {
|
||||||
GUILayout.Label("Emission", EditorStyles.boldLabel);
|
Heading("Normals");
|
||||||
{
|
bool meshNormals = UseMeshNormalsCheckbox(material);
|
||||||
RenderEmissionProperties(material);
|
if (!meshNormals) {
|
||||||
|
Vector3 normal;
|
||||||
|
EditorGUI.BeginChangeCheck();
|
||||||
|
normal = showAdvanced ? EditorGUILayout.Vector3Field(new GUIContent("Fixed Normal", "Defined in Camera Space. Should normally be (0,0,-1)."), _fixedNormal.vectorValue) : (Vector3)_fixedNormal.vectorValue;
|
||||||
|
if (EditorGUI.EndChangeCheck())
|
||||||
|
_fixedNormal.vectorValue = new Vector4(normal.x, normal.y, normal.z, 1.0f);
|
||||||
|
|
||||||
|
bool backRendering;
|
||||||
|
EditorGUI.BeginChangeCheck();
|
||||||
|
if (showAdvanced) {
|
||||||
|
backRendering = EditorGUILayout.Toggle(new GUIContent("Fixed Normal Back Rendering", "Tick only if you are going to rotate the sprite to face away from the camera, the fixed normal will be flipped to compensate."),
|
||||||
|
material.IsKeywordEnabled("_FIXED_NORMALS_BACK_RENDERING"));
|
||||||
|
} else {
|
||||||
|
backRendering = material.IsKeywordEnabled("_FIXED_NORMALS_BACK_RENDERING");
|
||||||
|
}
|
||||||
|
if (EditorGUI.EndChangeCheck()) {
|
||||||
|
SetKeyword(material, "_FIXED_NORMALS_BACK_RENDERING", backRendering);
|
||||||
|
SetKeyword(material, "_FIXED_NORMALS", !backRendering);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
using (new SpineInspectorUtility.BoxScope()) {
|
||||||
|
EditorGUI.BeginChangeCheck();
|
||||||
|
bool writeTodepth = EditorGUILayout.Toggle(new GUIContent("Write to Depth", "Write to Depth Buffer by clipping alpha."), _writeToDepth.floatValue != 0.0f);
|
||||||
|
if (EditorGUI.EndChangeCheck())
|
||||||
|
material.SetInt("_ZWrite", writeTodepth ? 1 : 0);
|
||||||
|
|
||||||
|
if (_fixedNormal != null)
|
||||||
|
UseMeshNormalsCheckbox(material);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_rimColor != null)
|
using (new SpineInspectorUtility.BoxScope())
|
||||||
{
|
RenderColorProperties("Color Adjustment", material);
|
||||||
GUILayout.Label("Rim Lighting", EditorStyles.boldLabel);
|
|
||||||
RenderRimLightingProperties(material);
|
|
||||||
}
|
|
||||||
|
|
||||||
GUILayout.Label("Fog", EditorStyles.boldLabel);
|
if (_emissionMap != null && _emissionColor != null && _rimColor != null) {
|
||||||
{
|
Heading("Extra Lighting");
|
||||||
RenderFogProperties(material);
|
|
||||||
|
if (_emissionMap != null && _emissionColor != null)
|
||||||
|
using (new SpineInspectorUtility.BoxScope())
|
||||||
|
RenderEmissionProperties(material);
|
||||||
|
|
||||||
|
if (_rimColor != null)
|
||||||
|
using (new SpineInspectorUtility.BoxScope())
|
||||||
|
RenderRimLightingProperties(material);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (EditorGUI.EndChangeCheck()) {
|
||||||
if (EditorGUI.EndChangeCheck())
|
|
||||||
{
|
|
||||||
foreach (var obj in _blendMode.targets)
|
foreach (var obj in _blendMode.targets)
|
||||||
MaterialChanged((Material)obj);
|
MaterialChanged((Material)obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void RenderModes (Material material) {
|
protected virtual void RenderTextureProperties (string label, Material material) {
|
||||||
LightingModePopup();
|
if (showAdvanced)
|
||||||
BlendModePopup();
|
Heading(label);
|
||||||
|
|
||||||
EditorGUI.BeginChangeCheck();
|
_materialEditor.TexturePropertySingleLine(new GUIContent(showAdvanced ? "Albedo" : "Main Texture"), _mainTexture, _color);
|
||||||
int renderQueue = EditorGUILayout.IntSlider("Renderer Queue", (int)_renderQueue.floatValue, 0, 49);
|
|
||||||
if (EditorGUI.EndChangeCheck())
|
|
||||||
{
|
|
||||||
material.SetInt("_RenderQueue", renderQueue);
|
|
||||||
}
|
|
||||||
|
|
||||||
EditorGUI.BeginChangeCheck();
|
|
||||||
eCulling culling = (eCulling)Mathf.RoundToInt(_culling.floatValue);
|
|
||||||
culling = (eCulling)EditorGUILayout.EnumPopup("Culling", culling);
|
|
||||||
if (EditorGUI.EndChangeCheck())
|
|
||||||
{
|
|
||||||
material.SetInt("_Cull", (int)culling);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void RenderTextureProperties (Material material) {
|
|
||||||
_materialEditor.TexturePropertySingleLine(new GUIContent("Albedo"), _mainTexture, _color);
|
|
||||||
|
|
||||||
if (_bumpMap != null)
|
if (_bumpMap != null)
|
||||||
_materialEditor.TexturePropertySingleLine(new GUIContent("Normal Map"), _bumpMap);
|
_materialEditor.TexturePropertySingleLine(new GUIContent("Normal Map"), _bumpMap);
|
||||||
|
|
||||||
if (_diffuseRamp != null)
|
if (showAdvanced) {
|
||||||
_materialEditor.TexturePropertySingleLine(new GUIContent("Diffuse Ramp", "A black and white gradient can be used to create a 'Toon Shading' effect."), _diffuseRamp);
|
if (_blendTexture != null) {
|
||||||
|
EditorGUI.BeginChangeCheck();
|
||||||
if (_blendTexture != null)
|
_materialEditor.TexturePropertySingleLine(new GUIContent("Blend Texture", "When a blend texture is set the albedo will be a mix of the blend texture and main texture based on the blend amount."), _blendTexture, _blendTextureLerp);
|
||||||
{
|
if (EditorGUI.EndChangeCheck())
|
||||||
EditorGUI.BeginChangeCheck();
|
SetKeyword(material, "_TEXTURE_BLEND", _blendTexture != null);
|
||||||
_materialEditor.TexturePropertySingleLine(new GUIContent("Blend Texture", "When a blend texture is set the albedo will be a mix of the blend texture and main texture based on the blend amount."), _blendTexture, _blendTextureLerp);
|
|
||||||
if (EditorGUI.EndChangeCheck())
|
|
||||||
{
|
|
||||||
SetKeyword(material, "_TEXTURE_BLEND", _blendTexture != null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_materialEditor.TextureScaleOffsetProperty(_mainTexture);
|
if (_diffuseRamp != null) {
|
||||||
}
|
EditorGUILayout.Space();
|
||||||
|
_materialEditor.TexturePropertySingleLine(new GUIContent("Diffuse Ramp", "A gradient can be used to create a 'Toon Shading' effect."), _diffuseRamp);
|
||||||
protected virtual void RenderEmissionProperties (Material material) {
|
|
||||||
bool emission = material.IsKeywordEnabled("_EMISSION");
|
|
||||||
|
|
||||||
EditorGUI.BeginChangeCheck();
|
|
||||||
emission = EditorGUILayout.Toggle("Enable Emission", emission);
|
|
||||||
if (EditorGUI.EndChangeCheck())
|
|
||||||
{
|
|
||||||
SetKeyword(material, "_EMISSION", emission);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (emission)
|
// if (showAdvanced)
|
||||||
{
|
// _materialEditor.TextureScaleOffsetProperty(_mainTexture);
|
||||||
_materialEditor.TexturePropertyWithHDRColor(new GUIContent("Emission"), _emissionMap, _emissionColor, new ColorPickerHDRConfig(0,1, 0.01010101f, 3), true);
|
|
||||||
_materialEditor.FloatProperty(_emissionPower, "Emission Power");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void RenderDepthProperties (Material material) {
|
protected virtual void RenderDepthProperties (string label, Material material) {
|
||||||
EditorGUI.BeginChangeCheck();
|
|
||||||
bool writeTodepth = EditorGUILayout.Toggle(new GUIContent("Write to Depth", "Write to Depth Buffer by clipping alpha."), _writeToDepth.floatValue != 0.0f);
|
|
||||||
if (EditorGUI.EndChangeCheck())
|
|
||||||
{
|
|
||||||
material.SetInt("_ZWrite", writeTodepth ? 1 : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (writeTodepth)
|
|
||||||
{
|
|
||||||
_materialEditor.RangeProperty(_depthAlphaCutoff, "Depth Alpha Cutoff");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void RenderNormalsProperties (Material material) {
|
protected virtual void RenderNormalsProperties (string label, Material material) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool UseMeshNormalsCheckbox (Material material) {
|
||||||
EditorGUI.BeginChangeCheck();
|
EditorGUI.BeginChangeCheck();
|
||||||
bool fixedNormals = material.IsKeywordEnabled("_FIXED_NORMALS");
|
bool fixedNormals = material.IsKeywordEnabled("_FIXED_NORMALS");
|
||||||
bool fixedNormalsBackRendering = material.IsKeywordEnabled("_FIXED_NORMALS_BACK_RENDERING");
|
bool fixedNormalsBackRendering = material.IsKeywordEnabled("_FIXED_NORMALS_BACK_RENDERING");
|
||||||
|
bool meshNormals = EditorGUILayout.Toggle(new GUIContent("Use Mesh Normals", "If this is unticked, a Fixed Normal value will be used instead of the vertex normals on the mesh. Using a fixed normal is better for performance and can result in better looking lighting effects on 2d objects."),
|
||||||
bool meshNormals = EditorGUILayout.Toggle(new GUIContent("Use Mesh Normals", "If this is unticked instead of requiring mesh normals a Fixed Normal will be used instead (it's quicker and can result in better looking lighting effects on 2d objects)."),
|
!fixedNormals && !fixedNormalsBackRendering);
|
||||||
!fixedNormals && !fixedNormalsBackRendering);
|
if (EditorGUI.EndChangeCheck()) {
|
||||||
if (EditorGUI.EndChangeCheck())
|
|
||||||
{
|
|
||||||
SetKeyword(material, "_FIXED_NORMALS", meshNormals ? false : fixedNormalsBackRendering ? false : true);
|
SetKeyword(material, "_FIXED_NORMALS", meshNormals ? false : fixedNormalsBackRendering ? false : true);
|
||||||
SetKeyword(material, "_FIXED_NORMALS_BACK_RENDERING", meshNormals ? false : fixedNormalsBackRendering);
|
SetKeyword(material, "_FIXED_NORMALS_BACK_RENDERING", meshNormals ? false : fixedNormalsBackRendering);
|
||||||
}
|
}
|
||||||
|
return meshNormals;
|
||||||
|
}
|
||||||
|
|
||||||
if (!meshNormals)
|
protected virtual void RenderColorProperties (string label, Material material) {
|
||||||
{
|
if (ToggleHeadingKeyword(label, material, "_COLOR_ADJUST")) {
|
||||||
Vector3 normal = EditorGUILayout.Vector3Field(new GUIContent("Fixed Normal", "Defined in Camera Space. Should normally be (0,0,-1)."), _fixedNormal.vectorValue);
|
_materialEditor.ColorProperty(_overlayColor, "Overlay Color");
|
||||||
_fixedNormal.vectorValue = new Vector4(normal.x, normal.y, normal.z, 1.0f);
|
EditorGUILayout.Space();
|
||||||
|
using (new SpineInspectorUtility.IndentScope()) {
|
||||||
EditorGUI.BeginChangeCheck();
|
_materialEditor.RangeProperty(_hue, "Hue");
|
||||||
|
_materialEditor.RangeProperty(_saturation, "Saturation");
|
||||||
|
_materialEditor.RangeProperty(_brightness, "Brightness");
|
||||||
|
|
||||||
bool backRendering = EditorGUILayout.Toggle(new GUIContent("Fixed Normal Back Rendering", "Tick only if you are going to rotate the sprite to face away from the camera, the fixed normal will be flipped to compensate."),
|
|
||||||
material.IsKeywordEnabled("_FIXED_NORMALS_BACK_RENDERING"));
|
|
||||||
if (EditorGUI.EndChangeCheck())
|
|
||||||
{
|
|
||||||
SetKeyword(material, "_FIXED_NORMALS_BACK_RENDERING", backRendering);
|
|
||||||
SetKeyword(material, "_FIXED_NORMALS", !backRendering);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void RenderShadowsProperties (Material material) {
|
protected virtual void RenderEmissionProperties (Material material) {
|
||||||
_materialEditor.FloatProperty(_shadowAlphaCutoff, "Shadow Alpha Cutoff");
|
if (ToggleHeadingKeyword("Emission", material, "_EMISSION")) {
|
||||||
}
|
_materialEditor.TexturePropertyWithHDRColor(new GUIContent("Emission"), _emissionMap, _emissionColor, new ColorPickerHDRConfig(0,1, 0.01010101f, 3), true);
|
||||||
|
_materialEditor.FloatProperty(_emissionPower, "Emission Power");
|
||||||
protected virtual void RenderColorProperties (Material material) {
|
|
||||||
EditorGUI.BeginChangeCheck();
|
|
||||||
bool colorAdjust = EditorGUILayout.Toggle("Enable Color Adjustment", material.IsKeywordEnabled("_COLOR_ADJUST"));
|
|
||||||
if (EditorGUI.EndChangeCheck())
|
|
||||||
{
|
|
||||||
SetKeyword(material, "_COLOR_ADJUST", colorAdjust);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (colorAdjust) {
|
|
||||||
_materialEditor.ColorProperty(_overlayColor, "Overlay Color");
|
|
||||||
_materialEditor.RangeProperty(_hue, "Hue");
|
|
||||||
_materialEditor.RangeProperty(_saturation, "Saturation");
|
|
||||||
_materialEditor.RangeProperty(_brightness, "Brightness");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void RenderRimLightingProperties (Material material) {
|
protected virtual void RenderRimLightingProperties (Material material) {
|
||||||
EditorGUI.BeginChangeCheck();
|
if (ToggleHeadingKeyword("Rim Lighting", material, "_RIM_LIGHTING")) {
|
||||||
bool rimLighting = EditorGUILayout.Toggle("Enable Rim Lighting", material.IsKeywordEnabled("_RIM_LIGHTING"));
|
|
||||||
if (EditorGUI.EndChangeCheck())
|
|
||||||
{
|
|
||||||
SetKeyword(material, "_RIM_LIGHTING", rimLighting);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rimLighting)
|
|
||||||
{
|
|
||||||
_materialEditor.ColorProperty(_rimColor, "Rim Color");
|
_materialEditor.ColorProperty(_rimColor, "Rim Color");
|
||||||
_materialEditor.FloatProperty(_rimPower, "Rim Power");
|
_materialEditor.FloatProperty(_rimPower, "Rim Power");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void RenderFogProperties (Material material) {
|
|
||||||
EditorGUI.BeginChangeCheck();
|
|
||||||
bool fog = EditorGUILayout.Toggle("Enable Fog", material.IsKeywordEnabled("_FOG"));
|
|
||||||
if (EditorGUI.EndChangeCheck())
|
|
||||||
{
|
|
||||||
SetKeyword(material, "_FOG", fog);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
void SetLightModeFromShader (Material material) {
|
void SetLightModeFromShader (Material material) {
|
||||||
if (material.shader.name == kShaderPixelLit)
|
if (material.shader.name == kShaderPixelLit)
|
||||||
{
|
|
||||||
_lightMode = eLightMode.PixelLit;
|
_lightMode = eLightMode.PixelLit;
|
||||||
}
|
|
||||||
else if (material.shader.name == kShaderUnlit)
|
else if (material.shader.name == kShaderUnlit)
|
||||||
{
|
|
||||||
_lightMode = eLightMode.Unlit;
|
_lightMode = eLightMode.Unlit;
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
_lightMode = eLightMode.VertexLit;
|
_lightMode = eLightMode.VertexLit;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetShaderFromLightMode() {
|
static void SetMaterialKeywords (Material material) {
|
||||||
Material material = _materialEditor.target as Material;
|
|
||||||
|
|
||||||
switch (_lightMode)
|
|
||||||
{
|
|
||||||
case eLightMode.VertexLit:
|
|
||||||
if (material.shader.name != kShaderVertexLit)
|
|
||||||
_materialEditor.SetShader(Shader.Find(kShaderVertexLit), false);
|
|
||||||
break;
|
|
||||||
case eLightMode.PixelLit:
|
|
||||||
if (material.shader.name != kShaderPixelLit)
|
|
||||||
_materialEditor.SetShader(Shader.Find(kShaderPixelLit), false);
|
|
||||||
break;
|
|
||||||
case eLightMode.Unlit:
|
|
||||||
if (material.shader.name != kShaderUnlit)
|
|
||||||
_materialEditor.SetShader(Shader.Find(kShaderUnlit), false);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
MaterialChanged(material);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void SetMaterialKeywords(Material material) {
|
|
||||||
eBlendMode blendMode = (eBlendMode)material.GetFloat("_BlendMode");
|
eBlendMode blendMode = (eBlendMode)material.GetFloat("_BlendMode");
|
||||||
|
|
||||||
bool normalMap = material.HasProperty("_BumpMap") && material.GetTexture("_BumpMap") != null;
|
bool normalMap = material.HasProperty("_BumpMap") && material.GetTexture("_BumpMap") != null;
|
||||||
@ -426,79 +374,114 @@ public class SpineSpriteShaderGUI : ShaderGUI {
|
|||||||
int renderQueue;
|
int renderQueue;
|
||||||
|
|
||||||
switch (blendMode) {
|
switch (blendMode) {
|
||||||
case eBlendMode.Solid:
|
case eBlendMode.Solid:
|
||||||
{
|
{
|
||||||
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
|
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
|
||||||
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
|
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
|
||||||
material.SetOverrideTag("RenderType", "Opaque");
|
material.SetOverrideTag("RenderType", "Opaque");
|
||||||
renderQueue = kSolidQueue;
|
renderQueue = kSolidQueue;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case eBlendMode.Additive:
|
case eBlendMode.Additive:
|
||||||
{
|
{
|
||||||
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
|
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
|
||||||
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.One);
|
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.One);
|
||||||
material.SetOverrideTag("RenderType", "Transparent");
|
material.SetOverrideTag("RenderType", "Transparent");
|
||||||
renderQueue = kTransparentQueue;
|
renderQueue = kTransparentQueue;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case eBlendMode.SoftAdditive:
|
case eBlendMode.SoftAdditive:
|
||||||
{
|
{
|
||||||
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
|
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
|
||||||
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcColor);
|
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcColor);
|
||||||
material.SetOverrideTag("RenderType", "Transparent");
|
material.SetOverrideTag("RenderType", "Transparent");
|
||||||
renderQueue = kTransparentQueue;
|
renderQueue = kTransparentQueue;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case eBlendMode.Multiply:
|
case eBlendMode.Multiply:
|
||||||
{
|
{
|
||||||
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
|
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
|
||||||
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.SrcColor);
|
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.SrcColor);
|
||||||
material.SetOverrideTag("RenderType", "Transparent");
|
material.SetOverrideTag("RenderType", "Transparent");
|
||||||
renderQueue = kTransparentQueue;
|
renderQueue = kTransparentQueue;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case eBlendMode.Multiplyx2:
|
case eBlendMode.Multiplyx2:
|
||||||
{
|
{
|
||||||
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.DstColor);
|
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.DstColor);
|
||||||
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.SrcColor);
|
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.SrcColor);
|
||||||
material.SetOverrideTag("RenderType", "Transparent");
|
material.SetOverrideTag("RenderType", "Transparent");
|
||||||
renderQueue = kTransparentQueue;
|
renderQueue = kTransparentQueue;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case eBlendMode.PreMultipliedAlpha:
|
case eBlendMode.PreMultipliedAlpha:
|
||||||
case eBlendMode.StandardAlpha:
|
case eBlendMode.StandardAlpha:
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
|
material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
|
||||||
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
|
material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
|
||||||
material.SetOverrideTag("RenderType", zWrite ? "TransparentCutout" : "Transparent");
|
material.SetOverrideTag("RenderType", zWrite ? "TransparentCutout" : "Transparent");
|
||||||
renderQueue = zWrite ? kAlphaTestQueue : kTransparentQueue;
|
renderQueue = zWrite ? kAlphaTestQueue : kTransparentQueue;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
material.renderQueue = renderQueue + material.GetInt("_RenderQueue");
|
material.renderQueue = renderQueue + material.GetInt("_RenderQueue");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void MaterialChanged (Material material) {
|
static void Heading (string label) {
|
||||||
|
GUILayout.Label(label, EditorStyles.boldLabel);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool ToggleHeadingKeyword (string label, Material material, string keyword) {
|
||||||
|
int i = EditorGUI.indentLevel;
|
||||||
|
var o = EditorStyles.label.fontStyle;
|
||||||
|
EditorGUI.indentLevel = 0;
|
||||||
|
EditorStyles.label.fontStyle = FontStyle.Bold;
|
||||||
|
|
||||||
|
EditorGUI.BeginChangeCheck();
|
||||||
|
bool r = EditorGUILayout.Toggle(new GUIContent(label, string.Format("This checkbox sets shader keyword: '{0}', which causes the Material to use extra shader features.", keyword)), material.IsKeywordEnabled(keyword));
|
||||||
|
if (EditorGUI.EndChangeCheck())
|
||||||
|
SetKeyword(material, keyword, r);
|
||||||
|
|
||||||
|
EditorStyles.label.fontStyle = o;
|
||||||
|
EditorGUI.indentLevel = i;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void MaterialChanged (Material material) {
|
||||||
SetMaterialKeywords(material);
|
SetMaterialKeywords(material);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SetKeyword (Material m, string keyword, bool state) {
|
static void SetKeyword (Material m, string keyword, bool state) {
|
||||||
if (state)
|
if (state)
|
||||||
m.EnableKeyword (keyword);
|
m.EnableKeyword(keyword);
|
||||||
else
|
else
|
||||||
m.DisableKeyword (keyword);
|
m.DisableKeyword(keyword);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LightingModePopup ()
|
void LightingModePopup () {
|
||||||
{
|
|
||||||
EditorGUI.BeginChangeCheck();
|
EditorGUI.BeginChangeCheck();
|
||||||
_lightMode = (eLightMode)EditorGUILayout.Popup("Lighting Mode", (int)_lightMode, Enum.GetNames(typeof(eLightMode)));
|
_lightMode = (eLightMode)EditorGUILayout.Popup("Lighting Mode", (int)_lightMode, Enum.GetNames(typeof(eLightMode)));
|
||||||
if (EditorGUI.EndChangeCheck())
|
if (EditorGUI.EndChangeCheck()) {
|
||||||
{
|
var material = _materialEditor.target as Material;
|
||||||
SetShaderFromLightMode();
|
|
||||||
|
switch (_lightMode) {
|
||||||
|
case eLightMode.VertexLit:
|
||||||
|
if (material.shader.name != kShaderVertexLit)
|
||||||
|
_materialEditor.SetShader(Shader.Find(kShaderVertexLit), false);
|
||||||
|
break;
|
||||||
|
case eLightMode.PixelLit:
|
||||||
|
if (material.shader.name != kShaderPixelLit)
|
||||||
|
_materialEditor.SetShader(Shader.Find(kShaderPixelLit), false);
|
||||||
|
break;
|
||||||
|
case eLightMode.Unlit:
|
||||||
|
if (material.shader.name != kShaderUnlit)
|
||||||
|
_materialEditor.SetShader(Shader.Find(kShaderUnlit), false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
MaterialChanged(material);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -506,8 +489,7 @@ public class SpineSpriteShaderGUI : ShaderGUI {
|
|||||||
eBlendMode mode = (eBlendMode)_blendMode.floatValue;
|
eBlendMode mode = (eBlendMode)_blendMode.floatValue;
|
||||||
EditorGUI.BeginChangeCheck();
|
EditorGUI.BeginChangeCheck();
|
||||||
mode = (eBlendMode)EditorGUILayout.Popup("Blend Mode", (int)mode, Enum.GetNames(typeof(eBlendMode)));
|
mode = (eBlendMode)EditorGUILayout.Popup("Blend Mode", (int)mode, Enum.GetNames(typeof(eBlendMode)));
|
||||||
if (EditorGUI.EndChangeCheck())
|
if (EditorGUI.EndChangeCheck()) {
|
||||||
{
|
|
||||||
_materialEditor.RegisterPropertyChangeUndo("Blend Mode");
|
_materialEditor.RegisterPropertyChangeUndo("Blend Mode");
|
||||||
_blendMode.floatValue = (float)mode;
|
_blendMode.floatValue = (float)mode;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -180,7 +180,7 @@ namespace Spine.Unity {
|
|||||||
for (int i = 0; i < bufferTargetSize; i++) {
|
for (int i = 0; i < bufferTargetSize; i++) {
|
||||||
int j = i * 2;
|
int j = i * 2;
|
||||||
float x = floats[j] - bwx, y = floats[j+1] - bwy;
|
float x = floats[j] - bwx, y = floats[j+1] - bwy;
|
||||||
buffer[i] = new Vector2(x * ia + y * ic, x * ib + y * id);
|
buffer[i] = new Vector2(x * ia + y * ib, x * ic + y * id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -184,7 +184,7 @@ namespace Spine.Unity.Editor {
|
|||||||
using (new EditorGUI.DisabledGroupScope(multiObject || boundingBoxTable.Count == 0)) {
|
using (new EditorGUI.DisabledGroupScope(multiObject || boundingBoxTable.Count == 0)) {
|
||||||
EditorGUILayout.LabelField(new GUIContent("Bounding Boxes", SpineEditorUtilities.Icons.boundingBox), EditorStyles.boldLabel);
|
EditorGUILayout.LabelField(new GUIContent("Bounding Boxes", SpineEditorUtilities.Icons.boundingBox), EditorStyles.boldLabel);
|
||||||
|
|
||||||
foreach(var entry in boundingBoxTable){
|
foreach (var entry in boundingBoxTable){
|
||||||
Slot slot = entry.Key;
|
Slot slot = entry.Key;
|
||||||
var boundingBoxes = entry.Value;
|
var boundingBoxes = entry.Value;
|
||||||
|
|
||||||
@ -195,19 +195,21 @@ namespace Spine.Unity.Editor {
|
|||||||
foreach (var box in boundingBoxes) {
|
foreach (var box in boundingBoxes) {
|
||||||
using (new GUILayout.HorizontalScope()) {
|
using (new GUILayout.HorizontalScope()) {
|
||||||
GUILayout.Space(30);
|
GUILayout.Space(30);
|
||||||
if (GUILayout.Button(box.Name, GUILayout.Width(200))) {
|
string buttonLabel = box.IsWeighted() ? box.Name + " (!)" : box.Name;
|
||||||
var child = utilityBone.transform.FindChild("[BoundingBox]" + box.Name);
|
if (GUILayout.Button(buttonLabel, GUILayout.Width(200))) {
|
||||||
if (child != null) {
|
utilityBone.bone.Skeleton.UpdateWorldTransform();
|
||||||
var originalCollider = child.GetComponent<PolygonCollider2D>();
|
var bbTransform = utilityBone.transform.FindChild("[BoundingBox]" + box.Name);
|
||||||
var updatedCollider = SkeletonUtility.AddBoundingBoxAsComponent(box, slot, child.gameObject, originalCollider.isTrigger);
|
if (bbTransform != null) {
|
||||||
originalCollider.points = updatedCollider.points;
|
var originalCollider = bbTransform.GetComponent<PolygonCollider2D>();
|
||||||
if (EditorApplication.isPlaying)
|
if (originalCollider != null)
|
||||||
Destroy(updatedCollider);
|
SkeletonUtility.SetColliderPointsLocal(originalCollider, slot, box);
|
||||||
else
|
else
|
||||||
DestroyImmediate(updatedCollider);
|
SkeletonUtility.AddBoundingBoxAsComponent(box, slot, bbTransform.gameObject);
|
||||||
} else {
|
} else {
|
||||||
utilityBone.AddBoundingBox(currentSkinName, slot.Data.Name, box.Name);
|
var newPolygonCollider = SkeletonUtility.AddBoundingBoxGameObject(null, box, slot, utilityBone.transform);
|
||||||
|
bbTransform = newPolygonCollider.transform;
|
||||||
}
|
}
|
||||||
|
EditorGUIUtility.PingObject(bbTransform);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -31,7 +31,6 @@
|
|||||||
// Contributed by: Mitch Thompson
|
// Contributed by: Mitch Thompson
|
||||||
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Spine;
|
using Spine;
|
||||||
|
|
||||||
@ -41,40 +40,55 @@ namespace Spine.Unity {
|
|||||||
public class SkeletonUtility : MonoBehaviour {
|
public class SkeletonUtility : MonoBehaviour {
|
||||||
|
|
||||||
#region BoundingBoxAttachment
|
#region BoundingBoxAttachment
|
||||||
public static PolygonCollider2D AddBoundingBox (Skeleton skeleton, string skinName, string slotName, string attachmentName, Transform parent, bool isTrigger = true) {
|
public static PolygonCollider2D AddBoundingBoxGameObject (Skeleton skeleton, string skinName, string slotName, string attachmentName, Transform parent, bool isTrigger = true) {
|
||||||
skinName = string.IsNullOrEmpty(skinName) ? skinName : skeleton.Data.DefaultSkin.Name;
|
Skin skin = string.IsNullOrEmpty(skinName) ? skeleton.data.defaultSkin : skeleton.data.FindSkin(skinName);
|
||||||
Skin skin = skeleton.Data.FindSkin(skinName);
|
|
||||||
if (skin == null) {
|
if (skin == null) {
|
||||||
Debug.LogError("Skin " + skinName + " not found!");
|
Debug.LogError("Skin " + skinName + " not found!");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int slotIndex = skeleton.FindSlotIndex(slotName);
|
||||||
var attachment = skin.GetAttachment(skeleton.FindSlotIndex(slotName), attachmentName);
|
var attachment = skin.GetAttachment(skeleton.FindSlotIndex(slotName), attachmentName);
|
||||||
var box = attachment as BoundingBoxAttachment;
|
if (attachment == null) {
|
||||||
if (box != null) {
|
Debug.LogFormat("Attachment in slot '{0}' named '{1}' not found in skin '{2}'.", slotName, attachmentName, skin.name);
|
||||||
var go = new GameObject("[BoundingBox]" + attachmentName);
|
return null;
|
||||||
var got = go.transform;
|
|
||||||
got.parent = parent;
|
|
||||||
got.localPosition = Vector3.zero;
|
|
||||||
got.localRotation = Quaternion.identity;
|
|
||||||
got.localScale = Vector3.one;
|
|
||||||
var slot = skeleton.FindSlot(slotName);
|
|
||||||
return AddBoundingBoxAsComponent(box, slot, go, isTrigger);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
var box = attachment as BoundingBoxAttachment;
|
||||||
|
if (box != null) {
|
||||||
|
var slot = skeleton.FindSlot(slotName);
|
||||||
|
return AddBoundingBoxGameObject(box.Name, box, slot, parent, isTrigger);
|
||||||
|
} else {
|
||||||
|
Debug.LogFormat("Attachment '{0}' was not a Bounding Box.", attachmentName);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PolygonCollider2D AddBoundingBoxGameObject (string name, BoundingBoxAttachment box, Slot slot, Transform parent, bool isTrigger = true) {
|
||||||
|
var go = new GameObject("[BoundingBox]" + (string.IsNullOrEmpty(name) ? box.Name : name));
|
||||||
|
var got = go.transform;
|
||||||
|
got.parent = parent;
|
||||||
|
got.localPosition = Vector3.zero;
|
||||||
|
got.localRotation = Quaternion.identity;
|
||||||
|
got.localScale = Vector3.one;
|
||||||
|
return AddBoundingBoxAsComponent(box, slot, go, isTrigger);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PolygonCollider2D AddBoundingBoxAsComponent (BoundingBoxAttachment box, Slot slot, GameObject gameObject, bool isTrigger = true) {
|
public static PolygonCollider2D AddBoundingBoxAsComponent (BoundingBoxAttachment box, Slot slot, GameObject gameObject, bool isTrigger = true) {
|
||||||
if (box == null) return null;
|
if (box == null) return null;
|
||||||
if (box.IsWeighted()) Debug.LogWarning("UnityEngine.PolygonCollider2D does not support weighted or animated points. Collider will not be animated. Please remove weights and animations from the bounding box in Spine editor.");
|
|
||||||
var verts = box.GetLocalVertices(slot, null);
|
|
||||||
var collider = gameObject.AddComponent<PolygonCollider2D>();
|
var collider = gameObject.AddComponent<PolygonCollider2D>();
|
||||||
collider.isTrigger = isTrigger;
|
collider.isTrigger = isTrigger;
|
||||||
collider.SetPath(0, verts);
|
SetColliderPointsLocal(collider, slot, box);
|
||||||
return collider;
|
return collider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void SetColliderPointsLocal (PolygonCollider2D collider, Slot slot, BoundingBoxAttachment box) {
|
||||||
|
if (box == null) return;
|
||||||
|
if (box.IsWeighted()) Debug.LogWarning("UnityEngine.PolygonCollider2D does not support weighted or animated points. Collider points will not be animated and may have incorrect orientation. If you want to use it as a collider, please remove weights and animations from the bounding box in Spine editor.");
|
||||||
|
var verts = box.GetLocalVertices(slot, null);
|
||||||
|
collider.SetPath(0, verts);
|
||||||
|
}
|
||||||
|
|
||||||
public static Bounds GetBoundingBoxBounds (BoundingBoxAttachment boundingBox, float depth = 0) {
|
public static Bounds GetBoundingBoxBounds (BoundingBoxAttachment boundingBox, float depth = 0) {
|
||||||
float[] floats = boundingBox.Vertices;
|
float[] floats = boundingBox.Vertices;
|
||||||
int floatCount = floats.Length;
|
int floatCount = floats.Length;
|
||||||
|
|||||||
@ -63,9 +63,7 @@ namespace Spine.Unity {
|
|||||||
Transform cachedTransform;
|
Transform cachedTransform;
|
||||||
Transform skeletonTransform;
|
Transform skeletonTransform;
|
||||||
bool incompatibleTransformMode;
|
bool incompatibleTransformMode;
|
||||||
public bool IncompatibleTransformMode {
|
public bool IncompatibleTransformMode { get { return incompatibleTransformMode; } }
|
||||||
get { return incompatibleTransformMode; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Reset () {
|
public void Reset () {
|
||||||
bone = null;
|
bone = null;
|
||||||
@ -132,7 +130,7 @@ namespace Spine.Unity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (scale) {
|
if (scale) {
|
||||||
cachedTransform.localScale = new Vector3(bone.scaleX, bone.scaleY, 1f);//, bone.WorldSignX);
|
cachedTransform.localScale = new Vector3(bone.scaleX, bone.scaleY, 1f);
|
||||||
incompatibleTransformMode = BoneTransformModeIncompatible(bone);
|
incompatibleTransformMode = BoneTransformModeIncompatible(bone);
|
||||||
}
|
}
|
||||||
} else if (mode == Mode.Override) {
|
} else if (mode == Mode.Override) {
|
||||||
@ -193,7 +191,7 @@ namespace Spine.Unity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void AddBoundingBox (string skinName, string slotName, string attachmentName) {
|
public void AddBoundingBox (string skinName, string slotName, string attachmentName) {
|
||||||
SkeletonUtility.AddBoundingBox(bone.skeleton, skinName, slotName, attachmentName, transform);
|
SkeletonUtility.AddBoundingBoxGameObject(bone.skeleton, skinName, slotName, attachmentName, transform);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user