Skip to content

Commit

Permalink
Merge pull request fairygui#184 from EP-Toushirou/master
Browse files Browse the repository at this point in the history
Add support for New Input System & Remove support for versions before Unity 5.6
  • Loading branch information
xiaoguzhu committed Mar 18, 2024
2 parents d8c7851 + 7d13498 commit 09d4363
Show file tree
Hide file tree
Showing 10 changed files with 213 additions and 156 deletions.
5 changes: 0 additions & 5 deletions Assets/Scripts/Core/CaptureCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,9 @@ public static void CheckMain()
camera.nearClipPlane = -30;
camera.farClipPlane = 30;
camera.enabled = false;
#if UNITY_5_4_OR_NEWER
camera.stereoTargetEye = StereoTargetEyeMask.None;
#endif

#if UNITY_5_6_OR_NEWER
camera.allowHDR = false;
camera.allowMSAA = false;
#endif
cameraObject.AddComponent<CaptureCamera>();
}

Expand Down
53 changes: 0 additions & 53 deletions Assets/Scripts/Core/NGraphics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ public class VertexMatrix
internal int _maskFlag;
StencilEraser _stencilEraser;

#if !UNITY_5_6_OR_NEWER
Color32[] _colors;
#endif

MaterialPropertyBlock _propertyBlock;
bool _blockUpdated;

Expand Down Expand Up @@ -388,28 +384,18 @@ public void Tint()
if (vertCount == 0)
return;

#if !UNITY_5_6_OR_NEWER
Color32[] colors = _colors;
if (colors == null)
colors = mesh.colors32;
#else
VertexBuffer vb = VertexBuffer.Begin();
mesh.GetColors(vb.colors);
List<Color32> colors = vb.colors;
#endif
for (int i = 0; i < vertCount; i++)
{
Color32 col = _color;
col.a = (byte)(_alpha * (hasAlphaBackup ? _alphaBackup[i] : (byte)255));
colors[i] = col;
}

#if !UNITY_5_6_OR_NEWER
mesh.colors32 = colors;
#else
mesh.SetColors(vb.colors);
vb.End();
#endif
}

void ChangeAlpha(float value)
Expand All @@ -420,28 +406,18 @@ void ChangeAlpha(float value)
if (vertCount == 0)
return;

#if !UNITY_5_6_OR_NEWER
Color32[] colors = _colors;
if (colors == null)
colors = mesh.colors32;
#else
VertexBuffer vb = VertexBuffer.Begin();
mesh.GetColors(vb.colors);
List<Color32> colors = vb.colors;
#endif
for (int i = 0; i < vertCount; i++)
{
Color32 col = colors[i];
col.a = (byte)(_alpha * (hasAlphaBackup ? _alphaBackup[i] : (byte)255));
colors[i] = col;
}

#if !UNITY_5_6_OR_NEWER
mesh.colors32 = colors;
#else
mesh.SetColors(vb.colors);
vb.End();
#endif
}

/// <summary>
Expand Down Expand Up @@ -756,8 +732,6 @@ void UpdateMeshNow()
}

mesh.Clear();

#if UNITY_5_2 || UNITY_5_3_OR_NEWER
mesh.SetVertices(vb.vertices);
if (vb._isArbitraryQuad)
mesh.SetUVs(0, vb.FixUVForArbitraryQuad());
Expand All @@ -767,33 +741,6 @@ void UpdateMeshNow()
mesh.SetTriangles(vb.triangles, 0);
if (vb.uvs2.Count == vb.uvs.Count)
mesh.SetUVs(1, vb.uvs2);

#if !UNITY_5_6_OR_NEWER
_colors = null;
#endif
#else
Vector3[] vertices = new Vector3[vertCount];
Vector2[] uv = new Vector2[vertCount];
_colors = new Color32[vertCount];
int[] triangles = new int[vb.triangles.Count];

vb.vertices.CopyTo(vertices);
vb.uvs.CopyTo(uv);
vb.colors.CopyTo(_colors);
vb.triangles.CopyTo(triangles);

mesh.vertices = vertices;
mesh.uv = uv;
mesh.triangles = triangles;
mesh.colors32 = _colors;

if(vb.uvs2.Count==uv.Length)
{
uv = new Vector2[vertCount];
vb.uvs2.CopyTo(uv);
mesh.uv2 = uv;
}
#endif
vb.End();

if (meshModifier != null)
Expand Down
Loading

0 comments on commit 09d4363

Please sign in to comment.