private bool IsMouseOverOutlinePoints() { bool result; if (this.m_Selected == null) { result = false; } else { Vector2 b = new Vector2(0.5f * this.m_Selected.rect.width + this.m_Selected.rect.x, 0.5f * this.m_Selected.rect.height + this.m_Selected.rect.y); float handleSize = this.GetHandleSize(); Rect rect = new Rect(0f, 0f, handleSize * 2f, handleSize * 2f); for (int i = 0; i < this.selectedShapeOutline.Count; i++) { SpriteOutline spriteOutline = this.selectedShapeOutline[i]; for (int j = 0; j < spriteOutline.Count; j++) { rect.center = spriteOutline[j] + b; if (rect.Contains(this.m_MousePosition)) { result = true; return(result); } } } result = false; } return(result); }
public SpriteOutlineList(GUID guid, List <Vector2[]> list) { this.spriteID = guid; this.m_SpriteOutlines = new List <SpriteOutline>(list.Count); for (int i = 0; i < list.Count; i++) { SpriteOutline spriteOutline = new SpriteOutline(); spriteOutline.m_Path.AddRange(list[i]); this.m_SpriteOutlines.Add(spriteOutline); } }
public SpriteOutlineList(GUID guid, List <Vector2[]> list) { this.spriteID = guid; m_SpriteOutlines = new List <SpriteOutline>(list.Count); for (int i = 0; i < list.Count; ++i) { var newList = new SpriteOutline(); newList.m_Path.AddRange(list[i]); m_SpriteOutlines.Add(newList); } }
public Vector3 GetPointPosition(int outlineIndex, int pointIndex) { Vector3 result; if (outlineIndex >= 0 && outlineIndex < this.selectedShapeOutline.Count) { SpriteOutline spriteOutline = this.selectedShapeOutline[outlineIndex]; if (pointIndex >= 0 && pointIndex < spriteOutline.Count) { result = this.ConvertSpriteRectSpaceToTextureSpace(spriteOutline[pointIndex]); return(result); } } result = new Vector3(float.NaN, float.NaN, float.NaN); return(result); }
protected static List <SpriteOutline> GenerateSpriteRectOutline(Rect rect, float detail, byte alphaTolerance, ITextureDataProvider textureProvider) { List <SpriteOutline> outline = new List <SpriteOutline>(); var texture = textureProvider.GetReadableTexture2D(); if (texture != null) { Vector2[][] paths; // we might have a texture that is capped because of max size or NPOT. // in that case, we need to convert values from capped space to actual texture space and back. int actualWidth = 0, actualHeight = 0; int cappedWidth, cappedHeight; textureProvider.GetTextureActualWidthAndHeight(out actualWidth, out actualHeight); cappedWidth = texture.width; cappedHeight = texture.height; Vector2 scale = new Vector2(cappedWidth / (float)actualWidth, cappedHeight / (float)actualHeight); Rect spriteRect = rect; spriteRect.xMin *= scale.x; spriteRect.xMax *= scale.x; spriteRect.yMin *= scale.y; spriteRect.yMax *= scale.y; Sprites.SpriteUtility.GenerateOutline(texture, spriteRect, detail, alphaTolerance, true, out paths); Rect capRect = new Rect(); capRect.size = rect.size; capRect.center = Vector2.zero; for (int j = 0; j < paths.Length; ++j) { SpriteOutline points = new SpriteOutline(); foreach (Vector2 v in paths[j]) { points.Add(CapPointToRect(new Vector2(v.x / scale.x, v.y / scale.y), capRect)); } outline.Add(points); } } return(outline); }
public void CreateNewOutline(Rect rectOutline) { Rect rect = this.m_Selected.rect; if (rect.Contains(rectOutline.min) && rect.Contains(rectOutline.max)) { this.RecordUndo(); SpriteOutline spriteOutline = new SpriteOutline(); Vector2 b = new Vector2(0.5f * rect.width + rect.x, 0.5f * rect.height + rect.y); Rect rect2 = new Rect(rectOutline); rect2.min = this.SnapPoint(rectOutline.min); rect2.max = this.SnapPoint(rectOutline.max); spriteOutline.Add(SpriteOutlineModule.CapPointToRect(new Vector2(rect2.xMin, rect2.yMin), rect) - b); spriteOutline.Add(SpriteOutlineModule.CapPointToRect(new Vector2(rect2.xMin, rect2.yMax), rect) - b); spriteOutline.Add(SpriteOutlineModule.CapPointToRect(new Vector2(rect2.xMax, rect2.yMax), rect) - b); spriteOutline.Add(SpriteOutlineModule.CapPointToRect(new Vector2(rect2.xMax, rect2.yMin), rect) - b); this.selectedShapeOutline.Add(spriteOutline); this.spriteEditorWindow.SetDataModified(); this.shapeEditorDirty = true; } }
public void CreateNewOutline(Rect rectOutline) { Rect rect = m_Selected.rect; if (rect.Contains(rectOutline.min) && rect.Contains(rectOutline.max)) { RecordUndo(); SpriteOutline so = new SpriteOutline(); Vector2 outlineOffset = new Vector2(0.5f * rect.width + rect.x, 0.5f * rect.height + rect.y); Rect selectionRect = new Rect(rectOutline); selectionRect.min = SnapPoint(rectOutline.min); selectionRect.max = SnapPoint(rectOutline.max); so.Add(CapPointToRect(new Vector2(selectionRect.xMin, selectionRect.yMin), rect) - outlineOffset); so.Add(CapPointToRect(new Vector2(selectionRect.xMin, selectionRect.yMax), rect) - outlineOffset); so.Add(CapPointToRect(new Vector2(selectionRect.xMax, selectionRect.yMax), rect) - outlineOffset); so.Add(CapPointToRect(new Vector2(selectionRect.xMax, selectionRect.yMin), rect) - outlineOffset); selectedShapeOutline.Add(so); spriteEditorWindow.SetDataModified(); shapeEditorDirty = true; } }
protected static List <SpriteOutline> GenerateSpriteRectOutline(Rect rect, ITexture2D texture, float detail, byte alphaTolerance) { List <SpriteOutline> list = new List <SpriteOutline>(); if (texture != null) { int num = 0; int num2 = 0; UnityEditor.TextureImporter textureImporter = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(texture)) as UnityEditor.TextureImporter; textureImporter.GetWidthAndHeight(ref num, ref num2); int width = texture.width; int height = texture.height; Vector2 vector = new Vector2((float)width / (float)num, (float)height / (float)num2); Rect rect2 = rect; rect2.xMin *= vector.x; rect2.xMax *= vector.x; rect2.yMin *= vector.y; rect2.yMax *= vector.y; Vector2[][] array; UnityEditor.Sprites.SpriteUtility.GenerateOutline(texture, rect2, detail, alphaTolerance, true, out array); Rect r = default(Rect); r.size = rect.size; r.center = Vector2.zero; for (int i = 0; i < array.Length; i++) { SpriteOutline spriteOutline = new SpriteOutline(); Vector2[] array2 = array[i]; for (int j = 0; j < array2.Length; j++) { Vector2 vector2 = array2[j]; spriteOutline.Add(SpriteOutlineModule.CapPointToRect(new Vector2(vector2.x / vector.x, vector2.y / vector.y), r)); } list.Add(spriteOutline); } } return(list); }