mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
Merge remote-tracking branch 'esotericsoftware/master'
This commit is contained in:
commit
92fb16b7c2
@ -70,6 +70,7 @@
|
|||||||
<Compile Include="src\AnimationState.cs" />
|
<Compile Include="src\AnimationState.cs" />
|
||||||
<Compile Include="src\Event.cs" />
|
<Compile Include="src\Event.cs" />
|
||||||
<Compile Include="src\EventData.cs" />
|
<Compile Include="src\EventData.cs" />
|
||||||
|
<Compile Include="src\ExposedList.cs" />
|
||||||
<Compile Include="src\IkConstraint.cs" />
|
<Compile Include="src\IkConstraint.cs" />
|
||||||
<Compile Include="src\IkConstraintData.cs" />
|
<Compile Include="src\IkConstraintData.cs" />
|
||||||
<Compile Include="src\Json.cs" />
|
<Compile Include="src\Json.cs" />
|
||||||
@ -82,12 +83,12 @@
|
|||||||
<Compile Include="src\SlotData.cs" />
|
<Compile Include="src\SlotData.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
<!--
|
<!--
|
||||||
To modify your build process, add your task inside one of the targets below and uncomment it.
|
To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
Other similar extension points exist, see Microsoft.Common.targets.
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
<Target Name="BeforeBuild">
|
<Target Name="BeforeBuild">
|
||||||
</Target>
|
</Target>
|
||||||
<Target Name="AfterBuild">
|
<Target Name="AfterBuild">
|
||||||
</Target>
|
</Target>
|
||||||
-->
|
-->
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@ -110,6 +110,7 @@
|
|||||||
<Compile Include="src\IkConstraintData.cs" />
|
<Compile Include="src\IkConstraintData.cs" />
|
||||||
<Compile Include="src\Event.cs" />
|
<Compile Include="src\Event.cs" />
|
||||||
<Compile Include="src\EventData.cs" />
|
<Compile Include="src\EventData.cs" />
|
||||||
|
<Compile Include="src\ExposedList.cs" />
|
||||||
<Compile Include="src\Json.cs" />
|
<Compile Include="src\Json.cs" />
|
||||||
<Compile Include="src\Skeleton.cs" />
|
<Compile Include="src\Skeleton.cs" />
|
||||||
<Compile Include="src\SkeletonBinary.cs" />
|
<Compile Include="src\SkeletonBinary.cs" />
|
||||||
@ -136,4 +137,4 @@
|
|||||||
<Target Name="AfterBuild">
|
<Target Name="AfterBuild">
|
||||||
</Target>
|
</Target>
|
||||||
-->
|
-->
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@ -114,7 +114,10 @@ namespace Spine {
|
|||||||
} else {
|
} else {
|
||||||
float previousTime = previous.time;
|
float previousTime = previous.time;
|
||||||
if (!previous.loop && previousTime > previous.endTime) previousTime = previous.endTime;
|
if (!previous.loop && previousTime > previous.endTime) previousTime = previous.endTime;
|
||||||
previous.animation.Apply(skeleton, previousTime, previousTime, previous.loop, null);
|
previous.animation.Apply(skeleton, previous.lastTime, previousTime, previous.loop, null);
|
||||||
|
// Remove the line above, and uncomment the line below, to allow previous animations to fire events during mixing.
|
||||||
|
//previous.animation.Apply(skeleton, previous.lastTime, previousTime, previous.loop, events);
|
||||||
|
previous.lastTime = previousTime;
|
||||||
|
|
||||||
float alpha = current.mixTime / current.mixDuration * current.mix;
|
float alpha = current.mixTime / current.mixDuration * current.mix;
|
||||||
if (alpha >= 1) {
|
if (alpha >= 1) {
|
||||||
|
|||||||
@ -94,6 +94,7 @@ namespace Spine {
|
|||||||
ikConstraints.Add(new IkConstraint(ikConstraintData, this));
|
ikConstraints.Add(new IkConstraint(ikConstraintData, this));
|
||||||
|
|
||||||
UpdateCache();
|
UpdateCache();
|
||||||
|
UpdateWorldTransform();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Caches information about bones and IK constraints. Must be called if bones or IK constraints are added or
|
/// <summary>Caches information about bones and IK constraints. Must be called if bones or IK constraints are added or
|
||||||
|
|||||||
@ -36,19 +36,20 @@ using Spine;
|
|||||||
|
|
||||||
[CustomEditor(typeof(SkeletonAnimation))]
|
[CustomEditor(typeof(SkeletonAnimation))]
|
||||||
public class SkeletonAnimationInspector : SkeletonRendererInspector {
|
public class SkeletonAnimationInspector : SkeletonRendererInspector {
|
||||||
protected SerializedProperty animationName, loop, timeScale;
|
protected SerializedProperty animationName, loop, timeScale, autoReset;
|
||||||
protected bool isPrefab;
|
protected bool m_isPrefab;
|
||||||
|
protected GUIContent autoResetLabel;
|
||||||
|
|
||||||
protected override void OnEnable () {
|
protected override void OnEnable () {
|
||||||
base.OnEnable();
|
base.OnEnable();
|
||||||
animationName = serializedObject.FindProperty("_animationName");
|
animationName = serializedObject.FindProperty("_animationName");
|
||||||
loop = serializedObject.FindProperty("loop");
|
loop = serializedObject.FindProperty("loop");
|
||||||
timeScale = serializedObject.FindProperty("timeScale");
|
timeScale = serializedObject.FindProperty("timeScale");
|
||||||
|
autoReset = serializedObject.FindProperty("autoReset");
|
||||||
|
autoResetLabel = new GUIContent("Generic Auto-reset");
|
||||||
|
|
||||||
if (PrefabUtility.GetPrefabType(this.target) == PrefabType.Prefab)
|
if (PrefabUtility.GetPrefabType(this.target) == PrefabType.Prefab)
|
||||||
isPrefab = true;
|
m_isPrefab = true;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void gui () {
|
protected override void gui () {
|
||||||
@ -96,11 +97,12 @@ public class SkeletonAnimationInspector : SkeletonRendererInspector {
|
|||||||
|
|
||||||
EditorGUILayout.PropertyField(loop);
|
EditorGUILayout.PropertyField(loop);
|
||||||
EditorGUILayout.PropertyField(timeScale);
|
EditorGUILayout.PropertyField(timeScale);
|
||||||
|
EditorGUILayout.PropertyField(autoReset, autoResetLabel);
|
||||||
component.timeScale = Math.Max(component.timeScale, 0);
|
component.timeScale = Math.Max(component.timeScale, 0);
|
||||||
|
|
||||||
EditorGUILayout.Space();
|
EditorGUILayout.Space();
|
||||||
|
|
||||||
if (!isPrefab) {
|
if (!m_isPrefab) {
|
||||||
if (component.GetComponent<SkeletonUtility>() == null) {
|
if (component.GetComponent<SkeletonUtility>() == null) {
|
||||||
if (GUILayout.Button(new GUIContent("Add Skeleton Utility", SpineEditorUtilities.Icons.skeletonUtility), GUILayout.Height(30))) {
|
if (GUILayout.Button(new GUIContent("Add Skeleton Utility", SpineEditorUtilities.Icons.skeletonUtility), GUILayout.Height(30))) {
|
||||||
component.gameObject.AddComponent<SkeletonUtility>();
|
component.gameObject.AddComponent<SkeletonUtility>();
|
||||||
|
|||||||
@ -38,7 +38,7 @@ public class SkeletonDataAssetInspector : Editor {
|
|||||||
private bool needToSerialize;
|
private bool needToSerialize;
|
||||||
|
|
||||||
List<string> warnings = new List<string>();
|
List<string> warnings = new List<string>();
|
||||||
|
|
||||||
void OnEnable () {
|
void OnEnable () {
|
||||||
|
|
||||||
SpineEditorUtilities.ConfirmInitialization();
|
SpineEditorUtilities.ConfirmInitialization();
|
||||||
@ -117,7 +117,7 @@ public class SkeletonDataAssetInspector : Editor {
|
|||||||
DrawAnimationList();
|
DrawAnimationList();
|
||||||
DrawSlotList();
|
DrawSlotList();
|
||||||
DrawUnityTools();
|
DrawUnityTools();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
DrawReimportButton();
|
DrawReimportButton();
|
||||||
@ -131,8 +131,8 @@ public class SkeletonDataAssetInspector : Editor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DrawMecanim () {
|
void DrawMecanim () {
|
||||||
|
|
||||||
EditorGUILayout.PropertyField(controller, new GUIContent("Controller", SpineEditorUtilities.Icons.controllerIcon));
|
EditorGUILayout.PropertyField(controller, new GUIContent("Controller", SpineEditorUtilities.Icons.controllerIcon));
|
||||||
if (controller.objectReferenceValue == null) {
|
if (controller.objectReferenceValue == null) {
|
||||||
GUILayout.BeginHorizontal();
|
GUILayout.BeginHorizontal();
|
||||||
GUILayout.Space(32);
|
GUILayout.Space(32);
|
||||||
@ -142,7 +142,7 @@ public class SkeletonDataAssetInspector : Editor {
|
|||||||
GUILayout.EndHorizontal();
|
GUILayout.EndHorizontal();
|
||||||
EditorGUILayout.LabelField("Alternative to SkeletonAnimation, not required", EditorStyles.miniLabel);
|
EditorGUILayout.LabelField("Alternative to SkeletonAnimation, not required", EditorStyles.miniLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawUnityTools () {
|
void DrawUnityTools () {
|
||||||
@ -292,7 +292,7 @@ public class SkeletonDataAssetInspector : Editor {
|
|||||||
serializedObject.ApplyModifiedProperties();
|
serializedObject.ApplyModifiedProperties();
|
||||||
needToSerialize = true;
|
needToSerialize = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
void DrawAnimationList () {
|
void DrawAnimationList () {
|
||||||
showAnimationList = EditorGUILayout.Foldout(showAnimationList, new GUIContent("Animations", SpineEditorUtilities.Icons.animationRoot));
|
showAnimationList = EditorGUILayout.Foldout(showAnimationList, new GUIContent("Animations", SpineEditorUtilities.Icons.animationRoot));
|
||||||
@ -648,7 +648,7 @@ public class SkeletonDataAssetInspector : Editor {
|
|||||||
this.m_previewUtility.m_Camera.orthographicSize = orthoSet;
|
this.m_previewUtility.m_Camera.orthographicSize = orthoSet;
|
||||||
|
|
||||||
float dist = Vector3.Distance(m_previewUtility.m_Camera.transform.position, m_posGoal);
|
float dist = Vector3.Distance(m_previewUtility.m_Camera.transform.position, m_posGoal);
|
||||||
if (dist > 60f * ((SkeletonDataAsset)target).scale) {
|
if(dist > 0f) {
|
||||||
Vector3 pos = Vector3.Lerp(this.m_previewUtility.m_Camera.transform.position, m_posGoal, 0.1f);
|
Vector3 pos = Vector3.Lerp(this.m_previewUtility.m_Camera.transform.position, m_posGoal, 0.1f);
|
||||||
pos.x = 0;
|
pos.x = 0;
|
||||||
this.m_previewUtility.m_Camera.transform.position = pos;
|
this.m_previewUtility.m_Camera.transform.position = pos;
|
||||||
@ -676,7 +676,7 @@ public class SkeletonDataAssetInspector : Editor {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (drawHandles) {
|
if (drawHandles) {
|
||||||
Handles.SetCamera(m_previewUtility.m_Camera);
|
Handles.SetCamera(m_previewUtility.m_Camera);
|
||||||
Handles.color = m_originColor;
|
Handles.color = m_originColor;
|
||||||
|
|
||||||
@ -724,8 +724,8 @@ public class SkeletonDataAssetInspector : Editor {
|
|||||||
|
|
||||||
Handles.DrawLine(lastVert, firstVert);
|
Handles.DrawLine(lastVert, firstVert);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Update () {
|
void Update () {
|
||||||
@ -857,7 +857,7 @@ public class SkeletonDataAssetInspector : Editor {
|
|||||||
case EventType.ScrollWheel:
|
case EventType.ScrollWheel:
|
||||||
if (position.Contains(current.mousePosition)) {
|
if (position.Contains(current.mousePosition)) {
|
||||||
|
|
||||||
m_orthoGoal += current.delta.y * ((SkeletonDataAsset)target).scale * 10;
|
m_orthoGoal += current.delta.y;
|
||||||
GUIUtility.hotControl = controlID;
|
GUIUtility.hotControl = controlID;
|
||||||
current.Use();
|
current.Use();
|
||||||
}
|
}
|
||||||
@ -882,7 +882,7 @@ public class SkeletonDataAssetInspector : Editor {
|
|||||||
EditorGUIUtility.SetWantsMouseJumping(1);
|
EditorGUIUtility.SetWantsMouseJumping(1);
|
||||||
}
|
}
|
||||||
return scrollPosition;
|
return scrollPosition;
|
||||||
|
|
||||||
case EventType.MouseUp:
|
case EventType.MouseUp:
|
||||||
if (GUIUtility.hotControl == controlID)
|
if (GUIUtility.hotControl == controlID)
|
||||||
{
|
{
|
||||||
@ -890,10 +890,10 @@ public class SkeletonDataAssetInspector : Editor {
|
|||||||
}
|
}
|
||||||
EditorGUIUtility.SetWantsMouseJumping(0);
|
EditorGUIUtility.SetWantsMouseJumping(0);
|
||||||
return scrollPosition;
|
return scrollPosition;
|
||||||
|
|
||||||
case EventType.MouseMove:
|
case EventType.MouseMove:
|
||||||
return scrollPosition;
|
return scrollPosition;
|
||||||
|
|
||||||
case EventType.MouseDrag:
|
case EventType.MouseDrag:
|
||||||
if (GUIUtility.hotControl == controlID)
|
if (GUIUtility.hotControl == controlID)
|
||||||
{
|
{
|
||||||
@ -956,4 +956,4 @@ public class SkeletonDataAssetInspector : Editor {
|
|||||||
tex = this.m_previewUtility.EndStaticPreview();
|
tex = this.m_previewUtility.EndStaticPreview();
|
||||||
return tex;
|
return tex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* Spine Attribute Drawers created by Mitch Thompson
|
* Spine Attribute Drawers created by Mitch Thompson
|
||||||
* Full irrevocable rights and permissions granted to Esoteric Software
|
* Full irrevocable rights and permissions granted to Esoteric Software
|
||||||
@ -8,9 +7,6 @@ using UnityEngine;
|
|||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
|
||||||
using System.Text;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Spine;
|
using Spine;
|
||||||
|
|
||||||
@ -25,21 +21,18 @@ public struct SpineDrawerValuePair {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[CustomPropertyDrawer(typeof(SpineSlot))]
|
public abstract class SpineTreeItemDrawerBase<T> : PropertyDrawer where T:SpineAttributeBase {
|
||||||
public class SpineSlotDrawer : PropertyDrawer {
|
protected SkeletonDataAsset skeletonDataAsset;
|
||||||
SkeletonDataAsset skeletonDataAsset;
|
protected T TargetAttribute { get { return (T)attribute; } }
|
||||||
|
|
||||||
|
public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) {
|
||||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
|
|
||||||
if (property.propertyType != SerializedPropertyType.String) {
|
if (property.propertyType != SerializedPropertyType.String) {
|
||||||
EditorGUI.LabelField(position, "ERROR:", "May only apply to type string");
|
EditorGUI.LabelField(position, "ERROR:", "May only apply to type string");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SpineSlot attrib = (SpineSlot)attribute;
|
var dataProperty = property.serializedObject.FindProperty(TargetAttribute.dataField);
|
||||||
|
|
||||||
var dataProperty = property.serializedObject.FindProperty(attrib.dataField);
|
|
||||||
|
|
||||||
if (dataProperty != null) {
|
if (dataProperty != null) {
|
||||||
if (dataProperty.objectReferenceValue is SkeletonDataAsset) {
|
if (dataProperty.objectReferenceValue is SkeletonDataAsset) {
|
||||||
skeletonDataAsset = (SkeletonDataAsset)dataProperty.objectReferenceValue;
|
skeletonDataAsset = (SkeletonDataAsset)dataProperty.objectReferenceValue;
|
||||||
@ -51,7 +44,7 @@ public class SpineSlotDrawer : PropertyDrawer {
|
|||||||
EditorGUI.LabelField(position, "ERROR:", "Invalid reference type");
|
EditorGUI.LabelField(position, "ERROR:", "Invalid reference type");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (property.serializedObject.targetObject is Component) {
|
} else if (property.serializedObject.targetObject is Component) {
|
||||||
var component = (Component)property.serializedObject.targetObject;
|
var component = (Component)property.serializedObject.targetObject;
|
||||||
if (component.GetComponentInChildren<SkeletonRenderer>() != null) {
|
if (component.GetComponentInChildren<SkeletonRenderer>() != null) {
|
||||||
@ -59,43 +52,60 @@ public class SpineSlotDrawer : PropertyDrawer {
|
|||||||
skeletonDataAsset = skeletonRenderer.skeletonDataAsset;
|
skeletonDataAsset = skeletonRenderer.skeletonDataAsset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (skeletonDataAsset == null) {
|
if (skeletonDataAsset == null) {
|
||||||
EditorGUI.LabelField(position, "ERROR:", "Must have reference to a SkeletonDataAsset");
|
EditorGUI.LabelField(position, "ERROR:", "Must have reference to a SkeletonDataAsset");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
position = EditorGUI.PrefixLabel(position, label);
|
position = EditorGUI.PrefixLabel(position, label);
|
||||||
|
|
||||||
if (GUI.Button(position, property.stringValue, EditorStyles.popup)) {
|
if (GUI.Button(position, property.stringValue, EditorStyles.popup)) {
|
||||||
Selector(property);
|
Selector(property);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Selector(SerializedProperty property) {
|
protected virtual void Selector (SerializedProperty property) {
|
||||||
SpineSlot attrib = (SpineSlot)attribute;
|
|
||||||
SkeletonData data = skeletonDataAsset.GetSkeletonData(true);
|
SkeletonData data = skeletonDataAsset.GetSkeletonData(true);
|
||||||
if (data == null)
|
if (data == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
GenericMenu menu = new GenericMenu();
|
GenericMenu menu = new GenericMenu();
|
||||||
|
PopulateMenu (menu, property, this.TargetAttribute, data);
|
||||||
|
menu.ShowAsContext();
|
||||||
|
}
|
||||||
|
|
||||||
menu.AddDisabledItem(new GUIContent(skeletonDataAsset.name));
|
protected abstract void PopulateMenu (GenericMenu menu, SerializedProperty property, T targetAttribute, SkeletonData data);
|
||||||
menu.AddSeparator("");
|
|
||||||
|
|
||||||
|
protected virtual void HandleSelect (object val) {
|
||||||
|
var pair = (SpineDrawerValuePair)val;
|
||||||
|
pair.property.stringValue = pair.str;
|
||||||
|
pair.property.serializedObject.ApplyModifiedProperties();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) {
|
||||||
|
return 18;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[CustomPropertyDrawer(typeof(SpineSlot))]
|
||||||
|
public class SpineSlotDrawer : SpineTreeItemDrawerBase<SpineSlot> {
|
||||||
|
|
||||||
|
protected override void PopulateMenu (GenericMenu menu, SerializedProperty property, SpineSlot targetAttribute, SkeletonData data) {
|
||||||
for (int i = 0; i < data.Slots.Count; i++) {
|
for (int i = 0; i < data.Slots.Count; i++) {
|
||||||
string name = data.Slots.Items[i].Name;
|
string name = data.Slots.Items[i].Name;
|
||||||
if (name.StartsWith(attrib.startsWith)) {
|
if (name.StartsWith(targetAttribute.startsWith)) {
|
||||||
if (attrib.containsBoundingBoxes) {
|
if (targetAttribute.containsBoundingBoxes) {
|
||||||
|
|
||||||
int slotIndex = i;
|
int slotIndex = i;
|
||||||
|
|
||||||
List<Attachment> attachments = new List<Attachment>();
|
List<Attachment> attachments = new List<Attachment>();
|
||||||
foreach (var skin in data.Skins) {
|
foreach (var skin in data.Skins) {
|
||||||
skin.FindAttachmentsForSlot(slotIndex, attachments);
|
skin.FindAttachmentsForSlot(slotIndex, attachments);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasBoundingBox = false;
|
bool hasBoundingBox = false;
|
||||||
foreach (var attachment in attachments) {
|
foreach (var attachment in attachments) {
|
||||||
if (attachment is BoundingBoxAttachment) {
|
if (attachment is BoundingBoxAttachment) {
|
||||||
@ -104,315 +114,83 @@ public class SpineSlotDrawer : PropertyDrawer {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hasBoundingBox)
|
if (!hasBoundingBox)
|
||||||
menu.AddDisabledItem(new GUIContent(name));
|
menu.AddDisabledItem(new GUIContent(name));
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
menu.AddItem(new GUIContent(name), name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property));
|
menu.AddItem(new GUIContent(name), name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
menu.ShowAsContext();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandleSelect(object val) {
|
|
||||||
var pair = (SpineDrawerValuePair)val;
|
|
||||||
pair.property.stringValue = pair.str;
|
|
||||||
pair.property.serializedObject.ApplyModifiedProperties();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) {
|
|
||||||
return 18;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[CustomPropertyDrawer(typeof(SpineSkin))]
|
[CustomPropertyDrawer(typeof(SpineSkin))]
|
||||||
public class SpineSkinDrawer : PropertyDrawer {
|
public class SpineSkinDrawer : SpineTreeItemDrawerBase<SpineSkin> {
|
||||||
SkeletonDataAsset skeletonDataAsset;
|
|
||||||
|
|
||||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
|
|
||||||
if (property.propertyType != SerializedPropertyType.String) {
|
|
||||||
EditorGUI.LabelField(position, "ERROR:", "May only apply to type string");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
SpineSkin attrib = (SpineSkin)attribute;
|
|
||||||
|
|
||||||
var dataProperty = property.serializedObject.FindProperty(attrib.dataField);
|
|
||||||
|
|
||||||
if (dataProperty != null) {
|
|
||||||
if (dataProperty.objectReferenceValue is SkeletonDataAsset) {
|
|
||||||
skeletonDataAsset = (SkeletonDataAsset)dataProperty.objectReferenceValue;
|
|
||||||
} else if (dataProperty.objectReferenceValue is SkeletonRenderer) {
|
|
||||||
var renderer = (SkeletonRenderer)dataProperty.objectReferenceValue;
|
|
||||||
if (renderer != null)
|
|
||||||
skeletonDataAsset = renderer.skeletonDataAsset;
|
|
||||||
} else {
|
|
||||||
EditorGUI.LabelField(position, "ERROR:", "Invalid reference type");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (property.serializedObject.targetObject is Component) {
|
|
||||||
var component = (Component)property.serializedObject.targetObject;
|
|
||||||
if (component.GetComponentInChildren<SkeletonRenderer>() != null) {
|
|
||||||
var skeletonRenderer = component.GetComponentInChildren<SkeletonRenderer>();
|
|
||||||
skeletonDataAsset = skeletonRenderer.skeletonDataAsset;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (skeletonDataAsset == null) {
|
|
||||||
EditorGUI.LabelField(position, "ERROR:", "Must have reference to a SkeletonDataAsset");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
position = EditorGUI.PrefixLabel(position, label);
|
|
||||||
|
|
||||||
if (GUI.Button(position, property.stringValue, EditorStyles.popup)) {
|
|
||||||
Selector(property);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void Selector(SerializedProperty property) {
|
|
||||||
SpineSkin attrib = (SpineSkin)attribute;
|
|
||||||
SkeletonData data = skeletonDataAsset.GetSkeletonData(true);
|
|
||||||
if (data == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
GenericMenu menu = new GenericMenu();
|
|
||||||
|
|
||||||
|
protected override void PopulateMenu (GenericMenu menu, SerializedProperty property, SpineSkin targetAttribute, SkeletonData data) {
|
||||||
menu.AddDisabledItem(new GUIContent(skeletonDataAsset.name));
|
menu.AddDisabledItem(new GUIContent(skeletonDataAsset.name));
|
||||||
menu.AddSeparator("");
|
menu.AddSeparator("");
|
||||||
|
|
||||||
for (int i = 0; i < data.Skins.Count; i++) {
|
for (int i = 0; i < data.Skins.Count; i++) {
|
||||||
string name = data.Skins.Items[i].Name;
|
string name = data.Skins.Items[i].Name;
|
||||||
if (name.StartsWith(attrib.startsWith))
|
if (name.StartsWith(targetAttribute.startsWith))
|
||||||
menu.AddItem(new GUIContent(name), name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property));
|
menu.AddItem(new GUIContent(name), name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property));
|
||||||
}
|
}
|
||||||
|
|
||||||
menu.ShowAsContext();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandleSelect(object val) {
|
|
||||||
var pair = (SpineDrawerValuePair)val;
|
|
||||||
pair.property.stringValue = pair.str;
|
|
||||||
pair.property.serializedObject.ApplyModifiedProperties();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) {
|
|
||||||
return 18;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[CustomPropertyDrawer(typeof(SpineAtlasRegion))]
|
|
||||||
public class SpineAtlasRegionDrawer : PropertyDrawer {
|
|
||||||
Component component;
|
|
||||||
SerializedProperty atlasProp;
|
|
||||||
|
|
||||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
|
|
||||||
if (property.propertyType != SerializedPropertyType.String) {
|
|
||||||
EditorGUI.LabelField(position, "ERROR:", "May only apply to type string");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
component = (Component)property.serializedObject.targetObject;
|
|
||||||
|
|
||||||
if (component != null)
|
|
||||||
atlasProp = property.serializedObject.FindProperty("atlasAsset");
|
|
||||||
else
|
|
||||||
atlasProp = null;
|
|
||||||
|
|
||||||
|
|
||||||
if (atlasProp == null) {
|
|
||||||
EditorGUI.LabelField(position, "ERROR:", "Must have AtlasAsset variable!");
|
|
||||||
return;
|
|
||||||
} else if (atlasProp.objectReferenceValue == null) {
|
|
||||||
EditorGUI.LabelField(position, "ERROR:", "Atlas variable must not be null!");
|
|
||||||
return;
|
|
||||||
} else if (atlasProp.objectReferenceValue.GetType() != typeof(AtlasAsset)) {
|
|
||||||
EditorGUI.LabelField(position, "ERROR:", "Atlas variable must be of type AtlasAsset!");
|
|
||||||
}
|
|
||||||
|
|
||||||
position = EditorGUI.PrefixLabel(position, label);
|
|
||||||
|
|
||||||
if (GUI.Button(position, property.stringValue, EditorStyles.popup)) {
|
|
||||||
Selector(property);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void Selector(SerializedProperty property) {
|
|
||||||
GenericMenu menu = new GenericMenu();
|
|
||||||
AtlasAsset atlasAsset = (AtlasAsset)atlasProp.objectReferenceValue;
|
|
||||||
Atlas atlas = atlasAsset.GetAtlas();
|
|
||||||
FieldInfo field = typeof(Atlas).GetField("regions", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.NonPublic);
|
|
||||||
List<AtlasRegion> regions = (List<AtlasRegion>)field.GetValue(atlas);
|
|
||||||
|
|
||||||
for (int i = 0; i < regions.Count; i++) {
|
|
||||||
string name = regions[i].name;
|
|
||||||
menu.AddItem(new GUIContent(name), name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
menu.ShowAsContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
void HandleSelect(object val) {
|
|
||||||
var pair = (SpineDrawerValuePair)val;
|
|
||||||
pair.property.stringValue = pair.str;
|
|
||||||
pair.property.serializedObject.ApplyModifiedProperties();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) {
|
|
||||||
return 18;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[CustomPropertyDrawer(typeof(SpineAnimation))]
|
[CustomPropertyDrawer(typeof(SpineAnimation))]
|
||||||
public class SpineAnimationDrawer : PropertyDrawer {
|
public class SpineAnimationDrawer : SpineTreeItemDrawerBase<SpineAnimation> {
|
||||||
SkeletonDataAsset skeletonDataAsset;
|
protected override void PopulateMenu (GenericMenu menu, SerializedProperty property, SpineAnimation targetAttribute, SkeletonData data) {
|
||||||
|
|
||||||
|
|
||||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
|
|
||||||
|
|
||||||
|
|
||||||
if (property.propertyType != SerializedPropertyType.String) {
|
|
||||||
EditorGUI.LabelField(position, "ERROR:", "May only apply to type string");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
SpineAnimation attrib = (SpineAnimation)attribute;
|
|
||||||
|
|
||||||
var dataProperty = property.serializedObject.FindProperty(attrib.dataField);
|
|
||||||
|
|
||||||
if (dataProperty != null) {
|
|
||||||
if (dataProperty.objectReferenceValue is SkeletonDataAsset) {
|
|
||||||
skeletonDataAsset = (SkeletonDataAsset)dataProperty.objectReferenceValue;
|
|
||||||
} else if (dataProperty.objectReferenceValue is SkeletonRenderer) {
|
|
||||||
var renderer = (SkeletonRenderer)dataProperty.objectReferenceValue;
|
|
||||||
if (renderer != null)
|
|
||||||
skeletonDataAsset = renderer.skeletonDataAsset;
|
|
||||||
} else {
|
|
||||||
EditorGUI.LabelField(position, "ERROR:", "Invalid reference type");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else if (property.serializedObject.targetObject is Component) {
|
|
||||||
var component = (Component)property.serializedObject.targetObject;
|
|
||||||
if (component.GetComponentInChildren<SkeletonRenderer>() != null) {
|
|
||||||
var skeletonRenderer = component.GetComponentInChildren<SkeletonRenderer>();
|
|
||||||
skeletonDataAsset = skeletonRenderer.skeletonDataAsset;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (skeletonDataAsset == null) {
|
|
||||||
EditorGUI.LabelField(position, "ERROR:", "Must have reference to a SkeletonDataAsset");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
position = EditorGUI.PrefixLabel(position, label);
|
|
||||||
|
|
||||||
if (GUI.Button(position, property.stringValue, EditorStyles.popup)) {
|
|
||||||
Selector(property);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void Selector(SerializedProperty property) {
|
|
||||||
|
|
||||||
SpineAnimation attrib = (SpineAnimation)attribute;
|
|
||||||
|
|
||||||
GenericMenu menu = new GenericMenu();
|
|
||||||
|
|
||||||
var animations = skeletonDataAsset.GetAnimationStateData().SkeletonData.Animations;
|
var animations = skeletonDataAsset.GetAnimationStateData().SkeletonData.Animations;
|
||||||
for (int i = 0; i < animations.Count; i++) {
|
for (int i = 0; i < animations.Count; i++) {
|
||||||
string name = animations.Items[i].Name;
|
string name = animations.Items[i].Name;
|
||||||
if (name.StartsWith(attrib.startsWith))
|
if (name.StartsWith(targetAttribute.startsWith))
|
||||||
menu.AddItem(new GUIContent(name), name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property));
|
menu.AddItem(new GUIContent(name), name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property));
|
||||||
}
|
}
|
||||||
|
|
||||||
menu.ShowAsContext();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandleSelect(object val) {
|
}
|
||||||
var pair = (SpineDrawerValuePair)val;
|
|
||||||
pair.property.stringValue = pair.str;
|
[CustomPropertyDrawer(typeof(SpineEventData))]
|
||||||
pair.property.serializedObject.ApplyModifiedProperties();
|
public class SpineEventDataDrawer : SpineTreeItemDrawerBase<SpineEventData> {
|
||||||
|
protected override void PopulateMenu (GenericMenu menu, SerializedProperty property, SpineEventData targetAttribute, SkeletonData data) {
|
||||||
|
var events = skeletonDataAsset.GetSkeletonData(false).Events;
|
||||||
|
for (int i = 0; i < events.Count; i++) {
|
||||||
|
string name = events.Items[i].Name;
|
||||||
|
if (name.StartsWith(targetAttribute.startsWith))
|
||||||
|
menu.AddItem(new GUIContent(name), name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) {
|
|
||||||
return 18;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[CustomPropertyDrawer(typeof(SpineAttachment))]
|
[CustomPropertyDrawer(typeof(SpineAttachment))]
|
||||||
public class SpineAttachmentDrawer : PropertyDrawer {
|
public class SpineAttachmentDrawer : SpineTreeItemDrawerBase<SpineAttachment> {
|
||||||
|
protected override void PopulateMenu (GenericMenu menu, SerializedProperty property, SpineAttachment targetAttribute, SkeletonData data) {
|
||||||
|
List<Skin> validSkins = new List<Skin>();
|
||||||
|
SkeletonRenderer skeletonRenderer = null;
|
||||||
|
|
||||||
SkeletonDataAsset skeletonDataAsset;
|
if (property.serializedObject.targetObject is Component) {
|
||||||
SkeletonRenderer skeletonRenderer;
|
|
||||||
|
|
||||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
|
|
||||||
|
|
||||||
if (property.propertyType != SerializedPropertyType.String) {
|
|
||||||
EditorGUI.LabelField(position, "ERROR:", "May only apply to type string");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
SpineAttachment attrib = (SpineAttachment)attribute;
|
|
||||||
|
|
||||||
var dataProperty = property.serializedObject.FindProperty(attrib.dataField);
|
|
||||||
|
|
||||||
if (dataProperty != null) {
|
|
||||||
if (dataProperty.objectReferenceValue is SkeletonDataAsset) {
|
|
||||||
skeletonDataAsset = (SkeletonDataAsset)dataProperty.objectReferenceValue;
|
|
||||||
} else if (dataProperty.objectReferenceValue is SkeletonRenderer) {
|
|
||||||
var renderer = (SkeletonRenderer)dataProperty.objectReferenceValue;
|
|
||||||
if (renderer != null)
|
|
||||||
skeletonDataAsset = renderer.skeletonDataAsset;
|
|
||||||
else {
|
|
||||||
EditorGUI.LabelField(position, "ERROR:", "No SkeletonRenderer");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
EditorGUI.LabelField(position, "ERROR:", "Invalid reference type");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (property.serializedObject.targetObject is Component) {
|
|
||||||
var component = (Component)property.serializedObject.targetObject;
|
var component = (Component)property.serializedObject.targetObject;
|
||||||
if (component.GetComponentInChildren<SkeletonRenderer>() != null) {
|
if (component.GetComponentInChildren<SkeletonRenderer>() != null) {
|
||||||
skeletonRenderer = component.GetComponentInChildren<SkeletonRenderer>();
|
skeletonRenderer = component.GetComponentInChildren<SkeletonRenderer>();
|
||||||
|
if (skeletonDataAsset != skeletonRenderer.skeletonDataAsset) {
|
||||||
|
Debug.LogError("DataField SkeletonDataAsset and SkeletonRenderer/SkeletonAnimation's SkeletonDataAsset do not match. Remove the explicit dataField parameter of your [SpineAttachment] field.");
|
||||||
|
}
|
||||||
|
|
||||||
skeletonDataAsset = skeletonRenderer.skeletonDataAsset;
|
skeletonDataAsset = skeletonRenderer.skeletonDataAsset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (skeletonDataAsset == null && skeletonRenderer == null) {
|
if (skeletonRenderer != null && targetAttribute.currentSkinOnly) {
|
||||||
EditorGUI.LabelField(position, "ERROR:", "Must have reference to a SkeletonDataAsset or SkeletonRenderer");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
position = EditorGUI.PrefixLabel(position, label);
|
|
||||||
|
|
||||||
if (GUI.Button(position, property.stringValue, EditorStyles.popup)) {
|
|
||||||
Selector(property);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void Selector(SerializedProperty property) {
|
|
||||||
SkeletonData data = skeletonDataAsset.GetSkeletonData(true);
|
|
||||||
|
|
||||||
if (data == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
SpineAttachment attrib = (SpineAttachment)attribute;
|
|
||||||
|
|
||||||
List<Skin> validSkins = new List<Skin>();
|
|
||||||
|
|
||||||
if (skeletonRenderer != null && attrib.currentSkinOnly) {
|
|
||||||
if (skeletonRenderer.skeleton.Skin != null) {
|
if (skeletonRenderer.skeleton.Skin != null) {
|
||||||
validSkins.Add(skeletonRenderer.skeleton.Skin);
|
validSkins.Add(skeletonRenderer.skeleton.Skin);
|
||||||
} else {
|
} else {
|
||||||
@ -424,62 +202,61 @@ public class SpineAttachmentDrawer : PropertyDrawer {
|
|||||||
validSkins.Add(skin);
|
validSkins.Add(skin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GenericMenu menu = new GenericMenu();
|
|
||||||
List<string> attachmentNames = new List<string>();
|
List<string> attachmentNames = new List<string>();
|
||||||
List<string> placeholderNames = new List<string>();
|
List<string> placeholderNames = new List<string>();
|
||||||
|
|
||||||
string prefix = "";
|
string prefix = "";
|
||||||
|
|
||||||
if (skeletonRenderer != null && attrib.currentSkinOnly)
|
if (skeletonRenderer != null && targetAttribute.currentSkinOnly)
|
||||||
menu.AddDisabledItem(new GUIContent(skeletonRenderer.gameObject.name + " (SkeletonRenderer)"));
|
menu.AddDisabledItem(new GUIContent(skeletonRenderer.gameObject.name + " (SkeletonRenderer)"));
|
||||||
else
|
else
|
||||||
menu.AddDisabledItem(new GUIContent(skeletonDataAsset.name));
|
menu.AddDisabledItem(new GUIContent(skeletonDataAsset.name));
|
||||||
menu.AddSeparator("");
|
menu.AddSeparator("");
|
||||||
|
|
||||||
menu.AddItem(new GUIContent("Null"), property.stringValue == "", HandleSelect, new SpineDrawerValuePair("", property));
|
menu.AddItem(new GUIContent("Null"), property.stringValue == "", HandleSelect, new SpineDrawerValuePair("", property));
|
||||||
menu.AddSeparator("");
|
menu.AddSeparator("");
|
||||||
|
|
||||||
Skin defaultSkin = data.Skins.Items[0];
|
Skin defaultSkin = data.Skins.Items[0];
|
||||||
|
|
||||||
SerializedProperty slotProperty = property.serializedObject.FindProperty(attrib.slotField);
|
SerializedProperty slotProperty = property.serializedObject.FindProperty(targetAttribute.slotField);
|
||||||
string slotMatch = "";
|
string slotMatch = "";
|
||||||
if (slotProperty != null) {
|
if (slotProperty != null) {
|
||||||
if (slotProperty.propertyType == SerializedPropertyType.String) {
|
if (slotProperty.propertyType == SerializedPropertyType.String) {
|
||||||
slotMatch = slotProperty.stringValue.ToLower();
|
slotMatch = slotProperty.stringValue.ToLower();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (Skin skin in validSkins) {
|
foreach (Skin skin in validSkins) {
|
||||||
string skinPrefix = skin.Name + "/";
|
string skinPrefix = skin.Name + "/";
|
||||||
|
|
||||||
if (validSkins.Count > 1)
|
if (validSkins.Count > 1)
|
||||||
prefix = skinPrefix;
|
prefix = skinPrefix;
|
||||||
|
|
||||||
for (int i = 0; i < data.Slots.Count; i++) {
|
for (int i = 0; i < data.Slots.Count; i++) {
|
||||||
if (slotMatch.Length > 0 && data.Slots.Items[i].Name.ToLower().Contains(slotMatch) == false)
|
if (slotMatch.Length > 0 && data.Slots.Items[i].Name.ToLower().Contains(slotMatch) == false)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
attachmentNames.Clear();
|
attachmentNames.Clear();
|
||||||
placeholderNames.Clear();
|
placeholderNames.Clear();
|
||||||
|
|
||||||
skin.FindNamesForSlot(i, attachmentNames);
|
skin.FindNamesForSlot(i, attachmentNames);
|
||||||
if (skin != defaultSkin) {
|
if (skin != defaultSkin) {
|
||||||
defaultSkin.FindNamesForSlot(i, attachmentNames);
|
defaultSkin.FindNamesForSlot(i, attachmentNames);
|
||||||
skin.FindNamesForSlot(i, placeholderNames);
|
skin.FindNamesForSlot(i, placeholderNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (int a = 0; a < attachmentNames.Count; a++) {
|
for (int a = 0; a < attachmentNames.Count; a++) {
|
||||||
|
|
||||||
string attachmentPath = attachmentNames[a];
|
string attachmentPath = attachmentNames[a];
|
||||||
string menuPath = prefix + data.Slots.Items[i].Name + "/" + attachmentPath;
|
string menuPath = prefix + data.Slots.Items[i].Name + "/" + attachmentPath;
|
||||||
string name = attachmentNames[a];
|
string name = attachmentNames[a];
|
||||||
|
|
||||||
if (attrib.returnAttachmentPath)
|
if (targetAttribute.returnAttachmentPath)
|
||||||
name = skin.Name + "/" + data.Slots.Items[i].Name + "/" + attachmentPath;
|
name = skin.Name + "/" + data.Slots.Items[i].Name + "/" + attachmentPath;
|
||||||
|
|
||||||
if (attrib.placeholdersOnly && placeholderNames.Contains(attachmentPath) == false) {
|
if (targetAttribute.placeholdersOnly && placeholderNames.Contains(attachmentPath) == false) {
|
||||||
menu.AddDisabledItem(new GUIContent(menuPath));
|
menu.AddDisabledItem(new GUIContent(menuPath));
|
||||||
} else {
|
} else {
|
||||||
menu.AddItem(new GUIContent(menuPath), name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property));
|
menu.AddItem(new GUIContent(menuPath), name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property));
|
||||||
@ -489,96 +266,83 @@ public class SpineAttachmentDrawer : PropertyDrawer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
menu.ShowAsContext();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandleSelect(object val) {
|
|
||||||
var pair = (SpineDrawerValuePair)val;
|
|
||||||
pair.property.stringValue = pair.str;
|
|
||||||
pair.property.serializedObject.ApplyModifiedProperties();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) {
|
|
||||||
return 18;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[CustomPropertyDrawer(typeof(SpineBone))]
|
[CustomPropertyDrawer(typeof(SpineBone))]
|
||||||
public class SpineBoneDrawer : PropertyDrawer {
|
public class SpineBoneDrawer : SpineTreeItemDrawerBase<SpineBone> {
|
||||||
SkeletonDataAsset skeletonDataAsset;
|
|
||||||
|
|
||||||
|
protected override void PopulateMenu (GenericMenu menu, SerializedProperty property, SpineBone targetAttribute, SkeletonData data) {
|
||||||
|
menu.AddDisabledItem(new GUIContent(skeletonDataAsset.name));
|
||||||
|
menu.AddSeparator("");
|
||||||
|
|
||||||
|
for (int i = 0; i < data.Bones.Count; i++) {
|
||||||
|
string name = data.Bones.Items[i].Name;
|
||||||
|
if (name.StartsWith(targetAttribute.startsWith))
|
||||||
|
menu.AddItem(new GUIContent(name), name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[CustomPropertyDrawer(typeof(SpineAtlasRegion))]
|
||||||
|
public class SpineAtlasRegionDrawer : PropertyDrawer {
|
||||||
|
Component component;
|
||||||
|
SerializedProperty atlasProp;
|
||||||
|
|
||||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
|
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
|
||||||
if (property.propertyType != SerializedPropertyType.String) {
|
if (property.propertyType != SerializedPropertyType.String) {
|
||||||
EditorGUI.LabelField(position, "ERROR:", "May only apply to type string");
|
EditorGUI.LabelField(position, "ERROR:", "May only apply to type string");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SpineBone attrib = (SpineBone)attribute;
|
component = (Component)property.serializedObject.targetObject;
|
||||||
|
|
||||||
var dataProperty = property.serializedObject.FindProperty(attrib.dataField);
|
if (component != null)
|
||||||
|
atlasProp = property.serializedObject.FindProperty("atlasAsset");
|
||||||
if (dataProperty != null) {
|
else
|
||||||
if (dataProperty.objectReferenceValue is SkeletonDataAsset) {
|
atlasProp = null;
|
||||||
skeletonDataAsset = (SkeletonDataAsset)dataProperty.objectReferenceValue;
|
|
||||||
} else if (dataProperty.objectReferenceValue is SkeletonRenderer) {
|
|
||||||
var renderer = (SkeletonRenderer)dataProperty.objectReferenceValue;
|
if (atlasProp == null) {
|
||||||
if (renderer != null)
|
EditorGUI.LabelField(position, "ERROR:", "Must have AtlasAsset variable!");
|
||||||
skeletonDataAsset = renderer.skeletonDataAsset;
|
|
||||||
} else {
|
|
||||||
EditorGUI.LabelField(position, "ERROR:", "Invalid reference type");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (property.serializedObject.targetObject is Component) {
|
|
||||||
var component = (Component)property.serializedObject.targetObject;
|
|
||||||
if (component.GetComponentInChildren<SkeletonRenderer>() != null) {
|
|
||||||
var skeletonRenderer = component.GetComponentInChildren<SkeletonRenderer>();
|
|
||||||
skeletonDataAsset = skeletonRenderer.skeletonDataAsset;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (skeletonDataAsset == null) {
|
|
||||||
EditorGUI.LabelField(position, "ERROR:", "Must have reference to a SkeletonDataAsset");
|
|
||||||
return;
|
return;
|
||||||
|
} else if (atlasProp.objectReferenceValue == null) {
|
||||||
|
EditorGUI.LabelField(position, "ERROR:", "Atlas variable must not be null!");
|
||||||
|
return;
|
||||||
|
} else if (atlasProp.objectReferenceValue.GetType() != typeof(AtlasAsset)) {
|
||||||
|
EditorGUI.LabelField(position, "ERROR:", "Atlas variable must be of type AtlasAsset!");
|
||||||
}
|
}
|
||||||
|
|
||||||
position = EditorGUI.PrefixLabel(position, label);
|
position = EditorGUI.PrefixLabel(position, label);
|
||||||
|
|
||||||
if (GUI.Button(position, property.stringValue, EditorStyles.popup)) {
|
if (GUI.Button(position, property.stringValue, EditorStyles.popup)) {
|
||||||
Selector(property);
|
Selector(property);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Selector(SerializedProperty property) {
|
void Selector (SerializedProperty property) {
|
||||||
SpineBone attrib = (SpineBone)attribute;
|
|
||||||
SkeletonData data = skeletonDataAsset.GetSkeletonData(true);
|
|
||||||
if (data == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
GenericMenu menu = new GenericMenu();
|
GenericMenu menu = new GenericMenu();
|
||||||
|
AtlasAsset atlasAsset = (AtlasAsset)atlasProp.objectReferenceValue;
|
||||||
menu.AddDisabledItem(new GUIContent(skeletonDataAsset.name));
|
Atlas atlas = atlasAsset.GetAtlas();
|
||||||
menu.AddSeparator("");
|
FieldInfo field = typeof(Atlas).GetField("regions", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.NonPublic);
|
||||||
|
List<AtlasRegion> regions = (List<AtlasRegion>)field.GetValue(atlas);
|
||||||
for (int i = 0; i < data.Bones.Count; i++) {
|
|
||||||
string name = data.Bones.Items[i].Name;
|
for (int i = 0; i < regions.Count; i++) {
|
||||||
if (name.StartsWith(attrib.startsWith))
|
string name = regions[i].name;
|
||||||
menu.AddItem(new GUIContent(name), name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property));
|
menu.AddItem(new GUIContent(name), name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
menu.ShowAsContext();
|
menu.ShowAsContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandleSelect(object val) {
|
static void HandleSelect (object val) {
|
||||||
var pair = (SpineDrawerValuePair)val;
|
var pair = (SpineDrawerValuePair)val;
|
||||||
pair.property.stringValue = pair.str;
|
pair.property.stringValue = pair.str;
|
||||||
pair.property.serializedObject.ApplyModifiedProperties();
|
pair.property.serializedObject.ApplyModifiedProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) {
|
}
|
||||||
return 18;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -30,7 +30,6 @@
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Spine;
|
using Spine;
|
||||||
@ -38,12 +37,12 @@ using Spine;
|
|||||||
[ExecuteInEditMode]
|
[ExecuteInEditMode]
|
||||||
[AddComponentMenu("Spine/SkeletonAnimation")]
|
[AddComponentMenu("Spine/SkeletonAnimation")]
|
||||||
public class SkeletonAnimation : SkeletonRenderer, ISkeletonAnimation {
|
public class SkeletonAnimation : SkeletonRenderer, ISkeletonAnimation {
|
||||||
public float timeScale = 1;
|
|
||||||
public bool loop;
|
/// <summary>
|
||||||
|
/// This is the Spine.AnimationState object of this SkeletonAnimation. You can control animations through it.
|
||||||
|
/// Note that this object, like .skeleton, is not guaranteed to exist in Awake. Do all accesses and caching to it in Start</summary>
|
||||||
public Spine.AnimationState state;
|
public Spine.AnimationState state;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public event UpdateBonesDelegate UpdateLocal {
|
public event UpdateBonesDelegate UpdateLocal {
|
||||||
add { _UpdateLocal += value; }
|
add { _UpdateLocal += value; }
|
||||||
remove { _UpdateLocal -= value; }
|
remove { _UpdateLocal -= value; }
|
||||||
@ -63,18 +62,21 @@ public class SkeletonAnimation : SkeletonRenderer, ISkeletonAnimation {
|
|||||||
protected event UpdateBonesDelegate _UpdateWorld;
|
protected event UpdateBonesDelegate _UpdateWorld;
|
||||||
protected event UpdateBonesDelegate _UpdateComplete;
|
protected event UpdateBonesDelegate _UpdateComplete;
|
||||||
|
|
||||||
|
// TODO: Make this a safe getter. Lazy-initialize and avoid double-initialization.
|
||||||
public Skeleton Skeleton {
|
public Skeleton Skeleton {
|
||||||
get {
|
get { return this.skeleton; }
|
||||||
return this.skeleton;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private String
|
private String _animationName;
|
||||||
_animationName;
|
|
||||||
|
|
||||||
public String AnimationName {
|
public String AnimationName {
|
||||||
get {
|
get {
|
||||||
|
if (!valid) {
|
||||||
|
Debug.LogWarning("You tried access AnimationName but the SkeletonAnimation was not valid. Try checking your Skeleton Data for errors.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
TrackEntry entry = state.GetCurrent(0);
|
TrackEntry entry = state.GetCurrent(0);
|
||||||
return entry == null ? null : entry.Animation.Name;
|
return entry == null ? null : entry.Animation.Name;
|
||||||
}
|
}
|
||||||
@ -82,6 +84,12 @@ public class SkeletonAnimation : SkeletonRenderer, ISkeletonAnimation {
|
|||||||
if (_animationName == value)
|
if (_animationName == value)
|
||||||
return;
|
return;
|
||||||
_animationName = value;
|
_animationName = value;
|
||||||
|
|
||||||
|
if (!valid) {
|
||||||
|
Debug.LogWarning("You tried to change AnimationName but the SkeletonAnimation was not valid. Try checking your Skeleton Data for errors.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (value == null || value.Length == 0)
|
if (value == null || value.Length == 0)
|
||||||
state.ClearTrack(0);
|
state.ClearTrack(0);
|
||||||
else
|
else
|
||||||
@ -89,17 +97,62 @@ public class SkeletonAnimation : SkeletonRenderer, ISkeletonAnimation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>Whether or not an animation should loop. This only applies to the initial animation specified in the inspector, or any subsequent Animations played through .AnimationName. Animations set through state.SetAnimation are unaffected.</summary>
|
||||||
|
#if UNITY_5
|
||||||
|
[Tooltip("Whether or not an animation should loop. This only applies to the initial animation specified in the inspector, or any subsequent Animations played through .AnimationName. Animations set through state.SetAnimation are unaffected.")]
|
||||||
|
#endif
|
||||||
|
public bool loop;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The rate at which animations progress over time. 1 means 100%. 0.5 means 50%.
|
||||||
|
/// AnimationState and TrackEntry also have their own timeScale. These are combined multiplicatively.</summary>
|
||||||
|
#if UNITY_5
|
||||||
|
[Tooltip("The rate at which animations progress over time. 1 means 100%. 0.5 means 50%.")]
|
||||||
|
#endif
|
||||||
|
public float timeScale = 1;
|
||||||
|
|
||||||
|
#if UNITY_5
|
||||||
|
[Tooltip("Setting this to true makes the SkeletonAnimation behave similar to Spine editor. New animations will not inherit the pose from a previous animation. If you need to intermittently and programmatically pose your skeleton, leave this false.")]
|
||||||
|
#endif
|
||||||
|
[SerializeField]
|
||||||
|
protected bool autoReset = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Setting this to true makes the SkeletonAnimation behave similar to Spine editor.
|
||||||
|
/// New animations will not inherit the pose from a previous animation.
|
||||||
|
/// If you need to intermittently and programmatically pose your skeleton, leave this false.</summary>
|
||||||
|
public bool AutoReset {
|
||||||
|
get { return this.autoReset; }
|
||||||
|
set {
|
||||||
|
if (!autoReset && value) {
|
||||||
|
state.Start -= HandleNewAnimationAutoreset; // make sure there isn't a double-subscription.
|
||||||
|
state.Start += HandleNewAnimationAutoreset;
|
||||||
|
}
|
||||||
|
autoReset = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override void Reset () {
|
public override void Reset () {
|
||||||
base.Reset();
|
base.Reset();
|
||||||
if (!valid)
|
if (!valid)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
state = new Spine.AnimationState(skeletonDataAsset.GetAnimationStateData());
|
state = new Spine.AnimationState(skeletonDataAsset.GetAnimationStateData());
|
||||||
|
|
||||||
|
if (autoReset) {
|
||||||
|
state.Start += HandleNewAnimationAutoreset;
|
||||||
|
}
|
||||||
|
|
||||||
if (_animationName != null && _animationName.Length > 0) {
|
if (_animationName != null && _animationName.Length > 0) {
|
||||||
state.SetAnimation(0, _animationName, loop);
|
state.SetAnimation(0, _animationName, loop);
|
||||||
Update(0);
|
Update(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected virtual void HandleNewAnimationAutoreset (Spine.AnimationState state, int trackIndex) {
|
||||||
|
if (!autoReset) return;
|
||||||
|
if (skeleton != null) skeleton.SetToSetupPose();
|
||||||
|
}
|
||||||
|
|
||||||
public virtual void Update () {
|
public virtual void Update () {
|
||||||
Update(Time.deltaTime);
|
Update(Time.deltaTime);
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* Spine Runtimes Software License
|
* Spine Runtimes Software License
|
||||||
* Version 2.3
|
* Version 2.3
|
||||||
*
|
*
|
||||||
* Copyright (c) 2013-2015, Esoteric Software
|
* Copyright (c) 2013-2015, Esoteric Software
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* You are granted a perpetual, non-exclusive, non-sublicensable and
|
* You are granted a perpetual, non-exclusive, non-sublicensable and
|
||||||
* non-transferable license to use, install, execute and perform the Spine
|
* non-transferable license to use, install, execute and perform the Spine
|
||||||
* Runtimes Software (the "Software") and derivative works solely for personal
|
* Runtimes Software (the "Software") and derivative works solely for personal
|
||||||
@ -16,7 +16,7 @@
|
|||||||
* or other intellectual property or proprietary rights notices on or in the
|
* or other intellectual property or proprietary rights notices on or in the
|
||||||
* Software, including any copy thereof. Redistributions in binary or source
|
* Software, including any copy thereof. Redistributions in binary or source
|
||||||
* form must include this license and terms.
|
* form must include this license and terms.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR
|
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR
|
||||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||||
@ -108,7 +108,7 @@ public class SkeletonDataAsset : ScriptableObject {
|
|||||||
#else
|
#else
|
||||||
if (spriteCollection != null) {
|
if (spriteCollection != null) {
|
||||||
attachmentLoader = new SpriteCollectionAttachmentLoader(spriteCollection);
|
attachmentLoader = new SpriteCollectionAttachmentLoader(spriteCollection);
|
||||||
skeletonDataScale = (1.0f / (spriteCollection.invOrthoSize * spriteCollection.halfTargetHeight) * scale) * 100f;
|
skeletonDataScale = (1.0f / (spriteCollection.invOrthoSize * spriteCollection.halfTargetHeight) * scale);
|
||||||
} else {
|
} else {
|
||||||
if (atlasArr.Length == 0) {
|
if (atlasArr.Length == 0) {
|
||||||
Reset();
|
Reset();
|
||||||
|
|||||||
@ -39,39 +39,46 @@ using Spine;
|
|||||||
public class SkeletonRenderer : MonoBehaviour {
|
public class SkeletonRenderer : MonoBehaviour {
|
||||||
|
|
||||||
public delegate void SkeletonRendererDelegate (SkeletonRenderer skeletonRenderer);
|
public delegate void SkeletonRendererDelegate (SkeletonRenderer skeletonRenderer);
|
||||||
|
|
||||||
public SkeletonRendererDelegate OnReset;
|
public SkeletonRendererDelegate OnReset;
|
||||||
[System.NonSerialized]
|
|
||||||
public bool valid;
|
|
||||||
[System.NonSerialized]
|
|
||||||
public Skeleton skeleton;
|
|
||||||
public SkeletonDataAsset skeletonDataAsset;
|
public SkeletonDataAsset skeletonDataAsset;
|
||||||
public String initialSkinName;
|
public String initialSkinName;
|
||||||
|
|
||||||
|
#region Advanced
|
||||||
public bool calculateNormals, calculateTangents;
|
public bool calculateNormals, calculateTangents;
|
||||||
public float zSpacing;
|
public float zSpacing;
|
||||||
public bool renderMeshes = true, immutableTriangles;
|
public bool renderMeshes = true, immutableTriangles;
|
||||||
public bool frontFacing;
|
public bool frontFacing;
|
||||||
public bool logErrors = false;
|
public bool logErrors = false;
|
||||||
|
|
||||||
[SpineSlot]
|
// Submesh Separation
|
||||||
public string[] submeshSeparators = new string[0];
|
[SpineSlot] public string[] submeshSeparators = new string[0];
|
||||||
|
[HideInInspector] public List<Slot> submeshSeparatorSlots = new List<Slot>();
|
||||||
|
#endregion
|
||||||
|
|
||||||
[HideInInspector]
|
[System.NonSerialized] public bool valid;
|
||||||
public List<Slot> submeshSeparatorSlots = new List<Slot>();
|
[System.NonSerialized] public Skeleton skeleton;
|
||||||
|
|
||||||
private MeshRenderer meshRenderer;
|
private MeshRenderer meshRenderer;
|
||||||
private MeshFilter meshFilter;
|
private MeshFilter meshFilter;
|
||||||
|
|
||||||
private Mesh mesh1, mesh2;
|
private Mesh mesh1, mesh2;
|
||||||
private bool useMesh1;
|
private bool useMesh1;
|
||||||
|
|
||||||
private float[] tempVertices = new float[8];
|
private float[] tempVertices = new float[8];
|
||||||
private Vector3[] vertices;
|
private Vector3[] vertices;
|
||||||
private Color32[] colors;
|
private Color32[] colors;
|
||||||
private Vector2[] uvs;
|
private Vector2[] uvs;
|
||||||
private Material[] sharedMaterials = new Material[0];
|
private Material[] sharedMaterials = new Material[0];
|
||||||
|
|
||||||
|
private MeshState meshState = new MeshState();
|
||||||
private readonly ExposedList<Material> submeshMaterials = new ExposedList<Material>();
|
private readonly ExposedList<Material> submeshMaterials = new ExposedList<Material>();
|
||||||
private readonly ExposedList<Submesh> submeshes = new ExposedList<Submesh>();
|
private readonly ExposedList<Submesh> submeshes = new ExposedList<Submesh>();
|
||||||
private SkeletonUtilitySubmeshRenderer[] submeshRenderers;
|
private SkeletonUtilitySubmeshRenderer[] submeshRenderers;
|
||||||
private MeshState meshState = new MeshState();
|
|
||||||
|
public virtual void Awake () {
|
||||||
|
Reset();
|
||||||
|
}
|
||||||
|
|
||||||
public virtual void Reset () {
|
public virtual void Reset () {
|
||||||
if (meshFilter != null)
|
if (meshFilter != null)
|
||||||
@ -144,10 +151,6 @@ public class SkeletonRenderer : MonoBehaviour {
|
|||||||
submeshRenderers = GetComponentsInChildren<SkeletonUtilitySubmeshRenderer>();
|
submeshRenderers = GetComponentsInChildren<SkeletonUtilitySubmeshRenderer>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Awake () {
|
|
||||||
Reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual void OnDestroy () {
|
public virtual void OnDestroy () {
|
||||||
if (mesh1 != null) {
|
if (mesh1 != null) {
|
||||||
if (Application.isPlaying)
|
if (Application.isPlaying)
|
||||||
@ -167,7 +170,7 @@ public class SkeletonRenderer : MonoBehaviour {
|
|||||||
mesh2 = null;
|
mesh2 = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Mesh newMesh () {
|
private static Mesh newMesh () {
|
||||||
Mesh mesh = new Mesh();
|
Mesh mesh = new Mesh();
|
||||||
mesh.name = "Skeleton Mesh";
|
mesh.name = "Skeleton Mesh";
|
||||||
mesh.hideFlags = HideFlags.HideAndDontSave;
|
mesh.hideFlags = HideFlags.HideAndDontSave;
|
||||||
@ -185,6 +188,7 @@ public class SkeletonRenderer : MonoBehaviour {
|
|||||||
|
|
||||||
// Count vertices and submesh triangles.
|
// Count vertices and submesh triangles.
|
||||||
int vertexCount = 0;
|
int vertexCount = 0;
|
||||||
|
|
||||||
int submeshTriangleCount = 0, submeshFirstVertex = 0, submeshStartSlotIndex = 0;
|
int submeshTriangleCount = 0, submeshFirstVertex = 0, submeshStartSlotIndex = 0;
|
||||||
Material lastMaterial = null;
|
Material lastMaterial = null;
|
||||||
ExposedList<Slot> drawOrder = skeleton.drawOrder;
|
ExposedList<Slot> drawOrder = skeleton.drawOrder;
|
||||||
@ -193,26 +197,41 @@ public class SkeletonRenderer : MonoBehaviour {
|
|||||||
bool renderMeshes = this.renderMeshes;
|
bool renderMeshes = this.renderMeshes;
|
||||||
|
|
||||||
// Clear last state of attachments and submeshes
|
// Clear last state of attachments and submeshes
|
||||||
MeshState.SingleMeshState stateTemp = meshState.stateTemp;
|
MeshState.SingleMeshState workingState = meshState.buffer;
|
||||||
stateTemp.attachments.Clear(true);
|
var workingAttachments = workingState.attachments;
|
||||||
stateTemp.UpdateDrawOrderCount(drawOrderCount);
|
var workingFlips = workingState.attachmentsFlipState;
|
||||||
|
var workingSubmeshArguments = workingState.addSubmeshArguments;
|
||||||
|
workingAttachments.Clear(true);
|
||||||
|
workingState.UpdateAttachmentCount(drawOrderCount);
|
||||||
|
workingSubmeshArguments.Clear(false);
|
||||||
|
|
||||||
|
MeshState.SingleMeshState storedState = useMesh1 ? meshState.stateMesh1 : meshState.stateMesh2;
|
||||||
|
var storedAttachments = storedState.attachments;
|
||||||
|
var storedFlips = storedState.attachmentsFlipState;
|
||||||
|
|
||||||
|
bool mustUpdateMeshStructure = storedState.requiresUpdate || // Force update if the mesh was cleared. (prevents flickering due to incorrect state)
|
||||||
|
drawOrder.Count != storedAttachments.Count || // Number of slots changed (when does this happen?)
|
||||||
|
immutableTriangles != storedState.immutableTriangles; // Immutable Triangles flag changed.
|
||||||
|
|
||||||
stateTemp.addSubmeshArguments.Clear(false);
|
|
||||||
for (int i = 0; i < drawOrderCount; i++) {
|
for (int i = 0; i < drawOrderCount; i++) {
|
||||||
Slot slot = drawOrder.Items[i];
|
Slot slot = drawOrder.Items[i];
|
||||||
Bone bone = slot.bone;
|
Bone bone = slot.bone;
|
||||||
Attachment attachment = slot.attachment;
|
Attachment attachment = slot.attachment;
|
||||||
|
|
||||||
object rendererObject;
|
object rendererObject; // An AtlasRegion in plain Spine-Unity. Spine-TK2D hooks into TK2D's system. eventual source of Material object.
|
||||||
int attachmentVertexCount, attachmentTriangleCount;
|
int attachmentVertexCount, attachmentTriangleCount;
|
||||||
bool worldScaleXIsPositive = bone.worldScaleX >= 0f;
|
|
||||||
bool worldScaleYIsPositive = bone.worldScaleY >= 0f;
|
|
||||||
bool worldScaleIsSameSigns = (worldScaleXIsPositive && worldScaleYIsPositive) ||
|
|
||||||
(!worldScaleXIsPositive && !worldScaleYIsPositive);
|
|
||||||
bool flip = frontFacing && ((bone.worldFlipX != bone.worldFlipY) == worldScaleIsSameSigns);
|
|
||||||
stateTemp.attachmentsFlipState.Items[i] = flip;
|
|
||||||
|
|
||||||
stateTemp.attachments.Items[i] = attachment;
|
// Handle flipping for normals (for lighting).
|
||||||
|
bool worldScaleIsSameSigns = ((bone.worldScaleY >= 0f) == (bone.worldScaleX >= 0f));
|
||||||
|
bool flip = frontFacing && ((bone.worldFlipX != bone.worldFlipY) == worldScaleIsSameSigns); // TODO: bone flipX and flipY will be removed in Spine 3.0
|
||||||
|
|
||||||
|
workingFlips.Items[i] = flip;
|
||||||
|
workingAttachments.Items[i] = attachment;
|
||||||
|
|
||||||
|
mustUpdateMeshStructure = mustUpdateMeshStructure || // Always prefer short circuited or. || and not |=.
|
||||||
|
(attachment != storedAttachments.Items[i]) || // Attachment order changed. // This relies on the drawOrder.Count != storedAttachments.Count check above as a bounds check.
|
||||||
|
(flip != storedFlips.Items[i]); // Flip states changed.
|
||||||
|
|
||||||
RegionAttachment regionAttachment = attachment as RegionAttachment;
|
RegionAttachment regionAttachment = attachment as RegionAttachment;
|
||||||
if (regionAttachment != null) {
|
if (regionAttachment != null) {
|
||||||
rendererObject = regionAttachment.RendererObject;
|
rendererObject = regionAttachment.RendererObject;
|
||||||
@ -237,17 +256,27 @@ public class SkeletonRenderer : MonoBehaviour {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Populate submesh when material changes.
|
#if !SPINE_TK2D
|
||||||
#if !SPINE_TK2D
|
|
||||||
Material material = (Material)((AtlasRegion)rendererObject).page.rendererObject;
|
Material material = (Material)((AtlasRegion)rendererObject).page.rendererObject;
|
||||||
#else
|
#else
|
||||||
Material material = (rendererObject.GetType() == typeof(Material)) ? (Material)rendererObject : (Material)((AtlasRegion)rendererObject).page.rendererObject;
|
Material material = (rendererObject.GetType() == typeof(Material)) ? (Material)rendererObject : (Material)((AtlasRegion)rendererObject).page.rendererObject;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Populate submesh when material changes. (or when forced to separate by a submeshSeparator)
|
||||||
if ((lastMaterial != null && lastMaterial.GetInstanceID() != material.GetInstanceID()) ||
|
if ((lastMaterial != null && lastMaterial.GetInstanceID() != material.GetInstanceID()) ||
|
||||||
(submeshSeparatorSlotsCount > 0 && submeshSeparatorSlots.Contains(slot))) {
|
(submeshSeparatorSlotsCount > 0 && submeshSeparatorSlots.Contains(slot))) {
|
||||||
stateTemp.addSubmeshArguments.Add(
|
|
||||||
new MeshState.AddSubmeshArguments(lastMaterial, submeshStartSlotIndex, i, submeshTriangleCount, submeshFirstVertex, false)
|
workingSubmeshArguments.Add(
|
||||||
);
|
new MeshState.AddSubmeshArguments {
|
||||||
|
material = lastMaterial,
|
||||||
|
startSlot = submeshStartSlotIndex,
|
||||||
|
endSlot = i,
|
||||||
|
triangleCount = submeshTriangleCount,
|
||||||
|
firstVertex = submeshFirstVertex,
|
||||||
|
isLastSubmesh = false
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
submeshTriangleCount = 0;
|
submeshTriangleCount = 0;
|
||||||
submeshFirstVertex = vertexCount;
|
submeshFirstVertex = vertexCount;
|
||||||
submeshStartSlotIndex = i;
|
submeshStartSlotIndex = i;
|
||||||
@ -257,24 +286,41 @@ public class SkeletonRenderer : MonoBehaviour {
|
|||||||
submeshTriangleCount += attachmentTriangleCount;
|
submeshTriangleCount += attachmentTriangleCount;
|
||||||
vertexCount += attachmentVertexCount;
|
vertexCount += attachmentVertexCount;
|
||||||
}
|
}
|
||||||
stateTemp.addSubmeshArguments.Add(
|
|
||||||
new MeshState.AddSubmeshArguments(lastMaterial, submeshStartSlotIndex, drawOrderCount, submeshTriangleCount, submeshFirstVertex, true)
|
|
||||||
);
|
|
||||||
|
|
||||||
bool mustUpdateMeshStructure = CheckIfMustUpdateMeshStructure(stateTemp.attachments, stateTemp.attachmentsFlipState, stateTemp.addSubmeshArguments);
|
|
||||||
|
workingSubmeshArguments.Add(
|
||||||
|
new MeshState.AddSubmeshArguments {
|
||||||
|
material = lastMaterial,
|
||||||
|
startSlot = submeshStartSlotIndex,
|
||||||
|
endSlot = drawOrderCount,
|
||||||
|
triangleCount = submeshTriangleCount,
|
||||||
|
firstVertex = submeshFirstVertex,
|
||||||
|
isLastSubmesh = true
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
mustUpdateMeshStructure = mustUpdateMeshStructure ||
|
||||||
|
this.sharedMaterials.Length != workingSubmeshArguments.Count || // Material array changed in size
|
||||||
|
CheckIfMustUpdateMeshStructure(workingSubmeshArguments); // Submesh Argument Array changed.
|
||||||
|
|
||||||
|
// CheckIfMustUpdateMaterialArray (workingMaterials, sharedMaterials)
|
||||||
|
if (!mustUpdateMeshStructure) {
|
||||||
|
// Narrow phase material array check.
|
||||||
|
var workingMaterials = workingSubmeshArguments.Items;
|
||||||
|
for (int i = 0, n = sharedMaterials.Length; i < n; i++) {
|
||||||
|
if (this.sharedMaterials[i] != workingMaterials[i].material) { // Bounds check is implied above.
|
||||||
|
mustUpdateMeshStructure = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOT ELSE
|
||||||
|
|
||||||
if (mustUpdateMeshStructure) {
|
if (mustUpdateMeshStructure) {
|
||||||
submeshMaterials.Clear();
|
this.submeshMaterials.Clear();
|
||||||
for (int i = 0, n = stateTemp.addSubmeshArguments.Count; i < n; i++) {
|
for (int i = 0, n = workingSubmeshArguments.Count; i < n; i++) {
|
||||||
MeshState.AddSubmeshArguments arguments = stateTemp.addSubmeshArguments.Items[i];
|
AddSubmesh(workingSubmeshArguments.Items[i], workingFlips);
|
||||||
AddSubmesh(
|
|
||||||
arguments.material,
|
|
||||||
arguments.startSlot,
|
|
||||||
arguments.endSlot,
|
|
||||||
arguments.triangleCount,
|
|
||||||
arguments.firstVertex,
|
|
||||||
arguments.lastSubmesh,
|
|
||||||
stateTemp.attachmentsFlipState
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set materials.
|
// Set materials.
|
||||||
@ -286,6 +332,7 @@ public class SkeletonRenderer : MonoBehaviour {
|
|||||||
meshRenderer.sharedMaterials = sharedMaterials;
|
meshRenderer.sharedMaterials = sharedMaterials;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Ensure mesh data is the right size.
|
// Ensure mesh data is the right size.
|
||||||
Vector3[] vertices = this.vertices;
|
Vector3[] vertices = this.vertices;
|
||||||
bool newTriangles = vertexCount > vertices.Length;
|
bool newTriangles = vertexCount > vertices.Length;
|
||||||
@ -294,8 +341,12 @@ public class SkeletonRenderer : MonoBehaviour {
|
|||||||
this.vertices = vertices = new Vector3[vertexCount];
|
this.vertices = vertices = new Vector3[vertexCount];
|
||||||
this.colors = new Color32[vertexCount];
|
this.colors = new Color32[vertexCount];
|
||||||
this.uvs = new Vector2[vertexCount];
|
this.uvs = new Vector2[vertexCount];
|
||||||
|
|
||||||
mesh1.Clear();
|
mesh1.Clear();
|
||||||
mesh2.Clear();
|
mesh2.Clear();
|
||||||
|
meshState.stateMesh1.requiresUpdate = true;
|
||||||
|
meshState.stateMesh2.requiresUpdate = true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Too many vertices, zero the extra.
|
// Too many vertices, zero the extra.
|
||||||
Vector3 zero = Vector3.zero;
|
Vector3 zero = Vector3.zero;
|
||||||
@ -502,6 +553,9 @@ public class SkeletonRenderer : MonoBehaviour {
|
|||||||
mesh.subMeshCount = submeshCount;
|
mesh.subMeshCount = submeshCount;
|
||||||
for (int i = 0; i < submeshCount; ++i)
|
for (int i = 0; i < submeshCount; ++i)
|
||||||
mesh.SetTriangles(submeshes.Items[i].triangles, i);
|
mesh.SetTriangles(submeshes.Items[i].triangles, i);
|
||||||
|
|
||||||
|
// Done updating mesh.
|
||||||
|
storedState.requiresUpdate = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 meshBoundsExtents = meshBoundsMax - meshBoundsMin;
|
Vector3 meshBoundsExtents = meshBoundsMax - meshBoundsMin;
|
||||||
@ -526,24 +580,25 @@ public class SkeletonRenderer : MonoBehaviour {
|
|||||||
mesh2.tangents = tangents;
|
mesh2.tangents = tangents;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update previous state
|
// Update previous state
|
||||||
MeshState.SingleMeshState currentMeshState = useMesh1 ? meshState.stateMesh1 : meshState.stateMesh2;
|
storedState.immutableTriangles = immutableTriangles;
|
||||||
currentMeshState.immutableTriangles = immutableTriangles;
|
|
||||||
|
|
||||||
currentMeshState.attachments.Clear(true);
|
storedAttachments.Clear(true);
|
||||||
currentMeshState.attachments.GrowIfNeeded(stateTemp.attachments.Capacity);
|
storedAttachments.GrowIfNeeded(workingAttachments.Capacity);
|
||||||
currentMeshState.attachments.Count = stateTemp.attachments.Count;
|
storedAttachments.Count = workingAttachments.Count;
|
||||||
stateTemp.attachments.CopyTo(currentMeshState.attachments.Items);
|
workingAttachments.CopyTo(storedAttachments.Items);
|
||||||
|
|
||||||
currentMeshState.attachmentsFlipState.GrowIfNeeded(stateTemp.attachmentsFlipState.Capacity);
|
storedFlips.GrowIfNeeded(workingFlips.Capacity);
|
||||||
currentMeshState.attachmentsFlipState.Count = stateTemp.attachmentsFlipState.Count;
|
storedFlips.Count = workingFlips.Count;
|
||||||
stateTemp.attachmentsFlipState.CopyTo(currentMeshState.attachmentsFlipState.Items);
|
workingFlips.CopyTo(storedFlips.Items);
|
||||||
|
|
||||||
currentMeshState.addSubmeshArguments.GrowIfNeeded(stateTemp.addSubmeshArguments.Capacity);
|
storedState.addSubmeshArguments.GrowIfNeeded(workingSubmeshArguments.Capacity);
|
||||||
currentMeshState.addSubmeshArguments.Count = stateTemp.addSubmeshArguments.Count;
|
storedState.addSubmeshArguments.Count = workingSubmeshArguments.Count;
|
||||||
stateTemp.addSubmeshArguments.CopyTo(currentMeshState.addSubmeshArguments.Items);
|
workingSubmeshArguments.CopyTo(storedState.addSubmeshArguments.Items);
|
||||||
|
|
||||||
|
|
||||||
|
// Submesh Renderers
|
||||||
if (submeshRenderers.Length > 0) {
|
if (submeshRenderers.Length > 0) {
|
||||||
for (int i = 0; i < submeshRenderers.Length; i++) {
|
for (int i = 0; i < submeshRenderers.Length; i++) {
|
||||||
SkeletonUtilitySubmeshRenderer submeshRenderer = submeshRenderers[i];
|
SkeletonUtilitySubmeshRenderer submeshRenderer = submeshRenderers[i];
|
||||||
@ -558,59 +613,32 @@ public class SkeletonRenderer : MonoBehaviour {
|
|||||||
useMesh1 = !useMesh1;
|
useMesh1 = !useMesh1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool CheckIfMustUpdateMeshStructure (ExposedList<Attachment> attachmentsTemp, ExposedList<bool> attachmentsFlipStateTemp, ExposedList<MeshState.AddSubmeshArguments> addSubmeshArgumentsTemp) {
|
private bool CheckIfMustUpdateMeshStructure (ExposedList<MeshState.AddSubmeshArguments> workingAddSubmeshArguments) {
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
if (!Application.isPlaying)
|
if (!Application.isPlaying)
|
||||||
return true;
|
return true;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Check if any mesh settings were changed
|
// Check if any mesh settings were changed
|
||||||
bool mustUpdateMeshStructure =
|
|
||||||
immutableTriangles != (useMesh1 ? meshState.stateMesh1.immutableTriangles : meshState.stateMesh2.immutableTriangles);
|
|
||||||
|
|
||||||
if (mustUpdateMeshStructure)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// Check if any attachments were enabled/disabled
|
|
||||||
// or submesh structures has changed
|
|
||||||
MeshState.SingleMeshState currentMeshState = useMesh1 ? meshState.stateMesh1 : meshState.stateMesh2;
|
MeshState.SingleMeshState currentMeshState = useMesh1 ? meshState.stateMesh1 : meshState.stateMesh2;
|
||||||
ExposedList<Attachment> attachmentsCurrentMesh = currentMeshState.attachments;
|
|
||||||
|
// Check if submesh structures has changed
|
||||||
ExposedList<MeshState.AddSubmeshArguments> addSubmeshArgumentsCurrentMesh = currentMeshState.addSubmeshArguments;
|
ExposedList<MeshState.AddSubmeshArguments> addSubmeshArgumentsCurrentMesh = currentMeshState.addSubmeshArguments;
|
||||||
ExposedList<bool> attachmentsFlipStateCurrentMesh = currentMeshState.attachmentsFlipState;
|
int submeshCount = workingAddSubmeshArguments.Count;
|
||||||
|
|
||||||
// Check attachments
|
|
||||||
int attachmentCount = attachmentsTemp.Count;
|
|
||||||
if (attachmentsCurrentMesh.Count != attachmentCount)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
for (int i = 0; i < attachmentCount; i++) {
|
|
||||||
if (attachmentsCurrentMesh.Items[i] != attachmentsTemp.Items[i])
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check flip state
|
|
||||||
for (int i = 0; i < attachmentCount; i++) {
|
|
||||||
if (attachmentsFlipStateCurrentMesh.Items[i] != attachmentsFlipStateTemp.Items[i])
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check submeshes
|
|
||||||
int submeshCount = addSubmeshArgumentsTemp.Count;
|
|
||||||
if (addSubmeshArgumentsCurrentMesh.Count != submeshCount)
|
if (addSubmeshArgumentsCurrentMesh.Count != submeshCount)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
for (int i = 0; i < submeshCount; i++) {
|
for (int i = 0; i < submeshCount; i++) {
|
||||||
if (!addSubmeshArgumentsCurrentMesh.Items[i].Equals(ref addSubmeshArgumentsTemp.Items[i]))
|
if (!addSubmeshArgumentsCurrentMesh.Items[i].Equals(ref workingAddSubmeshArguments.Items[i]))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Stores vertices and triangles for a single material. */
|
private void AddSubmesh (MeshState.AddSubmeshArguments submeshArguments, ExposedList<bool> flipStates) {
|
||||||
private void AddSubmesh (Material material, int startSlot, int endSlot, int triangleCount, int firstVertex, bool lastSubmesh, ExposedList<bool> flipStates) {
|
|
||||||
int submeshIndex = submeshMaterials.Count;
|
int submeshIndex = submeshMaterials.Count;
|
||||||
submeshMaterials.Add(material);
|
submeshMaterials.Add(submeshArguments.material);
|
||||||
|
|
||||||
if (submeshes.Count <= submeshIndex)
|
if (submeshes.Count <= submeshIndex)
|
||||||
submeshes.Add(new Submesh());
|
submeshes.Add(new Submesh());
|
||||||
@ -618,10 +646,13 @@ public class SkeletonRenderer : MonoBehaviour {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
Submesh submesh = submeshes.Items[submeshIndex];
|
Submesh submesh = submeshes.Items[submeshIndex];
|
||||||
|
|
||||||
int[] triangles = submesh.triangles;
|
int[] triangles = submesh.triangles;
|
||||||
|
|
||||||
|
int triangleCount = submeshArguments.triangleCount;
|
||||||
|
int firstVertex = submeshArguments.firstVertex;
|
||||||
|
|
||||||
int trianglesCapacity = triangles.Length;
|
int trianglesCapacity = triangles.Length;
|
||||||
if (lastSubmesh && trianglesCapacity > triangleCount) {
|
if (submeshArguments.isLastSubmesh && trianglesCapacity > triangleCount) {
|
||||||
// Last submesh may have more triangles than required, so zero triangles to the end.
|
// Last submesh may have more triangles than required, so zero triangles to the end.
|
||||||
for (int i = triangleCount; i < trianglesCapacity; i++)
|
for (int i = triangleCount; i < trianglesCapacity; i++)
|
||||||
triangles[i] = 0;
|
triangles[i] = 0;
|
||||||
@ -637,8 +668,8 @@ public class SkeletonRenderer : MonoBehaviour {
|
|||||||
if (submesh.firstVertex != firstVertex || submesh.triangleCount < triangleCount) {
|
if (submesh.firstVertex != firstVertex || submesh.triangleCount < triangleCount) {
|
||||||
submesh.triangleCount = triangleCount;
|
submesh.triangleCount = triangleCount;
|
||||||
submesh.firstVertex = firstVertex;
|
submesh.firstVertex = firstVertex;
|
||||||
int drawOrderIndex = 0;
|
//int drawOrderIndex = 0;
|
||||||
for (int i = 0; i < triangleCount; i += 6, firstVertex += 4, drawOrderIndex++) {
|
for (int i = 0; i < triangleCount; i += 6, firstVertex += 4/*, drawOrderIndex++*/) {
|
||||||
triangles[i] = firstVertex;
|
triangles[i] = firstVertex;
|
||||||
triangles[i + 1] = firstVertex + 2;
|
triangles[i + 1] = firstVertex + 2;
|
||||||
triangles[i + 2] = firstVertex + 1;
|
triangles[i + 2] = firstVertex + 1;
|
||||||
@ -650,14 +681,16 @@ public class SkeletonRenderer : MonoBehaviour {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store triangles.
|
// Iterate through all slots and store their triangles.
|
||||||
ExposedList<Slot> drawOrder = skeleton.DrawOrder;
|
ExposedList<Slot> drawOrder = skeleton.DrawOrder;
|
||||||
for (int i = startSlot, triangleIndex = 0; i < endSlot; i++) {
|
int triangleIndex = 0; // Modified by loop
|
||||||
|
for (int i = submeshArguments.startSlot, n = submeshArguments.endSlot; i < n; i++) {
|
||||||
Slot slot = drawOrder.Items[i];
|
Slot slot = drawOrder.Items[i];
|
||||||
Attachment attachment = slot.attachment;
|
Attachment attachment = slot.attachment;
|
||||||
|
|
||||||
bool flip = flipStates.Items[i];
|
bool flip = flipStates.Items[i];
|
||||||
|
|
||||||
|
// Add RegionAttachment triangles
|
||||||
if (attachment is RegionAttachment) {
|
if (attachment is RegionAttachment) {
|
||||||
if (!flip) {
|
if (!flip) {
|
||||||
triangles[triangleIndex] = firstVertex;
|
triangles[triangleIndex] = firstVertex;
|
||||||
@ -679,16 +712,18 @@ public class SkeletonRenderer : MonoBehaviour {
|
|||||||
firstVertex += 4;
|
firstVertex += 4;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add (Skinned)MeshAttachment triangles
|
||||||
int[] attachmentTriangles;
|
int[] attachmentTriangles;
|
||||||
int attachmentVertexCount;
|
int attachmentVertexCount;
|
||||||
MeshAttachment meshAttachment = attachment as MeshAttachment;
|
MeshAttachment meshAttachment = attachment as MeshAttachment;
|
||||||
if (meshAttachment != null) {
|
if (meshAttachment != null) {
|
||||||
attachmentVertexCount = meshAttachment.vertices.Length >> 1;
|
attachmentVertexCount = meshAttachment.vertices.Length >> 1; // length/2
|
||||||
attachmentTriangles = meshAttachment.triangles;
|
attachmentTriangles = meshAttachment.triangles;
|
||||||
} else {
|
} else {
|
||||||
SkinnedMeshAttachment skinnedMeshAttachment = attachment as SkinnedMeshAttachment;
|
SkinnedMeshAttachment skinnedMeshAttachment = attachment as SkinnedMeshAttachment;
|
||||||
if (skinnedMeshAttachment != null) {
|
if (skinnedMeshAttachment != null) {
|
||||||
attachmentVertexCount = skinnedMeshAttachment.uvs.Length >> 1;
|
attachmentVertexCount = skinnedMeshAttachment.uvs.Length >> 1; // length/2
|
||||||
attachmentTriangles = skinnedMeshAttachment.triangles;
|
attachmentTriangles = skinnedMeshAttachment.triangles;
|
||||||
} else
|
} else
|
||||||
continue;
|
continue;
|
||||||
@ -710,7 +745,7 @@ public class SkeletonRenderer : MonoBehaviour {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
void OnDrawGizmos () {
|
void OnDrawGizmos () {
|
||||||
// Make selection easier by drawing a clear gizmo over the skeleton.
|
// Make selection easier by drawing a clear gizmo over the skeleton.
|
||||||
meshFilter = GetComponent<MeshFilter>();
|
meshFilter = GetComponent<MeshFilter>();
|
||||||
@ -724,26 +759,27 @@ public class SkeletonRenderer : MonoBehaviour {
|
|||||||
Gizmos.matrix = transform.localToWorldMatrix;
|
Gizmos.matrix = transform.localToWorldMatrix;
|
||||||
Gizmos.DrawCube(meshBounds.center, meshBounds.size);
|
Gizmos.DrawCube(meshBounds.center, meshBounds.size);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private class MeshState {
|
private class MeshState {
|
||||||
public int vertexCount;
|
public int vertexCount;
|
||||||
public readonly SingleMeshState stateTemp = new SingleMeshState();
|
public readonly SingleMeshState buffer = new SingleMeshState();
|
||||||
public readonly SingleMeshState stateMesh1 = new SingleMeshState();
|
public readonly SingleMeshState stateMesh1 = new SingleMeshState();
|
||||||
public readonly SingleMeshState stateMesh2 = new SingleMeshState();
|
public readonly SingleMeshState stateMesh2 = new SingleMeshState();
|
||||||
|
|
||||||
public class SingleMeshState {
|
public class SingleMeshState {
|
||||||
public bool immutableTriangles;
|
public bool immutableTriangles;
|
||||||
|
public bool requiresUpdate;
|
||||||
public readonly ExposedList<Attachment> attachments = new ExposedList<Attachment>();
|
public readonly ExposedList<Attachment> attachments = new ExposedList<Attachment>();
|
||||||
public readonly ExposedList<bool> attachmentsFlipState = new ExposedList<bool>();
|
public readonly ExposedList<bool> attachmentsFlipState = new ExposedList<bool>();
|
||||||
public readonly ExposedList<AddSubmeshArguments> addSubmeshArguments = new ExposedList<AddSubmeshArguments>();
|
public readonly ExposedList<AddSubmeshArguments> addSubmeshArguments = new ExposedList<AddSubmeshArguments>();
|
||||||
|
|
||||||
public void UpdateDrawOrderCount(int drawOrderCount) {
|
public void UpdateAttachmentCount (int attachmentCount) {
|
||||||
attachmentsFlipState.GrowIfNeeded(drawOrderCount);
|
attachmentsFlipState.GrowIfNeeded(attachmentCount);
|
||||||
attachmentsFlipState.Count = drawOrderCount;
|
attachmentsFlipState.Count = attachmentCount;
|
||||||
|
|
||||||
attachments.GrowIfNeeded(drawOrderCount);
|
attachments.GrowIfNeeded(attachmentCount);
|
||||||
attachments.Count = drawOrderCount;
|
attachments.Count = attachmentCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -753,22 +789,13 @@ public class SkeletonRenderer : MonoBehaviour {
|
|||||||
public int endSlot;
|
public int endSlot;
|
||||||
public int triangleCount;
|
public int triangleCount;
|
||||||
public int firstVertex;
|
public int firstVertex;
|
||||||
public bool lastSubmesh;
|
public bool isLastSubmesh;
|
||||||
|
|
||||||
public AddSubmeshArguments (Material material, int startSlot, int endSlot, int triangleCount, int firstVertex, bool lastSubmesh) {
|
|
||||||
this.material = material;
|
|
||||||
this.startSlot = startSlot;
|
|
||||||
this.endSlot = endSlot;
|
|
||||||
this.triangleCount = triangleCount;
|
|
||||||
this.firstVertex = firstVertex;
|
|
||||||
this.lastSubmesh = lastSubmesh;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool Equals (ref AddSubmeshArguments other) {
|
public bool Equals (ref AddSubmeshArguments other) {
|
||||||
return
|
return
|
||||||
!ReferenceEquals(material, null) &&
|
//!ReferenceEquals(material, null) &&
|
||||||
!ReferenceEquals(other.material, null) &&
|
//!ReferenceEquals(other.material, null) &&
|
||||||
material.GetInstanceID() == other.material.GetInstanceID() &&
|
//material.GetInstanceID() == other.material.GetInstanceID() &&
|
||||||
startSlot == other.startSlot &&
|
startSlot == other.startSlot &&
|
||||||
endSlot == other.endSlot &&
|
endSlot == other.endSlot &&
|
||||||
triangleCount == other.triangleCount &&
|
triangleCount == other.triangleCount &&
|
||||||
|
|||||||
@ -7,9 +7,12 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
|
||||||
public class SpineSlot : PropertyAttribute {
|
public abstract class SpineAttributeBase : PropertyAttribute {
|
||||||
public string startsWith = "";
|
|
||||||
public string dataField = "";
|
public string dataField = "";
|
||||||
|
public string startsWith = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public class SpineSlot : SpineAttributeBase {
|
||||||
public bool containsBoundingBoxes = false;
|
public bool containsBoundingBoxes = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -21,17 +24,29 @@ public class SpineSlot : PropertyAttribute {
|
|||||||
/// If left empty and the script the attribute is applied to is derived from Component, GetComponent<SkeletonRenderer>() will be called as a fallback.
|
/// If left empty and the script the attribute is applied to is derived from Component, GetComponent<SkeletonRenderer>() will be called as a fallback.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <param name="containsBoundingBoxes">Disables popup results that don't contain bounding box attachments when true.</param>
|
/// <param name="containsBoundingBoxes">Disables popup results that don't contain bounding box attachments when true.</param>
|
||||||
public SpineSlot (string startsWith = "", string dataField = "", bool containsBoundingBoxes = false) {
|
public SpineSlot(string startsWith = "", string dataField = "", bool containsBoundingBoxes = false) {
|
||||||
this.startsWith = startsWith;
|
this.startsWith = startsWith;
|
||||||
this.dataField = dataField;
|
this.dataField = dataField;
|
||||||
this.containsBoundingBoxes = containsBoundingBoxes;
|
this.containsBoundingBoxes = containsBoundingBoxes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SpineSkin : PropertyAttribute {
|
public class SpineEventData : SpineAttributeBase {
|
||||||
public string startsWith = "";
|
/// <summary>
|
||||||
public string dataField = "";
|
/// Smart popup menu for Spine Events (Spine.EventData)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="startsWith">Filters popup results to elements that begin with supplied string.</param>
|
||||||
|
/// <param name="dataField">If specified, a locally scoped field with the name supplied by in dataField will be used to fill the popup results.
|
||||||
|
/// Valid types are SkeletonDataAsset and SkeletonRenderer (and derivatives).
|
||||||
|
/// If left empty and the script the attribute is applied to is derived from Component, GetComponent<SkeletonRenderer>() will be called as a fallback.
|
||||||
|
/// </param>
|
||||||
|
public SpineEventData(string startsWith = "", string dataField = "") {
|
||||||
|
this.startsWith = startsWith;
|
||||||
|
this.dataField = dataField;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class SpineSkin : SpineAttributeBase {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Smart popup menu for Spine Skins
|
/// Smart popup menu for Spine Skins
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -40,15 +55,12 @@ public class SpineSkin : PropertyAttribute {
|
|||||||
/// Valid types are SkeletonDataAsset and SkeletonRenderer (and derivatives)
|
/// Valid types are SkeletonDataAsset and SkeletonRenderer (and derivatives)
|
||||||
/// If left empty and the script the attribute is applied to is derived from Component, GetComponent<SkeletonRenderer>() will be called as a fallback.
|
/// If left empty and the script the attribute is applied to is derived from Component, GetComponent<SkeletonRenderer>() will be called as a fallback.
|
||||||
/// </param>
|
/// </param>
|
||||||
public SpineSkin (string startsWith = "", string dataField = "") {
|
public SpineSkin(string startsWith = "", string dataField = "") {
|
||||||
this.startsWith = startsWith;
|
this.startsWith = startsWith;
|
||||||
this.dataField = dataField;
|
this.dataField = dataField;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public class SpineAnimation : PropertyAttribute {
|
public class SpineAnimation : SpineAttributeBase {
|
||||||
public string startsWith = "";
|
|
||||||
public string dataField = "";
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Smart popup menu for Spine Animations
|
/// Smart popup menu for Spine Animations
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -57,24 +69,18 @@ public class SpineAnimation : PropertyAttribute {
|
|||||||
/// Valid types are SkeletonDataAsset and SkeletonRenderer (and derivatives)
|
/// Valid types are SkeletonDataAsset and SkeletonRenderer (and derivatives)
|
||||||
/// If left empty and the script the attribute is applied to is derived from Component, GetComponent<SkeletonRenderer>() will be called as a fallback.
|
/// If left empty and the script the attribute is applied to is derived from Component, GetComponent<SkeletonRenderer>() will be called as a fallback.
|
||||||
/// </param>
|
/// </param>
|
||||||
public SpineAnimation (string startsWith = "", string dataField = "") {
|
public SpineAnimation(string startsWith = "", string dataField = "") {
|
||||||
this.startsWith = startsWith;
|
this.startsWith = startsWith;
|
||||||
this.dataField = dataField;
|
this.dataField = dataField;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SpineAttachment : PropertyAttribute {
|
public class SpineAttachment : SpineAttributeBase {
|
||||||
public bool returnAttachmentPath = false;
|
public bool returnAttachmentPath = false;
|
||||||
public bool currentSkinOnly = false;
|
public bool currentSkinOnly = false;
|
||||||
public bool placeholdersOnly = false;
|
public bool placeholdersOnly = false;
|
||||||
public string dataField = "";
|
|
||||||
public string slotField = "";
|
public string slotField = "";
|
||||||
|
|
||||||
|
|
||||||
public SpineAttachment () {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Smart popup menu for Spine Attachments
|
/// Smart popup menu for Spine Attachments
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -86,19 +92,19 @@ public class SpineAttachment : PropertyAttribute {
|
|||||||
/// Valid types are SkeletonDataAsset and SkeletonRenderer (and derivatives)
|
/// Valid types are SkeletonDataAsset and SkeletonRenderer (and derivatives)
|
||||||
/// If left empty and the script the attribute is applied to is derived from Component, GetComponent<SkeletonRenderer>() will be called as a fallback.
|
/// If left empty and the script the attribute is applied to is derived from Component, GetComponent<SkeletonRenderer>() will be called as a fallback.
|
||||||
/// </param>
|
/// </param>
|
||||||
public SpineAttachment (bool currentSkinOnly = true, bool returnAttachmentPath = false, bool placeholdersOnly = false, string slotField = "", string dataField = "") {
|
public SpineAttachment(bool currentSkinOnly = true, bool returnAttachmentPath = false, bool placeholdersOnly = false, string slotField = "", string dataField = "") {
|
||||||
this.currentSkinOnly = currentSkinOnly;
|
this.currentSkinOnly = currentSkinOnly;
|
||||||
this.returnAttachmentPath = returnAttachmentPath;
|
this.returnAttachmentPath = returnAttachmentPath;
|
||||||
this.placeholdersOnly = placeholdersOnly;
|
this.placeholdersOnly = placeholdersOnly;
|
||||||
this.slotField = slotField;
|
this.slotField = slotField;
|
||||||
this.dataField = dataField;
|
this.dataField = dataField;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Hierarchy GetHierarchy (string fullPath) {
|
public static Hierarchy GetHierarchy(string fullPath) {
|
||||||
return new Hierarchy(fullPath);
|
return new Hierarchy(fullPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Spine.Attachment GetAttachment (string attachmentPath, Spine.SkeletonData skeletonData) {
|
public static Spine.Attachment GetAttachment(string attachmentPath, Spine.SkeletonData skeletonData) {
|
||||||
var hierarchy = SpineAttachment.GetHierarchy(attachmentPath);
|
var hierarchy = SpineAttachment.GetHierarchy(attachmentPath);
|
||||||
if (hierarchy.name == "")
|
if (hierarchy.name == "")
|
||||||
return null;
|
return null;
|
||||||
@ -106,7 +112,7 @@ public class SpineAttachment : PropertyAttribute {
|
|||||||
return skeletonData.FindSkin(hierarchy.skin).GetAttachment(skeletonData.FindSlotIndex(hierarchy.slot), hierarchy.name);
|
return skeletonData.FindSkin(hierarchy.skin).GetAttachment(skeletonData.FindSlotIndex(hierarchy.slot), hierarchy.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Spine.Attachment GetAttachment (string attachmentPath, SkeletonDataAsset skeletonDataAsset) {
|
public static Spine.Attachment GetAttachment(string attachmentPath, SkeletonDataAsset skeletonDataAsset) {
|
||||||
return GetAttachment(attachmentPath, skeletonDataAsset.GetSkeletonData(true));
|
return GetAttachment(attachmentPath, skeletonDataAsset.GetSkeletonData(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,14 +121,15 @@ public class SpineAttachment : PropertyAttribute {
|
|||||||
public string slot;
|
public string slot;
|
||||||
public string name;
|
public string name;
|
||||||
|
|
||||||
public Hierarchy (string fullPath) {
|
public Hierarchy(string fullPath) {
|
||||||
string[] chunks = fullPath.Split(new char[] { '/' }, System.StringSplitOptions.RemoveEmptyEntries);
|
string[] chunks = fullPath.Split(new char[]{'/'}, System.StringSplitOptions.RemoveEmptyEntries);
|
||||||
if (chunks.Length == 0) {
|
if (chunks.Length == 0) {
|
||||||
skin = "";
|
skin = "";
|
||||||
slot = "";
|
slot = "";
|
||||||
name = "";
|
name = "";
|
||||||
return;
|
return;
|
||||||
} else if (chunks.Length < 2) {
|
}
|
||||||
|
else if (chunks.Length < 2) {
|
||||||
throw new System.Exception("Cannot generate Attachment Hierarchy from string! Not enough components! [" + fullPath + "]");
|
throw new System.Exception("Cannot generate Attachment Hierarchy from string! Not enough components! [" + fullPath + "]");
|
||||||
}
|
}
|
||||||
skin = chunks[0];
|
skin = chunks[0];
|
||||||
@ -135,10 +142,7 @@ public class SpineAttachment : PropertyAttribute {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SpineBone : PropertyAttribute {
|
public class SpineBone : SpineAttributeBase {
|
||||||
public string startsWith = "";
|
|
||||||
public string dataField = "";
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Smart popup menu for Spine Bones
|
/// Smart popup menu for Spine Bones
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -147,19 +151,19 @@ public class SpineBone : PropertyAttribute {
|
|||||||
/// Valid types are SkeletonDataAsset and SkeletonRenderer (and derivatives)
|
/// Valid types are SkeletonDataAsset and SkeletonRenderer (and derivatives)
|
||||||
/// If left empty and the script the attribute is applied to is derived from Component, GetComponent<SkeletonRenderer>() will be called as a fallback.
|
/// If left empty and the script the attribute is applied to is derived from Component, GetComponent<SkeletonRenderer>() will be called as a fallback.
|
||||||
/// </param>
|
/// </param>
|
||||||
public SpineBone (string startsWith = "", string dataField = "") {
|
public SpineBone(string startsWith = "", string dataField = "") {
|
||||||
this.startsWith = startsWith;
|
this.startsWith = startsWith;
|
||||||
this.dataField = dataField;
|
this.dataField = dataField;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Spine.Bone GetBone (string boneName, SkeletonRenderer renderer) {
|
public static Spine.Bone GetBone(string boneName, SkeletonRenderer renderer) {
|
||||||
if (renderer.skeleton == null)
|
if (renderer.skeleton == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return renderer.skeleton.FindBone(boneName);
|
return renderer.skeleton.FindBone(boneName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Spine.BoneData GetBoneData (string boneName, SkeletonDataAsset skeletonDataAsset) {
|
public static Spine.BoneData GetBoneData(string boneName, SkeletonDataAsset skeletonDataAsset) {
|
||||||
var data = skeletonDataAsset.GetSkeletonData(true);
|
var data = skeletonDataAsset.GetSkeletonData(true);
|
||||||
|
|
||||||
return data.FindBone(boneName);
|
return data.FindBone(boneName);
|
||||||
@ -169,4 +173,4 @@ public class SpineBone : PropertyAttribute {
|
|||||||
public class SpineAtlasRegion : PropertyAttribute {
|
public class SpineAtlasRegion : PropertyAttribute {
|
||||||
//TODO: Standardize with Skeleton attributes
|
//TODO: Standardize with Skeleton attributes
|
||||||
//NOTE: For now, relies on locally scoped field named "atlasAsset" for source.
|
//NOTE: For now, relies on locally scoped field named "atlasAsset" for source.
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user