Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 into 4.1
  • Loading branch information
badlogic committed Apr 17, 2023
2 parents 98f060b + 245ff29 commit 889148c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
Expand Up @@ -116,6 +116,7 @@ public enum LayoutMode {
public bool updateSeparatorPartLocation = true;

private bool wasUpdatedAfterInit = true;
private bool requiresInstructionUpate = true;
private Texture baseTexture = null;

#if UNITY_EDITOR
Expand Down Expand Up @@ -308,7 +309,10 @@ public enum LayoutMode {
public override void Rebuild (CanvasUpdate update) {
base.Rebuild(update);
if (canvasRenderer.cull) return;
if (update == CanvasUpdate.PreRender) UpdateMeshToInstructions();
if (update == CanvasUpdate.PreRender) {
if (requiresInstructionUpate) PrepareInstructionsAndRenderers(isInRebuild: true);
UpdateMeshToInstructions();
}
if (allowMultipleCanvasRenderers) canvasRenderer.Clear();
}

Expand Down Expand Up @@ -404,8 +408,7 @@ public enum LayoutMode {
if (updateMode != UpdateMode.FullUpdate) return;

PrepareInstructionsAndRenderers();
if (OnInstructionsPrepared != null)
OnInstructionsPrepared(this.currentInstructions);

SetVerticesDirty(); // triggers Rebuild and avoids potential double-update in a single frame
}

Expand Down Expand Up @@ -452,9 +455,11 @@ public enum LayoutMode {
public Skeleton Skeleton {
get {
Initialize(false);
requiresInstructionUpate = true;
return skeleton;
}
set {
requiresInstructionUpate = true;
skeleton = value;
}
}
Expand Down Expand Up @@ -690,11 +695,12 @@ public enum LayoutMode {
OnAnimationRebuild(this);
}

public void PrepareInstructionsAndRenderers () {
public void PrepareInstructionsAndRenderers (bool isInRebuild = false) {
requiresInstructionUpate = false;
if (!this.allowMultipleCanvasRenderers) {
MeshGenerator.GenerateSingleSubmeshInstruction(currentInstructions, skeleton, null);
if (canvasRenderers.Count > 0)
DisableUnusedCanvasRenderers(usedCount: 0);
DisableUnusedCanvasRenderers(usedCount: 0, isInRebuild: isInRebuild);
usedRenderersCount = 0;
} else {
MeshGenerator.GenerateSkeletonRendererInstruction(currentInstructions, skeleton, null,
Expand All @@ -707,8 +713,10 @@ public enum LayoutMode {
EnsureMeshesCount(submeshCount);
EnsureUsedTexturesAndMaterialsCount(submeshCount);
EnsureSeparatorPartCount();
PrepareRendererGameObjects(currentInstructions);
PrepareRendererGameObjects(currentInstructions, isInRebuild);
}
if (OnInstructionsPrepared != null)
OnInstructionsPrepared(this.currentInstructions);
}

public void UpdateMesh () {
Expand Down Expand Up @@ -922,9 +930,11 @@ public enum LayoutMode {
}
}

protected void PrepareRendererGameObjects (SkeletonRendererInstruction currentInstructions) {
protected void PrepareRendererGameObjects (SkeletonRendererInstruction currentInstructions,
bool isInRebuild = false) {

int submeshCount = currentInstructions.submeshInstructions.Count;
DisableUnusedCanvasRenderers(usedCount: submeshCount);
DisableUnusedCanvasRenderers(usedCount: submeshCount, isInRebuild: isInRebuild);

int separatorSlotGroupIndex = 0;
int targetSiblingIndex = 0;
Expand Down Expand Up @@ -961,13 +971,14 @@ public enum LayoutMode {
usedRenderersCount = submeshCount;
}

protected void DisableUnusedCanvasRenderers (int usedCount) {
protected void DisableUnusedCanvasRenderers (int usedCount, bool isInRebuild = false) {
#if UNITY_EDITOR
RemoveNullCanvasRenderers();
#endif
for (int i = usedCount; i < canvasRenderers.Count; i++) {
canvasRenderers[i].Clear();
canvasRenderers[i].gameObject.SetActive(false);
if (!isInRebuild) // rebuild does not allow disabling Graphic and thus removing it from rebuild list.
canvasRenderers[i].gameObject.SetActive(false);
}
}

Expand Down
Expand Up @@ -813,8 +813,8 @@ public struct Settings {
b2.x *= alpha;
b2.y = slot.Data.BlendMode == BlendMode.Additive ? 0 : alpha;
}
int meshVertexCount = meshAttachment.WorldVerticesLength;
for (int iii = 0; iii < meshVertexCount; iii += 2) {
int verticesArrayLength = meshAttachment.WorldVerticesLength;
for (int iii = 0; iii < verticesArrayLength; iii += 2) {
uv2i[vi] = rg;
uv3i[vi] = b2;
vi++;
Expand Down Expand Up @@ -886,8 +886,8 @@ public struct Settings {
} else { //if (settings.renderMeshes) {
MeshAttachment meshAttachment = attachment as MeshAttachment;
if (meshAttachment != null) {
int meshVertexCount = meshAttachment.WorldVerticesLength;
if (tempVerts.Length < meshVertexCount) this.tempVerts = tempVerts = new float[meshVertexCount];
int verticesArrayLength = meshAttachment.WorldVerticesLength;
if (tempVerts.Length < verticesArrayLength) this.tempVerts = tempVerts = new float[verticesArrayLength];
meshAttachment.ComputeWorldVertices(slot, tempVerts);

if (settings.pmaVertexColors) {
Expand Down Expand Up @@ -917,7 +917,7 @@ public struct Settings {
if (fy > bmax.y) bmax.y = fy;
}

for (int iii = 0; iii < meshVertexCount; iii += 2) {
for (int iii = 0; iii < verticesArrayLength; iii += 2) {
float x = tempVerts[iii], y = tempVerts[iii + 1];
vbi[vertexIndex].x = x; vbi[vertexIndex].y = y; vbi[vertexIndex].z = z;
cbi[vertexIndex] = color; ubi[vertexIndex].x = attachmentUVs[iii]; ubi[vertexIndex].y = attachmentUVs[iii + 1];
Expand Down

0 comments on commit 889148c

Please sign in to comment.