Add files using upload-large-folder tool
Browse files- benchmark/NYU_CTF_Bench/test/2022/CSAW-Quals/rev/AnyaGacha/src/client/Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Editor/AssemblyInfo.cs +2 -0
- benchmark/NYU_CTF_Bench/test/2022/CSAW-Quals/rev/AnyaGacha/src/client/Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Editor/AssemblyInfo.cs.meta +11 -0
- benchmark/NYU_CTF_Bench/test/2022/CSAW-Quals/rev/AnyaGacha/src/client/Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Editor/ContextMenu.cs +43 -0
- benchmark/NYU_CTF_Bench/test/2022/CSAW-Quals/rev/AnyaGacha/src/client/Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Editor/ContextMenu.cs.meta +13 -0
- benchmark/NYU_CTF_Bench/test/2022/CSAW-Quals/rev/AnyaGacha/src/client/Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Editor/EditorSpriteGUIUtility.cs +236 -0
- benchmark/NYU_CTF_Bench/test/2022/CSAW-Quals/rev/AnyaGacha/src/client/Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Editor/EditorSpriteGUIUtility.cs.meta +13 -0
- benchmark/NYU_CTF_Bench/test/2022/CSAW-Quals/rev/AnyaGacha/src/client/Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Editor/Handles.meta +8 -0
- benchmark/NYU_CTF_Bench/test/2022/CSAW-Quals/rev/AnyaGacha/src/client/Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Editor/Icons.meta +8 -0
- benchmark/NYU_CTF_Bench/test/2022/CSAW-Quals/rev/AnyaGacha/src/client/Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Editor/ObjectMenuCreation.meta +8 -0
- benchmark/NYU_CTF_Bench/test/2022/CSAW-Quals/rev/AnyaGacha/src/client/Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Editor/SceneDragAndDrop.cs +244 -0
- benchmark/NYU_CTF_Bench/test/2022/CSAW-Quals/rev/AnyaGacha/src/client/Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Editor/SceneDragAndDrop.cs.meta +13 -0
- benchmark/NYU_CTF_Bench/test/2022/CSAW-Quals/rev/AnyaGacha/src/client/Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Editor/SpriteSelector.cs +312 -0
- benchmark/NYU_CTF_Bench/test/2022/CSAW-Quals/rev/AnyaGacha/src/client/Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Editor/SpriteSelector.cs.meta +11 -0
- benchmark/NYU_CTF_Bench/test/2022/CSAW-Quals/rev/AnyaGacha/src/client/Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Editor/SpriteShapeAnalytics.cs +168 -0
- benchmark/NYU_CTF_Bench/test/2022/CSAW-Quals/rev/AnyaGacha/src/client/Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Editor/SpriteShapeAnalytics.cs.meta +11 -0
- benchmark/NYU_CTF_Bench/test/2022/CSAW-Quals/rev/AnyaGacha/src/client/Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Editor/SpriteShapeAssetPostProcessor.cs +25 -0
- benchmark/NYU_CTF_Bench/test/2022/CSAW-Quals/rev/AnyaGacha/src/client/Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Editor/SpriteShapeAssetPostProcessor.cs.meta +13 -0
- benchmark/NYU_CTF_Bench/test/2022/CSAW-Quals/rev/AnyaGacha/src/client/Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Editor/SpriteShapeControllerEditor.cs +605 -0
- benchmark/NYU_CTF_Bench/test/2022/CSAW-Quals/rev/AnyaGacha/src/client/Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Editor/SpriteShapeControllerEditor.cs.meta +13 -0
- benchmark/NYU_CTF_Bench/test/2022/CSAW-Quals/rev/AnyaGacha/src/client/Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Editor/SpriteShapeEditor.cs +656 -0
benchmark/NYU_CTF_Bench/test/2022/CSAW-Quals/rev/AnyaGacha/src/client/Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Editor/AssemblyInfo.cs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using System.Runtime.CompilerServices;
|
| 2 |
+
[assembly: InternalsVisibleTo("Unity.2D.SpriteShape.Tests.EditorTests")]
|
benchmark/NYU_CTF_Bench/test/2022/CSAW-Quals/rev/AnyaGacha/src/client/Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Editor/AssemblyInfo.cs.meta
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fileFormatVersion: 2
|
| 2 |
+
guid: ad27c05e1cd134511a1636ea68b7f2a2
|
| 3 |
+
MonoImporter:
|
| 4 |
+
externalObjects: {}
|
| 5 |
+
serializedVersion: 2
|
| 6 |
+
defaultReferences: []
|
| 7 |
+
executionOrder: 0
|
| 8 |
+
icon: {instanceID: 0}
|
| 9 |
+
userData:
|
| 10 |
+
assetBundleName:
|
| 11 |
+
assetBundleVariant:
|
benchmark/NYU_CTF_Bench/test/2022/CSAW-Quals/rev/AnyaGacha/src/client/Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Editor/ContextMenu.cs
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using UnityEngine;
|
| 2 |
+
using UnityEngine.U2D;
|
| 3 |
+
using UnityEditor.U2D.SpriteShape;
|
| 4 |
+
|
| 5 |
+
namespace UnityEditor.U2D
|
| 6 |
+
{
|
| 7 |
+
public class ContextMenu
|
| 8 |
+
{
|
| 9 |
+
private static AngleRange CreateAngleRange(float start, float end, int order)
|
| 10 |
+
{
|
| 11 |
+
AngleRange angleRange = new AngleRange();
|
| 12 |
+
|
| 13 |
+
angleRange.start = start;
|
| 14 |
+
angleRange.end = end;
|
| 15 |
+
angleRange.order = order;
|
| 16 |
+
|
| 17 |
+
return angleRange;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
//[MenuItem("Assets/Create/Sprite Shape Profile/Open Shape", false, 358)]
|
| 21 |
+
public static void CreateNewSpriteStrip()
|
| 22 |
+
{
|
| 23 |
+
UnityEngine.U2D.SpriteShape newSpriteShape = SpriteShapeEditorUtility.CreateSpriteShapeAsset();
|
| 24 |
+
newSpriteShape.angleRanges.Add(CreateAngleRange(-180.0f, 180.0f, 0));
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
//[MenuItem("Assets/Create/Sprite Shape Profile/Closed Shape", false, 359)]
|
| 28 |
+
public static void CreateNewSpriteShape()
|
| 29 |
+
{
|
| 30 |
+
UnityEngine.U2D.SpriteShape newSpriteShape = SpriteShapeEditorUtility.CreateSpriteShapeAsset();
|
| 31 |
+
newSpriteShape.angleRanges.Add(CreateAngleRange(-45.0f, 45.0f, 4));
|
| 32 |
+
newSpriteShape.angleRanges.Add(CreateAngleRange(-135.0f, -45.0f, 3));
|
| 33 |
+
newSpriteShape.angleRanges.Add(CreateAngleRange(135.0f, 225.0f, 2));
|
| 34 |
+
newSpriteShape.angleRanges.Add(CreateAngleRange(45.0f, 135.0f, 1));
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
//[MenuItem("GameObject/2D Object/Sprite Shape")]
|
| 38 |
+
internal static void CreateSpriteShapeEmpty()
|
| 39 |
+
{
|
| 40 |
+
SpriteShapeEditorUtility.SetShapeFromAsset(SpriteShapeEditorUtility.CreateSpriteShapeControllerFromSelection());
|
| 41 |
+
}
|
| 42 |
+
}
|
| 43 |
+
}
|
benchmark/NYU_CTF_Bench/test/2022/CSAW-Quals/rev/AnyaGacha/src/client/Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Editor/ContextMenu.cs.meta
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fileFormatVersion: 2
|
| 2 |
+
guid: 98a4cc9d9dadb844e8669b0665d53897
|
| 3 |
+
timeCreated: 1503992201
|
| 4 |
+
licenseType: Pro
|
| 5 |
+
MonoImporter:
|
| 6 |
+
externalObjects: {}
|
| 7 |
+
serializedVersion: 2
|
| 8 |
+
defaultReferences: []
|
| 9 |
+
executionOrder: 0
|
| 10 |
+
icon: {instanceID: 0}
|
| 11 |
+
userData:
|
| 12 |
+
assetBundleName:
|
| 13 |
+
assetBundleVariant:
|
benchmark/NYU_CTF_Bench/test/2022/CSAW-Quals/rev/AnyaGacha/src/client/Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Editor/EditorSpriteGUIUtility.cs
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using UnityEditor;
|
| 2 |
+
using UnityEngine;
|
| 3 |
+
using UnityEditor.Sprites;
|
| 4 |
+
using System.Collections;
|
| 5 |
+
using System.Collections.Generic;
|
| 6 |
+
|
| 7 |
+
namespace UnityEditor.U2D
|
| 8 |
+
{
|
| 9 |
+
public static class EditorSpriteGUIUtility
|
| 10 |
+
{
|
| 11 |
+
public enum FitMode
|
| 12 |
+
{
|
| 13 |
+
BestFit,
|
| 14 |
+
FitHorizontal,
|
| 15 |
+
FitVertical,
|
| 16 |
+
Fill,
|
| 17 |
+
Tiled
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
private static Material s_SpriteMaterial;
|
| 21 |
+
public static Material spriteMaterial
|
| 22 |
+
{
|
| 23 |
+
get
|
| 24 |
+
{
|
| 25 |
+
if (s_SpriteMaterial == null)
|
| 26 |
+
{
|
| 27 |
+
s_SpriteMaterial = new Material(Shader.Find("Hidden/InternalSpritesInspector"));
|
| 28 |
+
s_SpriteMaterial.hideFlags = HideFlags.DontSave;
|
| 29 |
+
}
|
| 30 |
+
s_SpriteMaterial.SetFloat("_AdjustLinearForGamma", PlayerSettings.colorSpace == ColorSpace.Linear ? 1.0f : 0.0f);
|
| 31 |
+
return s_SpriteMaterial;
|
| 32 |
+
}
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
public static Texture GetOriginalSpriteTexture(Sprite sprite)
|
| 36 |
+
{
|
| 37 |
+
return UnityEditor.Sprites.SpriteUtility.GetSpriteTexture(sprite, false);
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
public static Vector2[] GetOriginalSpriteUvs(Sprite sprite)
|
| 41 |
+
{
|
| 42 |
+
return UnityEditor.Sprites.SpriteUtility.GetSpriteUVs(sprite, false);
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
public static void DrawSpriteInRectPrepare(Rect rect, Sprite sprite, FitMode fitMode, bool excludeBorders, bool forceQuad, Mesh mesh)
|
| 46 |
+
{
|
| 47 |
+
var vertices = new List<Vector3>();
|
| 48 |
+
var uvs = new List<Vector2>();
|
| 49 |
+
var indices = new List<int>();
|
| 50 |
+
mesh.Clear();
|
| 51 |
+
|
| 52 |
+
if (!sprite)
|
| 53 |
+
{
|
| 54 |
+
mesh.UploadMeshData(false);
|
| 55 |
+
return;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
Vector2 scale = Vector2.one;
|
| 59 |
+
Rect spriteRect = sprite.textureRect;
|
| 60 |
+
Vector2 bottomLeftBorderOffset = sprite.rect.position + new Vector2(sprite.border.x, sprite.border.y) - spriteRect.position;
|
| 61 |
+
Vector2 topRightBorderOffset = new Vector2(sprite.border.z, sprite.border.w) + (spriteRect.position + spriteRect.size) - (sprite.rect.position + sprite.rect.size);
|
| 62 |
+
|
| 63 |
+
if (excludeBorders)
|
| 64 |
+
{
|
| 65 |
+
forceQuad = true;
|
| 66 |
+
spriteRect.position = spriteRect.position + bottomLeftBorderOffset;
|
| 67 |
+
spriteRect.size = spriteRect.size - bottomLeftBorderOffset - topRightBorderOffset;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
bool tiled = false;
|
| 71 |
+
|
| 72 |
+
if (fitMode == FitMode.Tiled)
|
| 73 |
+
{
|
| 74 |
+
tiled = true;
|
| 75 |
+
forceQuad = true;
|
| 76 |
+
fitMode = FitMode.BestFit;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
if (fitMode == FitMode.BestFit)
|
| 80 |
+
{
|
| 81 |
+
float spriteRatio = spriteRect.width / spriteRect.height;
|
| 82 |
+
float frameRatio = rect.width / rect.height;
|
| 83 |
+
|
| 84 |
+
if (spriteRatio < frameRatio)
|
| 85 |
+
fitMode = FitMode.FitVertical;
|
| 86 |
+
else
|
| 87 |
+
fitMode = FitMode.FitHorizontal;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
if (fitMode == FitMode.FitHorizontal)
|
| 91 |
+
scale = Vector2.one * (rect.width / spriteRect.width);
|
| 92 |
+
|
| 93 |
+
if (fitMode == FitMode.FitVertical)
|
| 94 |
+
scale = Vector2.one * (rect.height / spriteRect.height);
|
| 95 |
+
|
| 96 |
+
if (fitMode == FitMode.Fill)
|
| 97 |
+
{
|
| 98 |
+
scale.x = rect.width / spriteRect.width;
|
| 99 |
+
scale.y = rect.height / spriteRect.height;
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
Texture spriteTexture = GetOriginalSpriteTexture(sprite);
|
| 103 |
+
if (spriteTexture == null)
|
| 104 |
+
return;
|
| 105 |
+
|
| 106 |
+
if (forceQuad)
|
| 107 |
+
{
|
| 108 |
+
Vector2 uvScale = new Vector2(1f / spriteTexture.width, 1f / spriteTexture.height);
|
| 109 |
+
Vector2 uvPos = Vector2.Scale(spriteRect.position, uvScale);
|
| 110 |
+
Vector2 uvSize = Vector2.Scale(spriteRect.size, uvScale);
|
| 111 |
+
Vector2 uv0 = uvPos;
|
| 112 |
+
Vector2 uv1 = uvPos + Vector2.up * uvSize.y;
|
| 113 |
+
Vector2 uv2 = uvPos + Vector2.right * uvSize.x;
|
| 114 |
+
Vector2 uv3 = uvPos + uvSize;
|
| 115 |
+
Vector3 v0 = new Vector3(uv0.x * spriteTexture.width - spriteRect.position.x - spriteRect.width * 0.5f, uv0.y * spriteTexture.height - spriteRect.position.y - spriteRect.height * 0.5f, 0f);
|
| 116 |
+
Vector3 v1 = new Vector3(uv1.x * spriteTexture.width - spriteRect.position.x - spriteRect.width * 0.5f, uv1.y * spriteTexture.height - spriteRect.position.y - spriteRect.height * 0.5f, 0f);
|
| 117 |
+
Vector3 v2 = new Vector3(uv2.x * spriteTexture.width - spriteRect.position.x - spriteRect.width * 0.5f, uv2.y * spriteTexture.height - spriteRect.position.y - spriteRect.height * 0.5f, 0f);
|
| 118 |
+
Vector3 v3 = new Vector3(uv3.x * spriteTexture.width - spriteRect.position.x - spriteRect.width * 0.5f, uv3.y * spriteTexture.height - spriteRect.position.y - spriteRect.height * 0.5f, 0f);
|
| 119 |
+
v0 = Vector3.Scale(v0, scale);
|
| 120 |
+
v1 = Vector3.Scale(v1, scale);
|
| 121 |
+
v2 = Vector3.Scale(v2, scale);
|
| 122 |
+
v3 = Vector3.Scale(v3, scale);
|
| 123 |
+
|
| 124 |
+
//TODO: Support vertical tiling when horizontal fitted
|
| 125 |
+
if (tiled && fitMode == FitMode.FitVertical)
|
| 126 |
+
{
|
| 127 |
+
Vector2 scaledRectSize = Vector2.Scale(rect.size, new Vector2(1f / scale.x, 1f / scale.y));
|
| 128 |
+
float halfDistanceToFill = (scaledRectSize.x - spriteRect.width) * 0.5f;
|
| 129 |
+
int halfFillSegmentCount = (int)Mathf.Ceil(halfDistanceToFill / spriteRect.width);
|
| 130 |
+
int segmentCount = halfFillSegmentCount * 2 + 1;
|
| 131 |
+
int vertexCount = segmentCount * 4;
|
| 132 |
+
|
| 133 |
+
vertices.Capacity = vertexCount;
|
| 134 |
+
uvs.Capacity = vertexCount;
|
| 135 |
+
indices.Capacity = vertexCount;
|
| 136 |
+
|
| 137 |
+
Vector3 offset = Vector3.zero;
|
| 138 |
+
Vector3 offsetStep = Vector3.Scale(Vector3.right * spriteRect.width, scale);
|
| 139 |
+
|
| 140 |
+
float distanceStep = spriteRect.width;
|
| 141 |
+
float distanceToFill = halfDistanceToFill + distanceStep;
|
| 142 |
+
|
| 143 |
+
int vertexIndex = 0;
|
| 144 |
+
|
| 145 |
+
for (int i = 0; i <= halfFillSegmentCount; ++i)
|
| 146 |
+
{
|
| 147 |
+
float t = Mathf.Clamp01(distanceToFill / spriteRect.width);
|
| 148 |
+
|
| 149 |
+
uvs.Add(uv0);
|
| 150 |
+
uvs.Add(uv1);
|
| 151 |
+
uvs.Add(Vector3.Lerp(uv0, uv2, t));
|
| 152 |
+
uvs.Add(Vector3.Lerp(uv1, uv3, t));
|
| 153 |
+
|
| 154 |
+
vertices.Add(v0 + offset);
|
| 155 |
+
vertices.Add(v1 + offset);
|
| 156 |
+
vertices.Add(Vector3.Lerp(v0, v2, t) + offset);
|
| 157 |
+
vertices.Add(Vector3.Lerp(v1, v3, t) + offset);
|
| 158 |
+
|
| 159 |
+
indices.Add(vertexIndex);
|
| 160 |
+
indices.Add(vertexIndex + 2);
|
| 161 |
+
indices.Add(vertexIndex + 1);
|
| 162 |
+
indices.Add(vertexIndex + 2);
|
| 163 |
+
indices.Add(vertexIndex + 3);
|
| 164 |
+
indices.Add(vertexIndex + 1);
|
| 165 |
+
|
| 166 |
+
vertexIndex += 4;
|
| 167 |
+
|
| 168 |
+
if (i > 0)
|
| 169 |
+
{
|
| 170 |
+
uvs.Add(Vector2.Lerp(uv0, uv2, 1f - t));
|
| 171 |
+
uvs.Add(Vector2.Lerp(uv1, uv3, 1f - t));
|
| 172 |
+
uvs.Add(uv2);
|
| 173 |
+
uvs.Add(uv3);
|
| 174 |
+
|
| 175 |
+
vertices.Add(Vector3.Lerp(v0, v2, 1f - t) - offset);
|
| 176 |
+
vertices.Add(Vector3.Lerp(v1, v3, 1f - t) - offset);
|
| 177 |
+
vertices.Add(v2 - offset);
|
| 178 |
+
vertices.Add(v3 - offset);
|
| 179 |
+
|
| 180 |
+
indices.Add(vertexIndex);
|
| 181 |
+
indices.Add(vertexIndex + 2);
|
| 182 |
+
indices.Add(vertexIndex + 1);
|
| 183 |
+
indices.Add(vertexIndex + 2);
|
| 184 |
+
indices.Add(vertexIndex + 3);
|
| 185 |
+
indices.Add(vertexIndex + 1);
|
| 186 |
+
|
| 187 |
+
vertexIndex += 4;
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
offset += offsetStep;
|
| 191 |
+
distanceToFill -= distanceStep;
|
| 192 |
+
}
|
| 193 |
+
}
|
| 194 |
+
else
|
| 195 |
+
{
|
| 196 |
+
vertices.AddRange(new Vector3[] { v0, v1, v2, v3 });
|
| 197 |
+
uvs.AddRange(new Vector2[] { uv0, uv1, uv2, uv3 });
|
| 198 |
+
indices.AddRange(new int[] { 0, 2, 1, 2, 3, 1 });
|
| 199 |
+
}
|
| 200 |
+
}
|
| 201 |
+
else
|
| 202 |
+
{
|
| 203 |
+
ushort[] triangles = sprite.triangles;
|
| 204 |
+
indices.Capacity = triangles.Length;
|
| 205 |
+
|
| 206 |
+
for (int i = 0; i < triangles.Length; ++i)
|
| 207 |
+
indices.Add((int)triangles[i]);
|
| 208 |
+
|
| 209 |
+
uvs.AddRange(GetOriginalSpriteUvs(sprite));
|
| 210 |
+
vertices.Capacity = uvs.Count;
|
| 211 |
+
|
| 212 |
+
for (int i = 0; i < uvs.Count; ++i)
|
| 213 |
+
{
|
| 214 |
+
Vector3 v = new Vector3(uvs[i].x * spriteTexture.width - spriteRect.position.x - spriteRect.width * 0.5f, uvs[i].y * spriteTexture.height - spriteRect.position.y - spriteRect.height * 0.5f, 0f);
|
| 215 |
+
vertices.Add(Vector3.Scale(v, scale));
|
| 216 |
+
}
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
mesh.SetVertices(vertices);
|
| 220 |
+
mesh.SetUVs(0, uvs);
|
| 221 |
+
mesh.SetTriangles(indices, 0);
|
| 222 |
+
mesh.UploadMeshData(false);
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
public static void DrawMesh(Mesh mesh, Material material, Vector3 position, Quaternion rotation, Vector3 scale)
|
| 226 |
+
{
|
| 227 |
+
if (Event.current.type != EventType.Repaint)
|
| 228 |
+
return;
|
| 229 |
+
|
| 230 |
+
Matrix4x4 matrix = new Matrix4x4();
|
| 231 |
+
matrix.SetTRS(position, rotation, scale);
|
| 232 |
+
material.SetPass(0);
|
| 233 |
+
Graphics.DrawMeshNow(mesh, matrix);
|
| 234 |
+
}
|
| 235 |
+
}
|
| 236 |
+
}
|
benchmark/NYU_CTF_Bench/test/2022/CSAW-Quals/rev/AnyaGacha/src/client/Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Editor/EditorSpriteGUIUtility.cs.meta
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fileFormatVersion: 2
|
| 2 |
+
guid: aff60f81fc1eab749a82103779466d07
|
| 3 |
+
timeCreated: 1503758178
|
| 4 |
+
licenseType: Pro
|
| 5 |
+
MonoImporter:
|
| 6 |
+
externalObjects: {}
|
| 7 |
+
serializedVersion: 2
|
| 8 |
+
defaultReferences: []
|
| 9 |
+
executionOrder: 0
|
| 10 |
+
icon: {instanceID: 0}
|
| 11 |
+
userData:
|
| 12 |
+
assetBundleName:
|
| 13 |
+
assetBundleVariant:
|
benchmark/NYU_CTF_Bench/test/2022/CSAW-Quals/rev/AnyaGacha/src/client/Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Editor/Handles.meta
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fileFormatVersion: 2
|
| 2 |
+
guid: 15cbf89e8ba92694cb870a55b60f1b81
|
| 3 |
+
folderAsset: yes
|
| 4 |
+
DefaultImporter:
|
| 5 |
+
externalObjects: {}
|
| 6 |
+
userData:
|
| 7 |
+
assetBundleName:
|
| 8 |
+
assetBundleVariant:
|
benchmark/NYU_CTF_Bench/test/2022/CSAW-Quals/rev/AnyaGacha/src/client/Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Editor/Icons.meta
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fileFormatVersion: 2
|
| 2 |
+
guid: 574ba49617df66b40a29fe7f0b185aab
|
| 3 |
+
folderAsset: yes
|
| 4 |
+
DefaultImporter:
|
| 5 |
+
externalObjects: {}
|
| 6 |
+
userData:
|
| 7 |
+
assetBundleName:
|
| 8 |
+
assetBundleVariant:
|
benchmark/NYU_CTF_Bench/test/2022/CSAW-Quals/rev/AnyaGacha/src/client/Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Editor/ObjectMenuCreation.meta
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fileFormatVersion: 2
|
| 2 |
+
guid: 747c53103cdff47fe98cef9648120fc2
|
| 3 |
+
folderAsset: yes
|
| 4 |
+
DefaultImporter:
|
| 5 |
+
externalObjects: {}
|
| 6 |
+
userData:
|
| 7 |
+
assetBundleName:
|
| 8 |
+
assetBundleVariant:
|
benchmark/NYU_CTF_Bench/test/2022/CSAW-Quals/rev/AnyaGacha/src/client/Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Editor/SceneDragAndDrop.cs
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using UnityEngine;
|
| 2 |
+
using UnityEngine.U2D;
|
| 3 |
+
using System.Collections.Generic;
|
| 4 |
+
using UnityEditor.Experimental.SceneManagement;
|
| 5 |
+
using UnityEditor.U2D.SpriteShape;
|
| 6 |
+
using Object = UnityEngine.Object;
|
| 7 |
+
|
| 8 |
+
namespace UnityEditor.U2D
|
| 9 |
+
{
|
| 10 |
+
[InitializeOnLoad]
|
| 11 |
+
public static class SceneDragAndDrop
|
| 12 |
+
{
|
| 13 |
+
static SceneDragAndDrop()
|
| 14 |
+
{
|
| 15 |
+
#if UNITY_2019_1_OR_NEWER
|
| 16 |
+
SceneView.duringSceneGui += OnSceneGUI;
|
| 17 |
+
EditorApplication.hierarchyWindowItemOnGUI += OnHierarchyGUI;
|
| 18 |
+
#else
|
| 19 |
+
SceneView.onSceneGUIDelegate += OnSceneGUI;
|
| 20 |
+
#endif
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
static class Contents
|
| 24 |
+
{
|
| 25 |
+
public static readonly string createString = "Create Sprite Shape";
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
static List<Object> s_SceneDragObjects;
|
| 29 |
+
static DragType s_DragType;
|
| 30 |
+
enum DragType { NotInitialized, CreateMultiple }
|
| 31 |
+
|
| 32 |
+
public delegate string ShowFileDialogDelegate(string title, string defaultName, string extension, string message, string defaultPath);
|
| 33 |
+
|
| 34 |
+
static void OnSceneGUI(SceneView sceneView)
|
| 35 |
+
{
|
| 36 |
+
HandleSceneDrag(sceneView, Event.current, DragAndDrop.objectReferences, DragAndDrop.paths);
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
public static GameObject Create(UnityEngine.U2D.SpriteShape shape, Vector3 position, SceneView sceneView)
|
| 40 |
+
{
|
| 41 |
+
string name = string.IsNullOrEmpty(shape.name) ? "New SpriteShapeController" : shape.name;
|
| 42 |
+
name = GameObjectUtility.GetUniqueNameForSibling(null, name);
|
| 43 |
+
GameObject go = new GameObject(name);
|
| 44 |
+
|
| 45 |
+
SpriteShapeController shapeController = go.AddComponent<SpriteShapeController>();
|
| 46 |
+
shapeController.spriteShape = shape;
|
| 47 |
+
go.transform.position = position;
|
| 48 |
+
go.hideFlags = HideFlags.HideAndDontSave;
|
| 49 |
+
|
| 50 |
+
return go;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
static void OnHierarchyGUI(int instanceID, Rect rect)
|
| 54 |
+
{
|
| 55 |
+
HandleSceneDrag(null, Event.current, DragAndDrop.objectReferences, null);
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
static List<UnityEngine.U2D.SpriteShape> GetSpriteShapeFromPathsOrObjects(Object[] objects, string[] paths, EventType currentEventType)
|
| 59 |
+
{
|
| 60 |
+
List<UnityEngine.U2D.SpriteShape> result = new List<UnityEngine.U2D.SpriteShape>();
|
| 61 |
+
|
| 62 |
+
foreach (Object obj in objects)
|
| 63 |
+
{
|
| 64 |
+
if (AssetDatabase.Contains(obj))
|
| 65 |
+
{
|
| 66 |
+
if (obj is UnityEngine.U2D.SpriteShape)
|
| 67 |
+
result.Add(obj as UnityEngine.U2D.SpriteShape);
|
| 68 |
+
}
|
| 69 |
+
}
|
| 70 |
+
return result;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
static void HandleSceneDrag(SceneView sceneView, Event evt, Object[] objectReferences, string[] paths)
|
| 74 |
+
{
|
| 75 |
+
if (evt.type != EventType.DragUpdated && evt.type != EventType.DragPerform && evt.type != EventType.DragExited)
|
| 76 |
+
return;
|
| 77 |
+
|
| 78 |
+
switch (evt.type)
|
| 79 |
+
{
|
| 80 |
+
case EventType.DragUpdated:
|
| 81 |
+
{
|
| 82 |
+
DragType newDragType = DragType.CreateMultiple;
|
| 83 |
+
|
| 84 |
+
if (s_DragType != newDragType || s_SceneDragObjects == null)
|
| 85 |
+
// Either this is first time we are here OR evt.alt changed during drag
|
| 86 |
+
{
|
| 87 |
+
if (ExistingAssets(objectReferences)) // External drag with images that are not in the project
|
| 88 |
+
{
|
| 89 |
+
List<UnityEngine.U2D.SpriteShape> assets = GetSpriteShapeFromPathsOrObjects(objectReferences, paths,
|
| 90 |
+
evt.type);
|
| 91 |
+
|
| 92 |
+
if (assets.Count == 0)
|
| 93 |
+
return;
|
| 94 |
+
|
| 95 |
+
if (s_DragType != DragType.NotInitialized)
|
| 96 |
+
// evt.alt changed during drag, so we need to cleanup and start over
|
| 97 |
+
CleanUp(true);
|
| 98 |
+
|
| 99 |
+
s_DragType = newDragType;
|
| 100 |
+
CreateSceneDragObjects(assets);
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
if (s_SceneDragObjects != null)
|
| 105 |
+
{
|
| 106 |
+
if (sceneView != null)
|
| 107 |
+
PositionSceneDragObjects(s_SceneDragObjects, sceneView, evt.mousePosition);
|
| 108 |
+
|
| 109 |
+
DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
|
| 110 |
+
evt.Use();
|
| 111 |
+
}
|
| 112 |
+
}
|
| 113 |
+
break;
|
| 114 |
+
case EventType.DragPerform:
|
| 115 |
+
{
|
| 116 |
+
List<UnityEngine.U2D.SpriteShape> assets = GetSpriteShapeFromPathsOrObjects(objectReferences, paths, evt.type);
|
| 117 |
+
|
| 118 |
+
if (assets.Count > 0 && s_SceneDragObjects != null)
|
| 119 |
+
{
|
| 120 |
+
// For external drags, we have delayed all creation to DragPerform because only now we have the imported sprite assets
|
| 121 |
+
if (s_SceneDragObjects.Count == 0)
|
| 122 |
+
{
|
| 123 |
+
CreateSceneDragObjects(assets);
|
| 124 |
+
if (sceneView != null)
|
| 125 |
+
PositionSceneDragObjects(s_SceneDragObjects, sceneView, evt.mousePosition);
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
var prefabStage = PrefabStageUtility.GetCurrentPrefabStage();
|
| 129 |
+
|
| 130 |
+
foreach (GameObject dragGO in s_SceneDragObjects)
|
| 131 |
+
{
|
| 132 |
+
if (prefabStage != null)
|
| 133 |
+
{
|
| 134 |
+
var parTransform = Selection.activeTransform != null
|
| 135 |
+
? Selection.activeTransform
|
| 136 |
+
: prefabStage.prefabContentsRoot.transform;
|
| 137 |
+
dragGO.transform.SetParent(parTransform, true);
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
Undo.RegisterCreatedObjectUndo(dragGO, "Create Shape");
|
| 141 |
+
dragGO.hideFlags = HideFlags.None;
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
Selection.objects = s_SceneDragObjects.ToArray();
|
| 145 |
+
|
| 146 |
+
CleanUp(false);
|
| 147 |
+
evt.Use();
|
| 148 |
+
}
|
| 149 |
+
}
|
| 150 |
+
break;
|
| 151 |
+
case EventType.DragExited:
|
| 152 |
+
{
|
| 153 |
+
if (s_SceneDragObjects != null)
|
| 154 |
+
{
|
| 155 |
+
CleanUp(true);
|
| 156 |
+
evt.Use();
|
| 157 |
+
}
|
| 158 |
+
}
|
| 159 |
+
break;
|
| 160 |
+
}
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
static void PositionSceneDragObjects(List<Object> objects, SceneView sceneView, Vector2 mousePosition)
|
| 164 |
+
{
|
| 165 |
+
Vector3 position = Vector3.zero;
|
| 166 |
+
position = HandleUtility.GUIPointToWorldRay(mousePosition).GetPoint(10);
|
| 167 |
+
if (sceneView.in2DMode)
|
| 168 |
+
{
|
| 169 |
+
position.z = 0f;
|
| 170 |
+
}
|
| 171 |
+
else
|
| 172 |
+
{
|
| 173 |
+
DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
|
| 174 |
+
object hit = HandleUtility.RaySnap(HandleUtility.GUIPointToWorldRay(mousePosition));
|
| 175 |
+
if (hit != null)
|
| 176 |
+
{
|
| 177 |
+
RaycastHit rh = (RaycastHit)hit;
|
| 178 |
+
position = rh.point;
|
| 179 |
+
}
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
foreach (GameObject gameObject in objects)
|
| 183 |
+
{
|
| 184 |
+
gameObject.transform.position = position;
|
| 185 |
+
}
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
static void CreateSceneDragObjects(List<UnityEngine.U2D.SpriteShape> shapes)
|
| 189 |
+
{
|
| 190 |
+
if (s_SceneDragObjects == null)
|
| 191 |
+
s_SceneDragObjects = new List<Object>();
|
| 192 |
+
|
| 193 |
+
if (s_DragType == DragType.CreateMultiple)
|
| 194 |
+
{
|
| 195 |
+
foreach (UnityEngine.U2D.SpriteShape sprite in shapes)
|
| 196 |
+
s_SceneDragObjects.Add(CreateDragGO(sprite, Vector3.zero));
|
| 197 |
+
}
|
| 198 |
+
else
|
| 199 |
+
{
|
| 200 |
+
s_SceneDragObjects.Add(CreateDragGO(shapes[0], Vector3.zero));
|
| 201 |
+
}
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
static void CleanUp(bool deleteTempSceneObject)
|
| 205 |
+
{
|
| 206 |
+
if (deleteTempSceneObject)
|
| 207 |
+
{
|
| 208 |
+
foreach (GameObject gameObject in s_SceneDragObjects)
|
| 209 |
+
Object.DestroyImmediate(gameObject, false);
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
if (s_SceneDragObjects != null)
|
| 213 |
+
{
|
| 214 |
+
s_SceneDragObjects.Clear();
|
| 215 |
+
s_SceneDragObjects = null;
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
s_DragType = DragType.NotInitialized;
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
static bool ExistingAssets(Object[] objects)
|
| 222 |
+
{
|
| 223 |
+
foreach (Object obj in objects)
|
| 224 |
+
{
|
| 225 |
+
if (AssetDatabase.Contains(obj))
|
| 226 |
+
return true;
|
| 227 |
+
}
|
| 228 |
+
return false;
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
static GameObject CreateDragGO(UnityEngine.U2D.SpriteShape spriteShape, Vector3 position)
|
| 232 |
+
{
|
| 233 |
+
SpriteShapeController spriteShapeController = SpriteShapeEditorUtility.CreateSpriteShapeController(spriteShape);
|
| 234 |
+
GameObject gameObject = spriteShapeController.gameObject;
|
| 235 |
+
gameObject.transform.position = position;
|
| 236 |
+
gameObject.hideFlags = HideFlags.HideAndDontSave;
|
| 237 |
+
spriteShapeController.spriteShape = spriteShape;
|
| 238 |
+
|
| 239 |
+
SpriteShapeEditorUtility.SetShapeFromAsset(spriteShapeController);
|
| 240 |
+
|
| 241 |
+
return gameObject;
|
| 242 |
+
}
|
| 243 |
+
}
|
| 244 |
+
}
|
benchmark/NYU_CTF_Bench/test/2022/CSAW-Quals/rev/AnyaGacha/src/client/Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Editor/SceneDragAndDrop.cs.meta
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fileFormatVersion: 2
|
| 2 |
+
guid: cd24657e741f79a4685b9a4a0b23b5b5
|
| 3 |
+
timeCreated: 1504685300
|
| 4 |
+
licenseType: Pro
|
| 5 |
+
MonoImporter:
|
| 6 |
+
externalObjects: {}
|
| 7 |
+
serializedVersion: 2
|
| 8 |
+
defaultReferences: []
|
| 9 |
+
executionOrder: 0
|
| 10 |
+
icon: {instanceID: 0}
|
| 11 |
+
userData:
|
| 12 |
+
assetBundleName:
|
| 13 |
+
assetBundleVariant:
|
benchmark/NYU_CTF_Bench/test/2022/CSAW-Quals/rev/AnyaGacha/src/client/Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Editor/SpriteSelector.cs
ADDED
|
@@ -0,0 +1,312 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using System;
|
| 2 |
+
using UnityEngine;
|
| 3 |
+
|
| 4 |
+
namespace UnityEditor.U2D
|
| 5 |
+
{
|
| 6 |
+
internal class SpriteSelector
|
| 7 |
+
{
|
| 8 |
+
int m_SelectedSprite = 0;
|
| 9 |
+
Sprite[] m_SpriteList = null;
|
| 10 |
+
Texture[] m_Thumbnails;
|
| 11 |
+
Vector2 m_ScrollPos;
|
| 12 |
+
|
| 13 |
+
public int selectedIndex
|
| 14 |
+
{
|
| 15 |
+
get { return m_SelectedSprite; }
|
| 16 |
+
set { m_SelectedSprite = value; }
|
| 17 |
+
}
|
| 18 |
+
internal static class Styles
|
| 19 |
+
{
|
| 20 |
+
public static GUIStyle gridList = "GridList";
|
| 21 |
+
public static GUIContent spriteList = EditorGUIUtility.TrTextContent("Sprite Variant");
|
| 22 |
+
public static GUIContent missingSprites = EditorGUIUtility.TrTextContent("No brushes defined.");
|
| 23 |
+
public static GUIStyle localGrid = null;
|
| 24 |
+
}
|
| 25 |
+
public SpriteSelector()
|
| 26 |
+
{
|
| 27 |
+
m_SpriteList = null;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
public void UpdateSprites(Sprite[] sprites)
|
| 31 |
+
{
|
| 32 |
+
m_SpriteList = sprites;
|
| 33 |
+
UpdateSelection(0);
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
public void UpdateSelection(int newSelectedBrush)
|
| 37 |
+
{
|
| 38 |
+
m_SelectedSprite = newSelectedBrush;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
private static int CalcTotalHorizSpacing(int xCount, GUIStyle style, GUIStyle firstStyle, GUIStyle midStyle, GUIStyle lastStyle)
|
| 42 |
+
{
|
| 43 |
+
if (xCount < 2)
|
| 44 |
+
return 0;
|
| 45 |
+
if (xCount == 2)
|
| 46 |
+
return Mathf.Max(firstStyle.margin.right, lastStyle.margin.left);
|
| 47 |
+
|
| 48 |
+
int internalSpace = Mathf.Max(midStyle.margin.left, midStyle.margin.right);
|
| 49 |
+
return Mathf.Max(firstStyle.margin.right, midStyle.margin.left) + Mathf.Max(midStyle.margin.right, lastStyle.margin.left) + internalSpace * (xCount - 3);
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
// Helper function: Get all mouse rects
|
| 53 |
+
private static Rect[] CalcMouseRects(Rect position, GUIContent[] contents, int xCount, float elemWidth, float elemHeight, GUIStyle style, GUIStyle firstStyle, GUIStyle midStyle, GUIStyle lastStyle, bool addBorders, GUI.ToolbarButtonSize buttonSize)
|
| 54 |
+
{
|
| 55 |
+
int count = contents.Length;
|
| 56 |
+
int x = 0;
|
| 57 |
+
float xPos = position.xMin, yPos = position.yMin;
|
| 58 |
+
GUIStyle currentStyle = style;
|
| 59 |
+
Rect[] retval = new Rect[count];
|
| 60 |
+
if (count > 1)
|
| 61 |
+
currentStyle = firstStyle;
|
| 62 |
+
for (int i = 0; i < count; i++)
|
| 63 |
+
{
|
| 64 |
+
float w = 0;
|
| 65 |
+
switch (buttonSize)
|
| 66 |
+
{
|
| 67 |
+
case GUI.ToolbarButtonSize.Fixed:
|
| 68 |
+
w = elemWidth;
|
| 69 |
+
break;
|
| 70 |
+
case GUI.ToolbarButtonSize.FitToContents:
|
| 71 |
+
w = currentStyle.CalcSize(contents[i]).x;
|
| 72 |
+
break;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
if (!addBorders)
|
| 76 |
+
retval[i] = new Rect(xPos, yPos, w, elemHeight);
|
| 77 |
+
else
|
| 78 |
+
retval[i] = currentStyle.margin.Add(new Rect(xPos, yPos, w, elemHeight));
|
| 79 |
+
|
| 80 |
+
//we round the values to the dpi-aware pixel grid
|
| 81 |
+
retval[i] = GUIUtility.AlignRectToDevice(retval[i]);
|
| 82 |
+
|
| 83 |
+
GUIStyle nextStyle = midStyle;
|
| 84 |
+
if (i == count - 2 || i == xCount - 2)
|
| 85 |
+
nextStyle = lastStyle;
|
| 86 |
+
|
| 87 |
+
xPos = retval[i].xMax + Mathf.Max(currentStyle.margin.right, nextStyle.margin.left);
|
| 88 |
+
|
| 89 |
+
x++;
|
| 90 |
+
if (x >= xCount)
|
| 91 |
+
{
|
| 92 |
+
x = 0;
|
| 93 |
+
yPos += elemHeight + Mathf.Max(style.margin.top, style.margin.bottom);
|
| 94 |
+
xPos = position.xMin;
|
| 95 |
+
nextStyle = firstStyle;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
currentStyle = nextStyle;
|
| 99 |
+
}
|
| 100 |
+
return retval;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
static void DrawRectangleOutline(Rect rect, Color color)
|
| 104 |
+
{
|
| 105 |
+
Color currentColor = Handles.color;
|
| 106 |
+
Handles.color = color;
|
| 107 |
+
|
| 108 |
+
// Draw viewport outline
|
| 109 |
+
Vector3[] points = new Vector3[5];
|
| 110 |
+
points[0] = new Vector3(rect.x, rect.y, 0.0f);
|
| 111 |
+
points[1] = new Vector3(rect.x + rect.width, rect.y, 0.0f);
|
| 112 |
+
points[2] = new Vector3(rect.x + rect.width, rect.y + rect.height, 0.0f);
|
| 113 |
+
points[3] = new Vector3(rect.x, rect.y + rect.height, 0.0f);
|
| 114 |
+
points[4] = new Vector3(rect.x, rect.y, 0.0f);
|
| 115 |
+
Handles.DrawPolyLine(points);
|
| 116 |
+
|
| 117 |
+
Handles.color = currentColor;
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
// Make a button grid
|
| 121 |
+
private static int DoButtonGrid(Rect position, int selected, GUIContent[] contents, string[] controlNames, int xCount, GUIStyle style, GUIStyle firstStyle, GUIStyle midStyle, GUIStyle lastStyle, GUI.ToolbarButtonSize buttonSize, bool[] contentsEnabled = null)
|
| 122 |
+
{
|
| 123 |
+
int count = contents.Length;
|
| 124 |
+
if (count == 0)
|
| 125 |
+
return selected;
|
| 126 |
+
if (xCount <= 0)
|
| 127 |
+
{
|
| 128 |
+
Debug.LogWarning("You are trying to create a SelectionGrid with zero or less elements to be displayed in the horizontal direction. Set xCount to a positive value.");
|
| 129 |
+
return selected;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
if (contentsEnabled != null && contentsEnabled.Length != count)
|
| 133 |
+
throw new ArgumentException("contentsEnabled");
|
| 134 |
+
|
| 135 |
+
// Figure out how large each element should be
|
| 136 |
+
int rows = count / xCount;
|
| 137 |
+
if (count % xCount != 0)
|
| 138 |
+
rows++;
|
| 139 |
+
|
| 140 |
+
float totalHorizSpacing = CalcTotalHorizSpacing(xCount, style, firstStyle, midStyle, lastStyle);
|
| 141 |
+
float totalVerticalSpacing = Mathf.Max(style.margin.top, style.margin.bottom) * (rows - 1);
|
| 142 |
+
float elemWidth = (position.width - totalHorizSpacing) / xCount;
|
| 143 |
+
float elemHeight = (position.height - totalVerticalSpacing) / rows;
|
| 144 |
+
|
| 145 |
+
if (style.fixedWidth != 0)
|
| 146 |
+
elemWidth = style.fixedWidth;
|
| 147 |
+
if (style.fixedHeight != 0)
|
| 148 |
+
elemHeight = style.fixedHeight;
|
| 149 |
+
|
| 150 |
+
Rect[] buttonRects = CalcMouseRects(position, contents, xCount, elemWidth, elemHeight, style, firstStyle, midStyle, lastStyle, false, buttonSize);
|
| 151 |
+
GUIStyle selectedButtonStyle = null;
|
| 152 |
+
int selectedButtonID = 0;
|
| 153 |
+
for (int buttonIndex = 0; buttonIndex < count; ++buttonIndex)
|
| 154 |
+
{
|
| 155 |
+
bool wasEnabled = GUI.enabled;
|
| 156 |
+
GUI.enabled &= (contentsEnabled == null || contentsEnabled[buttonIndex]);
|
| 157 |
+
var buttonRect = buttonRects[buttonIndex];
|
| 158 |
+
var content = contents[buttonIndex];
|
| 159 |
+
|
| 160 |
+
if (controlNames != null)
|
| 161 |
+
GUI.SetNextControlName(controlNames[buttonIndex]);
|
| 162 |
+
var id = GUIUtility.GetControlID("ButtonGrid".GetHashCode(), FocusType.Passive, buttonRect);
|
| 163 |
+
if (buttonIndex == selected)
|
| 164 |
+
selectedButtonID = id;
|
| 165 |
+
|
| 166 |
+
switch (Event.current.GetTypeForControl(id))
|
| 167 |
+
{
|
| 168 |
+
case EventType.MouseDown:
|
| 169 |
+
if (buttonRect.Contains(Event.current.mousePosition))
|
| 170 |
+
{
|
| 171 |
+
GUIUtility.hotControl = id;
|
| 172 |
+
Event.current.Use();
|
| 173 |
+
}
|
| 174 |
+
break;
|
| 175 |
+
case EventType.MouseDrag:
|
| 176 |
+
if (GUIUtility.hotControl == id)
|
| 177 |
+
Event.current.Use();
|
| 178 |
+
break;
|
| 179 |
+
case EventType.MouseUp:
|
| 180 |
+
if (GUIUtility.hotControl == id)
|
| 181 |
+
{
|
| 182 |
+
GUIUtility.hotControl = 0;
|
| 183 |
+
Event.current.Use();
|
| 184 |
+
|
| 185 |
+
GUI.changed = true;
|
| 186 |
+
return buttonIndex;
|
| 187 |
+
}
|
| 188 |
+
break;
|
| 189 |
+
case EventType.Repaint:
|
| 190 |
+
var buttonStyle = count == 1 ? style : (buttonIndex == 0 ? firstStyle : (buttonIndex == count - 1 ? lastStyle : midStyle));
|
| 191 |
+
var isSelected = selected == buttonIndex;
|
| 192 |
+
|
| 193 |
+
if (!isSelected)
|
| 194 |
+
{
|
| 195 |
+
GUI.DrawTexture(buttonRect, content.image, ScaleMode.ScaleToFit, true);
|
| 196 |
+
GUI.Label(new Rect(buttonRect.x, buttonRect.y, 32, 32), buttonIndex.ToString());
|
| 197 |
+
}
|
| 198 |
+
else
|
| 199 |
+
selectedButtonStyle = buttonStyle;
|
| 200 |
+
break;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
GUI.enabled = wasEnabled;
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
// draw selected button at the end so it overflows nicer
|
| 207 |
+
if (selectedButtonStyle != null)
|
| 208 |
+
{
|
| 209 |
+
var buttonRect = buttonRects[selected];
|
| 210 |
+
var content = contents[selected];
|
| 211 |
+
var wasEnabled = GUI.enabled;
|
| 212 |
+
GUI.enabled &= (contentsEnabled == null || contentsEnabled[selected]);
|
| 213 |
+
|
| 214 |
+
GUI.DrawTexture(new Rect(buttonRect.x + 4, buttonRect.y + 4, buttonRect.width - 8, buttonRect.height - 8), content.image, ScaleMode.ScaleToFit, true);
|
| 215 |
+
DrawRectangleOutline(buttonRect, GUI.skin.settings.selectionColor);
|
| 216 |
+
GUI.Label(new Rect(buttonRect.x, buttonRect.y, 32, 32), selected.ToString());
|
| 217 |
+
GUI.enabled = wasEnabled;
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
return selected;
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
// Get Temp Texture Contents for Sprites.
|
| 224 |
+
private static GUIContent[] Temp(Texture[] images)
|
| 225 |
+
{
|
| 226 |
+
GUIContent[] retval = new GUIContent[images.Length];
|
| 227 |
+
for (int i = 0; i < images.Length; i++)
|
| 228 |
+
{
|
| 229 |
+
retval[i] = new GUIContent(images[i]);
|
| 230 |
+
}
|
| 231 |
+
return retval;
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
public Sprite GetActiveSprite()
|
| 235 |
+
{
|
| 236 |
+
if (m_SelectedSprite >= m_SpriteList.Length)
|
| 237 |
+
m_SelectedSprite = 0;
|
| 238 |
+
return m_SpriteList[m_SelectedSprite];
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
public bool ShowGUI(int selectedIndex)
|
| 242 |
+
{
|
| 243 |
+
bool repaint = false;
|
| 244 |
+
if (m_SpriteList == null || m_SpriteList.Length == 0)
|
| 245 |
+
return false;
|
| 246 |
+
int approxSize = 64;
|
| 247 |
+
int approxHolderSize = 66;
|
| 248 |
+
|
| 249 |
+
if (Styles.localGrid == null)
|
| 250 |
+
{
|
| 251 |
+
Styles.localGrid = new GUIStyle(Styles.gridList);
|
| 252 |
+
Styles.localGrid.fixedWidth = approxSize;
|
| 253 |
+
Styles.localGrid.fixedHeight = approxSize;
|
| 254 |
+
}
|
| 255 |
+
m_SelectedSprite = (selectedIndex > m_SpriteList.Length) ? 0 : selectedIndex;
|
| 256 |
+
|
| 257 |
+
EditorGUILayout.BeginHorizontal();
|
| 258 |
+
{
|
| 259 |
+
GUILayout.Label(Styles.spriteList, EditorStyles.label, GUILayout.Width(EditorGUIUtility.labelWidth - 5));
|
| 260 |
+
|
| 261 |
+
int cviewwidth = (int)(EditorGUIUtility.currentViewWidth - EditorGUIUtility.labelWidth - approxSize);
|
| 262 |
+
int columns = (int)(cviewwidth) / approxSize;
|
| 263 |
+
columns = columns == 0 ? 1 : columns;
|
| 264 |
+
int rows = (int)Mathf.Ceil((m_SpriteList.Length + columns - 1) / columns);
|
| 265 |
+
int lyColumns = (rows == 1) ? (approxHolderSize): (approxHolderSize * 2);
|
| 266 |
+
|
| 267 |
+
GUILayout.BeginVertical("box", new GUILayoutOption[] { GUILayout.Height(lyColumns) } );
|
| 268 |
+
{
|
| 269 |
+
m_ScrollPos = EditorGUILayout.BeginScrollView(m_ScrollPos, new GUILayoutOption[] { GUILayout.Height(lyColumns) });
|
| 270 |
+
int newBrush = SpriteSelectionGrid(m_SelectedSprite, m_SpriteList, approxSize, Styles.localGrid, Styles.missingSprites, columns, rows);
|
| 271 |
+
if (newBrush != m_SelectedSprite)
|
| 272 |
+
{
|
| 273 |
+
UpdateSelection(newBrush);
|
| 274 |
+
repaint = true;
|
| 275 |
+
}
|
| 276 |
+
EditorGUILayout.EndScrollView();
|
| 277 |
+
}
|
| 278 |
+
GUILayout.EndVertical();
|
| 279 |
+
}
|
| 280 |
+
EditorGUILayout.EndHorizontal();
|
| 281 |
+
EditorGUILayout.Space();
|
| 282 |
+
return repaint;
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
int SpriteSelectionGrid(int selected, Sprite[] sprites, int approxSize, GUIStyle style, GUIContent emptyString, int columns, int rows)
|
| 286 |
+
{
|
| 287 |
+
int retval = 0;
|
| 288 |
+
if (sprites.Length != 0)
|
| 289 |
+
{
|
| 290 |
+
Rect r = GUILayoutUtility.GetRect((float)columns * approxSize, (float)rows * approxSize);
|
| 291 |
+
Event evt = Event.current;
|
| 292 |
+
if (evt.type == EventType.MouseDown && evt.clickCount == 2 && r.Contains(evt.mousePosition))
|
| 293 |
+
evt.Use();
|
| 294 |
+
|
| 295 |
+
m_Thumbnails = PreviewTexturesFromSprites(sprites);
|
| 296 |
+
retval = DoButtonGrid(r, selected, Temp(m_Thumbnails), null, (int)columns, style, style, style, style, GUI.ToolbarButtonSize.FitToContents);
|
| 297 |
+
}
|
| 298 |
+
else
|
| 299 |
+
GUILayout.Label(emptyString);
|
| 300 |
+
return retval;
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
+
|
| 304 |
+
internal static Texture[] PreviewTexturesFromSprites(Sprite[] sprites)
|
| 305 |
+
{
|
| 306 |
+
Texture[] retval = new Texture[sprites.Length];
|
| 307 |
+
for (int i = 0; i < sprites.Length; i++)
|
| 308 |
+
retval[i] = AssetPreview.GetAssetPreview(sprites[i]) ?? Texture2D.whiteTexture;
|
| 309 |
+
return retval;
|
| 310 |
+
}
|
| 311 |
+
}
|
| 312 |
+
} //namespace
|
benchmark/NYU_CTF_Bench/test/2022/CSAW-Quals/rev/AnyaGacha/src/client/Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Editor/SpriteSelector.cs.meta
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fileFormatVersion: 2
|
| 2 |
+
guid: efd5d361c5243f44093e56522f66225a
|
| 3 |
+
MonoImporter:
|
| 4 |
+
externalObjects: {}
|
| 5 |
+
serializedVersion: 2
|
| 6 |
+
defaultReferences: []
|
| 7 |
+
executionOrder: 0
|
| 8 |
+
icon: {instanceID: 0}
|
| 9 |
+
userData:
|
| 10 |
+
assetBundleName:
|
| 11 |
+
assetBundleVariant:
|
benchmark/NYU_CTF_Bench/test/2022/CSAW-Quals/rev/AnyaGacha/src/client/Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Editor/SpriteShapeAnalytics.cs
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using System;
|
| 2 |
+
using System.Collections.Generic;
|
| 3 |
+
using UnityEngine.Analytics;
|
| 4 |
+
using UnityEngine;
|
| 5 |
+
using UnityEngine.U2D;
|
| 6 |
+
using UnityEngine.Events;
|
| 7 |
+
|
| 8 |
+
namespace UnityEditor.U2D
|
| 9 |
+
{
|
| 10 |
+
|
| 11 |
+
internal class SpriteShapeAnalyticsEvents
|
| 12 |
+
{
|
| 13 |
+
public class SpriteShapeEvent : UnityEvent<UnityEngine.U2D.SpriteShape> { }
|
| 14 |
+
public class SpriteShapeRendererEvent : UnityEvent<SpriteShapeRenderer> { }
|
| 15 |
+
|
| 16 |
+
private SpriteShapeEvent m_SpriteShape = new SpriteShapeEvent();
|
| 17 |
+
private SpriteShapeRendererEvent m_SpriteShapeRenderer = new SpriteShapeRendererEvent();
|
| 18 |
+
|
| 19 |
+
public virtual SpriteShapeEvent spriteShapeEvent { get { return m_SpriteShape; } }
|
| 20 |
+
public virtual SpriteShapeRendererEvent spriteShapeRendererEvent { get { return m_SpriteShapeRenderer; } }
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
[Serializable]
|
| 24 |
+
enum SpriteShapeAnalyticsEventType
|
| 25 |
+
{
|
| 26 |
+
SpriteShapeProfileCreated = 0,
|
| 27 |
+
SpriteShapeRendererCreated = 1
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
[Serializable]
|
| 31 |
+
struct SpriteShapeAnalyticsEvent
|
| 32 |
+
{
|
| 33 |
+
[SerializeField]
|
| 34 |
+
public SpriteShapeAnalyticsEventType sub_type;
|
| 35 |
+
[SerializeField]
|
| 36 |
+
public string data;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
internal interface ISpriteShapeAnalyticsStorage
|
| 40 |
+
{
|
| 41 |
+
AnalyticsResult SendUsageEvent(SpriteShapeAnalyticsEvent evt);
|
| 42 |
+
void Dispose();
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
internal static class SpriteShapeAnalyticConstant
|
| 46 |
+
{
|
| 47 |
+
public const int k_MaxEventsPerHour = 1000;
|
| 48 |
+
public const int k_MaxNumberOfElements = 1000;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
[Serializable]
|
| 52 |
+
internal class SpriteShapeAnalytics
|
| 53 |
+
{
|
| 54 |
+
const int k_SpriteShapeEventElementCount = 2;
|
| 55 |
+
ISpriteShapeAnalyticsStorage m_AnalyticsStorage;
|
| 56 |
+
[SerializeField]
|
| 57 |
+
SpriteShapeAnalyticsEvents m_EventBus = null;
|
| 58 |
+
|
| 59 |
+
internal SpriteShapeAnalyticsEvents eventBus
|
| 60 |
+
{
|
| 61 |
+
get
|
| 62 |
+
{
|
| 63 |
+
if (m_EventBus == null)
|
| 64 |
+
m_EventBus = new SpriteShapeAnalyticsEvents();
|
| 65 |
+
return m_EventBus;
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
public SpriteShapeAnalytics(ISpriteShapeAnalyticsStorage analyticsStorage)
|
| 70 |
+
{
|
| 71 |
+
m_AnalyticsStorage = analyticsStorage;
|
| 72 |
+
eventBus.spriteShapeEvent.AddListener(OnSpriteShapeCreated);
|
| 73 |
+
eventBus.spriteShapeRendererEvent.AddListener(OnSpriteShapeRendererCreated);
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
public void Dispose()
|
| 77 |
+
{
|
| 78 |
+
eventBus.spriteShapeEvent.RemoveListener(OnSpriteShapeCreated);
|
| 79 |
+
eventBus.spriteShapeRendererEvent.RemoveListener(OnSpriteShapeRendererCreated);
|
| 80 |
+
m_AnalyticsStorage.Dispose();
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
void OnSpriteShapeCreated(UnityEngine.U2D.SpriteShape shape)
|
| 84 |
+
{
|
| 85 |
+
SendUsageEvent(new SpriteShapeAnalyticsEvent()
|
| 86 |
+
{
|
| 87 |
+
sub_type = SpriteShapeAnalyticsEventType.SpriteShapeProfileCreated,
|
| 88 |
+
data = ""
|
| 89 |
+
});
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
void OnSpriteShapeRendererCreated(SpriteShapeRenderer renderer)
|
| 93 |
+
{
|
| 94 |
+
SendUsageEvent(new SpriteShapeAnalyticsEvent()
|
| 95 |
+
{
|
| 96 |
+
sub_type = SpriteShapeAnalyticsEventType.SpriteShapeRendererCreated,
|
| 97 |
+
data = ""
|
| 98 |
+
});
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
public void SendUsageEvent(SpriteShapeAnalyticsEvent evt)
|
| 102 |
+
{
|
| 103 |
+
m_AnalyticsStorage.SendUsageEvent(evt);
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
// For testing.
|
| 109 |
+
internal class SpriteShapeJsonAnalyticsStorage : ISpriteShapeAnalyticsStorage
|
| 110 |
+
{
|
| 111 |
+
[Serializable]
|
| 112 |
+
struct SpriteShapeToolEvents
|
| 113 |
+
{
|
| 114 |
+
[SerializeField]
|
| 115 |
+
public List<SpriteShapeAnalyticsEvent> events;
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
SpriteShapeToolEvents m_TotalEvents = new SpriteShapeToolEvents()
|
| 119 |
+
{
|
| 120 |
+
events = new List<SpriteShapeAnalyticsEvent>()
|
| 121 |
+
};
|
| 122 |
+
|
| 123 |
+
public AnalyticsResult SendUsageEvent(SpriteShapeAnalyticsEvent evt)
|
| 124 |
+
{
|
| 125 |
+
m_TotalEvents.events.Add(evt);
|
| 126 |
+
return AnalyticsResult.Ok;
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
public void Dispose()
|
| 130 |
+
{
|
| 131 |
+
try
|
| 132 |
+
{
|
| 133 |
+
string file = string.Format("analytics_{0}.json", System.DateTime.Now.ToString("yyyy-dd-M--HH-mm-ss"));
|
| 134 |
+
if (System.IO.File.Exists(file))
|
| 135 |
+
System.IO.File.Delete(file);
|
| 136 |
+
System.IO.File.WriteAllText(file, JsonUtility.ToJson(m_TotalEvents, true));
|
| 137 |
+
}
|
| 138 |
+
catch (Exception ex)
|
| 139 |
+
{
|
| 140 |
+
Debug.Log(ex);
|
| 141 |
+
}
|
| 142 |
+
finally
|
| 143 |
+
{
|
| 144 |
+
m_TotalEvents.events.Clear();
|
| 145 |
+
}
|
| 146 |
+
}
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
[InitializeOnLoad]
|
| 150 |
+
internal class SpriteShapeUnityAnalyticsStorage : ISpriteShapeAnalyticsStorage
|
| 151 |
+
{
|
| 152 |
+
const string k_VendorKey = "unity.2d.spriteshape";
|
| 153 |
+
const int k_Version = 1;
|
| 154 |
+
|
| 155 |
+
public SpriteShapeUnityAnalyticsStorage()
|
| 156 |
+
{
|
| 157 |
+
EditorAnalytics.RegisterEventWithLimit("u2dSpriteShapeToolUsage", SpriteShapeAnalyticConstant.k_MaxEventsPerHour, SpriteShapeAnalyticConstant.k_MaxNumberOfElements, k_VendorKey, k_Version);
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
public AnalyticsResult SendUsageEvent(SpriteShapeAnalyticsEvent evt)
|
| 161 |
+
{
|
| 162 |
+
return EditorAnalytics.SendEventWithLimit("u2dSpriteShapeToolUsage", evt, k_Version);
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
public void Dispose() { }
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
}
|
benchmark/NYU_CTF_Bench/test/2022/CSAW-Quals/rev/AnyaGacha/src/client/Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Editor/SpriteShapeAnalytics.cs.meta
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fileFormatVersion: 2
|
| 2 |
+
guid: 7d38d0857bee3b54084cf5988bf12db1
|
| 3 |
+
MonoImporter:
|
| 4 |
+
externalObjects: {}
|
| 5 |
+
serializedVersion: 2
|
| 6 |
+
defaultReferences: []
|
| 7 |
+
executionOrder: 0
|
| 8 |
+
icon: {instanceID: 0}
|
| 9 |
+
userData:
|
| 10 |
+
assetBundleName:
|
| 11 |
+
assetBundleVariant:
|
benchmark/NYU_CTF_Bench/test/2022/CSAW-Quals/rev/AnyaGacha/src/client/Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Editor/SpriteShapeAssetPostProcessor.cs
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using UnityEngine;
|
| 2 |
+
using UnityEngine.U2D;
|
| 3 |
+
using UnityEditor;
|
| 4 |
+
|
| 5 |
+
namespace UnityEditor.U2D
|
| 6 |
+
{
|
| 7 |
+
public class SpriteShapeAssetPostProcessor : AssetPostprocessor
|
| 8 |
+
{
|
| 9 |
+
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
|
| 10 |
+
{
|
| 11 |
+
if (importedAssets.Length > 0)
|
| 12 |
+
{
|
| 13 |
+
GameObject[] allGOs = UnityEngine.Object.FindObjectsOfType<GameObject>();
|
| 14 |
+
foreach (GameObject go in allGOs)
|
| 15 |
+
{
|
| 16 |
+
if (!go.activeInHierarchy)
|
| 17 |
+
continue;
|
| 18 |
+
SpriteShapeController sc = go.GetComponent<SpriteShapeController>();
|
| 19 |
+
if (sc != null)
|
| 20 |
+
sc.RefreshSpriteShape();
|
| 21 |
+
}
|
| 22 |
+
}
|
| 23 |
+
}
|
| 24 |
+
}
|
| 25 |
+
}
|
benchmark/NYU_CTF_Bench/test/2022/CSAW-Quals/rev/AnyaGacha/src/client/Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Editor/SpriteShapeAssetPostProcessor.cs.meta
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fileFormatVersion: 2
|
| 2 |
+
guid: b9102a9258b50f949a55f81945829f85
|
| 3 |
+
timeCreated: 1504669359
|
| 4 |
+
licenseType: Pro
|
| 5 |
+
MonoImporter:
|
| 6 |
+
externalObjects: {}
|
| 7 |
+
serializedVersion: 2
|
| 8 |
+
defaultReferences: []
|
| 9 |
+
executionOrder: 0
|
| 10 |
+
icon: {instanceID: 0}
|
| 11 |
+
userData:
|
| 12 |
+
assetBundleName:
|
| 13 |
+
assetBundleVariant:
|
benchmark/NYU_CTF_Bench/test/2022/CSAW-Quals/rev/AnyaGacha/src/client/Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Editor/SpriteShapeControllerEditor.cs
ADDED
|
@@ -0,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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using System.Collections.Generic;
|
| 2 |
+
using System.Linq;
|
| 3 |
+
using UnityEngine;
|
| 4 |
+
using UnityEngine.U2D;
|
| 5 |
+
using UnityEditor;
|
| 6 |
+
using UnityEditor.U2D.SpriteShapeInternal;
|
| 7 |
+
using UnityEditor.U2D.Common;
|
| 8 |
+
using UnityEditor.AnimatedValues;
|
| 9 |
+
using UnityEditor.U2D.Path;
|
| 10 |
+
using UnityEngine.SceneManagement;
|
| 11 |
+
|
| 12 |
+
namespace UnityEditor.U2D
|
| 13 |
+
{
|
| 14 |
+
|
| 15 |
+
[CustomEditor(typeof(SpriteShapeController))]
|
| 16 |
+
[CanEditMultipleObjects]
|
| 17 |
+
internal class SpriteShapeControllerEditor : PathComponentEditor<CustomPath>
|
| 18 |
+
{
|
| 19 |
+
private static class Contents
|
| 20 |
+
{
|
| 21 |
+
public static readonly GUIContent splineLabel = new GUIContent("Spline");
|
| 22 |
+
public static readonly string editSplineLabel = "Edit Spline";
|
| 23 |
+
public static readonly GUIContent fillLabel = new GUIContent("Fill");
|
| 24 |
+
public static readonly GUIContent colliderLabel = new GUIContent("Collider");
|
| 25 |
+
public static readonly GUIContent fillPixelPerUnitLabel = new GUIContent("Pixel Per Unit", "Pixel Per Unit for fill texture.");
|
| 26 |
+
public static readonly GUIContent spriteShapeProfile = new GUIContent("Profile", "The SpriteShape Profile to render");
|
| 27 |
+
public static readonly GUIContent materialLabel = new GUIContent("Material", "Material to be used by SpriteRenderer");
|
| 28 |
+
public static readonly GUIContent colorLabel = new GUIContent("Color", "Rendering color for the Sprite graphic");
|
| 29 |
+
public static readonly GUIContent metaDataLabel = new GUIContent("Meta Data", "SpriteShape specific controlpoint data");
|
| 30 |
+
public static readonly GUIContent showComponentsLabel = new GUIContent("Show Render Stuff", "Show Renderer Components.");
|
| 31 |
+
public static readonly GUIContent[] splineDetailOptions = { new GUIContent("High Quality"), new GUIContent("Medium Quality"), new GUIContent("Low Quality") };
|
| 32 |
+
public static readonly GUIContent splineDetail = new GUIContent("Detail", "Tessellation Quality for rendering.");
|
| 33 |
+
public static readonly GUIContent openEndedLabel = new GUIContent("Open Ended", "Is the path open ended or closed.");
|
| 34 |
+
public static readonly GUIContent adaptiveUVLabel = new GUIContent("Adaptive UV", "Allow Adaptive UV Generation");
|
| 35 |
+
public static readonly GUIContent enableTangentsLabel = new GUIContent("Enable Tangents", "Enable Tangents for 2D Lighting.");
|
| 36 |
+
public static readonly GUIContent worldUVLabel = new GUIContent("Worldspace UV", "Generate UV for world space.");
|
| 37 |
+
public static readonly GUIContent stretchUVLabel = new GUIContent("Stretch UV", "Stretch the Fill UV to full Rect.");
|
| 38 |
+
public static readonly GUIContent stretchTilingLabel = new GUIContent("Stretch Tiling", "Stretch Tiling Count.");
|
| 39 |
+
public static readonly GUIContent colliderDetail = new GUIContent("Detail", "Tessellation Quality on the collider.");
|
| 40 |
+
public static readonly GUIContent cornerThresholdDetail = new GUIContent("Corner Threshold", "Corner angle threshold below which corners wont be placed.");
|
| 41 |
+
public static readonly GUIContent colliderOffset = new GUIContent("Offset", "Extrude collider distance.");
|
| 42 |
+
public static readonly GUIContent updateColliderLabel = new GUIContent("Update Collider", "Update Collider as you edit SpriteShape");
|
| 43 |
+
public static readonly GUIContent optimizeColliderLabel = new GUIContent("Optimize Collider", "Cleanup planar self-intersections and optimize collider points");
|
| 44 |
+
public static readonly GUIContent optimizeGeometryLabel = new GUIContent("Optimize Geometry", "Simplify geometry");
|
| 45 |
+
public static readonly GUIContent cacheGeometryLabel = new GUIContent("Cache Geometry", "Bake geometry data. This will save geometry data on editor and load it on runtime instead of generating.");
|
| 46 |
+
public static readonly GUIContent uTess2DLabel = new GUIContent("Fill Tessellation (C# Job)", "Use C# Jobs to generate Fill Geometry. (Edge geometry always uses C# Jobs)");
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
private SerializedProperty m_SpriteShapeProp;
|
| 50 |
+
private SerializedProperty m_SplineDetailProp;
|
| 51 |
+
private SerializedProperty m_IsOpenEndedProp;
|
| 52 |
+
private SerializedProperty m_AdaptiveUVProp;
|
| 53 |
+
private SerializedProperty m_StretchUVProp;
|
| 54 |
+
private SerializedProperty m_StretchTilingProp;
|
| 55 |
+
private SerializedProperty m_WorldSpaceUVProp;
|
| 56 |
+
private SerializedProperty m_FillPixelPerUnitProp;
|
| 57 |
+
private SerializedProperty m_CornerAngleThresholdProp;
|
| 58 |
+
|
| 59 |
+
private SerializedProperty m_ColliderAutoUpdate;
|
| 60 |
+
private SerializedProperty m_ColliderDetailProp;
|
| 61 |
+
private SerializedProperty m_ColliderOffsetProp;
|
| 62 |
+
|
| 63 |
+
private SerializedProperty m_OptimizeColliderProp;
|
| 64 |
+
private SerializedProperty m_OptimizeGeometryProp;
|
| 65 |
+
private SerializedProperty m_EnableTangentsProp;
|
| 66 |
+
private SerializedProperty m_GeometryCachedProp;
|
| 67 |
+
private SerializedProperty m_UTess2DGeometryProp;
|
| 68 |
+
|
| 69 |
+
private int m_CollidersCount = 0;
|
| 70 |
+
private int[] m_QualityValues = new int[] { (int)QualityDetail.High, (int)QualityDetail.Mid, (int)QualityDetail.Low };
|
| 71 |
+
readonly AnimBool m_ShowStretchOption = new AnimBool();
|
| 72 |
+
readonly AnimBool m_ShowNonStretchOption = new AnimBool();
|
| 73 |
+
private struct ShapeSegment
|
| 74 |
+
{
|
| 75 |
+
public int start;
|
| 76 |
+
public int end;
|
| 77 |
+
public int angleRange;
|
| 78 |
+
};
|
| 79 |
+
|
| 80 |
+
private struct ShapeAngleRange
|
| 81 |
+
{
|
| 82 |
+
public float start;
|
| 83 |
+
public float end;
|
| 84 |
+
public int order;
|
| 85 |
+
public int index;
|
| 86 |
+
};
|
| 87 |
+
|
| 88 |
+
int m_SelectedPoint = -1;
|
| 89 |
+
int m_SelectedAngleRange = -1;
|
| 90 |
+
int m_SpriteShapeHashCode = 0;
|
| 91 |
+
int m_SplineHashCode = 0;
|
| 92 |
+
List<ShapeSegment> m_ShapeSegments = new List<ShapeSegment>();
|
| 93 |
+
SpriteSelector spriteSelector = new SpriteSelector();
|
| 94 |
+
|
| 95 |
+
private SpriteShapeController m_SpriteShapeController
|
| 96 |
+
{
|
| 97 |
+
get { return target as SpriteShapeController; }
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
private void OnEnable()
|
| 101 |
+
{
|
| 102 |
+
if (target == null)
|
| 103 |
+
return;
|
| 104 |
+
|
| 105 |
+
m_SpriteShapeProp = serializedObject.FindProperty("m_SpriteShape");
|
| 106 |
+
m_SplineDetailProp = serializedObject.FindProperty("m_SplineDetail");
|
| 107 |
+
m_IsOpenEndedProp = serializedObject.FindProperty("m_Spline").FindPropertyRelative("m_IsOpenEnded");
|
| 108 |
+
m_AdaptiveUVProp = serializedObject.FindProperty("m_AdaptiveUV");
|
| 109 |
+
m_StretchUVProp = serializedObject.FindProperty("m_StretchUV");
|
| 110 |
+
m_StretchTilingProp = serializedObject.FindProperty("m_StretchTiling");
|
| 111 |
+
m_WorldSpaceUVProp = serializedObject.FindProperty("m_WorldSpaceUV");
|
| 112 |
+
m_FillPixelPerUnitProp = serializedObject.FindProperty("m_FillPixelPerUnit");
|
| 113 |
+
m_CornerAngleThresholdProp = serializedObject.FindProperty("m_CornerAngleThreshold");
|
| 114 |
+
|
| 115 |
+
m_ColliderAutoUpdate = serializedObject.FindProperty("m_UpdateCollider");
|
| 116 |
+
m_ColliderDetailProp = serializedObject.FindProperty("m_ColliderDetail");
|
| 117 |
+
m_ColliderOffsetProp = serializedObject.FindProperty("m_ColliderOffset");
|
| 118 |
+
m_OptimizeColliderProp = serializedObject.FindProperty("m_OptimizeCollider");
|
| 119 |
+
m_OptimizeGeometryProp = serializedObject.FindProperty("m_OptimizeGeometry");
|
| 120 |
+
m_EnableTangentsProp = serializedObject.FindProperty("m_EnableTangents");
|
| 121 |
+
m_GeometryCachedProp = serializedObject.FindProperty("m_GeometryCached");
|
| 122 |
+
m_UTess2DGeometryProp = serializedObject.FindProperty("m_UTess2D");
|
| 123 |
+
|
| 124 |
+
m_ShowStretchOption.valueChanged.AddListener(Repaint);
|
| 125 |
+
m_ShowStretchOption.value = ShouldShowStretchOption();
|
| 126 |
+
|
| 127 |
+
m_ShowNonStretchOption.valueChanged.AddListener(Repaint);
|
| 128 |
+
m_ShowNonStretchOption.value = !ShouldShowStretchOption();
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
private bool OnCollidersAddedOrRemoved()
|
| 132 |
+
{
|
| 133 |
+
PolygonCollider2D polygonCollider = m_SpriteShapeController.polygonCollider;
|
| 134 |
+
EdgeCollider2D edgeCollider = m_SpriteShapeController.edgeCollider;
|
| 135 |
+
int collidersCount = 0;
|
| 136 |
+
|
| 137 |
+
if (polygonCollider != null)
|
| 138 |
+
collidersCount = collidersCount + 1;
|
| 139 |
+
if (edgeCollider != null)
|
| 140 |
+
collidersCount = collidersCount + 1;
|
| 141 |
+
|
| 142 |
+
if (collidersCount != m_CollidersCount)
|
| 143 |
+
{
|
| 144 |
+
m_CollidersCount = collidersCount;
|
| 145 |
+
return true;
|
| 146 |
+
}
|
| 147 |
+
return false;
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
public void DrawHeader(GUIContent content)
|
| 151 |
+
{
|
| 152 |
+
EditorGUILayout.LabelField(content, EditorStyles.boldLabel);
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
private bool ShouldShowStretchOption()
|
| 156 |
+
{
|
| 157 |
+
return m_StretchUVProp.boolValue;
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
static bool WithinRange(ShapeAngleRange angleRange, float inputAngle)
|
| 161 |
+
{
|
| 162 |
+
float range = angleRange.end - angleRange.start;
|
| 163 |
+
float angle = Mathf.Repeat(inputAngle - angleRange.start, 360f);
|
| 164 |
+
angle = (angle == 360.0f) ? 0 : angle;
|
| 165 |
+
return (angle >= 0f && angle <= range);
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
static int RangeFromAngle(List<ShapeAngleRange> angleRanges, float angle)
|
| 169 |
+
{
|
| 170 |
+
foreach (var range in angleRanges)
|
| 171 |
+
{
|
| 172 |
+
if (WithinRange(range, angle))
|
| 173 |
+
return range.index;
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
return -1;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
private List<ShapeAngleRange> GetAngleRangeSorted(UnityEngine.U2D.SpriteShape ss)
|
| 180 |
+
{
|
| 181 |
+
List<ShapeAngleRange> angleRanges = new List<ShapeAngleRange>();
|
| 182 |
+
int i = 0;
|
| 183 |
+
foreach (var angleRange in ss.angleRanges)
|
| 184 |
+
{
|
| 185 |
+
ShapeAngleRange sar = new ShapeAngleRange() { start = angleRange.start, end = angleRange.end, order = angleRange.order, index = i };
|
| 186 |
+
angleRanges.Add(sar);
|
| 187 |
+
i++;
|
| 188 |
+
}
|
| 189 |
+
angleRanges.Sort((a, b) => a.order.CompareTo(b.order));
|
| 190 |
+
return angleRanges;
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
private void GenerateSegments(SpriteShapeController sc, List<ShapeAngleRange> angleRanges)
|
| 194 |
+
{
|
| 195 |
+
var controlPointCount = sc.spline.GetPointCount();
|
| 196 |
+
var angleRangeIndices = new int[controlPointCount];
|
| 197 |
+
ShapeSegment activeSegment = new ShapeSegment() { start = -1, end = -1, angleRange = -1 };
|
| 198 |
+
m_ShapeSegments.Clear();
|
| 199 |
+
|
| 200 |
+
for (int i = 0; i < controlPointCount; ++i)
|
| 201 |
+
{
|
| 202 |
+
var actv = i;
|
| 203 |
+
var next = SplineUtility.NextIndex(actv, controlPointCount);
|
| 204 |
+
var pos1 = sc.spline.GetPosition(actv);
|
| 205 |
+
var pos2 = sc.spline.GetPosition(next);
|
| 206 |
+
bool continueStrip = (sc.spline.GetTangentMode(actv) == ShapeTangentMode.Continuous), edgeUpdated = false;
|
| 207 |
+
float angle = 0;
|
| 208 |
+
if (false == continueStrip || activeSegment.start == -1)
|
| 209 |
+
angle = SplineUtility.SlopeAngle(pos1, pos2) + 90.0f;
|
| 210 |
+
|
| 211 |
+
next = (!sc.spline.isOpenEnded && next == 0) ? (actv + 1) : next;
|
| 212 |
+
int mn = (actv < next) ? actv : next;
|
| 213 |
+
int mx = (actv > next) ? actv : next;
|
| 214 |
+
|
| 215 |
+
var anglerange = RangeFromAngle(angleRanges, angle);
|
| 216 |
+
angleRangeIndices[actv] = anglerange;
|
| 217 |
+
if (anglerange == -1)
|
| 218 |
+
{
|
| 219 |
+
activeSegment = new ShapeSegment() { start = mn, end = mx, angleRange = anglerange };
|
| 220 |
+
m_ShapeSegments.Add(activeSegment);
|
| 221 |
+
continue;
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
// Check for Segments. Also check if the Segment Start has been resolved. Otherwise simply start with the next one
|
| 225 |
+
if (activeSegment.start != -1)
|
| 226 |
+
continueStrip = continueStrip && (angleRangeIndices[activeSegment.start] != -1);
|
| 227 |
+
|
| 228 |
+
bool canContinue = (actv != (controlPointCount - 1)) || (!sc.spline.isOpenEnded && (actv == (controlPointCount - 1)));
|
| 229 |
+
if (continueStrip && canContinue)
|
| 230 |
+
{
|
| 231 |
+
for (int s = 0; s < m_ShapeSegments.Count; ++s)
|
| 232 |
+
{
|
| 233 |
+
activeSegment = m_ShapeSegments[s];
|
| 234 |
+
if (activeSegment.start - mn == 1)
|
| 235 |
+
{
|
| 236 |
+
edgeUpdated = true;
|
| 237 |
+
activeSegment.start = mn;
|
| 238 |
+
m_ShapeSegments[s] = activeSegment;
|
| 239 |
+
break;
|
| 240 |
+
}
|
| 241 |
+
if (mx - activeSegment.end == 1)
|
| 242 |
+
{
|
| 243 |
+
edgeUpdated = true;
|
| 244 |
+
activeSegment.end = mx;
|
| 245 |
+
m_ShapeSegments[s] = activeSegment;
|
| 246 |
+
break;
|
| 247 |
+
}
|
| 248 |
+
}
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
if (!edgeUpdated)
|
| 252 |
+
{
|
| 253 |
+
activeSegment.start = mn;
|
| 254 |
+
activeSegment.end = mx;
|
| 255 |
+
activeSegment.angleRange = anglerange;
|
| 256 |
+
m_ShapeSegments.Add(activeSegment);
|
| 257 |
+
}
|
| 258 |
+
|
| 259 |
+
}
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
private int GetAngleRange(SpriteShapeController sc, int point, ref int startPoint)
|
| 263 |
+
{
|
| 264 |
+
int angleRange = -1;
|
| 265 |
+
startPoint = point;
|
| 266 |
+
for (int i = 0; i < m_ShapeSegments.Count; ++i)
|
| 267 |
+
{
|
| 268 |
+
if (point >= m_ShapeSegments[i].start && point < m_ShapeSegments[i].end)
|
| 269 |
+
{
|
| 270 |
+
angleRange = m_ShapeSegments[i].angleRange;
|
| 271 |
+
startPoint = point; // m_ShapeSegments[i].start;
|
| 272 |
+
if (angleRange >= sc.spriteShape.angleRanges.Count)
|
| 273 |
+
angleRange = 0;
|
| 274 |
+
break;
|
| 275 |
+
}
|
| 276 |
+
}
|
| 277 |
+
return angleRange;
|
| 278 |
+
}
|
| 279 |
+
|
| 280 |
+
private void UpdateSegments()
|
| 281 |
+
{
|
| 282 |
+
var sc = target as SpriteShapeController;
|
| 283 |
+
|
| 284 |
+
// Either SpriteShape Asset or SpriteShape Data has changed.
|
| 285 |
+
if (m_SpriteShapeHashCode != sc.spriteShapeHashCode || m_SplineHashCode != sc.splineHashCode)
|
| 286 |
+
{
|
| 287 |
+
List<ShapeAngleRange> angleRanges = GetAngleRangeSorted(sc.spriteShape);
|
| 288 |
+
GenerateSegments(sc, angleRanges);
|
| 289 |
+
m_SpriteShapeHashCode = sc.spriteShapeHashCode;
|
| 290 |
+
m_SplineHashCode = sc.splineHashCode;
|
| 291 |
+
m_SelectedPoint = -1;
|
| 292 |
+
}
|
| 293 |
+
}
|
| 294 |
+
|
| 295 |
+
private int ResolveSpriteIndex(List<int> spriteIndices, ISelection<int> selection, ref List<int> startPoints)
|
| 296 |
+
{
|
| 297 |
+
var spriteIndexValue = spriteIndices.FirstOrDefault();
|
| 298 |
+
var sc = target as SpriteShapeController;
|
| 299 |
+
var spline = sc.spline;
|
| 300 |
+
|
| 301 |
+
if (sc == null || sc.spriteShape == null)
|
| 302 |
+
return -1;
|
| 303 |
+
UpdateSegments();
|
| 304 |
+
|
| 305 |
+
if (sc.spriteShape != null)
|
| 306 |
+
{
|
| 307 |
+
if (selection.Count == 1)
|
| 308 |
+
{
|
| 309 |
+
m_SelectedAngleRange = GetAngleRange(sc, selection.elements[0], ref m_SelectedPoint);
|
| 310 |
+
startPoints.Add(m_SelectedPoint);
|
| 311 |
+
spriteIndexValue = spline.GetSpriteIndex(m_SelectedPoint);
|
| 312 |
+
}
|
| 313 |
+
else
|
| 314 |
+
{
|
| 315 |
+
m_SelectedAngleRange = -1;
|
| 316 |
+
foreach (var index in selection.elements)
|
| 317 |
+
{
|
| 318 |
+
int startPoint = index;
|
| 319 |
+
int angleRange = GetAngleRange(sc, index, ref startPoint);
|
| 320 |
+
if (m_SelectedAngleRange != -1 && angleRange != m_SelectedAngleRange)
|
| 321 |
+
{
|
| 322 |
+
m_SelectedAngleRange = -1;
|
| 323 |
+
break;
|
| 324 |
+
}
|
| 325 |
+
startPoints.Add(startPoint);
|
| 326 |
+
m_SelectedAngleRange = angleRange;
|
| 327 |
+
}
|
| 328 |
+
}
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
if (m_SelectedAngleRange != -1)
|
| 332 |
+
spriteSelector.UpdateSprites(sc.spriteShape.angleRanges[m_SelectedAngleRange].sprites.ToArray());
|
| 333 |
+
else
|
| 334 |
+
spriteIndexValue = -1;
|
| 335 |
+
return spriteIndexValue;
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
+
public int GetAngleRange(int index)
|
| 339 |
+
{
|
| 340 |
+
int startPoint = 0;
|
| 341 |
+
var sc = target as SpriteShapeController;
|
| 342 |
+
UpdateSegments();
|
| 343 |
+
return GetAngleRange(sc, index, ref startPoint);
|
| 344 |
+
}
|
| 345 |
+
|
| 346 |
+
public override void OnInspectorGUI()
|
| 347 |
+
{
|
| 348 |
+
var updateCollider = false;
|
| 349 |
+
EditorGUI.BeginChangeCheck();
|
| 350 |
+
|
| 351 |
+
serializedObject.Update();
|
| 352 |
+
EditorGUILayout.PropertyField(m_SpriteShapeProp, Contents.spriteShapeProfile);
|
| 353 |
+
|
| 354 |
+
var hasEditToolChanged = DoEditButton<SpriteShapeEditorTool>(PathEditorToolContents.icon, Contents.editSplineLabel);
|
| 355 |
+
if (hasEditToolChanged && !UnityEditor.EditorTools.ToolManager.activeToolType.Equals(typeof(SpriteShapeEditorTool)))
|
| 356 |
+
SpriteShapeUpdateCache.UpdateCache(targets);
|
| 357 |
+
|
| 358 |
+
DoPathInspector<SpriteShapeEditorTool>();
|
| 359 |
+
var pathTool = SpriteShapeEditorTool.activeSpriteShapeEditorTool;
|
| 360 |
+
|
| 361 |
+
if (Selection.gameObjects.Length == 1 && pathTool != null)
|
| 362 |
+
{
|
| 363 |
+
|
| 364 |
+
var sc = target as SpriteShapeController;
|
| 365 |
+
var path = pathTool.GetPath(sc);
|
| 366 |
+
if (path != null)
|
| 367 |
+
{
|
| 368 |
+
|
| 369 |
+
var selection = path.selection;
|
| 370 |
+
|
| 371 |
+
if (selection.Count > 0)
|
| 372 |
+
{
|
| 373 |
+
|
| 374 |
+
var spline = sc.spline;
|
| 375 |
+
var spriteIndices = new List<int>();
|
| 376 |
+
|
| 377 |
+
List<int> startPoints = new List<int>();
|
| 378 |
+
foreach (int index in selection.elements)
|
| 379 |
+
spriteIndices.Add(spline.GetSpriteIndex(index));
|
| 380 |
+
|
| 381 |
+
var spriteIndexValue = ResolveSpriteIndex(spriteIndices, selection, ref startPoints);
|
| 382 |
+
if (spriteIndexValue != -1)
|
| 383 |
+
{
|
| 384 |
+
EditorGUI.BeginChangeCheck();
|
| 385 |
+
|
| 386 |
+
spriteSelector.ShowGUI(spriteIndexValue);
|
| 387 |
+
|
| 388 |
+
if (EditorGUI.EndChangeCheck())
|
| 389 |
+
{
|
| 390 |
+
foreach (var index in startPoints)
|
| 391 |
+
{
|
| 392 |
+
var data = path.GetData(index);
|
| 393 |
+
data.spriteIndex = spriteSelector.selectedIndex;
|
| 394 |
+
path.SetData(index, data);
|
| 395 |
+
}
|
| 396 |
+
pathTool.SetPath(target);
|
| 397 |
+
}
|
| 398 |
+
}
|
| 399 |
+
EditorGUILayout.Space();
|
| 400 |
+
}
|
| 401 |
+
}
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
+
DoSnappingInspector<SpriteShapeEditorTool>();
|
| 405 |
+
|
| 406 |
+
EditorGUILayout.Space();
|
| 407 |
+
DrawHeader(Contents.splineLabel);
|
| 408 |
+
|
| 409 |
+
EditorGUILayout.IntPopup(m_SplineDetailProp, Contents.splineDetailOptions, m_QualityValues, Contents.splineDetail);
|
| 410 |
+
serializedObject.ApplyModifiedProperties();
|
| 411 |
+
|
| 412 |
+
DoOpenEndedInspector<SpriteShapeEditorTool>(m_IsOpenEndedProp);
|
| 413 |
+
|
| 414 |
+
serializedObject.Update();
|
| 415 |
+
EditorGUILayout.PropertyField(m_AdaptiveUVProp, Contents.adaptiveUVLabel);
|
| 416 |
+
if (!m_IsOpenEndedProp.boolValue)
|
| 417 |
+
EditorGUILayout.PropertyField(m_OptimizeGeometryProp, Contents.optimizeGeometryLabel);
|
| 418 |
+
EditorGUILayout.PropertyField(m_EnableTangentsProp, Contents.enableTangentsLabel);
|
| 419 |
+
|
| 420 |
+
if (UnityEditor.EditorTools.ToolManager.activeToolType == typeof(SpriteShapeEditorTool))
|
| 421 |
+
{
|
| 422 |
+
// Cache Geometry is only editable for Scene Objects or when in Prefab Isolation Mode.
|
| 423 |
+
if (Selection.gameObjects.Length == 1 && Selection.transforms.Contains(Selection.gameObjects[0].transform))
|
| 424 |
+
{
|
| 425 |
+
EditorGUI.BeginChangeCheck();
|
| 426 |
+
EditorGUILayout.PropertyField(m_GeometryCachedProp, Contents.cacheGeometryLabel);
|
| 427 |
+
if (EditorGUI.EndChangeCheck())
|
| 428 |
+
{
|
| 429 |
+
if (m_GeometryCachedProp.boolValue)
|
| 430 |
+
{
|
| 431 |
+
var geometryCache = m_SpriteShapeController.spriteShapeGeometryCache;
|
| 432 |
+
if (!geometryCache)
|
| 433 |
+
geometryCache = m_SpriteShapeController.gameObject
|
| 434 |
+
.AddComponent<SpriteShapeGeometryCache>();
|
| 435 |
+
geometryCache.hideFlags = HideFlags.HideInInspector;
|
| 436 |
+
}
|
| 437 |
+
else
|
| 438 |
+
{
|
| 439 |
+
if (m_SpriteShapeController.spriteShapeGeometryCache)
|
| 440 |
+
Object.DestroyImmediate(m_SpriteShapeController.spriteShapeGeometryCache);
|
| 441 |
+
}
|
| 442 |
+
|
| 443 |
+
m_SpriteShapeController.RefreshSpriteShape();
|
| 444 |
+
}
|
| 445 |
+
}
|
| 446 |
+
SpriteShapeUpdateCache.s_cacheGeometrySet = true;
|
| 447 |
+
}
|
| 448 |
+
|
| 449 |
+
EditorGUI.BeginChangeCheck();
|
| 450 |
+
var threshold = EditorGUILayout.Slider(Contents.cornerThresholdDetail, m_CornerAngleThresholdProp.floatValue, 0.0f, 90.0f);
|
| 451 |
+
if (EditorGUI.EndChangeCheck())
|
| 452 |
+
{
|
| 453 |
+
m_CornerAngleThresholdProp.floatValue = threshold;
|
| 454 |
+
updateCollider = true;
|
| 455 |
+
}
|
| 456 |
+
|
| 457 |
+
EditorGUILayout.Space();
|
| 458 |
+
DrawHeader(Contents.fillLabel);
|
| 459 |
+
EditorGUILayout.PropertyField(m_UTess2DGeometryProp, Contents.uTess2DLabel);
|
| 460 |
+
EditorGUILayout.PropertyField(m_StretchUVProp, Contents.stretchUVLabel);
|
| 461 |
+
|
| 462 |
+
if (ShouldShowStretchOption())
|
| 463 |
+
{
|
| 464 |
+
EditorGUILayout.PropertyField(m_StretchTilingProp, Contents.stretchTilingLabel);
|
| 465 |
+
}
|
| 466 |
+
else
|
| 467 |
+
{
|
| 468 |
+
EditorGUILayout.PropertyField(m_FillPixelPerUnitProp, Contents.fillPixelPerUnitLabel);
|
| 469 |
+
EditorGUILayout.PropertyField(m_WorldSpaceUVProp, Contents.worldUVLabel);
|
| 470 |
+
}
|
| 471 |
+
|
| 472 |
+
if (m_SpriteShapeController.gameObject.GetComponent<PolygonCollider2D>() != null || m_SpriteShapeController.gameObject.GetComponent<EdgeCollider2D>() != null)
|
| 473 |
+
{
|
| 474 |
+
EditorGUILayout.Space();
|
| 475 |
+
DrawHeader(Contents.colliderLabel);
|
| 476 |
+
EditorGUILayout.PropertyField(m_ColliderAutoUpdate, Contents.updateColliderLabel);
|
| 477 |
+
if (m_ColliderAutoUpdate.boolValue)
|
| 478 |
+
{
|
| 479 |
+
EditorGUILayout.PropertyField(m_ColliderOffsetProp, Contents.colliderOffset);
|
| 480 |
+
EditorGUILayout.PropertyField(m_OptimizeColliderProp, Contents.optimizeColliderLabel);
|
| 481 |
+
if (m_OptimizeColliderProp.boolValue)
|
| 482 |
+
EditorGUILayout.IntPopup(m_ColliderDetailProp, Contents.splineDetailOptions, m_QualityValues, Contents.colliderDetail);
|
| 483 |
+
}
|
| 484 |
+
}
|
| 485 |
+
if (EditorGUI.EndChangeCheck())
|
| 486 |
+
{
|
| 487 |
+
updateCollider = true;
|
| 488 |
+
}
|
| 489 |
+
|
| 490 |
+
serializedObject.ApplyModifiedProperties();
|
| 491 |
+
|
| 492 |
+
if (updateCollider || OnCollidersAddedOrRemoved())
|
| 493 |
+
BakeCollider();
|
| 494 |
+
}
|
| 495 |
+
|
| 496 |
+
void BakeCollider()
|
| 497 |
+
{
|
| 498 |
+
if (m_SpriteShapeController.autoUpdateCollider == false)
|
| 499 |
+
return;
|
| 500 |
+
|
| 501 |
+
PolygonCollider2D polygonCollider = m_SpriteShapeController.polygonCollider;
|
| 502 |
+
if (polygonCollider)
|
| 503 |
+
{
|
| 504 |
+
Undo.RegisterCompleteObjectUndo(polygonCollider, Undo.GetCurrentGroupName());
|
| 505 |
+
EditorUtility.SetDirty(polygonCollider);
|
| 506 |
+
m_SpriteShapeController.RefreshSpriteShape();
|
| 507 |
+
}
|
| 508 |
+
|
| 509 |
+
EdgeCollider2D edgeCollider = m_SpriteShapeController.edgeCollider;
|
| 510 |
+
if (edgeCollider)
|
| 511 |
+
{
|
| 512 |
+
Undo.RegisterCompleteObjectUndo(edgeCollider, Undo.GetCurrentGroupName());
|
| 513 |
+
EditorUtility.SetDirty(edgeCollider);
|
| 514 |
+
m_SpriteShapeController.RefreshSpriteShape();
|
| 515 |
+
|
| 516 |
+
}
|
| 517 |
+
}
|
| 518 |
+
|
| 519 |
+
void ShowMaterials(bool show)
|
| 520 |
+
{
|
| 521 |
+
HideFlags hideFlags = HideFlags.HideInInspector;
|
| 522 |
+
|
| 523 |
+
if (show)
|
| 524 |
+
hideFlags = HideFlags.None;
|
| 525 |
+
|
| 526 |
+
Material[] materials = m_SpriteShapeController.spriteShapeRenderer.sharedMaterials;
|
| 527 |
+
|
| 528 |
+
foreach (Material material in materials)
|
| 529 |
+
{
|
| 530 |
+
material.hideFlags = hideFlags;
|
| 531 |
+
EditorUtility.SetDirty(material);
|
| 532 |
+
}
|
| 533 |
+
}
|
| 534 |
+
|
| 535 |
+
[DrawGizmo(GizmoType.InSelectionHierarchy)]
|
| 536 |
+
static void RenderSpline(SpriteShapeController m_SpriteShapeController, GizmoType gizmoType)
|
| 537 |
+
{
|
| 538 |
+
if (UnityEditor.EditorTools.ToolManager.activeToolType == typeof(SpriteShapeEditorTool))
|
| 539 |
+
return;
|
| 540 |
+
|
| 541 |
+
var m_Spline = m_SpriteShapeController.spline;
|
| 542 |
+
var oldMatrix = Handles.matrix;
|
| 543 |
+
var oldColor = Handles.color;
|
| 544 |
+
Handles.matrix = m_SpriteShapeController.transform.localToWorldMatrix;
|
| 545 |
+
Handles.color = Color.grey;
|
| 546 |
+
var pointCount = m_Spline.GetPointCount();
|
| 547 |
+
for (var i = 0; i < (m_Spline.isOpenEnded ? pointCount - 1 : pointCount); ++i)
|
| 548 |
+
{
|
| 549 |
+
Vector3 p1 = m_Spline.GetPosition(i);
|
| 550 |
+
Vector3 p2 = m_Spline.GetPosition((i + 1) % pointCount);
|
| 551 |
+
var t1 = p1 + m_Spline.GetRightTangent(i);
|
| 552 |
+
var t2 = p2 + m_Spline.GetLeftTangent((i + 1) % pointCount);
|
| 553 |
+
Vector3[] bezierPoints = Handles.MakeBezierPoints(p1, p2, t1, t2, m_SpriteShapeController.splineDetail);
|
| 554 |
+
Handles.DrawAAPolyLine(bezierPoints);
|
| 555 |
+
}
|
| 556 |
+
Handles.matrix = oldMatrix;
|
| 557 |
+
Handles.color = oldColor;
|
| 558 |
+
}
|
| 559 |
+
}
|
| 560 |
+
|
| 561 |
+
[UnityEditor.InitializeOnLoad]
|
| 562 |
+
internal static class SpriteShapeUpdateCache
|
| 563 |
+
{
|
| 564 |
+
|
| 565 |
+
internal static bool s_cacheGeometrySet = false;
|
| 566 |
+
static SpriteShapeUpdateCache()
|
| 567 |
+
{
|
| 568 |
+
UnityEditor.EditorApplication.playModeStateChanged += change =>
|
| 569 |
+
{
|
| 570 |
+
if (change == UnityEditor.PlayModeStateChange.ExitingEditMode)
|
| 571 |
+
UpdateSpriteShapeCacheInOpenScenes();
|
| 572 |
+
};
|
| 573 |
+
}
|
| 574 |
+
|
| 575 |
+
static void UpdateSpriteShapeCacheInOpenScenes()
|
| 576 |
+
{
|
| 577 |
+
for (int i = 0; s_cacheGeometrySet && (i < SceneManager.sceneCount); ++i)
|
| 578 |
+
{
|
| 579 |
+
var scene = SceneManager.GetSceneAt(i);
|
| 580 |
+
var gos = scene.GetRootGameObjects();
|
| 581 |
+
foreach (var go in gos)
|
| 582 |
+
{
|
| 583 |
+
var scs = go.GetComponentsInChildren<SpriteShapeController>();
|
| 584 |
+
foreach (var sc in scs)
|
| 585 |
+
if (sc.spriteShapeGeometryCache)
|
| 586 |
+
sc.spriteShapeGeometryCache.UpdateGeometryCache();
|
| 587 |
+
}
|
| 588 |
+
}
|
| 589 |
+
|
| 590 |
+
s_cacheGeometrySet = false;
|
| 591 |
+
}
|
| 592 |
+
|
| 593 |
+
internal static void UpdateCache(UnityEngine.Object[] targets)
|
| 594 |
+
{
|
| 595 |
+
foreach (var t in targets)
|
| 596 |
+
{
|
| 597 |
+
var s = t as SpriteShapeController;
|
| 598 |
+
if (s)
|
| 599 |
+
if (s.spriteShapeGeometryCache)
|
| 600 |
+
s.spriteShapeGeometryCache.UpdateGeometryCache();
|
| 601 |
+
}
|
| 602 |
+
}
|
| 603 |
+
}
|
| 604 |
+
|
| 605 |
+
}
|
benchmark/NYU_CTF_Bench/test/2022/CSAW-Quals/rev/AnyaGacha/src/client/Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Editor/SpriteShapeControllerEditor.cs.meta
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fileFormatVersion: 2
|
| 2 |
+
guid: 8dad9bd3cf16d46f794821e888c403c2
|
| 3 |
+
timeCreated: 1503819723
|
| 4 |
+
licenseType: Pro
|
| 5 |
+
MonoImporter:
|
| 6 |
+
externalObjects: {}
|
| 7 |
+
serializedVersion: 2
|
| 8 |
+
defaultReferences: []
|
| 9 |
+
executionOrder: 0
|
| 10 |
+
icon: {instanceID: 0}
|
| 11 |
+
userData:
|
| 12 |
+
assetBundleName:
|
| 13 |
+
assetBundleVariant:
|
benchmark/NYU_CTF_Bench/test/2022/CSAW-Quals/rev/AnyaGacha/src/client/Library/PackageCache/com.unity.2d.spriteshape@5.1.1/Editor/SpriteShapeEditor.cs
ADDED
|
@@ -0,0 +1,656 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using UnityEngine;
|
| 2 |
+
using UnityEngine.U2D;
|
| 3 |
+
using UnityEditor;
|
| 4 |
+
using UnityEditor.AnimatedValues;
|
| 5 |
+
using UnityEditorInternal;
|
| 6 |
+
using UnityEditor.U2D.Common;
|
| 7 |
+
using System.Collections.Generic;
|
| 8 |
+
using UnityEditor.U2D.SpriteShape;
|
| 9 |
+
|
| 10 |
+
namespace UnityEditor.U2D
|
| 11 |
+
{
|
| 12 |
+
[CustomEditor(typeof(UnityEngine.U2D.SpriteShape)), CanEditMultipleObjects]
|
| 13 |
+
public class SpriteShapeEditor : Editor, IAngleRangeCache
|
| 14 |
+
{
|
| 15 |
+
private static class Contents
|
| 16 |
+
{
|
| 17 |
+
public static readonly GUIContent fillTextureLabel = new GUIContent("Texture", "Fill texture used for Shape Fill.");
|
| 18 |
+
public static readonly GUIContent fillScaleLabel = new GUIContent("Offset", "Determines Border Offset for Shape.");
|
| 19 |
+
public static readonly GUIContent useSpriteBorderLabel = new GUIContent("Use Sprite Borders", "Draw Sprite Borders on discontinuities");
|
| 20 |
+
public static readonly GUIContent cornerTypeLabel = new GUIContent("Corner Type", "Corner type sprite used.");
|
| 21 |
+
public static readonly GUIContent controlPointsLabel = new GUIContent("Control Points");
|
| 22 |
+
public static readonly GUIContent fillLabel = new GUIContent("Fill");
|
| 23 |
+
public static readonly GUIContent cornerLabel = new GUIContent("Corners");
|
| 24 |
+
public static readonly GUIContent cornerListLabel = new GUIContent("Corner List");
|
| 25 |
+
public static readonly GUIContent cornerSpriteTypeLabel = new GUIContent("Corner Sprite");
|
| 26 |
+
public static readonly GUIContent angleRangesLabel = new GUIContent("Angle Ranges");
|
| 27 |
+
public static readonly GUIContent spritesLabel = new GUIContent("Sprites");
|
| 28 |
+
public static readonly GUIContent angleRangeLabel = new GUIContent("Angle Range ({0})");
|
| 29 |
+
public static readonly GUIContent wrapModeErrorLabel = new GUIContent("Fill texture must have wrap modes set to Repeat. Please re-import.");
|
| 30 |
+
|
| 31 |
+
public static readonly Color proBackgroundColor = new Color32(49, 77, 121, 255);
|
| 32 |
+
public static readonly Color proBackgroundRangeColor = new Color32(25, 25, 25, 128);
|
| 33 |
+
public static readonly Color proColor1 = new Color32(10, 46, 42, 255);
|
| 34 |
+
public static readonly Color proColor2 = new Color32(33, 151, 138, 255);
|
| 35 |
+
public static readonly Color defaultColor1 = new Color32(25, 61, 57, 255);
|
| 36 |
+
public static readonly Color defaultColor2 = new Color32(47, 166, 153, 255);
|
| 37 |
+
public static readonly Color defaultBackgroundColor = new Color32(64, 92, 136, 255);
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
private SerializedProperty m_FillTextureProp;
|
| 41 |
+
private SerializedProperty m_AngleRangesProp;
|
| 42 |
+
private SerializedProperty m_CornerSpritesProp;
|
| 43 |
+
private SerializedProperty m_FillOffsetProp;
|
| 44 |
+
private SerializedProperty m_UseSpriteBordersProp;
|
| 45 |
+
|
| 46 |
+
private ReorderableList m_AngleRangeSpriteList = null;
|
| 47 |
+
private ReorderableList m_EmptySpriteList = null;
|
| 48 |
+
|
| 49 |
+
[SerializeField]
|
| 50 |
+
private float m_PreviewAngle = 0f;
|
| 51 |
+
[SerializeField]
|
| 52 |
+
private int m_SelectedIndex;
|
| 53 |
+
private const int kInvalidMinimum = -1;
|
| 54 |
+
private Rect m_AngleRangeRect;
|
| 55 |
+
private AngleRangeController controller;
|
| 56 |
+
private AngleRange m_CurrentAngleRange;
|
| 57 |
+
private Dictionary<int, int> m_SpriteSelection = new Dictionary<int, int>();
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
private Sprite m_PreviewSprite;
|
| 61 |
+
private Mesh m_PreviewSpriteMesh;
|
| 62 |
+
private Mesh previewSpriteMesh
|
| 63 |
+
{
|
| 64 |
+
get
|
| 65 |
+
{
|
| 66 |
+
if (m_PreviewSpriteMesh == null)
|
| 67 |
+
{
|
| 68 |
+
m_PreviewSpriteMesh = new Mesh();
|
| 69 |
+
m_PreviewSpriteMesh.MarkDynamic();
|
| 70 |
+
m_PreviewSpriteMesh.hideFlags = HideFlags.DontSave;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
return m_PreviewSpriteMesh;
|
| 74 |
+
}
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
public List<AngleRange> angleRanges
|
| 78 |
+
{
|
| 79 |
+
get
|
| 80 |
+
{
|
| 81 |
+
if (spriteShape == null)
|
| 82 |
+
return new List<AngleRange>();
|
| 83 |
+
Debug.Assert(spriteShape != null);
|
| 84 |
+
return spriteShape.angleRanges;
|
| 85 |
+
}
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
public int selectedIndex
|
| 89 |
+
{
|
| 90 |
+
get { return m_SelectedIndex; }
|
| 91 |
+
set { m_SelectedIndex = value; }
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
bool isSelectedIndexValid
|
| 95 |
+
{
|
| 96 |
+
get { return (selectedIndex != kInvalidMinimum && selectedIndex < angleRanges.Count); }
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
public float previewAngle
|
| 100 |
+
{
|
| 101 |
+
get { return m_PreviewAngle; }
|
| 102 |
+
set
|
| 103 |
+
{
|
| 104 |
+
m_PreviewAngle = value;
|
| 105 |
+
SessionState.SetFloat("SpriteShape/PreviewAngle/" + target.GetInstanceID(), value);
|
| 106 |
+
}
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
public UnityEngine.U2D.SpriteShape spriteShape
|
| 110 |
+
{
|
| 111 |
+
get
|
| 112 |
+
{
|
| 113 |
+
if (target == null)
|
| 114 |
+
return null;
|
| 115 |
+
return target as UnityEngine.U2D.SpriteShape;
|
| 116 |
+
}
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
public void RegisterUndo(string name)
|
| 120 |
+
{
|
| 121 |
+
Undo.RegisterCompleteObjectUndo(spriteShape, name);
|
| 122 |
+
Undo.RegisterCompleteObjectUndo(this, name);
|
| 123 |
+
EditorUtility.SetDirty(spriteShape);
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
public void OnEnable()
|
| 127 |
+
{
|
| 128 |
+
if (targets == null || targets.Length == 0)
|
| 129 |
+
return;
|
| 130 |
+
|
| 131 |
+
m_PreviewAngle = SessionState.GetFloat("SpriteShape/PreviewAngle/" + target.GetInstanceID(), m_PreviewAngle);
|
| 132 |
+
|
| 133 |
+
m_FillTextureProp = this.serializedObject.FindProperty("m_FillTexture");
|
| 134 |
+
m_UseSpriteBordersProp = serializedObject.FindProperty("m_UseSpriteBorders");
|
| 135 |
+
m_AngleRangesProp = this.serializedObject.FindProperty("m_Angles");
|
| 136 |
+
m_CornerSpritesProp = this.serializedObject.FindProperty("m_CornerSprites");
|
| 137 |
+
m_FillOffsetProp = this.serializedObject.FindProperty("m_FillOffset");
|
| 138 |
+
|
| 139 |
+
selectedIndex = SpriteShapeEditorUtility.GetRangeIndexFromAngle(angleRanges, m_PreviewAngle);
|
| 140 |
+
|
| 141 |
+
SetupAngleRangeController();
|
| 142 |
+
|
| 143 |
+
Undo.undoRedoPerformed += UndoRedoPerformed;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
public override bool RequiresConstantRepaint()
|
| 147 |
+
{
|
| 148 |
+
return true;
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
private void SetupAngleRangeController()
|
| 152 |
+
{
|
| 153 |
+
var radius = 125f;
|
| 154 |
+
var angleOffset = -90f;
|
| 155 |
+
var color1 = Contents.defaultColor1;
|
| 156 |
+
var color2 = Contents.defaultColor2;
|
| 157 |
+
|
| 158 |
+
if (!EditorGUIUtility.isProSkin)
|
| 159 |
+
{
|
| 160 |
+
color1 = Contents.proColor1;
|
| 161 |
+
color2 = Contents.proColor2;
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
controller = new AngleRangeController();
|
| 165 |
+
controller.view = new AngleRangeView();
|
| 166 |
+
controller.cache = this;
|
| 167 |
+
controller.radius = radius;
|
| 168 |
+
controller.angleOffset = angleOffset;
|
| 169 |
+
controller.gradientMin = color1;
|
| 170 |
+
controller.gradientMid = color2;
|
| 171 |
+
controller.gradientMax = color1;
|
| 172 |
+
controller.snap = true;
|
| 173 |
+
controller.selectionChanged += OnSelectionChange;
|
| 174 |
+
|
| 175 |
+
OnSelectionChange();
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
private void OnSelectionChange()
|
| 179 |
+
{
|
| 180 |
+
CreateReorderableSpriteList();
|
| 181 |
+
|
| 182 |
+
EditorApplication.delayCall += () =>
|
| 183 |
+
{
|
| 184 |
+
m_CurrentAngleRange = controller.selectedAngleRange;
|
| 185 |
+
};
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
private void OnDestroy()
|
| 189 |
+
{
|
| 190 |
+
if (m_PreviewSpriteMesh)
|
| 191 |
+
Object.DestroyImmediate(m_PreviewSpriteMesh);
|
| 192 |
+
|
| 193 |
+
Undo.undoRedoPerformed -= UndoRedoPerformed;
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
private void UndoRedoPerformed()
|
| 197 |
+
{
|
| 198 |
+
OnSelectionChange();
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
private void OnSelelectSpriteCallback(ReorderableList list)
|
| 202 |
+
{
|
| 203 |
+
if (selectedIndex >= 0)
|
| 204 |
+
{
|
| 205 |
+
SetPreviewSpriteIndex(selectedIndex, list.index);
|
| 206 |
+
}
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
private bool OnCanAddCallback(ReorderableList list)
|
| 210 |
+
{
|
| 211 |
+
return (list.count < 64);
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
private void OnRemoveSprite(ReorderableList list)
|
| 215 |
+
{
|
| 216 |
+
var count = list.count;
|
| 217 |
+
var index = list.index;
|
| 218 |
+
|
| 219 |
+
ReorderableList.defaultBehaviours.DoRemoveButton(list);
|
| 220 |
+
|
| 221 |
+
if (list.count < count && list.count > 0)
|
| 222 |
+
{
|
| 223 |
+
list.index = Mathf.Clamp(index, 0, list.count - 1);
|
| 224 |
+
OnSelelectSpriteCallback(list);
|
| 225 |
+
}
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
private void DrawSpriteListHeader(Rect rect)
|
| 229 |
+
{
|
| 230 |
+
EditorGUI.LabelField(rect, Contents.spritesLabel);
|
| 231 |
+
HandleAngleSpriteListGUI(rect);
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
private void DrawSpriteListElement(Rect rect, int index, bool selected, bool focused)
|
| 235 |
+
{
|
| 236 |
+
rect.y += 2f;
|
| 237 |
+
rect.height = EditorGUIUtility.singleLineHeight;
|
| 238 |
+
var sprite = m_AngleRangesProp.GetArrayElementAtIndex(selectedIndex).FindPropertyRelative("m_Sprites").GetArrayElementAtIndex(index);
|
| 239 |
+
EditorGUI.BeginChangeCheck();
|
| 240 |
+
EditorGUI.PropertyField(rect, sprite, GUIContent.none);
|
| 241 |
+
if (EditorGUI.EndChangeCheck())
|
| 242 |
+
{
|
| 243 |
+
m_AngleRangeSpriteList.index = index;
|
| 244 |
+
OnSelelectSpriteCallback(m_AngleRangeSpriteList);
|
| 245 |
+
}
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
public void DrawHeader(GUIContent content)
|
| 249 |
+
{
|
| 250 |
+
EditorGUILayout.LabelField(content, EditorStyles.boldLabel);
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
private void SetPreviewSpriteIndex(int rangeIndex, int index)
|
| 254 |
+
{
|
| 255 |
+
m_SpriteSelection[rangeIndex] = index;
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
private int GetPreviewSpriteIndex(int rangeIndex)
|
| 259 |
+
{
|
| 260 |
+
int index;
|
| 261 |
+
m_SpriteSelection.TryGetValue(rangeIndex, out index);
|
| 262 |
+
|
| 263 |
+
return index;
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
public override void OnInspectorGUI()
|
| 267 |
+
{
|
| 268 |
+
serializedObject.Update();
|
| 269 |
+
|
| 270 |
+
EditorGUILayout.Space();
|
| 271 |
+
DrawHeader(Contents.controlPointsLabel);
|
| 272 |
+
EditorGUILayout.PropertyField(m_UseSpriteBordersProp, Contents.useSpriteBorderLabel);
|
| 273 |
+
|
| 274 |
+
|
| 275 |
+
EditorGUILayout.Space();
|
| 276 |
+
DrawHeader(Contents.fillLabel);
|
| 277 |
+
EditorGUILayout.PropertyField(m_FillTextureProp, Contents.fillTextureLabel);
|
| 278 |
+
EditorGUILayout.Slider(m_FillOffsetProp, -0.5f, 0.5f, Contents.fillScaleLabel);
|
| 279 |
+
|
| 280 |
+
|
| 281 |
+
if (m_FillTextureProp.objectReferenceValue != null)
|
| 282 |
+
{
|
| 283 |
+
var fillTex = m_FillTextureProp.objectReferenceValue as Texture2D;
|
| 284 |
+
if (fillTex.wrapModeU != TextureWrapMode.Repeat || fillTex.wrapModeV != TextureWrapMode.Repeat)
|
| 285 |
+
EditorGUILayout.HelpBox(Contents.wrapModeErrorLabel.text, MessageType.Warning);
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
EditorGUILayout.Space();
|
| 289 |
+
DrawHeader(Contents.angleRangesLabel);
|
| 290 |
+
DoRangesGUI();
|
| 291 |
+
|
| 292 |
+
if (targets.Length == 1)
|
| 293 |
+
{
|
| 294 |
+
DoRangeInspector();
|
| 295 |
+
DoCreateRangeButton();
|
| 296 |
+
}
|
| 297 |
+
|
| 298 |
+
EditorGUILayout.Space();
|
| 299 |
+
DrawHeader(Contents.cornerLabel);
|
| 300 |
+
|
| 301 |
+
HashSet<Sprite> tightMeshSprites = new HashSet<Sprite>();
|
| 302 |
+
|
| 303 |
+
for (int i = 0; i < angleRanges.Count; ++i)
|
| 304 |
+
{
|
| 305 |
+
AngleRange angleRange = angleRanges[i];
|
| 306 |
+
foreach (Sprite sprite in angleRange.sprites)
|
| 307 |
+
{
|
| 308 |
+
if (sprite != null)
|
| 309 |
+
{
|
| 310 |
+
string assetPath = AssetDatabase.GetAssetPath(sprite);
|
| 311 |
+
TextureImporter importer = AssetImporter.GetAtPath(assetPath) as TextureImporter;
|
| 312 |
+
if (importer != null)
|
| 313 |
+
{
|
| 314 |
+
TextureImporterSettings textureSettings = new TextureImporterSettings();
|
| 315 |
+
importer.ReadTextureSettings(textureSettings);
|
| 316 |
+
if (textureSettings.spriteMeshType == SpriteMeshType.Tight)
|
| 317 |
+
tightMeshSprites.Add(sprite);
|
| 318 |
+
}
|
| 319 |
+
}
|
| 320 |
+
}
|
| 321 |
+
}
|
| 322 |
+
|
| 323 |
+
EditorGUIUtility.labelWidth = EditorGUIUtility.labelWidth + 20f;
|
| 324 |
+
|
| 325 |
+
for (int i = 0; i < m_CornerSpritesProp.arraySize; ++i)
|
| 326 |
+
{
|
| 327 |
+
var m_CornerProp = m_CornerSpritesProp.GetArrayElementAtIndex(i);
|
| 328 |
+
var m_CornerType = m_CornerProp.FindPropertyRelative("m_CornerType");
|
| 329 |
+
var m_CornerSprite = m_CornerProp.FindPropertyRelative("m_Sprites").GetArrayElementAtIndex(0);
|
| 330 |
+
|
| 331 |
+
EditorGUILayout.PropertyField(m_CornerSprite, new GUIContent(m_CornerType.enumDisplayNames[m_CornerType.intValue]));
|
| 332 |
+
|
| 333 |
+
var sprite = m_CornerSprite.objectReferenceValue as Sprite;
|
| 334 |
+
if (sprite != null)
|
| 335 |
+
{
|
| 336 |
+
string assetPath = AssetDatabase.GetAssetPath(sprite);
|
| 337 |
+
TextureImporter importer = AssetImporter.GetAtPath(assetPath) as TextureImporter;
|
| 338 |
+
if (importer != null)
|
| 339 |
+
{
|
| 340 |
+
TextureImporterSettings textureSettings = new TextureImporterSettings();
|
| 341 |
+
importer.ReadTextureSettings(textureSettings);
|
| 342 |
+
if (textureSettings.spriteMeshType == SpriteMeshType.Tight)
|
| 343 |
+
tightMeshSprites.Add(sprite);
|
| 344 |
+
}
|
| 345 |
+
}
|
| 346 |
+
}
|
| 347 |
+
|
| 348 |
+
|
| 349 |
+
EditorGUIUtility.labelWidth = 0;
|
| 350 |
+
|
| 351 |
+
serializedObject.ApplyModifiedProperties();
|
| 352 |
+
|
| 353 |
+
if (tightMeshSprites.Count > 0)
|
| 354 |
+
{
|
| 355 |
+
int i = 0;
|
| 356 |
+
string tightSpriteWarning = "The following sprites ( ";
|
| 357 |
+
foreach (var sprite in tightMeshSprites)
|
| 358 |
+
{
|
| 359 |
+
string appendString = (i < tightMeshSprites.Count - 1) ? ", " : " ) ";
|
| 360 |
+
tightSpriteWarning += (sprite.name + appendString);
|
| 361 |
+
++i;
|
| 362 |
+
}
|
| 363 |
+
tightSpriteWarning += "are imported as Sprites using Tight mesh. This can lead to Rendering Artifacts. Please use Full Rect.";
|
| 364 |
+
EditorGUILayout.HelpBox(tightSpriteWarning, MessageType.Warning);
|
| 365 |
+
}
|
| 366 |
+
|
| 367 |
+
controller.view.DoCreateRangeTooltip();
|
| 368 |
+
}
|
| 369 |
+
|
| 370 |
+
private void DoRangeInspector()
|
| 371 |
+
{
|
| 372 |
+
var start = 0f;
|
| 373 |
+
var end = 0f;
|
| 374 |
+
var order = 0;
|
| 375 |
+
|
| 376 |
+
if (m_CurrentAngleRange != null)
|
| 377 |
+
{
|
| 378 |
+
start = m_CurrentAngleRange.start;
|
| 379 |
+
end = m_CurrentAngleRange.end;
|
| 380 |
+
order = m_CurrentAngleRange.order;
|
| 381 |
+
}
|
| 382 |
+
|
| 383 |
+
using (new EditorGUI.DisabledGroupScope(m_CurrentAngleRange == null))
|
| 384 |
+
{
|
| 385 |
+
DrawHeader(new GUIContent(string.Format(Contents.angleRangeLabel.text, (end - start))));
|
| 386 |
+
|
| 387 |
+
EditorGUIUtility.labelWidth = 0f;
|
| 388 |
+
EditorGUI.BeginChangeCheck();
|
| 389 |
+
|
| 390 |
+
RangeField(ref start, ref end, ref order);
|
| 391 |
+
|
| 392 |
+
if (EditorGUI.EndChangeCheck() && m_CurrentAngleRange != null)
|
| 393 |
+
{
|
| 394 |
+
RegisterUndo("Set Range");
|
| 395 |
+
|
| 396 |
+
m_CurrentAngleRange.order = order;
|
| 397 |
+
controller.SetRange(m_CurrentAngleRange, start, end);
|
| 398 |
+
|
| 399 |
+
if (start >= end)
|
| 400 |
+
controller.RemoveInvalidRanges();
|
| 401 |
+
}
|
| 402 |
+
|
| 403 |
+
EditorGUILayout.Space();
|
| 404 |
+
|
| 405 |
+
var arSize = m_AngleRangesProp.arraySize;
|
| 406 |
+
|
| 407 |
+
if (m_AngleRangeSpriteList != null && arSize > 0)
|
| 408 |
+
m_AngleRangeSpriteList.DoLayoutList();
|
| 409 |
+
else
|
| 410 |
+
m_EmptySpriteList.DoLayoutList();
|
| 411 |
+
}
|
| 412 |
+
}
|
| 413 |
+
|
| 414 |
+
private void DoCreateRangeButton()
|
| 415 |
+
{
|
| 416 |
+
if (selectedIndex != kInvalidMinimum && angleRanges.Count != 0)
|
| 417 |
+
return;
|
| 418 |
+
|
| 419 |
+
EditorGUILayout.BeginHorizontal();
|
| 420 |
+
GUILayout.FlexibleSpace();
|
| 421 |
+
|
| 422 |
+
if (GUILayout.Button("Create Range", GUILayout.MaxWidth(100f)))
|
| 423 |
+
{
|
| 424 |
+
RegisterUndo("Create Range");
|
| 425 |
+
controller.CreateRange();
|
| 426 |
+
}
|
| 427 |
+
|
| 428 |
+
GUILayout.FlexibleSpace();
|
| 429 |
+
EditorGUILayout.EndHorizontal();
|
| 430 |
+
}
|
| 431 |
+
|
| 432 |
+
private void RangeField(ref float start, ref float end, ref int order)
|
| 433 |
+
{
|
| 434 |
+
var values = new int[] { Mathf.RoundToInt(-start), Mathf.RoundToInt(-end), order };
|
| 435 |
+
var labels = new GUIContent[] { new GUIContent("Start"), new GUIContent("End"), new GUIContent("Order") };
|
| 436 |
+
|
| 437 |
+
var position = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight);
|
| 438 |
+
EditorGUI.BeginChangeCheck();
|
| 439 |
+
SpriteShapeEditorGUI.MultiDelayedIntField(position, labels, values, 40f);
|
| 440 |
+
if (EditorGUI.EndChangeCheck())
|
| 441 |
+
{
|
| 442 |
+
start = -1f * values[0];
|
| 443 |
+
end = -1f * values[1];
|
| 444 |
+
order = values[2];
|
| 445 |
+
}
|
| 446 |
+
}
|
| 447 |
+
|
| 448 |
+
private void HandleAngleSpriteListGUI(Rect rect)
|
| 449 |
+
{
|
| 450 |
+
if (m_CurrentAngleRange == null || !isSelectedIndexValid)
|
| 451 |
+
return;
|
| 452 |
+
|
| 453 |
+
var currentEvent = Event.current;
|
| 454 |
+
var usedEvent = false;
|
| 455 |
+
var sprites = m_AngleRangesProp.GetArrayElementAtIndex(selectedIndex).FindPropertyRelative("m_Sprites");
|
| 456 |
+
switch (currentEvent.type)
|
| 457 |
+
{
|
| 458 |
+
case EventType.DragExited:
|
| 459 |
+
if (GUI.enabled)
|
| 460 |
+
HandleUtility.Repaint();
|
| 461 |
+
break;
|
| 462 |
+
|
| 463 |
+
case EventType.DragUpdated:
|
| 464 |
+
case EventType.DragPerform:
|
| 465 |
+
if (rect.Contains(currentEvent.mousePosition) && GUI.enabled)
|
| 466 |
+
{
|
| 467 |
+
// Check each single object, so we can add multiple objects in a single drag.
|
| 468 |
+
var didAcceptDrag = false;
|
| 469 |
+
var references = DragAndDrop.objectReferences;
|
| 470 |
+
foreach (var obj in references)
|
| 471 |
+
{
|
| 472 |
+
if (obj is Sprite)
|
| 473 |
+
{
|
| 474 |
+
Sprite spr = obj as Sprite;
|
| 475 |
+
if (spr.texture != null)
|
| 476 |
+
{
|
| 477 |
+
DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
|
| 478 |
+
if (currentEvent.type == EventType.DragPerform && sprites.arraySize < 64)
|
| 479 |
+
{
|
| 480 |
+
sprites.InsertArrayElementAtIndex(sprites.arraySize);
|
| 481 |
+
var spriteProp = sprites.GetArrayElementAtIndex(sprites.arraySize - 1);
|
| 482 |
+
spriteProp.objectReferenceValue = obj;
|
| 483 |
+
didAcceptDrag = true;
|
| 484 |
+
DragAndDrop.activeControlID = 0;
|
| 485 |
+
}
|
| 486 |
+
}
|
| 487 |
+
}
|
| 488 |
+
}
|
| 489 |
+
|
| 490 |
+
serializedObject.ApplyModifiedProperties();
|
| 491 |
+
|
| 492 |
+
if (didAcceptDrag)
|
| 493 |
+
{
|
| 494 |
+
GUI.changed = true;
|
| 495 |
+
DragAndDrop.AcceptDrag();
|
| 496 |
+
usedEvent = true;
|
| 497 |
+
}
|
| 498 |
+
}
|
| 499 |
+
break;
|
| 500 |
+
}
|
| 501 |
+
|
| 502 |
+
if (usedEvent)
|
| 503 |
+
currentEvent.Use();
|
| 504 |
+
}
|
| 505 |
+
|
| 506 |
+
private void DoRangesGUI()
|
| 507 |
+
{
|
| 508 |
+
var radius = controller.radius;
|
| 509 |
+
|
| 510 |
+
EditorGUILayout.Space();
|
| 511 |
+
EditorGUILayout.Space();
|
| 512 |
+
|
| 513 |
+
var rect = EditorGUILayout.GetControlRect(false, radius * 2f);
|
| 514 |
+
|
| 515 |
+
if (Event.current.type == EventType.Repaint)
|
| 516 |
+
m_AngleRangeRect = rect;
|
| 517 |
+
|
| 518 |
+
{ //Draw background
|
| 519 |
+
var backgroundColor = Contents.proBackgroundColor;
|
| 520 |
+
var backgroundRangeColor = Contents.proBackgroundRangeColor;
|
| 521 |
+
|
| 522 |
+
if (!EditorGUIUtility.isProSkin)
|
| 523 |
+
{
|
| 524 |
+
backgroundColor = Contents.defaultBackgroundColor;
|
| 525 |
+
backgroundRangeColor.a = 0.1f;
|
| 526 |
+
}
|
| 527 |
+
var c = Handles.color;
|
| 528 |
+
Handles.color = backgroundRangeColor;
|
| 529 |
+
SpriteShapeHandleUtility.DrawSolidArc(rect.center, Vector3.forward, Vector3.right, 360f, radius, AngleRangeGUI.kRangeWidth);
|
| 530 |
+
Handles.color = backgroundColor;
|
| 531 |
+
Handles.DrawSolidDisc(rect.center, Vector3.forward, radius - AngleRangeGUI.kRangeWidth + 1f);
|
| 532 |
+
Handles.color = c;
|
| 533 |
+
}
|
| 534 |
+
|
| 535 |
+
if (targets.Length == 1)
|
| 536 |
+
{
|
| 537 |
+
{ //Draw fill texture and sprite preview
|
| 538 |
+
SpriteShapeHandleUtility.DrawTextureArc(
|
| 539 |
+
m_FillTextureProp.objectReferenceValue as Texture, 100.0f,
|
| 540 |
+
rect.center, Vector3.forward, Quaternion.AngleAxis(m_PreviewAngle, Vector3.forward) * Vector3.right, 180f,
|
| 541 |
+
radius - AngleRangeGUI.kRangeWidth);
|
| 542 |
+
|
| 543 |
+
var rectSize = Vector2.one * (radius - AngleRangeGUI.kRangeWidth) * 2f;
|
| 544 |
+
rectSize.y *= 0.33f;
|
| 545 |
+
var spriteRect = new Rect(rect.center - rectSize * 0.5f, rectSize);
|
| 546 |
+
DrawSpritePreview(spriteRect);
|
| 547 |
+
HandleSpritePreviewCycle(spriteRect);
|
| 548 |
+
}
|
| 549 |
+
|
| 550 |
+
controller.rect = m_AngleRangeRect;
|
| 551 |
+
controller.OnGUI();
|
| 552 |
+
}
|
| 553 |
+
|
| 554 |
+
EditorGUILayout.Space();
|
| 555 |
+
EditorGUILayout.Space();
|
| 556 |
+
}
|
| 557 |
+
|
| 558 |
+
private void CreateReorderableSpriteList()
|
| 559 |
+
{
|
| 560 |
+
if (m_EmptySpriteList == null)
|
| 561 |
+
{
|
| 562 |
+
m_EmptySpriteList = new ReorderableList(new List<Sprite>(), typeof(Sprite), false, true, false, false)
|
| 563 |
+
{
|
| 564 |
+
drawHeaderCallback = (Rect rect) => { EditorGUI.LabelField(rect, Contents.spritesLabel); }
|
| 565 |
+
};
|
| 566 |
+
}
|
| 567 |
+
|
| 568 |
+
m_AngleRangeSpriteList = null;
|
| 569 |
+
|
| 570 |
+
serializedObject.UpdateIfRequiredOrScript();
|
| 571 |
+
|
| 572 |
+
Debug.Assert(angleRanges.Count == m_AngleRangesProp.arraySize);
|
| 573 |
+
Debug.Assert(selectedIndex < angleRanges.Count || selectedIndex == 0);
|
| 574 |
+
|
| 575 |
+
if (targets.Length == 1 && isSelectedIndexValid)
|
| 576 |
+
{
|
| 577 |
+
var spritesProp = m_AngleRangesProp.GetArrayElementAtIndex(selectedIndex).FindPropertyRelative("m_Sprites");
|
| 578 |
+
m_AngleRangeSpriteList = new ReorderableList(spritesProp.serializedObject, spritesProp)
|
| 579 |
+
{
|
| 580 |
+
drawElementCallback = DrawSpriteListElement,
|
| 581 |
+
drawHeaderCallback = DrawSpriteListHeader,
|
| 582 |
+
onSelectCallback = OnSelelectSpriteCallback,
|
| 583 |
+
onRemoveCallback = OnRemoveSprite,
|
| 584 |
+
onCanAddCallback = OnCanAddCallback,
|
| 585 |
+
elementHeight = EditorGUIUtility.singleLineHeight + 6f
|
| 586 |
+
};
|
| 587 |
+
}
|
| 588 |
+
}
|
| 589 |
+
|
| 590 |
+
private void DrawSpritePreview(Rect rect)
|
| 591 |
+
{
|
| 592 |
+
if (Event.current.type != EventType.Repaint)
|
| 593 |
+
return;
|
| 594 |
+
|
| 595 |
+
if (!isSelectedIndexValid)
|
| 596 |
+
return;
|
| 597 |
+
|
| 598 |
+
var sprites = angleRanges[selectedIndex].sprites;
|
| 599 |
+
|
| 600 |
+
if (sprites.Count == 0)
|
| 601 |
+
return;
|
| 602 |
+
|
| 603 |
+
var selectedSpriteIndex = GetPreviewSpriteIndex(selectedIndex);
|
| 604 |
+
|
| 605 |
+
if (selectedSpriteIndex == kInvalidMinimum || selectedSpriteIndex >= sprites.Count)
|
| 606 |
+
return;
|
| 607 |
+
|
| 608 |
+
var sprite = sprites[selectedSpriteIndex];
|
| 609 |
+
|
| 610 |
+
if (sprite == null)
|
| 611 |
+
return;
|
| 612 |
+
|
| 613 |
+
if (m_PreviewSprite != sprite)
|
| 614 |
+
{
|
| 615 |
+
m_PreviewSprite = sprite;
|
| 616 |
+
EditorSpriteGUIUtility.DrawSpriteInRectPrepare(rect, sprite, EditorSpriteGUIUtility.FitMode.Tiled, true, true, previewSpriteMesh);
|
| 617 |
+
}
|
| 618 |
+
|
| 619 |
+
var material = EditorSpriteGUIUtility.spriteMaterial;
|
| 620 |
+
material.mainTexture = EditorSpriteGUIUtility.GetOriginalSpriteTexture(sprite);
|
| 621 |
+
|
| 622 |
+
EditorSpriteGUIUtility.DrawMesh(previewSpriteMesh, material, rect.center, Quaternion.AngleAxis(m_PreviewAngle, Vector3.forward), new Vector3(1f, -1f, 1f));
|
| 623 |
+
}
|
| 624 |
+
|
| 625 |
+
private void HandleSpritePreviewCycle(Rect rect)
|
| 626 |
+
{
|
| 627 |
+
if (!isSelectedIndexValid)
|
| 628 |
+
return;
|
| 629 |
+
|
| 630 |
+
Debug.Assert(m_AngleRangeSpriteList != null);
|
| 631 |
+
|
| 632 |
+
var spriteIndex = GetPreviewSpriteIndex(selectedIndex);
|
| 633 |
+
var sprites = angleRanges[selectedIndex].sprites;
|
| 634 |
+
|
| 635 |
+
var ev = Event.current;
|
| 636 |
+
if (ev.type == EventType.MouseDown && ev.button == 0 && HandleUtility.nearestControl == 0 &&
|
| 637 |
+
ContainsPosition(rect, ev.mousePosition, m_PreviewAngle) && spriteIndex != kInvalidMinimum && sprites.Count > 0)
|
| 638 |
+
{
|
| 639 |
+
spriteIndex = Mathf.RoundToInt(Mathf.Repeat(spriteIndex + 1f, sprites.Count));
|
| 640 |
+
SetPreviewSpriteIndex(selectedIndex, spriteIndex);
|
| 641 |
+
|
| 642 |
+
m_AngleRangeSpriteList.GrabKeyboardFocus();
|
| 643 |
+
m_AngleRangeSpriteList.index = spriteIndex;
|
| 644 |
+
|
| 645 |
+
ev.Use();
|
| 646 |
+
}
|
| 647 |
+
}
|
| 648 |
+
|
| 649 |
+
private bool ContainsPosition(Rect rect, Vector2 position, float angle)
|
| 650 |
+
{
|
| 651 |
+
Vector2 delta = position - rect.center;
|
| 652 |
+
position = (Vector2)(Quaternion.AngleAxis(-angle, Vector3.forward) * (Vector3)delta) + rect.center;
|
| 653 |
+
return rect.Contains(position);
|
| 654 |
+
}
|
| 655 |
+
}
|
| 656 |
+
}
|