mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-07 11:16:53 +08:00
Merge branch '3.8' into 4.0-beta
This commit is contained in:
commit
dbb10f36f6
@ -126,41 +126,12 @@ void USpineSkeletonRendererComponent::UpdateRenderer(USpineSkeletonComponent* sk
|
|||||||
|
|
||||||
for (int i = 0; i < skeleton->Atlas->atlasPages.Num(); i++) {
|
for (int i = 0; i < skeleton->Atlas->atlasPages.Num(); i++) {
|
||||||
AtlasPage* currPage = skeleton->Atlas->GetAtlas()->getPages()[i];
|
AtlasPage* currPage = skeleton->Atlas->GetAtlas()->getPages()[i];
|
||||||
|
|
||||||
UTexture2D* texture = skeleton->Atlas->atlasPages[i];
|
UTexture2D* texture = skeleton->Atlas->atlasPages[i];
|
||||||
UTexture* oldTexture = nullptr;
|
|
||||||
|
|
||||||
UMaterialInstanceDynamic* current = atlasNormalBlendMaterials[i];
|
UpdateRendererMaterial(currPage, texture, atlasNormalBlendMaterials[i], NormalBlendMaterial, pageToNormalBlendMaterial);
|
||||||
if (!current || !current->GetTextureParameterValue(TextureParameterName, oldTexture) || oldTexture != texture) {
|
UpdateRendererMaterial(currPage, texture, atlasAdditiveBlendMaterials[i], AdditiveBlendMaterial, pageToAdditiveBlendMaterial);
|
||||||
UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(NormalBlendMaterial, this);
|
UpdateRendererMaterial(currPage, texture, atlasMultiplyBlendMaterials[i], MultiplyBlendMaterial, pageToMultiplyBlendMaterial);
|
||||||
material->SetTextureParameterValue(TextureParameterName, texture);
|
UpdateRendererMaterial(currPage, texture, atlasScreenBlendMaterials[i], ScreenBlendMaterial, pageToScreenBlendMaterial);
|
||||||
atlasNormalBlendMaterials[i] = material;
|
|
||||||
}
|
|
||||||
pageToNormalBlendMaterial.Add(currPage, atlasNormalBlendMaterials[i]);
|
|
||||||
|
|
||||||
current = atlasAdditiveBlendMaterials[i];
|
|
||||||
if (!current || !current->GetTextureParameterValue(TextureParameterName, oldTexture) || oldTexture != texture) {
|
|
||||||
UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(AdditiveBlendMaterial, this);
|
|
||||||
material->SetTextureParameterValue(TextureParameterName, texture);
|
|
||||||
atlasAdditiveBlendMaterials[i] = material;
|
|
||||||
}
|
|
||||||
pageToAdditiveBlendMaterial.Add(currPage, atlasAdditiveBlendMaterials[i]);
|
|
||||||
|
|
||||||
current = atlasMultiplyBlendMaterials[i];
|
|
||||||
if (!current || !current->GetTextureParameterValue(TextureParameterName, oldTexture) || oldTexture != texture) {
|
|
||||||
UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(MultiplyBlendMaterial, this);
|
|
||||||
material->SetTextureParameterValue(TextureParameterName, texture);
|
|
||||||
atlasMultiplyBlendMaterials[i] = material;
|
|
||||||
}
|
|
||||||
pageToMultiplyBlendMaterial.Add(currPage, atlasMultiplyBlendMaterials[i]);
|
|
||||||
|
|
||||||
current = atlasScreenBlendMaterials[i];
|
|
||||||
if (!current || !current->GetTextureParameterValue(TextureParameterName, oldTexture) || oldTexture != texture) {
|
|
||||||
UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(ScreenBlendMaterial, this);
|
|
||||||
material->SetTextureParameterValue(TextureParameterName, texture);
|
|
||||||
atlasScreenBlendMaterials[i] = material;
|
|
||||||
}
|
|
||||||
pageToScreenBlendMaterial.Add(currPage, atlasScreenBlendMaterials[i]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
UpdateMesh(skeleton->GetSkeleton());
|
UpdateMesh(skeleton->GetSkeleton());
|
||||||
@ -170,6 +141,21 @@ void USpineSkeletonRendererComponent::UpdateRenderer(USpineSkeletonComponent* sk
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void USpineSkeletonRendererComponent::UpdateRendererMaterial (spine::AtlasPage *CurrentPage, UTexture2D *Texture,
|
||||||
|
UMaterialInstanceDynamic *&CurrentInstance, UMaterialInterface *ParentMaterial,
|
||||||
|
TMap<spine::AtlasPage *, UMaterialInstanceDynamic *> &PageToBlendMaterial) {
|
||||||
|
|
||||||
|
UTexture* oldTexture = nullptr;
|
||||||
|
if (!CurrentInstance || !CurrentInstance->GetTextureParameterValue(TextureParameterName, oldTexture) ||
|
||||||
|
oldTexture != Texture || CurrentInstance->Parent != ParentMaterial) {
|
||||||
|
|
||||||
|
UMaterialInstanceDynamic* material = UMaterialInstanceDynamic::Create(ParentMaterial, this);
|
||||||
|
material->SetTextureParameterValue(TextureParameterName, Texture);
|
||||||
|
CurrentInstance = material;
|
||||||
|
}
|
||||||
|
PageToBlendMaterial.Add(CurrentPage, CurrentInstance);
|
||||||
|
}
|
||||||
|
|
||||||
void USpineSkeletonRendererComponent::Flush (int &Idx, TArray<FVector> &Vertices, TArray<int32> &Indices, TArray<FVector> &Normals, TArray<FVector2D> &Uvs, TArray<FColor> &Colors, TArray<FVector>& Colors2, UMaterialInstanceDynamic* Material) {
|
void USpineSkeletonRendererComponent::Flush (int &Idx, TArray<FVector> &Vertices, TArray<int32> &Indices, TArray<FVector> &Normals, TArray<FVector2D> &Uvs, TArray<FColor> &Colors, TArray<FVector>& Colors2, UMaterialInstanceDynamic* Material) {
|
||||||
if (Vertices.Num() == 0) return;
|
if (Vertices.Num() == 0) return;
|
||||||
SetMaterial(Idx, Material);
|
SetMaterial(Idx, Material);
|
||||||
@ -346,14 +332,25 @@ void USpineSkeletonRendererComponent::UpdateMesh(Skeleton* Skeleton) {
|
|||||||
colors.Add(FColor(r, g, b, a));
|
colors.Add(FColor(r, g, b, a));
|
||||||
darkColors.Add(FVector(dr, dg, db));
|
darkColors.Add(FVector(dr, dg, db));
|
||||||
vertices.Add(FVector(verticesPtr[j], depthOffset, verticesPtr[j + 1]));
|
vertices.Add(FVector(verticesPtr[j], depthOffset, verticesPtr[j + 1]));
|
||||||
normals.Add(FVector(0, -1, 0));
|
|
||||||
uvs.Add(FVector2D(attachmentUvs[j], attachmentUvs[j + 1]));
|
uvs.Add(FVector2D(attachmentUvs[j], attachmentUvs[j + 1]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int firstIndex = indices.Num();
|
||||||
for (int j = 0; j < numIndices; j++) {
|
for (int j = 0; j < numIndices; j++) {
|
||||||
indices.Add(idx + attachmentIndices[j]);
|
indices.Add(idx + attachmentIndices[j]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FVector normal = FVector(0, -1, 0);
|
||||||
|
if (numVertices > 2 &&
|
||||||
|
FVector::CrossProduct(
|
||||||
|
vertices[indices[firstIndex + 2]] - vertices[indices[firstIndex]],
|
||||||
|
vertices[indices[firstIndex + 1]] - vertices[indices[firstIndex]]).Y > 0.f) {
|
||||||
|
normal.Y = 1;
|
||||||
|
}
|
||||||
|
for (int j = 0; j < numVertices; j++) {
|
||||||
|
normals.Add(normal);
|
||||||
|
}
|
||||||
|
|
||||||
idx += numVertices;
|
idx += numVertices;
|
||||||
depthOffset += this->DepthOffset;
|
depthOffset += this->DepthOffset;
|
||||||
|
|
||||||
|
|||||||
@ -95,6 +95,10 @@ public:
|
|||||||
virtual void FinishDestroy() override;
|
virtual void FinishDestroy() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void UpdateRendererMaterial (spine::AtlasPage *CurrentPage, UTexture2D *Texture,
|
||||||
|
UMaterialInstanceDynamic *&CurrentInstance, UMaterialInterface *ParentMaterial,
|
||||||
|
TMap<spine::AtlasPage *, UMaterialInstanceDynamic *> &PageToBlendMaterial);
|
||||||
|
|
||||||
void UpdateMesh (spine::Skeleton* Skeleton);
|
void UpdateMesh (spine::Skeleton* Skeleton);
|
||||||
|
|
||||||
void Flush (int &Idx, TArray<FVector> &Vertices, TArray<int32> &Indices, TArray<FVector> &Normals, TArray<FVector2D> &Uvs, TArray<FColor> &Colors, TArray<FVector> &Colors2, UMaterialInstanceDynamic* Material);
|
void Flush (int &Idx, TArray<FVector> &Vertices, TArray<int32> &Indices, TArray<FVector> &Normals, TArray<FVector2D> &Uvs, TArray<FColor> &Colors, TArray<FVector> &Colors2, UMaterialInstanceDynamic* Material);
|
||||||
|
|||||||
@ -733,7 +733,13 @@ MonoBehaviour:
|
|||||||
|
|
||||||
|
|
||||||
Enter <b>PLAY</b> Mode, and try scrolling up and down, or tap and drag the scroll
|
Enter <b>PLAY</b> Mode, and try scrolling up and down, or tap and drag the scroll
|
||||||
view.'
|
view.
|
||||||
|
|
||||||
|
|
||||||
|
The <i>SkeletonGraphic''s</i> <b>RectTransform</b> shall not be smaller than the
|
||||||
|
mesh, otherwise a <i>RectMask2D</i> will omit drawing the skeleton when the <i>RectTransform</i>
|
||||||
|
is completely outside. You can fit the <i>RectTransform</i> to the current pose
|
||||||
|
via the Inspector button <b>Match RectTransform with Mesh</b>.'
|
||||||
--- !u!222 &774800196
|
--- !u!222 &774800196
|
||||||
CanvasRenderer:
|
CanvasRenderer:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|||||||
@ -337,7 +337,7 @@ namespace Spine.Unity.Examples {
|
|||||||
|
|
||||||
parentSpaceHelper.position = parentTransformWorldPosition;
|
parentSpaceHelper.position = parentTransformWorldPosition;
|
||||||
parentSpaceHelper.rotation = parentTransformWorldRotation;
|
parentSpaceHelper.rotation = parentTransformWorldRotation;
|
||||||
parentSpaceHelper.localScale = parentTransform.localScale;
|
parentSpaceHelper.localScale = parentTransform.lossyScale;
|
||||||
|
|
||||||
Vector3 boneWorldPosition = t.position;
|
Vector3 boneWorldPosition = t.position;
|
||||||
Vector3 right = parentSpaceHelper.InverseTransformDirection(t.right);
|
Vector3 right = parentSpaceHelper.InverseTransformDirection(t.right);
|
||||||
|
|||||||
@ -354,7 +354,7 @@ namespace Spine.Unity.Examples {
|
|||||||
|
|
||||||
parentSpaceHelper.position = parentTransformWorldPosition;
|
parentSpaceHelper.position = parentTransformWorldPosition;
|
||||||
parentSpaceHelper.rotation = parentTransformWorldRotation;
|
parentSpaceHelper.rotation = parentTransformWorldRotation;
|
||||||
parentSpaceHelper.localScale = parentTransform.localScale;
|
parentSpaceHelper.localScale = parentTransform.lossyScale;
|
||||||
|
|
||||||
Vector3 boneWorldPosition = t.position;
|
Vector3 boneWorldPosition = t.position;
|
||||||
Vector3 right = parentSpaceHelper.InverseTransformDirection(t.right);
|
Vector3 right = parentSpaceHelper.InverseTransformDirection(t.right);
|
||||||
|
|||||||
@ -37,7 +37,6 @@ namespace Spine.Unity.Editor {
|
|||||||
[CanEditMultipleObjects]
|
[CanEditMultipleObjects]
|
||||||
public class SkeletonAnimationInspector : SkeletonRendererInspector {
|
public class SkeletonAnimationInspector : SkeletonRendererInspector {
|
||||||
protected SerializedProperty animationName, loop, timeScale, autoReset;
|
protected SerializedProperty animationName, loop, timeScale, autoReset;
|
||||||
protected bool wasAnimationNameChanged;
|
|
||||||
protected bool requireRepaint;
|
protected bool requireRepaint;
|
||||||
readonly GUIContent LoopLabel = new GUIContent("Loop", "Whether or not .AnimationName 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.");
|
readonly GUIContent LoopLabel = new GUIContent("Loop", "Whether or not .AnimationName 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.");
|
||||||
readonly GUIContent TimeScaleLabel = new GUIContent("Time Scale", "The rate at which animations progress over time. 1 means normal speed. 0.5 means 50% speed.");
|
readonly GUIContent TimeScaleLabel = new GUIContent("Time Scale", "The rate at which animations progress over time. 1 means normal speed. 0.5 means 50% speed.");
|
||||||
@ -55,16 +54,13 @@ namespace Spine.Unity.Editor {
|
|||||||
bool sameData = SpineInspectorUtility.TargetsUseSameData(serializedObject);
|
bool sameData = SpineInspectorUtility.TargetsUseSameData(serializedObject);
|
||||||
|
|
||||||
foreach (var o in targets)
|
foreach (var o in targets)
|
||||||
TrySetAnimation(o as SkeletonAnimation, multi);
|
TrySetAnimation(o as SkeletonAnimation);
|
||||||
wasAnimationNameChanged = false;
|
|
||||||
|
|
||||||
EditorGUILayout.Space();
|
EditorGUILayout.Space();
|
||||||
if (!sameData) {
|
if (!sameData) {
|
||||||
EditorGUILayout.DelayedTextField(animationName);
|
EditorGUILayout.DelayedTextField(animationName);
|
||||||
} else {
|
} else {
|
||||||
EditorGUI.BeginChangeCheck();
|
|
||||||
EditorGUILayout.PropertyField(animationName);
|
EditorGUILayout.PropertyField(animationName);
|
||||||
wasAnimationNameChanged |= EditorGUI.EndChangeCheck(); // Value used in the next update.
|
|
||||||
}
|
}
|
||||||
EditorGUILayout.PropertyField(loop, LoopLabel);
|
EditorGUILayout.PropertyField(loop, LoopLabel);
|
||||||
EditorGUILayout.PropertyField(timeScale, TimeScaleLabel);
|
EditorGUILayout.PropertyField(timeScale, TimeScaleLabel);
|
||||||
@ -76,20 +72,25 @@ namespace Spine.Unity.Editor {
|
|||||||
EditorGUILayout.Space();
|
EditorGUILayout.Space();
|
||||||
SkeletonRootMotionParameter();
|
SkeletonRootMotionParameter();
|
||||||
|
|
||||||
|
serializedObject.ApplyModifiedProperties();
|
||||||
|
|
||||||
if (!isInspectingPrefab) {
|
if (!isInspectingPrefab) {
|
||||||
if (requireRepaint) {
|
if (requireRepaint) {
|
||||||
SceneView.RepaintAll();
|
UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
|
||||||
requireRepaint = false;
|
requireRepaint = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void TrySetAnimation (SkeletonAnimation skeletonAnimation, bool multi) {
|
protected void TrySetAnimation (SkeletonAnimation skeletonAnimation) {
|
||||||
if (skeletonAnimation == null) return;
|
if (skeletonAnimation == null) return;
|
||||||
if (!skeletonAnimation.valid)
|
if (!skeletonAnimation.valid)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
TrackEntry current = skeletonAnimation.AnimationState.GetCurrent(0);
|
||||||
if (!isInspectingPrefab) {
|
if (!isInspectingPrefab) {
|
||||||
|
string activeAnimation = (current != null) ? current.Animation.Name : null;
|
||||||
|
bool wasAnimationNameChanged = activeAnimation != animationName.stringValue;
|
||||||
if (wasAnimationNameChanged) {
|
if (wasAnimationNameChanged) {
|
||||||
var skeleton = skeletonAnimation.Skeleton;
|
var skeleton = skeletonAnimation.Skeleton;
|
||||||
var state = skeletonAnimation.AnimationState;
|
var state = skeletonAnimation.AnimationState;
|
||||||
@ -105,7 +106,7 @@ namespace Spine.Unity.Editor {
|
|||||||
if (animationToUse != null) {
|
if (animationToUse != null) {
|
||||||
skeletonAnimation.AnimationState.SetAnimation(0, animationToUse, loop.boolValue);
|
skeletonAnimation.AnimationState.SetAnimation(0, animationToUse, loop.boolValue);
|
||||||
}
|
}
|
||||||
skeleton.UpdateWorldTransform();
|
skeletonAnimation.Update(0);
|
||||||
skeletonAnimation.LateUpdate();
|
skeletonAnimation.LateUpdate();
|
||||||
requireRepaint = true;
|
requireRepaint = true;
|
||||||
} else {
|
} else {
|
||||||
@ -118,7 +119,6 @@ namespace Spine.Unity.Editor {
|
|||||||
|
|
||||||
// Reflect animationName serialized property in the inspector even if SetAnimation API was used.
|
// Reflect animationName serialized property in the inspector even if SetAnimation API was used.
|
||||||
if (Application.isPlaying) {
|
if (Application.isPlaying) {
|
||||||
TrackEntry current = skeletonAnimation.AnimationState.GetCurrent(0);
|
|
||||||
if (current != null) {
|
if (current != null) {
|
||||||
if (skeletonAnimation.AnimationName != animationName.stringValue)
|
if (skeletonAnimation.AnimationName != animationName.stringValue)
|
||||||
animationName.stringValue = current.Animation.Name;
|
animationName.stringValue = current.Animation.Name;
|
||||||
|
|||||||
@ -539,7 +539,7 @@ namespace Spine.Unity.Editor {
|
|||||||
|
|
||||||
if (mismatchDetected) {
|
if (mismatchDetected) {
|
||||||
mismatchDetected = false;
|
mismatchDetected = false;
|
||||||
SceneView.RepaintAll();
|
UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user