public SpriteMetaData[] GetSpriteSheet(SpriteAlignment spriteAlignment, float customX, float customY)
        {
            SpriteMetaData[] metaData = new SpriteMetaData[frames.Count];

            for (int i = 0; i < frames.Count; i++)
            {
                AsepriteFrame  frame  = frames[i];
                SpriteMetaData sprite = new SpriteMetaData();

                // sprite alignment
                sprite.alignment = (int)spriteAlignment;
                if (spriteAlignment == SpriteAlignment.Custom)
                {
                    sprite.pivot.x = customX;
                    sprite.pivot.y = customY;
                }

                sprite.name = frame.filename.Replace(".ase", "");
                sprite.rect = new Rect(frame.x, frame.y, frame.width, frame.height);

                metaData[i] = sprite;
            }

            return(metaData);
        }
Exemplo n.º 2
0
        // ================================================================================
        //  Sprite Data
        // --------------------------------------------------------------------------------

        static Vector2 GetPivotValue(SpriteAlignment alignment, Vector2 customOffset)
        {
            switch (alignment)
            {
            case SpriteAlignment.TopLeft:
                return(new Vector2(0f, 1f));

            case SpriteAlignment.TopCenter:
                return(new Vector2(0.5f, 1f));

            case SpriteAlignment.TopRight:
                return(new Vector2(1f, 1f));

            case SpriteAlignment.LeftCenter:
                return(new Vector2(0f, 0.5f));

            case SpriteAlignment.Center:
                return(new Vector2(0.5f, 0.5f));

            case SpriteAlignment.RightCenter:
                return(new Vector2(1f, 0.5f));

            case SpriteAlignment.BottomLeft:
                return(new Vector2(0f, 0f));

            case SpriteAlignment.BottomCenter:
                return(new Vector2(0.5f, 0f));

            case SpriteAlignment.BottomRight:
                return(new Vector2(1f, 0f));
            }

            return(customOffset);
        }
		public static Vector2 GetPivotValue(SpriteAlignment alignment, Vector2 customOffset)
		{
			switch (alignment)
			{
			case SpriteAlignment.Center:
				return new Vector2(0.5f, 0.5f);
			case SpriteAlignment.TopLeft:
				return new Vector2(0f, 1f);
			case SpriteAlignment.TopCenter:
				return new Vector2(0.5f, 1f);
			case SpriteAlignment.TopRight:
				return new Vector2(1f, 1f);
			case SpriteAlignment.LeftCenter:
				return new Vector2(0f, 0.5f);
			case SpriteAlignment.RightCenter:
				return new Vector2(1f, 0.5f);
			case SpriteAlignment.BottomLeft:
				return new Vector2(0f, 0f);
			case SpriteAlignment.BottomCenter:
				return new Vector2(0.5f, 0f);
			case SpriteAlignment.BottomRight:
				return new Vector2(1f, 0f);
			case SpriteAlignment.Custom:
				return customOffset;
			default:
				return Vector2.zero;
			}
		}
Exemplo n.º 4
0
        protected static SpriteMetaData[] GetSpriteMetaData(string nameSprite, int numberSubSprites, Vector4 sizeData)
        {
            List <SpriteMetaData> spriteMetaList = new List <SpriteMetaData>();
            string name = Path.GetFileNameWithoutExtension(nameSprite);

            for (int i = 0; i < numberSubSprites; i++)
            {
                SpriteMetaData spriteMetaData = new SpriteMetaData();
                spriteMetaData.name = name + "_" + i.ToString();
                spriteMetaData.rect = new Rect(sizeData.x * i, 0f, sizeData.x, sizeData.y);
                SpriteAlignment alignment = GetSpriteAlignment(sizeData);
                if (alignment == SpriteAlignment.Custom)
                {
                    spriteMetaData.alignment = (int)SpriteAlignment.Custom;
                    spriteMetaData.pivot     = new Vector2(sizeData.z, sizeData.w);
                }
                else
                {
                    spriteMetaData.alignment = (int)alignment;
                }

                spriteMetaList.Add(spriteMetaData);
            }

            return(spriteMetaList.ToArray());
        }
Exemplo n.º 5
0
    private static Vector2 GetPivotValue(SpriteAlignment alignment)
    {
        switch (alignment)
        {
        case SpriteAlignment.Center:
            return(new Vector2(0.5f, 0.5f));

        case SpriteAlignment.TopLeft:
            return(new Vector2(0.0f, 1f));

        case SpriteAlignment.TopCenter:
            return(new Vector2(0.5f, 1f));

        case SpriteAlignment.TopRight:
            return(new Vector2(1f, 1f));

        case SpriteAlignment.LeftCenter:
            return(new Vector2(0.0f, 0.5f));

        case SpriteAlignment.RightCenter:
            return(new Vector2(1f, 0.5f));

        case SpriteAlignment.BottomLeft:
            return(new Vector2(0.0f, 0.0f));

        case SpriteAlignment.BottomCenter:
            return(new Vector2(0.5f, 0.0f));

        case SpriteAlignment.BottomRight:
            return(new Vector2(1f, 0.0f));

        default:
            return(Vector2.zero);
        }
    }
        protected void HandlePivotHandle()
        {
            if (!hasSelected)
            {
                return;
            }

            EditorGUI.BeginChangeCheck();

            SpriteAlignment alignment = selectedSpriteAlignment;
            Vector2         pivot     = selectedSpritePivot;
            Rect            rect      = selectedSpriteRect;

            pivot = ApplySpriteAlignmentToPivot(pivot, rect, alignment);
            Vector2 pivotHandlePosition = SpriteEditorHandles.PivotSlider(rect, pivot, styles.pivotdot, styles.pivotdotactive);

            if (EditorGUI.EndChangeCheck())
            {
                // Pivot snapping only happen when ctrl is press. Same as scene view snapping move
                if (eventSystem.current.control)
                {
                    SnapPivot(pivotHandlePosition, out pivot, out alignment);
                }
                else
                {
                    pivot     = pivotHandlePosition;
                    alignment = SpriteAlignment.Custom;
                }
                SetSpritePivotAndAlignment(pivot, alignment);
                PopulateSpriteFrameInspectorField();
            }
        }
Exemplo n.º 7
0
    public static void Popup(Rect rect, SpriteAlignment alignment, Action <SpriteAlignment> callback)
    {
        var popup = new SpriteAlignUI();

        popup.SetData(rect, alignment, callback);
        PopupWindow.Show(rect, popup);
    }
Exemplo n.º 8
0
        static public Vector2 GetVector2(this SpriteAlignment item)
        {
            switch (item)
            {
            case SpriteAlignment.Center: return(new Vector2(0.5f, 0.5f));

            case SpriteAlignment.TopLeft: return(new Vector2(0.0f, 1.0f));

            case SpriteAlignment.TopCenter: return(new Vector2(0.5f, 1.0f));

            case SpriteAlignment.TopRight: return(new Vector2(1.0f, 1.0f));

            case SpriteAlignment.LeftCenter: return(new Vector2(0.0f, 0.5f));

            case SpriteAlignment.RightCenter: return(new Vector2(1.0f, 0.5f));

            case SpriteAlignment.BottomLeft: return(new Vector2(0.0f, 0.0f));

            case SpriteAlignment.BottomCenter: return(new Vector2(0.5f, 0.0f));

            case SpriteAlignment.BottomRight: return(new Vector2(1.0f, 0.0f));

            case SpriteAlignment.Custom: return(new Vector2(-10.0f, -10.0f));
            }

            throw new UnaccountedBranchException("item", item);
        }
Exemplo n.º 9
0
        protected void SnapPivot(Vector2 pivot, out Vector2 outPivot, out SpriteAlignment outAlignment)
        {
            Rect rect = selectedSpriteRect;

            // Convert from normalized space to texture space
            Vector2 texturePos = new Vector2(rect.xMin + rect.width * pivot.x, rect.yMin + rect.height * pivot.y);

            Vector2[] snapPoints = GetSnapPointsArray(rect);

            // Snapping is now a firm action, it will always snap to one of the snapping points.
            SpriteAlignment snappedAlignment = SpriteAlignment.Custom;
            float           nearestDistance  = float.MaxValue;

            for (int alignment = 0; alignment < snapPoints.Length; alignment++)
            {
                float distance = (texturePos - snapPoints[alignment]).magnitude * m_Zoom;
                if (distance < nearestDistance)
                {
                    snappedAlignment = (SpriteAlignment)alignment;
                    nearestDistance  = distance;
                }
            }

            outAlignment = snappedAlignment;
            outPivot     = ConvertFromTextureToNormalizedSpace(snapPoints[(int)snappedAlignment], rect);
        }
Exemplo n.º 10
0
        // ================================================================================
        //  Sprite Data
        // --------------------------------------------------------------------------------

        public SpriteMetaData[] GetSpriteSheet(SpriteAlignment spriteAlignment, float customX, float customY)
        {
            SpriteMetaData[] metaData = new SpriteMetaData[frames.Count];

            for (int i = 0; i < frames.Count; i++)
            {
                ImportedAnimationFrame spriteInfo     = frames[i];
                SpriteMetaData         spriteMetaData = new SpriteMetaData();

                // sprite alignment
                spriteMetaData.alignment = (int)spriteAlignment;
                if (spriteAlignment == SpriteAlignment.Custom)
                {
                    spriteMetaData.pivot.x = customX;
                    spriteMetaData.pivot.y = customY;
                }

                spriteMetaData.name = spriteInfo.name;
                spriteMetaData.rect = new Rect(spriteInfo.x, spriteInfo.y, spriteInfo.width, spriteInfo.height);

                metaData[i] = spriteMetaData;
            }

            return(metaData);
        }
Exemplo n.º 11
0
    public void Draw(Rect r, SpriteAlignment align)
    {
        if (_icon != null)
        {
            var x = r.x;
            if (align == SpriteAlignment.TopCenter || align == SpriteAlignment.Center || align == SpriteAlignment.BottomCenter)
            {
                x += (r.width - _icon.width) / 2;
            }
            if (align == SpriteAlignment.TopRight || align == SpriteAlignment.RightCenter || align == SpriteAlignment.BottomRight)
            {
                x += r.width - _icon.width;
            }

            var y = r.y;
            if (align == SpriteAlignment.RightCenter || align == SpriteAlignment.Center || align == SpriteAlignment.BottomCenter)
            {
                y += (r.height - _icon.height) / 2;
            }
            if (align == SpriteAlignment.TopRight || align == SpriteAlignment.TopCenter || align == SpriteAlignment.TopLeft)
            {
                y += r.height - _icon.height;
            }

            GUI.Label(new Rect(x, y, _icon.width, _icon.height), _icon);
        }
    }
		public Vector3 GetGroupPosition(GameObject groupRoot, SpriteAlignment alignment)
		{
			Transform t = groupRoot.transform;

			// Find all the SpriteRenderers that are children of the layer group
			var spriteList = t.GetComponentsInChildren<SpriteRenderer>();

			Vector3 min = new Vector3(float.MaxValue, float.MaxValue);
			Vector3 max = new Vector3(float.MinValue, float.MinValue);

			// From the SpriteRenderers, find the size of
			// the layer group by the bounds of the renderers
			foreach (var sprite in spriteList)
			{
				var bounds = sprite.bounds;
				min = Vector3.Min(min, bounds.min);
				max = Vector3.Max(max, bounds.max);
			}

			// Calculate the position for this layer group
			Vector2 pivot = PsdBuilder.GetPivot(alignment);
			Vector3 pos = Vector3.zero;
			pos.x = Mathf.Lerp(min.x, max.x, pivot.x);
			pos.y = Mathf.Lerp(min.y, max.y, pivot.y);
			return pos;
		}
        void OnGUI()
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label("Sheet to re-align:", EditorStyles.boldLabel);
            sheetToEdit = (Texture2D)EditorGUILayout.ObjectField(sheetToEdit, typeof(Texture2D), false, GUILayout.Width(220));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("New Pivot:", EditorStyles.boldLabel);
            newPivot = (SpriteAlignment)EditorGUILayout.EnumFlagsField(newPivot);
            GUILayout.EndHorizontal();

            GUILayout.Space(25f);
            if (GUILayout.Button("Change all pivots"))
            {
                if (sheetToEdit == null)
                {
                    Debug.LogWarning("Must select a spritesheet");
                }
                else
                {
                    ChangePivots();
                }
            }
        }
		public Vector3 GetGroupPosition(GameObject groupRoot, SpriteAlignment alignment)
		{

			Vector2 min = new Vector2(float.MaxValue, float.MaxValue);
			Vector2 max = new Vector2(float.MinValue, float.MinValue);

			var tList = groupRoot.GetComponentsInChildren<RectTransform>();
			foreach (var rectTransform in tList)
			{
				if (rectTransform.gameObject == groupRoot)
					continue;

				var rectSize = rectTransform.sizeDelta;
				var rectPivot = rectTransform.pivot;

				var calcMin = rectTransform.position;
				calcMin.x -= rectSize.x * rectPivot.x;
				calcMin.y -= rectSize.y * rectPivot.y;

				var calcMax = calcMin + new Vector3(rectSize.x, rectSize.y);

				min = Vector2.Min(min, calcMin);
				max = Vector2.Max(max, calcMax);
			}

			Vector2 pivot = PsdBuilder.GetPivot(alignment);
			Vector3 pos = Vector3.zero;
			pos.x = Mathf.Lerp(min.x, max.x, pivot.x);
			pos.y = Mathf.Lerp(min.y, max.y, pivot.y);
			return pos;
		}
Exemplo n.º 15
0
        public static Vector2 GetRelativePos(this SpriteAlignment alignment, Vector2 customPivot)
        {
            switch (alignment)
            {
            case SpriteAlignment.BottomCenter: return(new Vector2(0.5f, 0));

            case SpriteAlignment.BottomLeft:   return(new Vector2(0f, 0));

            case SpriteAlignment.BottomRight:  return(new Vector2(1f, 0));

            case SpriteAlignment.Center:       return(new Vector2(0.5f, 0.5f));

            case SpriteAlignment.Custom:       return(customPivot);

            case SpriteAlignment.LeftCenter:   return(new Vector2(0, 0.5f));

            case SpriteAlignment.RightCenter:  return(new Vector2(1, 0.5f));

            case SpriteAlignment.TopCenter:    return(new Vector2(0.5f, 1f));

            case SpriteAlignment.TopLeft:      return(new Vector2(0.0f, 1f));

            case SpriteAlignment.TopRight:     return(new Vector2(1.0f, 1f));

            default: return(Vector2.zero);
            }
        }
Exemplo n.º 16
0
    public Vector2 GetVertex(SpriteAlignment alignment)
    {
        const float CELL_SIZE = 0.7f;
        float halfOfCellSize = CELL_SIZE / 2.0f;
        int horizontalModifier;
        int verticalModifier;
        switch (alignment)
        {
            case SpriteAlignment.TopLeft:
                horizontalModifier = -1;
                verticalModifier = 1;
                break;
            case SpriteAlignment.TopRight:
                horizontalModifier = 1;
                verticalModifier = 1;
                break;
            case SpriteAlignment.BottomLeft:
                horizontalModifier = -1;
                verticalModifier = -1;
                break;
            case SpriteAlignment.BottomRight:
                horizontalModifier = 1;
                verticalModifier = -1;
                break;
            default:
                // Default is top left
                horizontalModifier = -1;
                verticalModifier = 1;
                break;
        }

        return new Vector2(position.x + (horizontalModifier * halfOfCellSize), position.y + (verticalModifier * halfOfCellSize));
    }
Exemplo n.º 17
0
        public static Vector2 GetPivot(SpriteAlignment spriteAlignment)
        {
            Vector2 pivot = new Vector2(0.5f, 0.5f);

            if (spriteAlignment == SpriteAlignment.TopLeft ||
                spriteAlignment == SpriteAlignment.LeftCenter ||
                spriteAlignment == SpriteAlignment.BottomLeft)
            {
                pivot.x = 0f;
            }
            if (spriteAlignment == SpriteAlignment.TopRight ||
                spriteAlignment == SpriteAlignment.RightCenter ||
                spriteAlignment == SpriteAlignment.BottomRight)
            {
                pivot.x = 1;
            }
            if (spriteAlignment == SpriteAlignment.TopLeft ||
                spriteAlignment == SpriteAlignment.TopCenter ||
                spriteAlignment == SpriteAlignment.TopRight)
            {
                pivot.y = 1;
            }
            if (spriteAlignment == SpriteAlignment.BottomLeft ||
                spriteAlignment == SpriteAlignment.BottomCenter ||
                spriteAlignment == SpriteAlignment.BottomRight)
            {
                pivot.y = 0;
            }
            return(pivot);
        }
Exemplo n.º 18
0
		public static void BuildSprites(GameObject root, PSDLayerGroupInfo group,
										PsdExportSettings settings, PsdFileInfo fileInfo,
										SpriteAlignment createAlign)
		{
			BuildPsd(root, group, settings, fileInfo,
					createAlign, new SpriteConstructor());
		}
Exemplo n.º 19
0
        public Vector3 GetGroupPosition(GameObject groupRoot, SpriteAlignment alignment)
        {
            Vector2 min = new Vector2(float.MaxValue, float.MaxValue);
            Vector2 max = new Vector2(float.MinValue, float.MinValue);

            var tList = groupRoot.GetComponentsInChildren <RectTransform>();

            foreach (var rectTransform in tList)
            {
                if (rectTransform.gameObject == groupRoot)
                {
                    continue;
                }

                var rectSize  = rectTransform.sizeDelta;
                var rectPivot = rectTransform.pivot;

                var calcMin = rectTransform.position;
                calcMin.x -= rectSize.x * rectPivot.x;
                calcMin.y -= rectSize.y * rectPivot.y;

                var calcMax = calcMin + new Vector3(rectSize.x, rectSize.y);

                min = Vector2.Min(min, calcMin);
                max = Vector2.Max(max, calcMax);
            }

            Vector2 pivot = PsdBuilder.GetPivot(alignment);
            Vector3 pos   = Vector3.zero;

            pos.x = Mathf.Lerp(min.x, max.x, pivot.x);
            pos.y = Mathf.Lerp(min.y, max.y, pivot.y);
            return(pos);
        }
Exemplo n.º 20
0
    private void SetPosition(RectTransform parent, Rect r, SpriteAlignment alignment, bool useCloseButton)
    {
        closeButton.SetActive(useCloseButton);
        var rt = GetObserver().GetComponent <RectTransform>();

        UIController.PositionElement(rt, parent, alignment, r);
    }
Exemplo n.º 21
0
 //SpriteEditorUtility
 public static Vector2 GetPivotValue(SpriteAlignment alignment, Vector2 customOffset)
 {
     switch (alignment)
     {
         case SpriteAlignment.Center:
             return new Vector2(0.5f, 0.5f);
         case SpriteAlignment.TopLeft:
             return new Vector2(0.0f, 1f);
         case SpriteAlignment.TopCenter:
             return new Vector2(0.5f, 1f);
         case SpriteAlignment.TopRight:
             return new Vector2(1f, 1f);
         case SpriteAlignment.LeftCenter:
             return new Vector2(0.0f, 0.5f);
         case SpriteAlignment.RightCenter:
             return new Vector2(1f, 0.5f);
         case SpriteAlignment.BottomLeft:
             return new Vector2(0.0f, 0.0f);
         case SpriteAlignment.BottomCenter:
             return new Vector2(0.5f, 0.0f);
         case SpriteAlignment.BottomRight:
             return new Vector2(1f, 0.0f);
         case SpriteAlignment.Custom:
             return customOffset;
         default:
             return Vector2.zero;
     }
 }
Exemplo n.º 22
0
 public void SetSpritePivotAndAlignment(Vector2 pivot, SpriteAlignment alignment)
 {
     undoSystem.RegisterCompleteObjectUndo(m_RectsCache, "Change Sprite Pivot");
     spriteEditor.SetDataModified();
     selected.alignment = alignment;
     selected.pivot     = SpriteEditorUtility.GetPivotValue(alignment, pivot);
 }
Exemplo n.º 23
0
    public void SetPosition(Rect r, SpriteAlignment alignment, bool drawOnMainCanvas)
    {
        var rt = GetComponent <RectTransform>();

        if (workOnMainCanvas != drawOnMainCanvas)
        {
            rt.transform.parent = drawOnMainCanvas ? UIController.current.mainCanvas : GameMaster.realMaster.globalMap.observer.GetComponent <GlobalMapUI>().GetMapCanvas();
            workOnMainCanvas    = drawOnMainCanvas;
            closeButton.SetActive(!workOnMainCanvas);
        }
        rt.position = r.position;
        rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, r.width);
        rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, r.height);
        Vector2 correctionVector = Vector2.zero;

        switch (alignment)
        {
        case SpriteAlignment.BottomRight: correctionVector = Vector2.left * rt.rect.width; break;

        case SpriteAlignment.RightCenter: correctionVector = new Vector2(-1f * rt.rect.width, -0.5f * rt.rect.height); break;

        case SpriteAlignment.TopRight: correctionVector = new Vector2(-1f * rt.rect.width, -1f * rt.rect.height); break;

        case SpriteAlignment.Center: correctionVector = new Vector2(-0.5f * rt.rect.width, -0.5f * rt.rect.height); break;

        case SpriteAlignment.TopCenter: correctionVector = new Vector2(-0.5f * rt.rect.width, -1f * rt.rect.height); break;

        case SpriteAlignment.BottomCenter: correctionVector = new Vector2(-0.5f * rt.rect.width, 0f); break;

        case SpriteAlignment.TopLeft: correctionVector = Vector2.down * rt.rect.height; break;

        case SpriteAlignment.LeftCenter: correctionVector = Vector2.down * rt.rect.height * 0.5f; break;
        }
        rt.anchoredPosition += correctionVector;
    }
Exemplo n.º 24
0
        private static Vector2 GetSpritePivot(SpriteAlignment alignment)
        {
            switch (alignment)
            {
            case SpriteAlignment.Center:
                return(new Vector2(.5f, .5f));

            case SpriteAlignment.TopLeft:
                return(new Vector2(0f, 1f));

            case SpriteAlignment.TopCenter:
                return(new Vector2(.5f, 1f));

            case SpriteAlignment.TopRight:
                return(new Vector2(1f, 1f));

            case SpriteAlignment.LeftCenter:
                return(new Vector2(0f, .5f));

            case SpriteAlignment.RightCenter:
                return(new Vector2(1f, .5f));

            case SpriteAlignment.BottomLeft:
                return(new Vector2(0f, 0f));

            case SpriteAlignment.BottomCenter:
                return(new Vector2(.5f, 0f));

            case SpriteAlignment.BottomRight:
                return(new Vector2(1f, 0f));
            }

            return(KazegamesEditor.spritePivot);
        }
Exemplo n.º 25
0
        public Vector3 GetGroupPosition(GameObject groupRoot, SpriteAlignment alignment)
        {
            Transform t = groupRoot.transform;

            // Find all the SpriteRenderers that are children of the layer group
            var spriteList = t.GetComponentsInChildren <SpriteRenderer>();

            Vector3 min = new Vector3(float.MaxValue, float.MaxValue);
            Vector3 max = new Vector3(float.MinValue, float.MinValue);

            // From the SpriteRenderers, find the size of
            // the layer group by the bounds of the renderers
            foreach (var sprite in spriteList)
            {
                var bounds = sprite.bounds;
                min = Vector3.Min(min, bounds.min);
                max = Vector3.Max(max, bounds.max);
            }

            // Calculate the position for this layer group
            Vector2 pivot = PsdBuilder.GetPivot(alignment);
            Vector3 pos   = Vector3.zero;

            pos.x = Mathf.Lerp(min.x, max.x, pivot.x);
            pos.y = Mathf.Lerp(min.y, max.y, pivot.y);
            return(pos);
        }
Exemplo n.º 26
0
        /// <summary>
        /// Copies shared data in from Preferences, used to upgrade versions of AnimationImporter
        /// </summary>
        public void CopyFromPreferences()
        {
            if (HasKeyInPreferences(PREFS_PREFIX + "spritePixelsPerUnit"))
            {
                _spritePixelsPerUnit = GetFloatFromPreferences(PREFS_PREFIX + "spritePixelsPerUnit");
            }
            if (HasKeyInPreferences(PREFS_PREFIX + "spriteTargetObjectType"))
            {
                _targetObjectType = (AnimationTargetObjectType)GetIntFromPreferences(PREFS_PREFIX + "spriteTargetObjectType");
            }
            if (HasKeyInPreferences(PREFS_PREFIX + "spriteAlignment"))
            {
                _spriteAlignment = (SpriteAlignment)GetIntFromPreferences(PREFS_PREFIX + "spriteAlignment");
            }
            if (HasKeyInPreferences(PREFS_PREFIX + "spriteAlignmentCustomX"))
            {
                _spriteAlignmentCustomX = GetFloatFromPreferences(PREFS_PREFIX + "spriteAlignmentCustomX");
            }
            if (HasKeyInPreferences(PREFS_PREFIX + "spriteAlignmentCustomY"))
            {
                _spriteAlignmentCustomY = GetFloatFromPreferences(PREFS_PREFIX + "spriteAlignmentCustomY");
            }

            if (HasKeyInPreferences(PREFS_PREFIX + "saveSpritesToSubfolder"))
            {
                _saveSpritesToSubfolder = GetBoolFromPreferences(PREFS_PREFIX + "saveSpritesToSubfolder");
            }
            if (HasKeyInPreferences(PREFS_PREFIX + "saveAnimationsToSubfolder"))
            {
                _saveAnimationsToSubfolder = GetBoolFromPreferences(PREFS_PREFIX + "saveAnimationsToSubfolder");
            }
            if (HasKeyInPreferences(PREFS_PREFIX + "automaticImporting"))
            {
                _automaticImporting = GetBoolFromPreferences(PREFS_PREFIX + "automaticImporting");
            }

            // Find all nonLoopingClip Prefences, load them into the sharedData.
            int    numOldClips  = 0;
            string loopCountKey = PREFS_PREFIX + "nonLoopCount";

            if (HasKeyInPreferences(loopCountKey))
            {
                numOldClips = GetIntFromPreferences(loopCountKey);
            }

            for (int i = 0; i < numOldClips; ++i)
            {
                string clipKey = PREFS_PREFIX + "nonLoopCount" + i.ToString();

                // If the clip hasn't already been moved to the shared data, do it now.
                if (HasKeyInPreferences(clipKey))
                {
                    var stringAtKey = GetStringFromPreferences(clipKey);
                    if (!_animationNamesThatDoNotLoop.Contains(stringAtKey))
                    {
                        _animationNamesThatDoNotLoop.Add(stringAtKey);
                    }
                }
            }
        }
Exemplo n.º 27
0
 public static void BuildSprites(GameObject root, PSDLayerGroupInfo group,
                                 PsdExportSettings settings, PsdFileInfo fileInfo,
                                 SpriteAlignment createAlign)
 {
     BuildPsd(root, group, settings, fileInfo,
              createAlign, new SpriteConstructor());
 }
Exemplo n.º 28
0
 protected void HandlePivotHandle()
 {
     if (this.hasSelected)
     {
         EditorGUI.BeginChangeCheck();
         SpriteAlignment alignment          = this.selectedSpriteAlignment;
         Vector2         vector             = this.selectedSpritePivot;
         Rect            selectedSpriteRect = this.selectedSpriteRect;
         vector = SpriteFrameModuleBase.ApplySpriteAlignmentToPivot(vector, selectedSpriteRect, alignment);
         Vector2 vector2 = SpriteEditorHandles.PivotSlider(selectedSpriteRect, vector, SpriteFrameModuleBase.styles.pivotdot, SpriteFrameModuleBase.styles.pivotdotactive);
         if (EditorGUI.EndChangeCheck())
         {
             if (this.eventSystem.current.control)
             {
                 this.SnapPivot(vector2, out vector, out alignment);
             }
             else
             {
                 vector    = vector2;
                 alignment = SpriteAlignment.Custom;
             }
             this.SetSpritePivotAndAlignment(vector, alignment);
         }
     }
 }
        public static void ShowValueBadge(this IBadgeContainer self,
                                          VisualElement parent,
                                          VisualElement target,
                                          SpriteAlignment alignment,
                                          string description, Color badgeColor)
        {
            Assert.IsNotNull(parent);
            Assert.IsTrue(self is VisualElement);

            if (self.ValueBadge == null)
            {
                self.ValueBadge = new ValueBadge();
                self.ValueBadge.AddToClassList("valueBadge");
                parent.Add(self.ValueBadge);
                self.ValueBadge.AttachTo(target, alignment);
            }
            else
            {
                self.ValueBadge.style.visibility = Visibility.Visible;
            }

            self.ValueBadge.BadgeColor = badgeColor;
            self.ValueBadge.Text       = description;

            target.EnableInClassList(k_HasValueBadge, true);
        }
Exemplo n.º 30
0
    static Vector2 ToCoords(SpriteAlignment _anchor)
    {
        switch (_anchor)
        {
        case SpriteAlignment.BottomLeft:
            return(new Vector2(0, 0));

        case SpriteAlignment.BottomCenter:
            return(new Vector2(0.5f, 0));

        case SpriteAlignment.BottomRight:
            return(new Vector2(1, 0));

        case SpriteAlignment.LeftCenter:
            return(new Vector2(0, 0.5f));

        case SpriteAlignment.Center:
            return(new Vector2(0.5f, 0.5f));

        case SpriteAlignment.RightCenter:
            return(new Vector2(1, 0.5f));

        case SpriteAlignment.TopLeft:
            return(new Vector2(0, 1));

        case SpriteAlignment.TopCenter:
            return(new Vector2(0.5f, 1));

        case SpriteAlignment.TopRight:
            return(new Vector2(1, 1));

        default:
            goto case SpriteAlignment.BottomLeft;
        }
    }
Exemplo n.º 31
0
    public void OnGUI()
    {
        xmlAsset = EditorGUILayout.ObjectField("XML Source", xmlAsset, typeof(TextAsset), false) as TextAsset;

        spriteAlignment = (SpriteAlignment)EditorGUILayout.EnumPopup("Pivot", spriteAlignment);

        bool enabled = GUI.enabled;

        if (spriteAlignment != SpriteAlignment.Custom)
        {
            GUI.enabled = false;
        }

        EditorGUILayout.Vector2Field("Custom Offset", customOffset);

        GUI.enabled = enabled;

        if (xmlAsset == null)
        {
            GUI.enabled = false;
        }

        if (GUILayout.Button("Slice"))
        {
            PerformSlice();
        }

        GUI.enabled = enabled;
    }
Exemplo n.º 32
0
        private static Vector2 GetAlignedPivot(SpriteAlignment alignment)
        {
            switch (alignment)
            {
            case SpriteAlignment.TopLeft:
                return(new Vector2(0, 1));

            case SpriteAlignment.TopCenter:
                return(new Vector2(.5f, 1));

            case SpriteAlignment.TopRight:
                return(new Vector2(1, 1));

            case SpriteAlignment.LeftCenter:
                return(new Vector2(0, .5f));

            case SpriteAlignment.Center:
                return(new Vector2(.5f, .5f));

            case SpriteAlignment.RightCenter:
                return(new Vector2(1, .5f));

            case SpriteAlignment.BottomLeft:
                return(new Vector2(0, 0));

            case SpriteAlignment.BottomCenter:
                return(new Vector2(.5f, 0));

            case SpriteAlignment.BottomRight:
                return(new Vector2(1, 0));
            }
            return(new Vector2(.5f, .5f));
        }
Exemplo n.º 33
0
    public void SetPosition(Rect r, SpriteAlignment alignment)
    {
        var rt = GetComponent <RectTransform>();

        rt.position = r.position;
        rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, r.width);
        rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, r.height);
        Vector2 correctionVector = Vector2.zero;

        switch (alignment)
        {
        case SpriteAlignment.BottomRight: correctionVector = Vector2.left * rt.rect.width; break;

        case SpriteAlignment.RightCenter: correctionVector = new Vector2(-1f * rt.rect.width, -0.5f * rt.rect.height); break;

        case SpriteAlignment.TopRight: correctionVector = new Vector2(-1f * rt.rect.width, -1f * rt.rect.height); break;

        case SpriteAlignment.Center: correctionVector = new Vector2(-0.5f * rt.rect.width, -0.5f * rt.rect.height); break;

        case SpriteAlignment.TopCenter: correctionVector = new Vector2(-0.5f * rt.rect.width, -1f * rt.rect.height); break;

        case SpriteAlignment.BottomCenter: correctionVector = new Vector2(-0.5f * rt.rect.width, 0f); break;

        case SpriteAlignment.TopLeft: correctionVector = Vector2.down * rt.rect.height; break;

        case SpriteAlignment.LeftCenter: correctionVector = Vector2.down * rt.rect.height * 0.5f; break;
        }
        rt.anchoredPosition += correctionVector;
    }
Exemplo n.º 34
0
        static bool CreateTileSprite(string targetPath, int pixelsPerUnit, int cellWidth, int cellHeight, int imageWidth, int imageHeight)
        {
            TextureImporter ti = AssetImporter.GetAtPath(targetPath) as TextureImporter;

            TextureImporterSettings textureSettings = new TextureImporterSettings();

            ti.ReadTextureSettings(textureSettings);

            SpriteMeshType  meshType   = SpriteMeshType.FullRect;
            SpriteAlignment alignment  = SpriteAlignment.Custom;
            Vector2         pivot      = GetPivot(imageWidth, imageHeight, cellWidth, cellHeight);
            FilterMode      filterMode = FilterMode.Point;

            if (textureSettings.spritePixelsPerUnit != pixelsPerUnit ||
                textureSettings.spriteMeshType != meshType ||
                textureSettings.spriteAlignment != (int)alignment ||
                textureSettings.spritePivot != pivot ||
                textureSettings.filterMode != filterMode)
            {
                textureSettings.spritePixelsPerUnit = pixelsPerUnit;
                textureSettings.spriteMeshType      = meshType;
                textureSettings.spriteAlignment     = (int)alignment;
                textureSettings.spritePivot         = pivot;
                textureSettings.filterMode          = filterMode;

                ti.SetTextureSettings(textureSettings);

                EditorUtility.SetDirty(ti);
                ti.SaveAndReimport();
            }

            return(true);
        }
Exemplo n.º 35
0
    void Split(Texture2D texture, Vector2Int grid, SpriteAlignment alignment)
    {
        var fn       = Path.GetFileNameWithoutExtension(assetPath);
        var importer = AssetImporter.GetAtPath(assetPath) as TextureImporter;

        importer.textureType      = TextureImporterType.Sprite;
        importer.spriteImportMode = SpriteImportMode.Single;
        importer.spriteImportMode = SpriteImportMode.Multiple;

        var metaData = new List <SpriteMetaData>();

        var nWidth  = grid.x;
        var nHeight = grid.y;

        var width  = texture.width / nWidth;
        var height = texture.height / nHeight;

        for (int h = nHeight - 1; h >= 0; h--)
        {
            for (int w = 0; w < nWidth; w++)
            {
                var data = new SpriteMetaData();
                data.alignment = (int)alignment;
                data.name      = $"{fn}_{metaData.Count}";
                data.rect      = new Rect(w * width, h * height, width, height);
                metaData.Add(data);
            }
        }
        importer.spritesheet = metaData.ToArray();
        AssetDatabase.SaveAssets();
    }
Exemplo n.º 36
0
    public static Rect ScreenAlign(this Rect input, SpriteAlignment align)
    {
        Vector2 size = new Vector2(input.width, input.height);

        // X align
        if (align == SpriteAlignment.TopLeft ||
            align == SpriteAlignment.LeftCenter ||
            align == SpriteAlignment.BottomLeft)
        {
            input.xMin = input.xMin;
        }

        if (align == SpriteAlignment.TopCenter ||
            align == SpriteAlignment.Center ||
            align == SpriteAlignment.BottomCenter)
        {
            input.xMin = (Screen.width / 2) + input.xMin;
        }

        if (align == SpriteAlignment.TopRight ||
            align == SpriteAlignment.RightCenter ||
            align == SpriteAlignment.BottomRight)
        {
            input.xMin = (Screen.width) - input.xMin;
        }

        // Y align
        if (align == SpriteAlignment.TopLeft ||
            align == SpriteAlignment.TopLeft ||
            align == SpriteAlignment.TopRight)
        {
            input.yMin = input.yMin;
        }
        if (align == SpriteAlignment.LeftCenter ||
            align == SpriteAlignment.Center ||
            align == SpriteAlignment.RightCenter)
        {
            input.yMin = (Screen.height / 2) + input.yMin;
        }
        if (align == SpriteAlignment.BottomLeft ||
            align == SpriteAlignment.BottomCenter ||
            align == SpriteAlignment.BottomRight)
        {
            input.yMin = (Screen.height) - input.yMin;
        }

        input.width = size.x;
        input.height = size.y;
        return input;
    }
Exemplo n.º 37
0
    void OnGUI()
    {
        text = EditorGUILayout.ObjectField("File: ", text, typeof(TextAsset), false);
        texture2d = (Texture2D)EditorGUILayout.ObjectField("Texture: ", texture2d, typeof(Texture2D), false);
        pivot = (SpriteAlignment)EditorGUILayout.EnumPopup("Pivot: ", pivot);
        if (pivot == SpriteAlignment.Custom)
        {
            Vector2 customPivotTemp = EditorGUILayout.Vector2Field("Custom pivot:", customPivot);
            //user change value,, it can be more than 1 or less than 0
            if (customPivotTemp != customPivot)
            {
                if (customPivotTemp.x > 1)
                {
                    customPivotTemp.x = 1;
                }
                else if (customPivotTemp.x < 0)
                {
                    customPivotTemp.x = 0;
                }
                if (customPivotTemp.y > 1)
                {
                    customPivotTemp.y = 1;
                }
                else if (customPivotTemp.y < 0)
                {
                    customPivotTemp.y = 0;
                }
                //apply changes
                customPivot = customPivotTemp;
            }
        }

        if (GUILayout.Button("Read") && text != null && texture2d != null)
        {
            Read();
        }
    }
Exemplo n.º 38
0
	public void OnGUI() {
		xmlAsset = EditorGUILayout.ObjectField("XML Source", xmlAsset, typeof (TextAsset), false) as TextAsset;

		spriteAlignment = (SpriteAlignment) EditorGUILayout.EnumPopup("Pivot", spriteAlignment);

		bool enabled = GUI.enabled;
		if (spriteAlignment != SpriteAlignment.Custom) {
			GUI.enabled = false;
		}

		EditorGUILayout.Vector2Field("Custom Offset", customOffset);

		GUI.enabled = enabled;

		if (xmlAsset == null) {
			GUI.enabled = false;
		}

		if (GUILayout.Button("Slice")) {
			PerformSlice();
		}

		GUI.enabled = enabled;
	}
Exemplo n.º 39
0
    static Vector2 ToCoords(SpriteAlignment _anchor)
    {
        switch (_anchor) {

        case SpriteAlignment.BottomLeft:
            return new Vector2(0, 0);

        case SpriteAlignment.BottomCenter:
            return new Vector2(0.5f, 0);

        case SpriteAlignment.BottomRight:
            return new Vector2(1, 0);

        case SpriteAlignment.LeftCenter:
            return new Vector2(0, 0.5f);

        case SpriteAlignment.Center:
            return new Vector2(0.5f, 0.5f);

        case SpriteAlignment.RightCenter:
            return new Vector2(1, 0.5f);

        case SpriteAlignment.TopLeft:
            return new Vector2(0, 1);

        case SpriteAlignment.TopCenter:
            return new Vector2(0.5f, 1);

        case SpriteAlignment.TopRight:
            return new Vector2(1, 1);

        default:
            goto case SpriteAlignment.BottomLeft;
        }
    }
Exemplo n.º 40
0
 private static Vector2 GetAlignedPivot(SpriteAlignment alignment)
 {
     switch (alignment)
     {
         case SpriteAlignment.TopLeft:
             return new Vector2(0, 1);
         case SpriteAlignment.TopCenter:
             return new Vector2(.5f, 1);
         case SpriteAlignment.TopRight:
             return new Vector2(1, 1);
         case SpriteAlignment.LeftCenter:
             return new Vector2(0, .5f);
         case SpriteAlignment.Center:
             return new Vector2(.5f, .5f);
         case SpriteAlignment.RightCenter:
             return new Vector2(1, .5f);
         case SpriteAlignment.BottomLeft:
             return new Vector2(0, 0);
         case SpriteAlignment.BottomCenter:
             return new Vector2(.5f, 0);
         case SpriteAlignment.BottomRight:
             return new Vector2(1, 0);
     }
     return new Vector2(.5f, .5f);
 }
Exemplo n.º 41
0
    public void OnGUI()
    {
        if (importer == null) {
            EditorGUILayout.LabelField("Please select a texture to slice.");
            return;
        }
        EditorGUI.BeginDisabledGroup(focusedWindow != this);
        {
            EditorGUI.BeginDisabledGroup(true);
            EditorGUILayout.ObjectField("Texture", Selection.activeObject, typeof (Texture), false);
            EditorGUI.EndDisabledGroup();

            if (importer.textureType != TextureImporterType.Sprite &&
                importer.textureType != TextureImporterType.Advanced) {
                EditorGUILayout.LabelField("The Texture Type needs to be Sprite or Advanced!");
            }

            EditorGUI.BeginDisabledGroup((importer.textureType != TextureImporterType.Sprite &&
                                          importer.textureType != TextureImporterType.Advanced));
            {
                EditorGUI.BeginChangeCheck();
                xmlAsset = EditorGUILayout.ObjectField("XML Source", xmlAsset, typeof (TextAsset), false) as TextAsset;
                if (EditorGUI.EndChangeCheck()) {
                    ParseXML();
                }

                spriteAlignment = (SpriteAlignment) EditorGUILayout.EnumPopup("Pivot", spriteAlignment);

                EditorGUI.BeginDisabledGroup(spriteAlignment != SpriteAlignment.Custom);
                EditorGUILayout.Vector2Field("Custom Offset", customOffset);
                EditorGUI.EndDisabledGroup();

                var needsToResizeTexture = wantedWidth > selectedTexture.width || wantedHeight > selectedTexture.height;

                if (xmlAsset != null && needsToResizeTexture) {
                    EditorGUILayout.LabelField(
                        string.Format("Texture size too small."
                                      + " It needs to be at least {0} by {1} pixels!",
                            wantedWidth,
                            wantedHeight));
                    EditorGUILayout.LabelField("Try changing the Max Size property in the importer.");
                }

                if (subTextures == null || subTextures.Length == 0) {
                    EditorGUILayout.LabelField("Could not find any SubTextures in XML.");
                }

                EditorGUI.BeginDisabledGroup(xmlAsset == null || needsToResizeTexture || subTextures == null ||
                                             subTextures.Length == 0);
                if (GUILayout.Button("Slice")) {
                    PerformSlice();
                }
                EditorGUI.EndDisabledGroup();
            }
            EditorGUI.EndDisabledGroup();
        }
        EditorGUI.EndDisabledGroup();
    }
Exemplo n.º 42
0
		public static Vector2 GetPivot(SpriteAlignment spriteAlignment)
		{
			Vector2 pivot = new Vector2(0.5f, 0.5f);
			if (spriteAlignment == SpriteAlignment.TopLeft ||
				spriteAlignment == SpriteAlignment.LeftCenter ||
				spriteAlignment == SpriteAlignment.BottomLeft)
			{
				pivot.x = 0f;
			}
			if (spriteAlignment == SpriteAlignment.TopRight ||
				spriteAlignment == SpriteAlignment.RightCenter ||
				spriteAlignment == SpriteAlignment.BottomRight)
			{
				pivot.x = 1;
			}
			if (spriteAlignment == SpriteAlignment.TopLeft ||
				spriteAlignment == SpriteAlignment.TopCenter ||
				spriteAlignment == SpriteAlignment.TopRight)
			{
				pivot.y = 1;
			}
			if (spriteAlignment == SpriteAlignment.BottomLeft ||
				spriteAlignment == SpriteAlignment.BottomCenter ||
				spriteAlignment == SpriteAlignment.BottomRight)
			{
				pivot.y = 0;
			}
			return pivot;
		}
Exemplo n.º 43
0
		public static void BuildPsd(GameObject root, PSDLayerGroupInfo group,
									PsdExportSettings settings, PsdFileInfo fileInfo,
									SpriteAlignment align, IPsdConstructor constructor)
		{
			// Run the export on non exported layers
			PSDExporter.Export(settings, fileInfo, false);

			// Find all the layers being exported
			var exportLayers = PSDExporter.GetExportLayers(settings, fileInfo);

			// Stores the root object for each encountered group
			Dictionary<PSDLayerGroupInfo, GameObject> groupHeaders = new Dictionary<PSDLayerGroupInfo, GameObject>();

			// Store the last parent, for traversal
			GameObject lastParent = root;

			GameObject rootBase = null;
			Transform rootBaseT = null;

			int groupVisibleMask = 1;
			int groupDepth = 0;

			// Loop through all the layers of the PSD file
			// backwards so they appear in the expected order
			// Going through all the layers, and not just the exported layers
			// so that the groups can be setup
			for (int i = group.end; i >= group.start; i--)
			{
				// Skip if layer is hidden
				if (fileInfo.LayerVisibility[i] == false)
					continue;

				var groupInfo = fileInfo.GetGroupByLayerIndex(i);
				bool inGroup = groupInfo != null;

				// Skip if layer belongs to a hidden group
				if (inGroup && groupInfo.visible == false)
					continue;

				// When inside a group...
				if (inGroup)
				{
					// Inverted because starting backwards
					bool startGroup = groupInfo.end == i;
					bool closeGroup = groupInfo.start == i;

					// Go up or down group depths
					if (startGroup)
					{
						groupDepth++;
						groupVisibleMask |= ((groupInfo.visible ? 1 : 0) << groupDepth);
					}
					if (closeGroup)
					{
						// Reset group visible flag when closing group
						groupVisibleMask &= ~(1 << groupDepth);
						groupDepth--;
					}

					// First, check if parents of this group is visible in the first place
					bool parentVisible = true;
					for (int parentMask = groupDepth - 1; parentMask > 0; parentMask--)
					{
						bool isVisible = (groupVisibleMask & (1 << parentMask)) > 0;
						parentVisible &= isVisible;
					}
					// Parents not visible, continue to next layer
					if (!parentVisible)
						continue;

					// Finally, check if layer being processed is start/end of group
					if (startGroup || closeGroup)
					{
						// If start or end of the group, call HandleGroupObject
						// which creates the group layer object and assignment of lastParent
						HandleGroupObject(groupInfo, groupHeaders,
										startGroup, constructor, ref lastParent);

						// A bunch of book keeping needs to be done at the start of a group
						if (startGroup)
						{
							// If this is the start of the group being constructed
							// store as the rootBase
							if (i == group.end)
							{
								rootBase = lastParent;
								rootBaseT = rootBase.transform;
							}
						}

						// Start or end group doesn't have visible sprite object, skip to next layer
						continue;
					}
				} // End processing of group start/end

				// If got to here, processing a visual layer

				// Skip if the export layers list doesn't contain this index
				if (exportLayers.Contains(i) == false)
					continue;

				// If got here and root base hasn't been set, that's a problem
				if (rootBase == null)
				{
					throw new Exception("Trying to create image layer before root base has been set");
				}

				// Get layer info
				Layer layer = settings.Psd.Layers[i];

				// Create the game object for the sprite
				GameObject spriteObject = constructor.CreateGameObject(layer.Name, lastParent);

				// Reparent created object to last parent
				if (lastParent != null)
					spriteObject.transform.SetParent(lastParent.transform, false);

				// Retrieve sprite from asset database
				string sprPath = PSDExporter.GetLayerFilename(settings, i);
				Sprite sprite = AssetDatabase.LoadAssetAtPath<Sprite>(sprPath);

				// Get the pivot settings for the sprite
				TextureImporter sprImporter = (TextureImporter)AssetImporter.GetAtPath(sprPath);
				TextureImporterSettings sprSettings = new TextureImporterSettings();
				sprImporter.ReadTextureSettings(sprSettings);
				sprImporter = null;

				// Add components to the sprite object for the visuals
				constructor.AddComponents(i, spriteObject, sprite, sprSettings);

				Transform spriteT = spriteObject.transform;

				// Reposition the sprite object according to PSD position
				Vector2 spritePivot = GetPivot(sprSettings);

				Vector3 layerPos = constructor.GetLayerPosition(layer.Rect, spritePivot, settings.PixelsToUnitSize);

				// Scaling factor, if sprites were scaled down
				float posScale = 1f;
				switch (settings.ScaleBy)
				{
					case 1:
						posScale = 0.5f;
						break;
					case 2:
						posScale = 0.25f;
						break;
				}
				layerPos *= posScale;

				// Sprite position is based on root object position initially
				spriteT.position = (rootBaseT.position + layerPos);
			} // End layer loop

			// Loop through the groups and reposition according to alignment
			var groups = groupHeaders.Values.ToArray();
			for (int grpIndex = 0; grpIndex < groups.Length; grpIndex++)
			{
				var groupObject = groups[grpIndex];
				if (groupObject == null)
					continue;

				Transform groupT = groupObject.transform;

				// Store the sibling index, order important for UI
				// reconstruction that was established earlier
				int siblingIndex = groupT.GetSiblingIndex();

				// Get the position from the root pos function
				Vector3 groupPos = constructor.GetGroupPosition(groupObject, align);

				// Create a new object
				GameObject newRoot = constructor.CreateGameObject(groupObject.name, groupObject);

				// Reparent new object to same parent as old group object
				Transform newRootT = newRoot.transform;
				newRootT.SetParent(groupT.parent);

				// Take over the sibling index of the old group object
				newRootT.SetSiblingIndex(siblingIndex);

				// Reposition the new object
				newRootT.position = groupPos;

				// Reparent the children from the old root object to new root
				while (groupT.childCount > 0)
				{
					groupT.GetChild(0).SetParent(newRootT, true);
				}

				// If the group we're handling is rootBaseT, position the
				// replacement group header over old root
				if (groupT == rootBaseT)
				{
					newRootT.position = rootBaseT.position;
				}

				// Destroy the old root
				Object.DestroyImmediate(groups[grpIndex]);
			} // End reposition loop

		} // End BuildPsd()
		public SpriteMetaData[] GetSpriteSheet(SpriteAlignment spriteAlignment, float customX, float customY)
		{
			SpriteMetaData[] metaData = new SpriteMetaData[frames.Count];

			for (int i = 0; i < frames.Count; i++)
			{
				AsepriteFrame frame = frames[i];
				SpriteMetaData sprite = new SpriteMetaData();

				// sprite alignment
				sprite.alignment = (int)spriteAlignment;
				if (spriteAlignment == SpriteAlignment.Custom)
				{
					sprite.pivot.x = customX;
					sprite.pivot.y = customY;
				}

				sprite.name = frame.filename.Replace(".ase","");
				sprite.rect = new Rect(frame.x, frame.y, frame.width, frame.height);

				metaData[i] = sprite;
			}

			return metaData;
		}
Exemplo n.º 45
0
    void OnGUI()
    {
        _xmlAsset = EditorGUILayout.ObjectField("XML file", _xmlAsset, typeof(TextAsset), false) as TextAsset;

        _alignment = (SpriteAlignment)EditorGUILayout.EnumPopup("Pivot", _alignment);

        bool enabled = GUI.enabled;
        if (_alignment != SpriteAlignment.Custom)
            GUI.enabled = false;

        _customOffset = EditorGUILayout.Vector2Field("Custom offset", _customOffset);

        GUI.enabled = enabled;

        if (_xmlAsset == null)
            GUI.enabled = false;

        if(GUILayout.Button("Slice"))
        {
            Slice();
        }

        GUI.enabled = enabled;
    }
		private void LoadMetaData()
		{
			AutoReImport = false;
			string[] pivotNameStrings = Enum.GetNames(typeof(SpriteAlignment));
			Array pivotNameVals = Enum.GetValues(typeof(SpriteAlignment));

			HasMetaData = false;
			string[] labels = AssetDatabase.GetLabels(Image);
			foreach (var label in labels)
			{
				if (label.Equals(TagImport1))
					ScaleBy = 0;
				if (label.Equals(TagImport2))
					ScaleBy = 1;
				if (label.Equals(TagImport4))
					ScaleBy = 2;

				if (label.StartsWith(TagImportAnchor))
				{
					string pivotType = label.Substring(12);
					if (pivotType.StartsWith("Custom"))
					{
						// Get the coordinates value inside the string "[]"
						//string values = pivotType.Substring(pivotType.IndexOf("["),
						//									pivotType.IndexOf("]"));
						//string[] vals = values.Split(',');
						//PivotVector = new Vector2(float.Parse(vals[0]), float.Parse(vals[1]));
						PivotVector = new Vector2(0.5f, 0.5f);
						Pivot = SpriteAlignment.Custom;
					}
					else
					{
						// Find by enum
						for (int i = 0; i < pivotNameStrings.Length; i++)
						{
							if (pivotType == pivotNameStrings[i])
								Pivot = (SpriteAlignment)pivotNameVals.GetValue(i);
						}
					}
				} // End import anchor if

				if (label.StartsWith(TagImportPTU))
				{
					string ptuVal = label.Substring(TagImportPTU.Length);
					PixelsToUnitSize = Single.Parse(ptuVal);
					HasMetaData = true;
				}

				if (label.StartsWith(TagImportPack))
				{
					string packTag = label.Substring(TagImportPack.Length);
					PackingTag = packTag;
				}

				if (label.StartsWith(TagExportPath))
				{
					string exportPath = label.Substring(TagExportPath.Length);
					ExportPath = exportPath;
				}

				if (label.StartsWith(TagExportAuto))
					AutoReImport = true;
			} // End label loop
		}
Exemplo n.º 47
0
 public Vector2 ApplySpriteAlignmentToPivot(Vector2 pivot, Rect rect, SpriteAlignment alignment)
 {
     Vector2[] snapPointsArray = this.GetSnapPointsArray(rect);
     if (alignment != SpriteAlignment.Custom)
     {
         Vector2 texturePos = snapPointsArray[(int) alignment];
         return this.ConvertFromTextureToNormalizedSpace(texturePos, rect);
     }
     return pivot;
 }
Exemplo n.º 48
0
 // Public interface.
 /**
  * @brief Set all parameters that effect mesh changes at once. Shortcut to the full fledged
  *	#SetTiling(), without the tile offset.
  *
  * @param _size Size of the tiled area.
  * @param _sprite Tile Sprite.
  * @param _anchor Position of the "first" tile respective to the tiled area. Custom results
  *	in Bottom Left (which is the default).
  *
  */
 public void SetTiling(Vector2 _size, Sprite _sprite, SpriteAlignment _anchor)
 {
     SetTiling(_size, _sprite, _anchor, new Vector2(0, 0));
 }
Exemplo n.º 49
0
    /**
     * @brief Set all parameters that effect mesh changes at once. For other settings, use
     *	respective properties.
     *
     * @param _size Size of the tiled area.
     * @param _sprite Tile Sprite.
     * @param _anchor Position of the "first" tile respective to the tiled area. Custom results
     *	in Bottom Left (which is the default).
     * @param _offset Offset of the "first" tile from the _anchor, in -1..1 tile range.
     *
     */
    public void SetTiling(Vector2 _size, Sprite _sprite, SpriteAlignment _anchor, Vector2 _offset)
    {
        m_size = _size;
        m_sprite = _sprite;
        m_tileAnchor = _anchor;
        m_tileOffset = _offset;

        UpdateTexRef();

        ValidateInput();
        UpdateMesh(false);
        UpdateMaterial();
    }
Exemplo n.º 50
0
    void ValidateInput()
    {
        // size
        if (Single.IsNaN(m_size.x) || Single.IsInfinity(m_size.x) || (m_size.x < 1)) {
            m_size.x = 1;
        }
        if (Single.IsNaN(m_size.y) || Single.IsInfinity(m_size.y) || (m_size.y < 1)) {
            m_size.y = 1;
        }

        // tile anchor
        if (m_tileAnchor == SpriteAlignment.Custom) {
            m_tileAnchor = SpriteAlignment.BottomLeft;
        }

        // tile offset
        if (Single.IsNaN(m_tileOffset.x)) {
            m_tileOffset.x = 0;
        }
        if (Single.IsNaN(m_tileOffset.y)) {
            m_tileOffset.y = 0;
        }
        m_tileOffset = new Vector2(Mathf.Clamp(m_tileOffset.x, -1, 1), Mathf.Clamp(m_tileOffset.y, -1, 1));

        // pivot
        if (m_pivot == SpriteAlignment.Custom) {
            m_pivot = SpriteAlignment.Center;
        }
    }
		public PsdExportSettings(Texture2D image)
		{
			string path = AssetDatabase.GetAssetPath(image);
			if (!path.ToUpper().EndsWith(".PSD"))
				return;

			Psd = new PsdFile(path, Encoding.Default);
			Filename = Path.GetFileNameWithoutExtension(path);
			Image = image;

			ScaleBy = 0;
			Pivot = SpriteAlignment.Center;
			PixelsToUnitSize = 100f;

			LoadMetaData();
		}