Exemplo n.º 1
0
 public SetRect( SetRect r )
 {
     if ( r.Orient ) {
         this.rect = new Rect( r.rect.x, r.rect.y + r.rect.height, r.rect.width, r.rect.height );
     } else {
         this.rect = new Rect( r.rect.x + r.rect.width, r.rect.y, r.rect.width, r.rect.height );
     }
     this.aWidth = 0;
     this.bWidth = 0;
     this.Orient = r.Orient;
     this.vOffset = r.vOffset;
     this.spritePivot = r.spritePivot;
     this.fontIndex = r.fontIndex;
     this.CIIndex = -1;
 }
Exemplo n.º 2
0
    //Auto set, looks for pixels which match the ignore condition, then floodfills to find the whole shape
    void AutoSet()
    {
        MakeTexAsInts();
        for ( int j = theTex.height - 1; j > -1; j-- ) {
            for ( int i = 0; i < theTex.width; i++ ) {
                if ( TexAsInts[i, j] != 0 && TexAsInts[i, j] != 2 ) {
                    Shape.Clear();
                    if ( SmartMode || SpriteEditor ) {
                        ShapeSmartLine.Clear();
                    }
                    FloodFill( i, j );
                    int xMin = theTex.width, xMax = 0, yMin = theTex.height, yMax = 0;
                    foreach ( Vector2 a in Shape ) {
                        if ( a.x > xMax ) xMax = (int) a.x;
                        if ( a.x < xMin ) xMin = (int) a.x;
                        if ( a.y > yMax ) yMax = (int) a.y;
                        if ( a.y < yMin ) yMin = (int) a.y;
                    }
                    Rect theRect = new Rect( xMin - FloodfillPadding, yMin - FloodfillPadding, xMax - xMin + 1 + FloodfillPadding * 2, yMax - yMin + 1 + FloodfillPadding * 2 );
                    SetRect newSetRect = new SetRect();
                    newSetRect.rect = theRect;
                    if ( SmartMode ) {
                        if ( ShapeSmartLine.Count > 1 ) {
                            if ( ShapeSmartLine[0].y == ShapeSmartLine[1].y ) {
                                //Compare the first smartline pixel with the second, if they have the same y,
                                //then the character is upright, otherwise rotated
                                newSetRect.Orient = false;
                                newSetRect.vOffset = theRect.yMax - ShapeSmartLine[0].y;
                            } else {
                                newSetRect.Orient = true;
                                newSetRect.vOffset = theRect.xMax - ShapeSmartLine[0].x;
                            }
                        }
                    }
                    if ( SpriteEditor ) {
                        if ( ShapeSmartLine.Count > 0 ) {
                            newSetRect.spritePivot = new Vector2( ShapeSmartLine[0].x - theRect.x, ShapeSmartLine[0].y - theRect.y );
                        }
                    }
                    UnsortAutoRectList.Add( newSetRect );
                }
            }
        }

        AutoRectList.Add( UnsortAutoRectList[0] );
        while ( UnsortAutoRectList.Count > 0 ) {
            AutoRectList.Add( UnsortAutoRectList[FindLeftMost()] );
            UnsortAutoRectList.Remove( AutoRectList[AutoRectList.Count - 1] );
        }
        AutoRectList.RemoveAt( 0 );

        if ( SpriteEditor ) {
            SpriteSetDialog = true;
        } else {
            AutoSetDialog = true;
        }
        SpriteIndex = 0;
        AutoSetIndex = 0;
        CameraOnRect( AutoRectList[0].rect );
    }
Exemplo n.º 3
0
 //Gets Rect information from the fontsettings object for all rects, and stores in lists
 void HarvestRects( int Cycle, bool Undoing )
 {
     SO = new SerializedObject( FontList[Cycle] );
     p = SO.FindProperty( "m_CharacterRects.Array.size" );
     if ( p.intValue < 1 || ( SpriteEditor && p.intValue < 2 ) ) {
         return;
     }
     if ( Cycle == 0 ) {
         Rects.Clear();
         CharCount = 0;
     }
     int RectCount = p.intValue;
     p = SO.FindProperty( "m_CharacterRects.Array" );
     for ( int i = 0; i < RectCount; i++ ) {
         if ( SpriteEditor && i == 0 ) { continue; }
         SetRect newSetRect = new SetRect();
         p2 = p.GetArrayElementAtIndex( i );
         p2.Next( true ); //p2 is now CharIndex
         p2.Next( false ); //p2 is now UV Rect
         Rect newRect = new Rect( 0, 0, 0, 0 );
         newRect.x = p2.rectValue.x * theTex.width;
         newRect.y = p2.rectValue.y * theTex.height;
         newRect.width = p2.rectValue.width * theTex.width;
         newRect.height = p2.rectValue.height * theTex.height;
         if ( newRect.height < 0 ) {
             newRect.height *= -1;
             newRect.y -= newRect.height;
         }
         newSetRect.rect = newRect;
         p2.Next( false ); //p2 is now Vert Rect
         newRect = p2.rectValue;
         newSetRect.vOffset = p2.rectValue.y;
         p2.Next( false ); //p2 is now Width
         newSetRect.aWidth = p2.floatValue - newRect.width - newRect.x;
         newSetRect.bWidth = newRect.x;
         p2.Next( false ); //p2 is now Flip bool
         newSetRect.Orient = p2.boolValue;
         if ( p2.boolValue ) {
             newSetRect.spritePivot = new Vector2( -newRect.height - newRect.y, newRect.width + newRect.x - 1 );
         } else {
             newSetRect.spritePivot = new Vector2( -newRect.x, -newRect.height - newRect.y );
         }
         newSetRect.CIIndex = i;
         newSetRect.fontIndex = Cycle;
         Rects.Add( newSetRect );
     }
     CharCount += SpriteEditor ? RectCount - 1 : RectCount;
     ClickedOnRect = true;
     if ( !Undoing ) {
         ClickedRectInd = 0;
     } else {
         if ( ClickedRectInd > Rects.Count - 1 ) {
             ClickedRectInd = Rects.Count - 1;
         }
     }
     if ( Cycle != FontList.Length - 1 ) {
         Cycle++;
         HarvestRects( Cycle, Undoing );
         return;
     }
     if ( SpriteEditor ) {
         CheckSprites();
     } else {
         CheckDupeChars();
     }
     CheckOverlapRects();
     GetFontInfoToGUI( Rects[ClickedRectInd].CIIndex, ( SpriteEditor ? Rects[ClickedRectInd].fontIndex : 0 ) );
     ClearLog();
 }
Exemplo n.º 4
0
    //OnGUI
    void OnGUI()
    {
        //qwer
        if ( UsingEditor && Rects == null ) {
            UsingEditor = false;
            UsingMenu = true;
            Debug.Log( Rects );
        }
        #if UNITY_2_6 || UNITY_2_6_1 ||UNITY_3_0 ||UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2
        Undo.CreateSnapshot();
        Undo.RegisterSnapshot();
        #else
        //This might not be needed?
        //Undo.RecordObjects( FontList, "Font Changed" );
        #endif
        wantsMouseMove = true;
        MenuBar = new Rect( 0, 0, 150, position.height );
        Event e = Event.current;

        //change gui focus to a blank control
        if ( ReFocusBlank ) {
            GUI.FocusControl( "" );
            ReFocusBlank = false;
        }

        //change gui focus to CharacterEntry
        if ( ReFocusChar ) {
            GUI.FocusControl( "CharacterEntry" );
            ReFocusChar = false;
        }

        //this disbles the editor when playmode is started - a bunch of vars are not preseved, leading to console being flooded with errors. better to just disable it
        if ( !PMS && PM != EditorApplication.isPlaying ) {
            if ( PM ) {
                PM = false;
            } else {
                position = new Rect( position.x, position.y - 5, 220, 150 );
                PMS = true;
                return;
            }
        }

        if ( PMS ) {
            GUI.skin = theGUISkin;
            GUI.BeginGroup( new Rect( position.width / 2 - 80, position.height / 2 - 50, 160, 80 ) );
            GUI.Box( new Rect( 0, 0, 160, 80 ), "" );
            GUI.Label( new Rect( 10, 4, 140, 80 ), "This extension doesn't support entering PlayMode, please close and re-open it's window" );
            GUI.EndGroup();
            return;
        }

        if ( UsingPacker ) {
            drawOffsetPos = Vector2.Lerp( drawOffsetPos, drawOffsetPosDest, 0.02f );
            //Rightmouse down, start drawOffset pan
            if ( e.type == EventType.MouseDown && ( e.button == 2 || e.button == 1 ) ) {
                drawOffsetClick = true;
            }

            //Right Mouseup from drawOffset move
            if ( e.type == EventType.MouseUp && ( e.button == 2 || e.button == 1 ) && drawOffsetClick ) {
                drawOffsetClick = false;
            }

            //Dragging with rightmouse, update drawOffset pan
            if ( e.type == EventType.MouseDrag && ( e.button == 2 || e.button == 1 ) && drawOffsetClick ) {
                drawOffsetPosDest = drawOffsetPosDest + Event.current.delta;
                drawOffsetPosDest = new Vector2( Mathf.Clamp( drawOffsetPosDest.x, -( outTex.width / 2 ), ( outTex.width / 2 ) ),
                                                    Mathf.Clamp( drawOffsetPosDest.y, -( outTex.height / 2 ), ( outTex.height / 2 ) ) );
            }

        }

        MouseOffGUI = new Rect( MenuBar.width, 0, position.width - 300, position.height ).Contains( Event.current.mousePosition );
        if ( UsingEditor ) {
            ShrunkX = ( theTex.width - ( position.width - ( MenuBar.width * 2 ) ) ) / 2;
            ShrunkY = ( theTex.height - position.height ) / 2;
            drawOffsetPos = Vector2.Lerp( drawOffsetPos, drawOffsetPosDest, 0.02f );

            if ( e.type == EventType.ScrollWheel ) {
                drawOffsetPosDest /= drawOffsetScaleDest;
                drawOffsetScaleDest = Mathf.Clamp( Mathf.RoundToInt( ( drawOffsetScale + ( e.delta.y > 0 ? -0.5f : 0.5f ) ) * 2 ) / 2.0f, 0.5f, 10 );
                drawOffsetPosDest *= drawOffsetScaleDest;
            }
            drawOffsetScale = Mathf.Lerp( drawOffsetScale, drawOffsetScaleDest, 0.02f );

            //Leftmouse down
            if ( e.type == EventType.MouseDown && e.button == 0 && MouseOffGUI && !AutoSetDialog && !SpriteSetDialog ) {
                //register undo for any mousedown inside the gui

        #if UNITY_2_6 || UNITY_2_6_1 ||UNITY_3_0 ||UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2
                Undo.CreateSnapshot();
                Undo.RegisterSnapshot();
        #else
                Undo.RecordObjects( FontList, "Font Changed" );
        #endif

                //checkPos is the position of the mouse with respect to the bitmap
                checkPos = new Vector2( ( e.mousePosition.x - MenuBar.width + ShrunkX ) - drawOffsetPosDest.x + ( ( theTex.width / 2 ) * ( drawOffsetScale - 1 ) ), theTex.height - ( e.mousePosition.y + ShrunkY - drawOffsetPosDest.y ) + ( ( theTex.height / 2 ) * ( drawOffsetScale - 1 ) ) ) / drawOffsetScale;
                bool found = false;
                int foundIndex = -1;
                for ( int i = 0; i < Rects.Count; i++ ) {
                    //Check for sprite center
                    Rect SpriteCenterRect = new Rect( Rects[i].rect.x + Rects[i].spritePivot.x - ( 7.0f / drawOffsetScale ), Rects[i].rect.y + Rects[i].spritePivot.y - ( 7.0f / drawOffsetScale ), ( 16.0f / drawOffsetScale ), ( 16.0f / drawOffsetScale ) );
                    if ( SpriteEditor && SpriteCenterRect.Contains( checkPos ) ) {
                        found = true;
                        MovingRectOffset = checkPos - new Vector2( SpriteCenterRect.x + ( 7.0f / drawOffsetScale ), SpriteCenterRect.y + ( 7.0f / drawOffsetScale ) );
                        MovingSpriteCenter = true;
                        MovingAllSpriteCenterStart = Rects[i].spritePivot;
                        foundIndex = i;
                        break;
                    }

                    //Check for offset slider
                    Rect SliderRect;
                    if ( Rects[i].Orient ) {
                        SliderRect = new Rect( Rects[i].rect.xMax - Rects[i].vOffset - ( SliderSize / drawOffsetScale ), Rects[i].rect.y, ( SliderSize / drawOffsetScale ) * 2, Rects[i].rect.height );
                    } else {
                        SliderRect = new Rect( Rects[i].rect.x, Rects[i].rect.yMax - Rects[i].vOffset - ( SliderSize / drawOffsetScale ), Rects[i].rect.width, ( SliderSize / drawOffsetScale ) * 2 );
                    }
                    if ( !SpriteEditor && PerCharacterOffset && SliderRect.Contains( checkPos ) ) {
                        found = true;
                        MovingRectOffset = checkPos - new Vector2( SliderRect.x, SliderRect.y );
                        MovingSlider = true;
                        MovingAllSliderStart = Rects[i].vOffset;
                        foundIndex = i;
                        break;
                    }

                    //Check for Rects
                    if ( Rects[i].rect.Contains( checkPos ) ) {
                        found = true;
                        Rect ResizerRect = new Rect( Rects[i].rect.xMax - 11.0f / drawOffsetScale, Rects[i].rect.y, 11.0f / drawOffsetScale, 11.0f / drawOffsetScale );
                        if ( ResizerRect.Contains( checkPos ) ) {
                            ResizingRect = true;
                            ResizingRectOffset = checkPos - new Vector2( Rects[i].rect.x + Rects[i].rect.width, Rects[i].rect.y );
                        } else {
                            MovingRect = true;
                            MovingRectOffset = checkPos - new Vector2( Rects[i].rect.x, Rects[i].rect.y );
                        }
                        foundIndex = i;
                        break;
                    }
                }

                if ( found ) {
                    ClickedRectInd = foundIndex;
                    GUI.FocusControl( "" );
                    GetFontInfoToGUI( Rects[foundIndex].CIIndex, ( SpriteEditor ? Rects[foundIndex].fontIndex : 0 ) );
                    ReFocusChar = true;
                    ClickedOnRect = true;
                }
            }

            //Leftmouse HOLD, dragging something
            if ( e.type == EventType.MouseDrag && e.button == 0 ) {
                checkPos = new Vector2( ( e.mousePosition.x - MenuBar.width + ShrunkX ) - drawOffsetPosDest.x + ( ( theTex.width / 2 ) * ( drawOffsetScale - 1 ) ), theTex.height - ( e.mousePosition.y + ShrunkY - drawOffsetPosDest.y ) + ( ( theTex.height / 2 ) * ( drawOffsetScale - 1 ) ) ) / drawOffsetScale;

                if ( MovingSpriteCenter ) {//Moving a sprite center
                    if ( MovingAllToggle ) {
                        switch ( Snap ) {
                            case 0:
                                for ( int i = 0; i < Rects.Count; i++ ) {
                                    if ( MovingAllSpriteToggle && Rects[i].fontIndex != Rects[ClickedRectInd].fontIndex ) { continue; }
                                    Rects[i].spritePivot = Rects[i].spritePivot + new Vector2( ( checkPos.x - MovingRectOffset.x ) - Rects[ClickedRectInd].rect.x, ( checkPos.y - MovingRectOffset.y ) - Rects[ClickedRectInd].rect.y ) - MovingAllSpriteCenterStart;
                                    UpdateFont( i, Rects[i].CIIndex, Rects[i].fontIndex, false );
                                }
                                break;
                            case 1:
                                Rects[ClickedRectInd].spritePivot = new Vector2( ( checkPos.x - MovingRectOffset.x ) - Rects[ClickedRectInd].rect.x, ( checkPos.y - MovingRectOffset.y ) - Rects[ClickedRectInd].rect.y );
                                Rects[ClickedRectInd].spritePivot.x = Mathf.Clamp( Mathf.RoundToInt( Rects[ClickedRectInd].spritePivot.x / ( Rects[ClickedRectInd].rect.width / 2 ) ) * ( Rects[ClickedRectInd].rect.width / 2 ), 0, Rects[ClickedRectInd].rect.width );
                                Rects[ClickedRectInd].spritePivot.y = Mathf.Clamp( Mathf.RoundToInt( Rects[ClickedRectInd].spritePivot.y / ( Rects[ClickedRectInd].rect.height / 2 ) ) * ( Rects[ClickedRectInd].rect.height / 2 ), 0, Rects[ClickedRectInd].rect.height );
                                Vector2 snapVector;
                                snapVector.x = Rects[ClickedRectInd].spritePivot.x / Rects[ClickedRectInd].rect.width;
                                snapVector.y = Rects[ClickedRectInd].spritePivot.y / Rects[ClickedRectInd].rect.height;
                                for ( int i = 0; i < Rects.Count; i++ ) {
                                    if ( MovingAllSpriteToggle && Rects[i].fontIndex != Rects[ClickedRectInd].fontIndex ) { continue; }
                                    if ( i == ClickedRectInd ) { continue; }
                                    Rects[i].spritePivot = new Vector2( snapVector.x * Rects[i].rect.width, snapVector.y * Rects[i].rect.height );
                                    UpdateFont( i, Rects[i].CIIndex, Rects[i].fontIndex, false );
                                }
                                break;
                            case 2:
                                for ( int i = 0; i < Rects.Count; i++ ) {
                                    if ( MovingAllSpriteToggle && Rects[i].fontIndex != Rects[ClickedRectInd].fontIndex ) { continue; }
                                    Rects[i].spritePivot = Rects[i].spritePivot + new Vector2( ( checkPos.x - MovingRectOffset.x ) - Rects[ClickedRectInd].rect.x, Rects[ClickedRectInd].spritePivot.y ) - MovingAllSpriteCenterStart;
                                    Rects[i].spritePivot = RoundedV2( Rects[i].spritePivot );
                                    UpdateFont( i, Rects[i].CIIndex, Rects[i].fontIndex, false );
                                }
                                break;
                            case 3:
                                for ( int i = 0; i < Rects.Count; i++ ) {
                                    if ( MovingAllSpriteToggle && Rects[i].fontIndex != Rects[ClickedRectInd].fontIndex ) { continue; }
                                    Rects[i].spritePivot = Rects[i].spritePivot + new Vector2( Rects[ClickedRectInd].spritePivot.x, ( checkPos.y - MovingRectOffset.y ) - Rects[ClickedRectInd].rect.y ) - MovingAllSpriteCenterStart;
                                    Rects[i].spritePivot = RoundedV2( Rects[i].spritePivot );
                                    UpdateFont( i, Rects[i].CIIndex, Rects[i].fontIndex, false );
                                }
                                break;
                        }
                        MovingAllSpriteCenterStart = Rects[ClickedRectInd].spritePivot;
                    } else {
                        switch ( Snap ) {
                            case 0:
                                Rects[ClickedRectInd].spritePivot = new Vector2( ( checkPos.x - MovingRectOffset.x ) - Rects[ClickedRectInd].rect.x, ( checkPos.y - MovingRectOffset.y ) - Rects[ClickedRectInd].rect.y );
                                break;
                            case 1:
                                Rects[ClickedRectInd].spritePivot = new Vector2( ( checkPos.x - MovingRectOffset.x ) - Rects[ClickedRectInd].rect.x, ( checkPos.y - MovingRectOffset.y ) - Rects[ClickedRectInd].rect.y );
                                Rects[ClickedRectInd].spritePivot.x = Mathf.Clamp( Mathf.RoundToInt( Rects[ClickedRectInd].spritePivot.x / ( Rects[ClickedRectInd].rect.width / 2 ) ) * ( Rects[ClickedRectInd].rect.width / 2 ), 0, Rects[ClickedRectInd].rect.width );
                                Rects[ClickedRectInd].spritePivot.y = Mathf.Clamp( Mathf.RoundToInt( Rects[ClickedRectInd].spritePivot.y / ( Rects[ClickedRectInd].rect.height / 2 ) ) * ( Rects[ClickedRectInd].rect.height / 2 ), 0, Rects[ClickedRectInd].rect.height );
                                break;
                            case 2:
                                Rects[ClickedRectInd].spritePivot = new Vector2( ( checkPos.x - MovingRectOffset.x ) - Rects[ClickedRectInd].rect.x, Rects[ClickedRectInd].spritePivot.y );
                                break;
                            case 3:
                                Rects[ClickedRectInd].spritePivot = new Vector2( Rects[ClickedRectInd].spritePivot.x, ( checkPos.y - MovingRectOffset.y ) - Rects[ClickedRectInd].rect.y );
                                break;
                        }
                        if ( Snap != 1 ) { Rects[ClickedRectInd].spritePivot = RoundedV2( Rects[ClickedRectInd].spritePivot ); }
                        UpdateFont( ClickedRectInd, Rects[ClickedRectInd].CIIndex, Rects[ClickedRectInd].fontIndex, true );
                    }
                }

                if ( MovingSlider ) { //Moving an offset slider
                    if ( MovingAllToggle ) {
                        for ( int i = 0; i < Rects.Count; i++ ) {
                            if ( Rects[ClickedRectInd].Orient ) {
                                Rects[i].vOffset = Rects[i].vOffset + ( -( checkPos.x - Rects[ClickedRectInd].rect.xMax - MovingRectOffset.x + ( SliderSize / drawOffsetScale ) ) - MovingAllSliderStart );
                            } else {
                                Rects[i].vOffset = Rects[i].vOffset + ( -( checkPos.y - Rects[ClickedRectInd].rect.yMax - MovingRectOffset.y + ( SliderSize / drawOffsetScale ) ) - MovingAllSliderStart );
                            }
                            UpdateFont( i, Rects[i].CIIndex, Rects[i].fontIndex, false );
                        }
                        MovingAllSliderStart = Rects[ClickedRectInd].vOffset;
                    } else {
                        switch ( Snap ) {
                            case 1: // SNAP
                                SnapFound = false;
                                for ( int i = 0; i < Rects.Count; i++ ) {
                                    if ( i == ClickedRectInd ) { continue; }
                                    if ( Rects[i].rect.Contains( checkPos ) ) {//Find a snap, set offset for this rect, to offset of that rect
                                        if ( Rects[ClickedRectInd].Orient ) {
                                            if ( Rects[i].Orient ) { //if Rect a is sideways, is rect b sideways too?
                                                Rects[ClickedRectInd].vOffset = Rects[i].vOffset - Rects[i].rect.xMax + Rects[ClickedRectInd].rect.xMax;
                                            } else {
                                                Rects[ClickedRectInd].vOffset = Rects[i].vOffset;
                                            }
                                        } else {
                                            if ( Rects[i].Orient ) { //if Rect a is upright, is rect b upright too?
                                                Rects[ClickedRectInd].vOffset = Rects[i].vOffset;
                                            } else {
                                                Rects[ClickedRectInd].vOffset = Rects[i].vOffset - Rects[i].rect.yMax + Rects[ClickedRectInd].rect.yMax;
                                            }
                                        }
                                        SnapFound = true;
                                        break;
                                    }
                                }
                                if ( !SnapFound ) {//Couldnt find a snap target, apply non-snap, depending on orient
                                    if ( Rects[ClickedRectInd].Orient ) {
                                        Rects[ClickedRectInd].vOffset = -( checkPos.x - Rects[ClickedRectInd].rect.xMax - MovingRectOffset.x + ( SliderSize / drawOffsetScale ) );
                                    } else {
                                        Rects[ClickedRectInd].vOffset = -( checkPos.y - Rects[ClickedRectInd].rect.yMax - MovingRectOffset.y + ( SliderSize / drawOffsetScale ) );
                                    }
                                }
                                break;
                            default: // Other (no SNAP), depending on orient
                                if ( Rects[ClickedRectInd].Orient ) {
                                    Rects[ClickedRectInd].vOffset = -( checkPos.x - Rects[ClickedRectInd].rect.xMax - MovingRectOffset.x + ( SliderSize / drawOffsetScale ) );
                                } else {
                                    Rects[ClickedRectInd].vOffset = -( checkPos.y - Rects[ClickedRectInd].rect.yMax - MovingRectOffset.y + ( SliderSize / drawOffsetScale ) );
                                }
                                break;
                        }
                        UpdateFont( ClickedRectInd, Rects[ClickedRectInd].CIIndex, Rects[ClickedRectInd].fontIndex, true );
                    }
                }

                if ( MovingRect || ResizingRect ) { //Moving or resizing a rect
                    Rect OldRect;
                    float OldMaxY = 0, newHeight = 0, newWidth = 0, newY = 0;
                    if ( ResizingRect ) {
                        checkPos -= ResizingRectOffset;
                        OldRect = Rects[ClickedRectInd].rect;
                        OldMaxY = OldRect.y + OldRect.height;
                        newHeight = Mathf.Max( OldMaxY - checkPos.y, 2 );
                        newWidth = Mathf.Max( checkPos.x - OldRect.x, 2 );
                        newY = Mathf.Min( checkPos.y, OldMaxY - 2 );
                    }
                    switch ( Snap ) {
                        case 0: //NO SNAP#
                            if ( MovingRect ) { Rects[ClickedRectInd].rect = new Rect( checkPos.x - MovingRectOffset.x, checkPos.y - MovingRectOffset.y, Rects[ClickedRectInd].rect.width, Rects[ClickedRectInd].rect.height ); }
                            if ( ResizingRect ) { Rects[ClickedRectInd].rect = new Rect( Rects[ClickedRectInd].rect.x, newY, newWidth, newHeight ); }
                            break;
                        case 1: // SNAP
                            if ( MovingRect ) { Rects[ClickedRectInd].rect = SnapToPos( new Rect( checkPos.x - MovingRectOffset.x, checkPos.y - MovingRectOffset.y, Rects[ClickedRectInd].rect.width, Rects[ClickedRectInd].rect.height ), ClickedRectInd ); }
                            if ( ResizingRect ) {
                                if ( !SnapFound ) {
                                    Rects[ClickedRectInd].rect = SnapToSize( new Rect( Rects[ClickedRectInd].rect.x, newY, newWidth, newHeight ), ClickedRectInd );
                                } else if ( !SnapRect.Contains( Event.current.mousePosition ) ) {
                                    SnapFound = false;
                                }
                            }
                            break;
                        case 2: // CONSTRAIN TO X
                            if ( MovingRect ) { Rects[ClickedRectInd].rect = new Rect( checkPos.x - MovingRectOffset.x, Rects[ClickedRectInd].rect.y, Rects[ClickedRectInd].rect.width, Rects[ClickedRectInd].rect.height ); }
                            if ( ResizingRect ) { Rects[ClickedRectInd].rect = new Rect( Rects[ClickedRectInd].rect.x, Rects[ClickedRectInd].rect.y, newWidth, Rects[ClickedRectInd].rect.height ); }
                            break;
                        case 3: // CONSTRAIN TO Y
                            if ( MovingRect ) { Rects[ClickedRectInd].rect = new Rect( Rects[ClickedRectInd].rect.x, checkPos.y - MovingRectOffset.y, Rects[ClickedRectInd].rect.width, Rects[ClickedRectInd].rect.height ); }
                            if ( ResizingRect ) { Rects[ClickedRectInd].rect = new Rect( Rects[ClickedRectInd].rect.x, newY, Rects[ClickedRectInd].rect.width, newHeight ); }
                            break;
                    }
                    Rects[ClickedRectInd].rect = RoundedRect( Rects[ClickedRectInd].rect );
                    UpdateFont( ClickedRectInd, Rects[ClickedRectInd].CIIndex, ( SpriteEditor ? Rects[ClickedRectInd].fontIndex : 0 ), true );
                }
            }

            //Leftmouse Up, END ANY MOVE OR RESIZE
            if ( e.rawType == EventType.MouseUp && e.button == 0 ) {
                CheckOverlapRects();
                MovingRect = false;
                ResizingRect = false;
                MovingSlider = false;
                MovingSpriteCenter = false;
            }

            //Rightmouse down, start drawOffset pan
            if ( e.type == EventType.MouseDown && ( e.button == 2 || e.button == 1 ) && MouseOffGUI ) {
                drawOffsetClick = true;
            }

            //Right Mouseup from drawOffset move
            if ( e.type == EventType.MouseUp && ( e.button == 2 || e.button == 1 ) && drawOffsetClick ) {
                drawOffsetClick = false;
            }

            //Dragging with rightmouse, update drawOffset pan
            if ( e.type == EventType.MouseDrag && ( e.button == 2 || e.button == 1 ) && drawOffsetClick ) {
                drawOffsetPosDest = drawOffsetPosDest + Event.current.delta;
                drawOffsetPosDest = new Vector2( Mathf.Clamp( drawOffsetPosDest.x, -( theTex.width / 2 ) * drawOffsetScale, ( theTex.width / 2 ) * drawOffsetScale ),
                                                    Mathf.Clamp( drawOffsetPosDest.y, -( theTex.height / 2 ) * drawOffsetScale, ( theTex.height / 2 ) * drawOffsetScale ) );
            }
        }

        //Now GUI drawing, buttons, etc

        PromptOffset1 = Mathf.Lerp( PromptOffset1, PromptOffset1Dest, 0.01f );
        PromptOffset2 = Mathf.Lerp( PromptOffset2, PromptOffset2Dest, 0.01f );
        PromptOffset3 = Mathf.Lerp( PromptOffset3, PromptOffset3Dest, 0.01f );
        PromptOffset4 = Mathf.Lerp( PromptOffset4, PromptOffset4Dest, 0.01f );
        if ( PromptOffset1 < 1 && PromptOffset1Dest == 0 ) { MenuPrompt = false; }
        if ( PromptOffset2 < 1 && PromptOffset2Dest == 0 ) { ResetPrompt = false; }
        if ( PromptOffset3 < 1 && PromptOffset3Dest == 0 ) { AutoPrompt = false; }
        if ( PromptOffset4 < 1 && PromptOffset4Dest == 0 ) { DialogStop = false; }

        GUI.skin = theGUISkin;

        //Draw Main Menu
        if ( UsingMenu ) {
            GUI.Box( MenuBar, "" ); //////Left Box
            GUI.BeginGroup( new Rect( 4, 4, position.width - 4, MenuBar.height - 8 ) );//Clip The Menu pics
            GUI.DrawTexture( new Rect( 0, 0, MenuPics[1].width, MenuPics[1].height ), MenuPics[1] );
            GUI.EndGroup();
            GUI.Box( new Rect( position.width - MenuBar.width, 0, MenuBar.width, MenuBar.height ), "" );/////RightBox
            GUI.BeginGroup( new Rect( 4, 4, position.width - 4, MenuBar.height - 8 ) );//Clip The Menu pics
            GUI.DrawTexture( new Rect( position.width - 8 - MenuPics[2].width, 0, MenuPics[2].width, MenuPics[2].height ), MenuPics[2] );
            GUI.EndGroup();

            GUI.skin = null;
            GUI.BeginGroup( new Rect( position.width - 140, 10, 130, 200 ) ); // Get tex and font for packer
            EditorGUIUtility.LookLikeControls( 65, 40 );
            if ( SpriteEditor ) {
                inFontContainer = (AnimatedSprite) EditorGUI.ObjectField( new Rect( 0, 5, 130, 20 ), "Sprite In", inFontContainer, typeof( AnimatedSprite ), false );
                outFontContainer = (AnimatedSprite) EditorGUI.ObjectField( new Rect( 0, 25, 130, 20 ), "Sprite Out", outFontContainer, typeof( AnimatedSprite ), false );
            } else {
                inFont = (Font) EditorGUI.ObjectField( new Rect( 0, 5, 130, 20 ), "Font In", inFont, typeof( Font ), false );
                outFont = (Font) EditorGUI.ObjectField( new Rect( 0, 25, 130, 20 ), "Font Out", outFont, typeof( Font ), false );
            }
            GUI.skin = theGUISkin;
            GUI.enabled = ( ( !SpriteEditor && inFont != null && outFont != null && inFont != outFont ) ||
             ( SpriteEditor && inFontContainer != null && outFontContainer != null && inFontContainer != outFontContainer ) );
            if ( GUI.Button( new Rect( 0, 55, 130, 30 ), SpriteEditor ? "Start SpritePacker" : "Start FontPacker" ) ) {
                Begin( SpriteEditor ? 3 : 2 );
            }
            GUI.EndGroup();

            GUI.enabled = true;
            GUI.skin = null;
            GUI.BeginGroup( new Rect( 10, 10, 130, 500 ) ); // Get tex and font for setter
            if ( SpriteEditor ) {
                EditorGUIUtility.LookLikeControls( 40, 80 );
                FontContainer = (AnimatedSprite) EditorGUI.ObjectField( new Rect( 0, 5, 130, 20 ), "Sprite", FontContainer, typeof( AnimatedSprite ), false );
            } else {
                EditorGUIUtility.LookLikeControls( 40, 80 );
                theFont = (Font) EditorGUI.ObjectField( new Rect( 0, 5, 130, 20 ), "Font", theFont, typeof( Font ), false );
            }
            GUI.skin = theGUISkin;
            GUI.enabled = ( ( !SpriteEditor && theFont != null ) || ( SpriteEditor && FontContainer != null ) );
            if ( GUI.Button( new Rect( 0, 55, 130, 30 ), SpriteEditor ? "Start SpriteSetter" : "Start FontSetter" ) ) {
                Begin( SpriteEditor ? 1 : 0 );
            }
            GUI.enabled = true;
            UsePreview = GUI.Toggle( new Rect( 0, 90, 130, 20 ), UsePreview, "Preview 3DText" );
            GUI.EndGroup();

            GUI.BeginGroup( new Rect( 4, position.height - 24, 130, 30 ) ); // Switch to SpriteEditor
            SpriteEditor = GUI.Toggle( new Rect( 0, 0, 130, 20 ), SpriteEditor, "Sprite Mode" );
            GUI.EndGroup();

        } //Enf of main menu

        //Draw FontSetter
        if ( UsingEditor ) {
            if ( e.type == EventType.ValidateCommand && e.commandName == "UndoRedoPerformed" ) {
                HarvestRects( 0, true );
            }
            GUI.skin = theGUISkin;
            GUI.Box( MenuBar, "" ); //////Left Box
            GUI.BeginGroup( new Rect( 4, 4, position.width - 4, MenuBar.height - 8 ) );//Clip The Menu pics
            GUI.DrawTexture( new Rect( 0, 0, MenuPics[1].width, MenuPics[1].height ), MenuPics[1] );
            GUI.EndGroup();
            GUI.Box( new Rect( position.width - MenuBar.width, 0, MenuBar.width, MenuBar.height ), "" );/////RightBox
            GUI.BeginGroup( new Rect( 4, 4, position.width - 4, MenuBar.height - 8 ) );//Clip The Menu pics
            GUI.DrawTexture( new Rect( position.width - 8 - MenuPics[0].width, 0, MenuPics[0].width, MenuPics[0].height ), MenuPics[0] );
            GUI.EndGroup();
            GUI.enabled = !AutoSetDialog && !SpriteSetDialog;

            GUI.BeginGroup( new Rect( position.width - 140, 10, 130, 80 ) ); //Undo and shrinkwrap buttons
            if ( GUI.Button( new Rect( 0, 0, 130, 30 ), "Undo" ) ) {
                Undo.PerformUndo();
            }
            GUI.enabled = !AutoSetDialog && !SpriteSetDialog && Rects.Count > 0;
            if ( GUI.Button( new Rect( 10, 40, 110, 25 ), "Shrinkwrap" ) ) {
                ShrinkWrap();
            }
            GUI.EndGroup();
            GUI.enabled = true;
            GUI.BeginGroup( new Rect( MenuBar.width, 0, position.width - 150, position.height ) );//Clip The Background Box
            GUI.color = Color.gray;
            GUI.skin = theGUISkin;
            GUI.Box( new Rect( 0, 0, position.width - 300, position.height ), "", "White" );
            GUI.color = Color.white;
            GUI.EndGroup();

            //Controls in sprite setter
            if ( SpriteEditor && !SpriteSetDialog ) {
                GUI.BeginGroup( new Rect( position.width - MenuBar.width, 100, MenuBar.width, 200 ) ); //Animation Properties group
                GUI.Box( new Rect( 0, 0, 150, (int) SpritePropertiesLoopBehaviour == 3 ? 160 : ( (int) SpritePropertiesLoopBehaviour == 2 ? 120 : 140 ) ), "" );
                GUI.Label( new Rect( 10, 2, 130, 20 ), "Animation Properties:" );
                EditorGUIUtility.LookLikeControls( 40, 60 );
                SpritePropertiesFontIndex = EditorGUI.Popup( new Rect( 10, 24, 130, 20 ), "Anim:", SpritePropertiesFontIndex, FontListNames );
                SpritePropertiesLoopBehaviour = (SpritePropertiesLoopBehaviourEnum) EditorGUI.EnumPopup( new Rect( 10, 44, 130, 20 ), "Loop:", SpritePropertiesLoopBehaviour );
                if ( (int) SpritePropertiesLoopBehaviour == 3 ) {
                    EditorGUIUtility.LookLikeControls( 70, 60 );
                    SpritePropertiesNextAnim = EditorGUI.Popup( new Rect( 10, 64, 130, 20 ), "Change to:", SpritePropertiesNextAnim, FontListNames );
                }
                if ( (int) SpritePropertiesLoopBehaviour == 0 || (int) SpritePropertiesLoopBehaviour == 1 || (int) SpritePropertiesLoopBehaviour == 3 ) {
                    EditorGUIUtility.LookLikeControls( 105, 60 );
                    SpritePropertiesLoopStart = Mathf.Clamp( EditorGUI.IntField( new Rect( 10, (int) SpritePropertiesLoopBehaviour == 3 ? 84 : 64, 130, 18 ), (int) SpritePropertiesLoopBehaviour == 3 ? "Starting at:" : "Loop start frame:", SpritePropertiesLoopStart ), 0, FontList[(int) SpritePropertiesLoopBehaviour == 3 ? SpritePropertiesNextAnim : SpritePropertiesFontIndex].characterInfo.Length - 2 );
                }
                EditorGUIUtility.LookLikeControls( 105, 60 );
                SpritePropertiesAnimFPS = EditorGUI.FloatField( new Rect( 10, (int) SpritePropertiesLoopBehaviour == 3 ? 102 : ( (int) SpritePropertiesLoopBehaviour == 2 ? 62 : 82 ), 130, 18 ), "Anim FPS Multip:", SpritePropertiesAnimFPS );
                AutoAnimate = GUI.Toggle( new Rect( 10, (int) SpritePropertiesLoopBehaviour == 3 ? 116 : ( (int) SpritePropertiesLoopBehaviour == 2 ? 76 : 96 ), 130, 20 ), AutoAnimate, "Auto-animate" );
                GUI.Label( new Rect( 10, (int) SpritePropertiesLoopBehaviour == 3 ? 134 : ( (int) SpritePropertiesLoopBehaviour == 2 ? 94 : 114 ), 30, 20 ), "" + SpriteFrame );
                SpriteFrame = (int) GUI.HorizontalSlider( new Rect( 28, (int) SpritePropertiesLoopBehaviour == 3 ? 140 : ( (int) SpritePropertiesLoopBehaviour == 2 ? 100 : 120 ), 112, 18 ), SpriteFrame, 0, FontList[SpritePropertiesFontIndex].characterInfo.Length - 2 );

                //if you switch auto on, go back to the start.
                if ( AutoAnimate != AutoAnimateOld ) {
                    AutoAnimateOld = AutoAnimate;
                    if ( AutoAnimate == true ) {
                        SpriteFrame = 0;
                    }
                }

                //choosing a new font needs to update the other fields
                if ( SpritePropertiesFontIndex != SpritePropertiesFontIndexOld ) {
                    ReFocusBlank = true;
                    SpritePropertiesFontIndexOld = SpritePropertiesFontIndex;
                    SpritePropertiesLoopBehaviour = (SpritePropertiesLoopBehaviourEnum) FontList[SpritePropertiesFontIndex].characterInfo[0].index;
                    SpritePropertiesLoopBehaviourOld = SpritePropertiesLoopBehaviour;
                    SpritePropertiesNextAnim = (int) FontList[SpritePropertiesFontIndex].characterInfo[0].uv.x;
                    SpritePropertiesNextAnimOld = SpritePropertiesNextAnim;
                    SpritePropertiesLoopStart = (int) FontList[SpritePropertiesFontIndex].characterInfo[0].uv.y;
                    SpritePropertiesLoopStartOld = SpritePropertiesLoopStart;
                    SpritePropertiesAnimFPS = FontList[SpritePropertiesFontIndex].characterInfo[0].uv.width + 1;
                    SpritePropertiesAnimFPSOld = SpritePropertiesAnimFPS;
                    if ( SpritePreview != null ) {
                        SpritePreviewT.font = FontList[SpritePropertiesFontIndex];
                    }
                    SpriteFrame = 0;
                    ClickedRectInd = FindFrame();
                    if ( ClickedRectInd != -1 ) {
                        GetFontInfoToGUI( Rects[ClickedRectInd].CIIndex, Rects[ClickedRectInd].fontIndex );
                    }

                }

                //changing anim properties needs to change the font.CI[0]
                if ( SpritePropertiesLoopBehaviour != SpritePropertiesLoopBehaviourOld ) {
                    SpritePropertiesLoopBehaviourOld = SpritePropertiesLoopBehaviour;
                    SO = new SerializedObject( FontList[SpritePropertiesFontIndex] );
                    p = SO.FindProperty( "m_CharacterRects.Array" );
                    p = p.GetArrayElementAtIndex( 0 );
                    p = p.FindPropertyRelative( "index" );
                    p.intValue = (int) SpritePropertiesLoopBehaviour;
                    SO.ApplyModifiedProperties();
                }

                if ( SpritePropertiesNextAnim != SpritePropertiesNextAnimOld ) {
                    SpritePropertiesNextAnimOld = SpritePropertiesNextAnim;
                    SO = new SerializedObject( FontList[SpritePropertiesFontIndex] );
                    p = SO.FindProperty( "m_CharacterRects.Array" );
                    p = p.GetArrayElementAtIndex( 0 );
                    p = p.FindPropertyRelative( "uv" );
                    p.rectValue = new Rect( SpritePropertiesNextAnim, p.rectValue.y, p.rectValue.width, p.rectValue.height );
                    SO.ApplyModifiedProperties();
                }

                if ( SpritePropertiesLoopStart != SpritePropertiesLoopStartOld ) {
                    SpritePropertiesLoopStartOld = SpritePropertiesLoopStart;
                    SO = new SerializedObject( FontList[SpritePropertiesFontIndex] );
                    p = SO.FindProperty( "m_CharacterRects.Array" );
                    p = p.GetArrayElementAtIndex( 0 );
                    p = p.FindPropertyRelative( "uv" );
                    p.rectValue = new Rect( p.rectValue.x, SpritePropertiesLoopStart, p.rectValue.width, p.rectValue.height );
                    SO.ApplyModifiedProperties();
                }

                if ( SpritePropertiesAnimFPS != SpritePropertiesAnimFPSOld ) {
                    SpritePropertiesAnimFPSOld = SpritePropertiesAnimFPS;
                    SO = new SerializedObject( FontList[SpritePropertiesFontIndex] );
                    p = SO.FindProperty( "m_CharacterRects.Array" );
                    p = p.GetArrayElementAtIndex( 0 );
                    p = p.FindPropertyRelative( "uv" );
                    p.rectValue = new Rect( p.rectValue.x, p.rectValue.y, SpritePropertiesAnimFPS - 1, p.rectValue.height );
                    SO.ApplyModifiedProperties();
                }

                if ( e.type == EventType.KeyDown && e.keyCode == KeyCode.Period && MouseOffGUI && !AutoAnimate ) {
                    SpriteFrame++;
                }

                if ( e.type == EventType.KeyDown && e.keyCode == KeyCode.Comma && MouseOffGUI && !AutoAnimate ) {
                    SpriteFrame--;
                }

                if ( SpriteFrame != SpriteFrameOld && !AutoAnimate && SpritePreview != null ) {
                    if ( SpriteFrame < 0 ) { SpriteFrame = FontList[SpritePropertiesFontIndex].characterInfo.Length - 2; }
                    if ( SpriteFrame > FontList[SpritePropertiesFontIndex].characterInfo.Length - 2 ) { SpriteFrame = 0; }
                    SpriteFrameOld = SpriteFrame;
                    char C = (char) ( SpriteFrame + 33 );
                    SpritePreviewT.text = "" + C;
                    ClickedRectInd = FindFrame();
                    if ( ClickedRectInd != -1 ) {
                        GetFontInfoToGUI( Rects[ClickedRectInd].CIIndex, Rects[ClickedRectInd].fontIndex );
                    }
                }
                GUI.EndGroup();

            }

            GUI.enabled = ( !AutoSetDialog && !SpriteSetDialog && !AutoPrompt && !MenuPrompt );
            GUI.BeginGroup( new Rect( position.width - MenuBar.width + 10, position.height - 150 - PromptOffset1, MenuBar.width - 10, 150 ) ); //RESET Group
            GUI.BeginGroup( new Rect( 0, 30 - PromptOffset2, 130, 30 ) ); //RESET Group
            if ( ResetPrompt ) {
                if ( GUI.Button( new Rect( 0, 0, 60, 30 ), "Reset" ) ) {
                    ResetFont( -1 );
                    PromptOffset2Dest = 0;
                    ResetPrompt = false;
                }
                if ( GUI.Button( new Rect( 70, 0, 60, 30 ), "Cancel" ) ) {
                    PromptOffset2Dest = 0;
                }
            }
            GUI.EndGroup();
            if ( GUI.Button( new Rect( 0, 31, 130, 30 ), "Reset Font" ) ) {
                PromptOffset2Dest = 30;
                PromptOffset1Dest = 0;
                MenuPrompt = false;
                AutoPrompt = false;
                ResetPrompt = true;
            }
            GUI.EndGroup();

            GUI.enabled = ( !AutoSetDialog && !SpriteSetDialog && !ResetPrompt && !MenuPrompt );
            GUI.BeginGroup( new Rect( position.width - MenuBar.width + 10, position.height - 230 - PromptOffset1 - PromptOffset2, MenuBar.width - 10, 200 ) ); //AUTO Group
            GUI.BeginGroup( new Rect( 0, 71 - PromptOffset3, 130, PromptOffset3 ) ); //AUTO Group
            if ( AutoPrompt ) {
                if ( !SpriteEditor ) {
                    if ( GUI.Button( new Rect( 0, 45, 60, 25 ), "Basic" ) ) {
                        ResetFont( -1 );
                        AutoSet();
                        AutoPrompt = false;
                    }
                    if ( GUI.Button( new Rect( 0, 10, 60, 25 ), "Smart" ) ) {
                        SmartMode = true;
                        ResetFont( -1 );
                        AutoSet();
                        AutoPrompt = false;
                    }
                } else {
                    if ( GUI.Button( new Rect( 0, 0, 60, 28 ), "Auto!" ) ) {
                        ResetFont( -1 );
                        AutoSet();
                        AutoPrompt = false;
                    }

                    if ( GUI.Button( new Rect( 0, 29, 60, 20 ), "Get Piv" ) ) {
                        LocatePivots();
                        if ( ClickedRectInd != -1 ) { GetFontInfoToGUI( Rects[ClickedRectInd].CIIndex, Rects[ClickedRectInd].fontIndex ); }
                        PromptOffset3Dest = 0;
                    }

                    if ( GUI.Button( new Rect( 0, 50, 60, 20 ), "Draw Piv" ) ) {
                        DrawSpritePivots();
                    }
                }

                GUI.Label( new Rect( 63, 0, 150, 20 ), SpriteEditor ? "Pivot Color:" : "SmartColor:" );
                SmartColor = EditorGUI.ColorField( new Rect( 71, 20, 60, 20 ), SmartColor );

                if ( GUI.Button( new Rect( 70, 45, 60, 25 ), "Cancel" ) ) {
                    PromptOffset3Dest = 0;
                }
            }
            GUI.EndGroup();
            if ( GUI.Button( new Rect( 0, 71, 130, 30 ), "Auto Set" ) ) {
                PromptOffset1Dest = 0;
                PromptOffset2Dest = 0;
                PromptOffset3Dest = 71;
                AutoPrompt = true;
                ResetPrompt = false;
                MenuPrompt = false;
            }
            GUI.EndGroup();
            GUI.enabled = true;

            GUI.BeginGroup( new Rect( position.width - MenuBar.width + 10, position.height - 80 - PromptOffset1, MenuBar.width, 150 ) ); //ResetCam Group
            if ( GUI.Button( new Rect( 0, 0, 130, 30 ), "Reset View" ) ) {
                drawOffsetPosDest = Vector2.zero;
                drawOffsetScaleDest = 1;
            }
            GUI.EndGroup();

            GUI.enabled = ( !AutoSetDialog && !SpriteSetDialog && !ResetPrompt && !AutoPrompt );
            GUI.BeginGroup( new Rect( position.width - MenuBar.width + 10, position.height - 70, MenuBar.width, 150 ) ); //Back to menu Group
            GUI.BeginGroup( new Rect( 0, 30 - PromptOffset1, 130, 150 ) ); //Back to menu Group
            if ( MenuPrompt ) {
                if ( GUI.Button( new Rect( 0, 0, 60, 30 ), "Return" ) ) {
                    UsingEditor = false;
                    UsingMenu = true;
                    ResetError();
                    MenuPrompt = false;
                    PromptOffset1Dest = 0;
                    position = new Rect( position.x, position.y - 5, 512, 512 );
                }
                if ( GUI.Button( new Rect( 70, 0, 60, 30 ), "Cancel" ) ) {
                    PromptOffset1Dest = 0;
                }
            }
            GUI.EndGroup();
            if ( GUI.Button( new Rect( 0, 31, 130, 30 ), "Return to Menu" ) ) {
                PromptOffset1Dest = 30;
                PromptOffset2Dest = 0;
                MenuPrompt = true;
                AutoPrompt = false;
                ResetPrompt = false;
            }
            GUI.EndGroup();

            GUI.skin = theGUISkin;
            GUI.enabled = !AutoSetDialog && !SpriteSetDialog;
            GUI.BeginGroup( new Rect( MenuBar.width, 0, ( position.width - 300 ), position.height ) ); //clip the Tex
            GUI.color = BGCol; //Draw a box for the background.
            GUI.Box( new Rect( drawOffsetPos.x - ShrunkX - ( theTex.width / 2 * ( drawOffsetScale - 1 ) ) - 6, drawOffsetPos.y - ShrunkY - ( theTex.height / 2 * ( drawOffsetScale - 1 ) ) - 6, 12 + theTex.width * drawOffsetScale, 12 + theTex.height * drawOffsetScale ), "", "theTexBG" );
            GUI.color = Color.white;//Draw the fonts texture
            GUI.DrawTexture( new Rect( drawOffsetPos.x - ShrunkX - ( theTex.width / 2 * ( drawOffsetScale - 1 ) ), drawOffsetPos.y - ShrunkY - ( theTex.height / 2 * ( drawOffsetScale - 1 ) ), theTex.width * drawOffsetScale, theTex.height * drawOffsetScale ), theTex );
            GUI.EndGroup();

            GUI.BeginGroup( new Rect( MenuBar.width, 0, position.width - 300, position.height ) );//Clip The Rects
            for ( int i = 0; i < Rects.Count; i++ ) {
                if ( RectOnScreen( ConvertPixelsToScreen( Rects[i].rect ) ) ) {
                    Rect ScreenRect = ConvertPixelsToScreen( Rects[i].rect );
                    GUI.Box( ScreenRect, "", i == ClickedRectInd ? "EmptyBoxSelected" : "EmptyBox" ); //draw a rect for each character
                    if ( PerCharacterOffset ) {
                        Rect SliderBox;
                        if ( Rects[i].Orient ) {
                            SliderBox = new Rect( Rects[i].rect.xMax - Rects[i].vOffset - ( SliderSize / drawOffsetScale ), Rects[i].rect.y, ( SliderSize / drawOffsetScale ) * 2, Rects[i].rect.height );
                        } else {
                            SliderBox = new Rect( Rects[i].rect.x, Rects[i].rect.yMax - Rects[i].vOffset - ( SliderSize / drawOffsetScale ), Rects[i].rect.width, ( SliderSize / drawOffsetScale ) * 2 );
                        }
                        GUI.Box( ConvertPixelsToScreen( SliderBox ), "", "GuideLine" ); //draw the slider for each rect
                    }
                    if ( SpriteEditor ) {
                        //draw the sprite pivot, and 2 labels for the sprite index
                        GUI.Box( ConvertPixelsToScreen( new Rect( Rects[i].rect.x + Rects[i].spritePivot.x - ( 7.0f / drawOffsetScale ), Rects[i].rect.y + Rects[i].spritePivot.y - ( 7.0f / drawOffsetScale ), 16.0f / drawOffsetScale, 16.0f / drawOffsetScale ) ), "", i == ClickedRectInd ? "SpritePivotSelected" : "SpritePivot" );
                        GUI.Label( new Rect( ScreenRect.x + 1, ScreenRect.y + 1, ScreenRect.width, ScreenRect.height ), "" + ( FontList[Rects[i].fontIndex].characterInfo[Rects[i].CIIndex].index - 33 ), "RectLabel2" );
                        GUI.color = Colors[Rects[i].fontIndex % Colors.Length];
                        GUI.Label( ScreenRect, "" + ( FontList[Rects[i].fontIndex].characterInfo[Rects[i].CIIndex].index - 33 ), "RectLabel" );
                        GUI.color = Color.white;
                    } else {
                        //draw 2 labels for the character
                        GUI.Label( new Rect( ScreenRect.x + 1, ScreenRect.y + 1, ScreenRect.width, ScreenRect.height ), "" + (char) ( FontList[0].characterInfo[Rects[i].CIIndex].index ), "RectLabel2" );
                        GUI.Label( ScreenRect, "" + (char) FontList[0].characterInfo[Rects[i].CIIndex].index, "RectLabel" );
                    }
                }
            }
            GUI.EndGroup();

            if ( AutoSetDialog || SpriteSetDialog ) {
                GUI.BeginGroup( new Rect( MenuBar.width, 0, position.width - 300, position.height ) );//Clip The Auto Rects
                GUI.enabled = true;
                GUI.Box( ConvertPixelsToScreen( AutoRectList[AutoSetIndex].rect ), "", "AutoBox" );
                GUI.EndGroup();
            }

            GUI.BeginGroup( new Rect( 10, 6, MenuBar.width - 10, 65 ) ); //Size Group
            GUI.Label( new Rect( 0, 0, 140, 40 ), SpriteEditor ? "Number of \nsprites:" : "Number of\ncharacters:" );
            GUI.enabled = false;
            CharCount = EditorGUI.IntField( new Rect( 80, 9, 40, 20 ), CharCount, "TextField" );
            GUI.enabled = !AutoSetDialog && !SpriteSetDialog;

            if ( GUI.Button( new Rect( 0, 42, 50, 20 ), "+1" ) ) {
        #if UNITY_2_6 || UNITY_2_6_1 ||UNITY_3_0 ||UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2
                Undo.CreateSnapshot();
                Undo.RegisterSnapshot();
        #else
                Undo.RecordObjects( FontList, "Font Changed" );
        #endif
                GUI.FocusControl( "" );
                SO = new SerializedObject( FontList[RectFontIndex] );
                p = SO.FindProperty( "m_CharacterRects.Array.size" );
                WidBefore = 0;
                WidBeforeOld = 0;
                WidAfter = 0;
                WidAfterOld = 0;
                Orient = 0;
                OrientOld = 0;
                SpriteIndex++;
                SpriteIndexOld = SpriteIndex;
                CharCount = CharCount + 1;
                p.intValue++;
                SO.ApplyModifiedProperties();
                SetRect newSetRect = new SetRect();
                if ( ClickedRectInd == -1 ) {
                    newSetRect.rect = new Rect( 0, 0, 100, 100 );
                } else {
                    newSetRect = new SetRect( Rects[ClickedRectInd] );
                }
                newSetRect.CIIndex = FontList[newSetRect.fontIndex].characterInfo.Length - 1;
                Rects.Add( newSetRect );
                ClickedRectInd = CharCount - 1;
                ClickedOnRect = true;
                char newChar = (char) ( ChrL + 1 );
                ChrStr = "" + newChar;
                ChrL++;
                UpdateFont( ClickedRectInd, Rects[ClickedRectInd].CIIndex, ( SpriteEditor ? Rects[ClickedRectInd].fontIndex : 0 ), true );
                if ( SpriteEditor ) {
                    CheckSprites();
                } else {
                    CheckDupeChars();
                }
                if ( Rects.Count == 1 ) { CameraOnRect( Rects[Rects.Count - 1].rect ); }
            }
            GUI.enabled = ClickedOnRect && !AutoSetDialog && !SpriteSetDialog && ClickedRectInd > -1;

            if ( e.type == EventType.KeyDown && e.keyCode == KeyCode.Delete && ClickedRectInd != -1 && MouseOffGUI ) {
                RemoveRect();
            }

            if ( GUI.Button( new Rect( 60, 42, 70, 20 ), "Remove" ) ) {
        #if UNITY_2_6 || UNITY_2_6_1 ||UNITY_3_0 ||UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2
                Undo.CreateSnapshot();
                Undo.RegisterSnapshot();
        #else
                Undo.RecordObjects( FontList, "Font Changed" );
        #endif
                RemoveRect();
            }

            GUI.EndGroup(); // End Size Set group

            GUI.BeginGroup( new Rect( 0, 80, MenuBar.width, 200 ) ); //Rect properties group
            GUI.Box( new Rect( 0, 0, 150, SpriteEditor ? 192 : 142 ), "" );
            GUI.Label( new Rect( 10, 2, 140, 20 ), SpriteEditor ? "Sprite Properties:" : "Character Properties:" );
            GUI.Label( new Rect( 33, 23, 140, 20 ), SpriteEditor ? "" : "Character:" );
            GUI.SetNextControlName( "CharacterEntry" );
            if ( SpriteEditor ) {
                EditorGUIUtility.LookLikeControls( 83, 25 );
                SpriteIndex = Mathf.Max( EditorGUI.IntField( new Rect( 15, 23, 128, 20 ), "Sprite Index:", SpriteIndex, "TextField" ), 0 );
                if ( ClickedRectInd > -1 && ( SpriteIndex != SpriteIndexOld ) && !AutoSetDialog && !SpriteSetDialog ) {
                    SpriteIndexOld = SpriteIndex;
                    ChrL = SpriteIndex + 33;
                    UpdateFont( ClickedRectInd, Rects[ClickedRectInd].CIIndex, ( SpriteEditor ? Rects[ClickedRectInd].fontIndex : 0 ), true );
                    CheckSprites();
                }
            } else {
                ChrStr = EditorGUI.TextField( new Rect( 98, 23, 45, 20 ), "", ChrStr, "TextField" );
                if ( ChrStr.Length != 0 && ChrL != ChrStr[0] && !AutoSetDialog && !SpriteSetDialog && ClickedRectInd != -1 ) {
                    ChrL = ChrStr[0];
                    UpdateFont( ClickedRectInd, Rects[ClickedRectInd].CIIndex, ( SpriteEditor ? Rects[ClickedRectInd].fontIndex : 0 ), true );
                    CheckDupeChars();
                }
            }

            EditorGUIUtility.LookLikeControls( 20, 25 );
            UVx = EditorGUI.IntField( new Rect( 10, 50, 65, 20 ), "X:", UVx, "TextField" );
            UVy = EditorGUI.IntField( new Rect( 78, 50, 65, 20 ), "Y:", UVy, "TextField" );
            UVw = EditorGUI.IntField( new Rect( 10, 70, 65, 20 ), "W:", UVw, "TextField" );
            UVh = EditorGUI.IntField( new Rect( 78, 70, 65, 20 ), "H:", UVh, "TextField" );

            if ( UVRect != new Rect( UVx, UVy, UVw, UVh ) && !AutoSetDialog && !SpriteSetDialog ) {
                UVRect = new Rect( UVx, UVy, UVw, UVh );
                Rects[ClickedRectInd].rect = UVRect;
                UpdateFont( ClickedRectInd, Rects[ClickedRectInd].CIIndex, ( SpriteEditor ? Rects[ClickedRectInd].fontIndex : 0 ), true );
            }

            if ( SpriteEditor ) {
                GUI.Label( new Rect( 12, 95, 100, 60 ), "Sprite Pivot:" );
                EditorGUIUtility.LookLikeControls( 20, 25 );
                Cx = EditorGUI.FloatField( new Rect( 10, 115, 65, 20 ), "X:", Cx, "TextField" );
                Cy = EditorGUI.FloatField( new Rect( 78, 115, 65, 20 ), "Y:", Cy, "TextField" );

                if ( CPos != new Vector2( Cx, Cy ) && !AutoSetDialog && !SpriteSetDialog ) {
                    CPos = new Vector2( Cx, Cy );
                    Rects[ClickedRectInd].spritePivot = CPos;
                    UpdateFont( ClickedRectInd, Rects[ClickedRectInd].CIIndex, ( SpriteEditor ? Rects[ClickedRectInd].fontIndex : 0 ), true );
                }

                EditorGUIUtility.LookLikeControls( 40, 60 );
                RectFontIndex = EditorGUI.Popup( new Rect( 10, 145, 130, 20 ), "Font:", RectFontIndex, FontListNames );

                //change the font index outside of autoset
                if ( RectFontIndex != RectFontIndexOld && !AutoSetDialog && !SpriteSetDialog && Rects.Count > 1 ) {
                    CharacterInfo CI = FontList[RectFontIndexOld].characterInfo[Rects[ClickedRectInd].CIIndex];
                    SO = new SerializedObject( FontList[RectFontIndexOld] );
                    p = SO.FindProperty( "m_CharacterRects.Array" );
                    p.DeleteArrayElementAtIndex( Rects[ClickedRectInd].CIIndex ); //Delete the CI from the old font
                    SO.ApplyModifiedProperties();
                    for ( int i = 0; i < Rects.Count; i++ ) { //Shift down all the CIindex for all rects in this font
                        if ( Rects[i].fontIndex == RectFontIndexOld && Rects[i].CIIndex > Rects[ClickedRectInd].CIIndex ) {
                            Rects[i].CIIndex--;
                        }
                    }
                    SO = new SerializedObject( FontList[RectFontIndex] );
                    p = SO.FindProperty( "m_CharacterRects.Array.size" );
                    p.intValue = FontList[RectFontIndex].characterInfo.Length + 1; //Expand the new font to accomodate the CI
                    p = SO.FindProperty( "m_CharacterRects.Array" );
                    p2 = p.GetArrayElementAtIndex( FontList[RectFontIndex].characterInfo.Length ); //Set all the values from the CI
                    p2.Next( true ); //p2 is now CharIndex
                    p2.intValue = CI.index;
                    p2.Next( false ); //p2 is now UV Rect
                    p2.rectValue = CI.uv;
                    p2.Next( false ); //p2 is now Vert Rect
                    p2.rectValue = CI.vert;
                    p2.Next( false ); //p2 is now Width
                    p2.floatValue = CI.width;
                    p2.Next( false ); //p2 is now Flip bool
                    p2.boolValue = CI.flipped;
                    SO.ApplyModifiedProperties();

                    Rects[ClickedRectInd].fontIndex = RectFontIndex;
                    Rects[ClickedRectInd].CIIndex = FontList[RectFontIndex].characterInfo.Length - 1;
                    UpdateFont( ClickedRectInd, Rects[ClickedRectInd].CIIndex, ( SpriteEditor ? Rects[ClickedRectInd].fontIndex : 0 ), true );
                    RectFontIndexOld = RectFontIndex;
                    CheckSprites();
                }

                //change the font index during autoset
                if ( RectFontIndex != RectFontIndexOld && !AutoSetDialog && SpriteSetDialog ) {
                    SpriteIndex = FontList[RectFontIndex].characterInfo.Length - 1;
                    RectFontIndexOld = RectFontIndex;
                }

                GUI.enabled = ErrorMsg[(int) Errors.DupeSprite] || ErrorMsg[(int) Errors.SkipSprite];
                if ( GUI.Button( new Rect( 50, 165, 90, 18 ), "Fix Indices" ) ) {
                    int missing = CheckSprites( Rects[ClickedRectInd].fontIndex );
                    while ( missing != -1 ) {
                        for ( int i = 0; i < Rects.Count; i++ ) {
                            if ( Rects[i].fontIndex == Rects[ClickedRectInd].fontIndex ) {
                                if (
                                ( ErrorMsg[(int) Errors.DupeSprite] && missing != i && FontList[Rects[ClickedRectInd].fontIndex].characterInfo[Rects[i].CIIndex].index >= FontList[Rects[ClickedRectInd].fontIndex].characterInfo[Rects[missing].CIIndex].index ) ||
                                ( ErrorMsg[(int) Errors.SkipSprite] && FontList[Rects[ClickedRectInd].fontIndex].characterInfo[Rects[i].CIIndex].index - 33 > missing ) ) {
                                    SO = new SerializedObject( FontList[Rects[ClickedRectInd].fontIndex] );
                                    p = SO.FindProperty( "m_CharacterRects.Array" );
                                    p2 = p.GetArrayElementAtIndex( Rects[i].CIIndex );
                                    p2.Next( true ); //p2 is now CharIndex
                                    p2.intValue += DupeMissOffset;
                                    SO.ApplyModifiedProperties();
                                }
                            }
                        }
                        missing = CheckSprites( Rects[ClickedRectInd].fontIndex );
                    }
                    GetFontInfoToGUI( Rects[ClickedRectInd].CIIndex, Rects[ClickedRectInd].fontIndex );
                }
            } else {
                EditorGUIUtility.LookLikeControls( 88, 25 );
                WidBefore = EditorGUI.FloatField( new Rect( 10, 95, 133, 20 ), "Leading Width:", WidBefore, "TextField" );
                WidAfter = EditorGUI.FloatField( new Rect( 10, 115, 133, 20 ), "Trailing Width:", WidAfter, "TextField" );

                if ( WidBefore != WidBeforeOld && !AutoSetDialog && !SpriteSetDialog ) {
                    WidBeforeOld = WidBefore;
                    Rects[ClickedRectInd].bWidth = WidBefore;
                    UpdateFont( ClickedRectInd, Rects[ClickedRectInd].CIIndex, ( SpriteEditor ? Rects[ClickedRectInd].fontIndex : 0 ), true );
                }

                if ( WidAfter != WidAfterOld && !AutoSetDialog && !SpriteSetDialog ) {
                    WidAfterOld = WidAfter;
                    Rects[ClickedRectInd].aWidth = WidAfter;
                    UpdateFont( ClickedRectInd, Rects[ClickedRectInd].CIIndex, ( SpriteEditor ? Rects[ClickedRectInd].fontIndex : 0 ), true );
                }
            }
            GUI.EndGroup(); // End Rect properties group

            if ( !SpriteEditor ) {
                GUI.enabled = !PerCharacterOffset && !AutoSetDialog;
                if ( GUI.Button( new Rect( 10, 230, 130, 35 ), "Use Per-Character\nVertical Offsets" ) ) {
                    for ( int i = 0; i < Rects.Count; i++ ) {
                        SO = new SerializedObject( FontList[0] );
                        p = SO.FindProperty( "m_CharacterRects" );
                        p.Next( true );
                        p2 = p.GetArrayElementAtIndex( i );
                        p2.Next( true ); //p2 is now CharIndex
                        p2.Next( false ); //p2 is now UV Rect
                        p2.Next( false ); //p2 is now Vert Rect
                        Rects[i].vOffset = p2.rectValue.y;
                    }
                    PerCharacterOffset = true;
                }
            }

            GUI.BeginGroup( new Rect( 10, 270, MenuBar.width - 10, 150 ) ); //Snaps Group
            GUI.Label( new Rect( 0, 0, 100, 20 ), "Snap:" );
            GUI.enabled = ClickedOnRect && !AutoSetDialog && !SpriteSetDialog && ClickedRectInd > -1;
            Snap = GUI.SelectionGrid( new Rect( 0, 20, 130, 40 ), Snap, Snaps, 2 );
            GUI.EndGroup();

            GUI.BeginGroup( new Rect( 0, 330, 150, 250 ) ); //Orientation buttons
            GUI.Label( new Rect( 10, 0, 130, 20 ), "Character Orientation:" );
            Orient = GUI.SelectionGrid( new Rect( 11, 20, 128, 64 ), Orient, OrientPics, 2, "BlankButton" );

            if ( Orient != OrientOld && !AutoSetDialog && !SpriteSetDialog ) {
                OrientOld = Orient;
                Rects[ClickedRectInd].Orient = ( Orient == 1 );
                UpdateFont( ClickedRectInd, Rects[ClickedRectInd].CIIndex, ( SpriteEditor ? Rects[ClickedRectInd].fontIndex : 0 ), true );
            }
            GUI.EndGroup();

            GUI.BeginGroup( new Rect( 0, 417, 150, 250 ) ); //interface toggles
            GUI.Label( new Rect( 30, 0, 130, 40 ), SpriteEditor ? "Move all\nsprite pivots" : "Move all\nvertical offsets" );
            MovingAllToggle = GUI.Toggle( new Rect( 10, 6, 130, 20 ), MovingAllToggle, "" );
            if ( MovingAllToggle && SpriteEditor ) {
                MovingAllSpriteToggle = GUI.Toggle( new Rect( 10, 32, 130, 20 ), MovingAllSpriteToggle, "Only this anim" );
            }
            GUI.EndGroup();

            GUI.enabled = true;

            GUI.BeginGroup( new Rect( 0, position.height - 40, MenuBar.width, 50 ) ); //BGCol Group
            GUI.Label( new Rect( 10, 0, 130, 40 ), "Background\ncolor:" );
            BGCol = EditorGUI.ColorField( new Rect( 90, 8, 50, 20 ), BGCol );
            GUI.EndGroup();

            if ( AutoSetDialog ) {//AutoSet Dialog
                GUI.BeginGroup( new Rect( position.width - 150, ( position.height / 2 ) - 120, 150, 200 ) ); //Clip AUTOSET Dialog
                GUI.Box( new Rect( 0, 0, 150, 135 + PromptOffset4 ), "" );
                GUI.Label( new Rect( 10, 10, 140, 20 ), "What character is this?" );
                if ( e.type == EventType.KeyDown && e.keyCode == KeyCode.Return && AutoSetCharStr.Length > 0 && GUI.GetNameOfFocusedControl() == "AutoText" ) {
                    AddRect( false, 0 );
                }
                if ( e.type == EventType.KeyDown && e.keyCode == KeyCode.Escape && GUI.GetNameOfFocusedControl() == "AutoText" ) {
                    SkipRect();
                }
                GUI.SetNextControlName( "AutoText" );
                AutoSetCharStr = EditorGUI.TextField( new Rect( 55, 30, 40, 21 ), "", AutoSetCharStr, "TextField" );
                GUI.enabled = AutoSetCharStr.Length > 0;
                if ( GUI.Button( new Rect( 10, 55, 60, 30 ), "Next" ) ) {
                    AddRect( false, 0 );
                }
                GUI.enabled = true;
                if ( GUI.Button( new Rect( 80, 55, 60, 30 ), "Skip" ) ) {
                    SkipRect();
                }
                GUI.BeginGroup( new Rect( 10, 90 + PromptOffset4, 130, 30 ) ); //stop AUTOSET Dialog
                if ( DialogStop ) {
                    if ( GUI.Button( new Rect( 0, 0, 60, 30 ), "Stop" ) ) {
                        PromptOffset4Dest = 0;
                        EndAutoSet();
                        AutoRectList.Clear();
                    }
                    if ( GUI.Button( new Rect( 70, 0, 60, 30 ), "Cancel" ) ) {
                        PromptOffset4Dest = 0;
                    }
                }
                GUI.EndGroup();
                if ( GUI.Button( new Rect( 10, 90, 130, 30 ), "Stop Auto Set" ) ) {
                    DialogStop = true;
                    PromptOffset4Dest = 30;
                }
                if ( CharRepeatList.Count > 1 && AutoSetIndex == 0 ) {
                    if ( GUI.Button( new Rect( 30, 135 + PromptOffset4, 90, 20 ), "Repeat Last" ) ) {
                        RepeatSetting = true;
                        for ( int i = 0; i < CharRepeatList.Count; i++ ) {
                            if ( CharRepeatList[i] == 0 ) {
                                AutoRectList.RemoveAt( AutoSetIndex );
                                AutoSetCharStr = "";
                            } else {
                                AutoSetCharStr = "" + CharRepeatList[i];
                                AddRect( false, 0 );
                            }
                        }
                        RepeatSetting = false;
                        EndAutoSet();
                    }
                }
                GUI.FocusControl( "AutoText" );
                GUI.EndGroup();
            }

            if ( ErrorMsg[(int) Errors.Spacebar] ) {
                GUI.BeginGroup( new Rect( position.width - MenuBar.width, 100, MenuBar.width, 200 ) );//SPACEBAR Prompt
                GUI.Box( new Rect( 0, 0, 150, 61 ), "" );
                GUI.Label( new Rect( 10, 4, 135, 60 ), "Don't forget to add a Rect for the Spacebar character!" );
                if ( GUI.Button( new Rect( 96, 39, 50, 18 ), "OK" ) ) {
                    ErrorMsg[(int) Errors.Spacebar] = false;
                }
                GUI.EndGroup();
            }

            if ( ErrorMsg[(int) Errors.SkipSprite] ) {
                GUI.BeginGroup( new Rect( position.width - MenuBar.width - ( ErrorMsg[(int) Errors.OverlapSprite] ? 323 : 169 ), position.height - 43, 170, 43 ) );//Skipped Sprite
                GUI.Box( new Rect( 0, 0, 170, 43 ), "" );
                SplitError = SkipErrorString.Split( '#' );
                GUI.color = Colors[int.Parse( SplitError[0] )];
                GUI.Label( new Rect( 6, 5, 160, 60 ), SplitError[1], "RectLabel" );
                GUI.color = Color.white;
                GUI.Label( new Rect( 10, 19, 160, 60 ), SplitError[2] );
                GUI.EndGroup();
            }

            if ( ErrorMsg[(int) Errors.DupeSprite] ) {
                GUI.BeginGroup( new Rect( position.width - MenuBar.width - ( ErrorMsg[(int) Errors.OverlapSprite] ? 308 : 154 ), position.height - 57, 170, 57 ) );//Duped Sprite
                GUI.Box( new Rect( 0, 0, 155, 57 ), "" );
                SplitError = DupeErrorString.Split( '#' );
                GUI.Label( new Rect( 10, 4, 150, 60 ), "" + SplitError[0] );
                GUI.color = Colors[int.Parse( SplitError[1] )];
                GUI.Label( new Rect( 8, 22, 150, 60 ), "" + SplitError[2], "RectLabel" );
                GUI.color = Color.white;
                GUI.Label( new Rect( 10, 34, 150, 60 ), "" + SplitError[3] );
                GUI.EndGroup();
            }

            if ( ErrorMsg[(int) Errors.OverlapSprite] ) {
                GUI.BeginGroup( new Rect( position.width - MenuBar.width - 154, position.height - 80, 170, 80 ) );//Overlapping Sprite
                GUI.Box( new Rect( 0, 0, 155, 80 ), "" );
                SplitError = OverlapErrorString.Split( '#' );
                GUI.Label( new Rect( 10, 3, 150, 30 ), "The Rect for" );
                GUI.color = Colors[int.Parse( SplitError[0] )];

                if ( GUI.Button( new Rect( 4, 22, 147, 18 ), SplitError[1] ) ) {
                    ClickedRectInd = SecondOverlapRect;
                    ReFocusBlank = true;
                    CameraOnRect( Rects[ClickedRectInd].rect );
                    GetFontInfoToGUI( Rects[ClickedRectInd].CIIndex, ( SpriteEditor ? Rects[ClickedRectInd].fontIndex : 0 ) );
                }

                GUI.color = Color.white;
                GUI.Label( new Rect( 10, 39, 150, 30 ), "overlaps with" );
                GUI.color = Colors[int.Parse( SplitError[2] )];

                if ( GUI.Button( new Rect( 4, 58, 147, 18 ), SplitError[3] ) ) {
                    ClickedRectInd = FirstOverlapRect;
                    ReFocusBlank = true;
                    CameraOnRect( Rects[ClickedRectInd].rect );
                    GetFontInfoToGUI( Rects[ClickedRectInd].CIIndex, ( SpriteEditor ? Rects[ClickedRectInd].fontIndex : 0 ) );
                }

                GUI.color = Color.white;
                GUI.EndGroup();
            }

            if ( ErrorMsg[(int) Errors.DupeChar] ) {
                GUI.BeginGroup( new Rect( position.width - MenuBar.width - 129, position.height - 60, 130, 60 ) );//Duped Character
                GUI.Box( new Rect( 0, 0, 130, 60 ), "" );
                GUI.Label( new Rect( 8, 2, 120, 60 ), DupeErrorString );
                if ( GUI.Button( new Rect( 4, 38, 60, 18 ), "First" ) ) {
                    ClickedRectInd = FirstDupeRect;
                    ReFocusBlank = true;
                    CameraOnRect( Rects[ClickedRectInd].rect );
                    GetFontInfoToGUI( Rects[ClickedRectInd].CIIndex, ( SpriteEditor ? Rects[ClickedRectInd].fontIndex : 0 ) );
                }
                if ( GUI.Button( new Rect( 66, 38, 60, 18 ), "Second" ) ) {
                    ClickedRectInd = SecondDupeRect;
                    ReFocusBlank = true;
                    CameraOnRect( Rects[ClickedRectInd].rect );
                    GetFontInfoToGUI( Rects[ClickedRectInd].CIIndex, ( SpriteEditor ? Rects[ClickedRectInd].fontIndex : 0 ) );
                }
                GUI.EndGroup();
            }

            if ( ErrorMsg[(int) Errors.OverlapChar] ) {
                GUI.BeginGroup( new Rect( position.width - MenuBar.width - ( ErrorMsg[(int) Errors.DupeChar] ? 228 : 99 ), position.height - 60, 130, 60 ) );//Overlapping Character Rects
                SplitError = OverlapErrorString.Split( '#' );
                GUI.Box( new Rect( 0, 0, 100, 60 ), "" );
                GUI.Label( new Rect( 6, 4, 90, 60 ), SplitError[0] );
                if ( GUI.Button( new Rect( 4, 38, 45, 18 ), SplitError[1] ) ) {
                    ClickedRectInd = FirstOverlapRect;
                    ReFocusBlank = true;
                    CameraOnRect( Rects[ClickedRectInd].rect );
                    GetFontInfoToGUI( Rects[ClickedRectInd].CIIndex, ( SpriteEditor ? Rects[ClickedRectInd].fontIndex : 0 ) );
                }
                if ( GUI.Button( new Rect( 51, 38, 45, 18 ), SplitError[2] ) ) {
                    ClickedRectInd = SecondOverlapRect;
                    ReFocusBlank = true;
                    CameraOnRect( Rects[ClickedRectInd].rect );
                    GetFontInfoToGUI( Rects[ClickedRectInd].CIIndex, ( SpriteEditor ? Rects[ClickedRectInd].fontIndex : 0 ) );
                }
                GUI.EndGroup();
            }

            if ( SpriteSetDialog ) {//SpriteSet Dialog
                GUI.BeginGroup( new Rect( position.width - 150, position.height / 2 - 120, 167, 200 ) ); //Clip SpriteSet Dialog
                GUI.Box( new Rect( 0, 0, 150, 149 + PromptOffset4 ), "" );
                if ( GUI.Button( new Rect( 10, 72, 60, 30 ), "Next" ) ) {
                    AddRect( true, RectFontIndex );
                }
                if ( e.type == EventType.KeyDown && e.keyCode == KeyCode.Return && GUI.GetNameOfFocusedControl() == "SpriteIndInput" ) {
                    AddRect( true, RectFontIndex );
                }
                if ( e.type == EventType.KeyDown && e.keyCode == KeyCode.Escape && GUI.GetNameOfFocusedControl() == "SpriteIndInput" ) {
                    SkipRect();
                }

                EditorGUIUtility.LookLikeControls( 40, 60 );
                RectFontIndex = EditorGUI.Popup( new Rect( 10, 10, 130, 20 ), "Font:", RectFontIndex, FontListNames );
                EditorGUIUtility.LookLikeControls( 80, 50 );
                GUI.SetNextControlName( "SpriteIndInput" );
                SpriteIndex = Mathf.Max( EditorGUI.IntField( new Rect( 10, 30, 130, 20 ), "Sprite Index:", SpriteIndex ), 0 );
                EditorGUIUtility.LookLikeControls( 40, 60 );
                defaultPivotPoint = (defaultPivotPointEnum) EditorGUI.EnumPopup( new Rect( 10, 53, 130, 20 ), "Pivot:", defaultPivotPoint );
                if ( GUI.Button( new Rect( 80, 72, 60, 30 ), "Skip" ) ) {
                    SkipRect();
                }
                GUI.BeginGroup( new Rect( 10, 107 + PromptOffset4, 130, 30 ) ); //stop SpriteSet Dialog
                if ( DialogStop ) {
                    if ( GUI.Button( new Rect( 0, 0, 60, 30 ), "Stop" ) ) {
                        PromptOffset4Dest = 0;
                        EndAutoSet();
                        AutoRectList.Clear();
                    }
                    if ( GUI.Button( new Rect( 70, 0, 60, 30 ), "Cancel" ) ) {
                        PromptOffset4Dest = 0;
                    }
                }
                GUI.EndGroup();
                if ( GUI.Button( new Rect( 10, 107, 130, 30 ), "Stop Sprite Set" ) ) {
                    DialogStop = true;
                    PromptOffset4Dest = 30;
                }
                if ( SpriteIndexRepeatList.Count > 1 && AutoSetIndex == 0 ) {
                    if ( GUI.Button( new Rect( 30, 149 + PromptOffset4, 90, 20 ), "Repeat Last" ) ) {
                        RepeatSetting = true;
                        for ( int i = 0; i < SpriteIndexRepeatList.Count; i++ ) {
                            if ( SpriteIndexRepeatList[i].x == -1 ) {
                                AutoRectList.RemoveAt( AutoSetIndex );
                            } else {
                                SpriteIndex = (int) SpriteIndexRepeatList[i].x;
                                RectFontIndex = (int) SpriteIndexRepeatList[i].y;
                                defaultPivotPoint = (defaultPivotPointEnum) ( SpriteIndexRepeatList[i].z );
                                AddRect( true, RectFontIndex );
                            }
                        }
                        RepeatSetting = false;
                        EndAutoSet();
                    }
                }
                GUI.FocusControl( "SpriteIndInput" );
                GUI.EndGroup();
            }
        } //End of font setter

        //Below here is drawing RectPacker GUI
        if ( UsingPacker ) {
            GUI.Box( new Rect( position.width - MenuBar.width, 0, MenuBar.width, MenuBar.height ), "" );/////RightBox
            GUI.BeginGroup( new Rect( 4, 4, position.width - 4, MenuBar.height - 8 ) );//Clip The Menu pics
            GUI.DrawTexture( new Rect( position.width - 8 - MenuPics[2].width, 0, MenuPics[2].width, MenuPics[2].height ), MenuPics[2] );
            GUI.EndGroup();
            GUI.BeginGroup( new Rect( position.width - MenuBar.width, position.height - 80 - PromptOffset1, MenuBar.width, 50 ) ); //BGCol Group
            GUI.Label( new Rect( 10, 0, 130, 40 ), "Background\ncolor:" );
            BGCol = EditorGUI.ColorField( new Rect( 90, 8, 50, 20 ), BGCol );
            GUI.EndGroup();

            GUI.BeginGroup( new Rect( position.width - MenuBar.width + 10, position.height - 70, MenuBar.width, 150 ) ); //Back to menu Group
            GUI.BeginGroup( new Rect( 0, 30 - PromptOffset1, 130, 200 ) ); //Back to menu Group
            if ( MenuPrompt ) {
                if ( GUI.Button( new Rect( 0, 0, 60, 30 ), "Return" ) ) {
                    UsingPacker = false;
                    UsingMenu = true;
                    ResetError();
                    MenuPrompt = false;
                    PromptOffset1Dest = 0;
                    position = new Rect( position.x, position.y - 5, 512, 512 );
                }
                if ( GUI.Button( new Rect( 70, 0, 60, 30 ), "Cancel" ) ) {
                    PromptOffset1Dest = 0;
                }
            }
            GUI.EndGroup();
            if ( GUI.Button( new Rect( 0, 31, 130, 30 ), "Return to Menu" ) ) {
                PromptOffset1Dest = 30;
                MenuPrompt = true;
            }
            GUI.EndGroup();

            GUI.BeginGroup( new Rect( 0, 0, position.width - 150, position.height ) );//Clip The Background Box
            GUI.color = BGCol;
            if ( outTex ) {
                GUI.Box( new Rect( 4 + drawOffsetPos.x, 4 + drawOffsetPos.y, outTex.width + 12, outTex.height + 12 ), "", "theTexBG" );
            } else {
                GUI.Box( new Rect( 4, 4, 256, 256 ), "", "theTexBG" );
            }
            GUI.color = Color.white;
            GUI.EndGroup();

            if ( GUI.Button( new Rect( position.width - 140, 10, 130, 30 ), "Pack!" ) ) {
                ClearLog();
                BeginPack();
            }

            GUI.BeginGroup( new Rect( position.width - 140, 45, 130, 500 ) );
            GUI.Label( new Rect( 0, 0, 130, 20 ), "Sort Rects:" );
            SortMode = GUI.SelectionGrid( new Rect( 0, 20, 130, 75 ), SortMode, Sorts, 2 );
            GUI.Label( new Rect( 0, 110, 130, 22 ), "Packing Method:" );
            PackMode = GUI.SelectionGrid( new Rect( 0, 130, 130, 75 ), PackMode, Packs, 2 );
            AllowNPOT = GUI.Toggle( new Rect( 0, 220, 130, 20 ), AllowNPOT, "Allow NPOT result" );
            AllowRotationTest = GUI.Toggle( new Rect( 0, 240, 130, 20 ), AllowRotationTest, "Allow Rotation test" ); ;
            AnchorSort = GUI.Toggle( new Rect( 0, 260, 130, 20 ), AnchorSort, "Sort Anchor Mode" ); ;
            FitToPOT = GUI.Toggle( new Rect( 0, 280, 130, 20 ), FitToPOT, "Fit to POT Texture" );
            EditorGUIUtility.LookLikeControls( 80, 25 );
            PackBuffer = Mathf.Max( EditorGUI.IntField( new Rect( 0, 305, 130, 20 ), "Rect Buffer:", PackBuffer, "TextField" ), 0 );
            GUI.EndGroup();

            if ( outTex ) {
                GUI.BeginGroup( new Rect( 0, 0, position.width - 150, position.height ) );
                GUI.DrawTexture( new Rect( 10 + drawOffsetPos.x, 10 + drawOffsetPos.y, outTex.width, outTex.height ), outTex );
                GUI.EndGroup();
            }
        }

        if ( ErrorMsg[(int) Errors.NoMaterial] ) {
            GUI.BeginGroup( new Rect( position.width / 2 - 75, position.height / 2 - 30, 150, 150 ) ); //Error NoMaterial Group
            GUI.Box( new Rect( 0, 0, 150, 90 ), "" );
            GUI.Label( new Rect( 8, 4, 135, 150 ), "One of your Fonts has no material attatched. Add a material that uses the \"Textured Text Shader\" shader." );
            GUI.EndGroup();
        }

        if ( ErrorMsg[(int) Errors.NoTexture] ) {
            GUI.BeginGroup( new Rect( position.width / 2 - 75, position.height / 2 - 30, 150, 150 ) ); //Error NoMaterial Group
            GUI.Box( new Rect( 0, 0, 150, 60 ), "" );
            GUI.Label( new Rect( 8, 4, 135, 150 ), "One of your Fonts has a material with no texture map assigned." );
            GUI.EndGroup();
        }

        if ( ErrorMsg[(int) Errors.NoSpriteMaterial] ) {
            GUI.BeginGroup( new Rect( position.width / 2 - 65, position.height / 2 - 30, 130, 150 ) ); //Error No Sprite Material Group
            GUI.Box( new Rect( 0, 0, 130, 60 ), "" );
            GUI.Label( new Rect( 8, 4, 125, 150 ), "Your sprite has no material and/or texture assigned." );
            GUI.EndGroup();
        }

        if ( ErrorMsg[(int) Errors.NoTextMesh] ) {
            GUI.BeginGroup( new Rect( position.width / 2 - 71, position.height / 2 - 30, 142, 150 ) ); //Error No TextMesh/Renderer Group
            GUI.Box( new Rect( 0, 0, 142, 60 ), "" );
            GUI.Label( new Rect( 8, 4, 137, 150 ), "Your sprite has no TextMesh and/or no Renderer components." );
            GUI.EndGroup();
        }

        if ( ErrorMsg[(int) Errors.NPOT] ) {
            GUI.BeginGroup( new Rect( position.width / 2 - 100, position.height / 2 - 30, 200, 60 ) ); //Error NPOT Group
            GUI.Box( new Rect( 0, 0, 200, 60 ), "" );
            GUI.Label( new Rect( 6, 4, 190, 150 ), "Your Font Map is NPOT, Change the Import Settings property for NPOT maps to 'None'." );
            GUI.EndGroup();
        }

        if ( ErrorMsg[(int) Errors.ReadWrite] ) {
            GUI.BeginGroup( new Rect( position.width / 2 - 100, position.height / 2 - 30, 200, 60 ) ); //Error ReadWrite Group
            GUI.Box( new Rect( 0, 0, 200, 60 ), "" );
            GUI.Label( new Rect( 10, 4, 190, 60 ), "Please set Read/Write Enabled in the texture settings for the Font Map before running." );
            GUI.EndGroup();
        }

        if ( ErrorMsg[(int) Errors.Format] ) {
            GUI.BeginGroup( new Rect( position.width / 2 - 100, position.height / 2 - 40, 200, 80 ) ); //Error Format Group
            GUI.Box( new Rect( 0, 0, 200, 80 ), "" );
            GUI.Label( new Rect( 10, 4, 185, 80 ), "Please set the Font Map to a compatible format in its Texture Settings (eg. Compressed, Truecolor, RGBA32)." );
            GUI.EndGroup();
        }

        if ( ErrorMsg[(int) Errors.Size] ) {
            GUI.BeginGroup( new Rect( position.width / 2 - 75, position.height / 2 - 30, 200, 130 ) ); //Error Size Group
            GUI.Box( new Rect( 0, 0, 150, 80 ), "" );
            GUI.Label( new Rect( 8, 4, 135, 130 ), "Your texture Map is larger than the import size, change this in the Import Settings" );
            GUI.EndGroup();
        }

        if ( ErrorMsg[(int) Errors.SameFont] ) {
            GUI.BeginGroup( new Rect( position.width / 2 - 90, position.height / 2 - 30, 180, 130 ) ); //Error SameFont Group
            GUI.Box( new Rect( 0, 0, 180, 60 ), "" );
            GUI.Label( new Rect( 8, 4, 170, 60 ), "You have assigned a sprite that has the same font (animation) more than once." );
            GUI.EndGroup();
        }

        if ( ErrorMsg[(int) Errors.NoFonts] ) {
            GUI.BeginGroup( new Rect( position.width / 2 - 75, position.height / 2 - 30, 150, 130 ) ); //Error NoFonts Group
            GUI.Box( new Rect( 0, 0, 150, 60 ), "" );
            GUI.Label( new Rect( 8, 4, 130, 60 ), "You have assigned a sprite that contains no fonts (animations)." );
            GUI.EndGroup();
        }

        if ( ErrorMsg[(int) Errors.MissedFont] ) {
            GUI.BeginGroup( new Rect( position.width / 2 - 75, position.height / 2 - 30, 150, 130 ) ); //Error MissedFont Group
            GUI.Box( new Rect( 0, 0, 150, 60 ), "" );
            GUI.Label( new Rect( 8, 4, 130, 60 ), "You have assigned a sprite with a missing font (animation)." );
            GUI.EndGroup();
        }

        if ( ErrorMsg[(int) Errors.ShareFont] ) {
            GUI.BeginGroup( new Rect( position.width / 2 - 70, position.height / 2 - 30, 140, 130 ) ); //Error ShareFont Group
            GUI.Box( new Rect( 0, 0, 140, 60 ), "" );
            GUI.Label( new Rect( 8, 4, 130, 60 ), "The in-sprite and out-sprite share font (animation) objects." );
            GUI.EndGroup();
        }

        if ( ErrorMsg[(int) Errors.UnevenLength] ) {
            GUI.BeginGroup( new Rect( position.width / 2 - 85, position.height / 2 - 30, 170, 130 ) ); //Error UnevenLength Group
            GUI.Box( new Rect( 0, 0, 170, 60 ), "" );
            GUI.Label( new Rect( 8, 4, 160, 60 ), "The in-sprite and out-sprite have a different number of fonts (animations)." );
            GUI.EndGroup();
        }

        this.Repaint();
    }
Exemplo n.º 5
0
 // Update is called once per frame
 void Update()
 {
     if (SetRect.isTouchDown)
     {
         if (Input.GetAxis("Mouse X") < -0.3)
         {
             //Code for action on mouse moving left
             dir = Direction.LEFT;
             print("Mouse moved left");
         }
         if (Input.GetAxis("Mouse X") > 0.3)
         {
             //Code for action on mouse moving right
             dir = Direction.RIGHT;
             print("Mouse moved right");
         }
         if (Input.GetAxis("Mouse Y") < -0.3)
         {
             //Code for action on mouse moving down
             dir = Direction.DOWN;
             print("Mouse moved down");
         }
         if (Input.GetAxis("Mouse Y") > 0.3)
         {
             //Code for action on mouse moving up
             dir = Direction.UP;
             print("Mouse moved up");
         }
         if (Input.GetAxis("Mouse Y") > -0.3 && Input.GetAxis("Mouse Y") < 0.3 &&
             Input.GetAxis("Mouse X") > -0.3 && Input.GetAxis("Mouse X") < 0.3)
         {
             dir = Direction.NONE;
         }
         print(objBlock.Length);
         for (int i = 0; i < objBlock.Length; i++)
         {
             SetRect tempRect = (SetRect)objBlock[i].GetComponent("SetRect");
             if (tempRect.isTouch)
             {
                 if (dir == Direction.LEFT)
                 {
                     tempRect.isTouch = false;
                     tempObj2         = (TouchEvent)objBlock[i].GetComponent("TouchEvent");
                     if (tempObj2.column != 0)
                     {
                         tempObj2.moveL();
                         arrNum = i;
                         isMove = true;
                         break;
                     }
                 }
                 if (dir == Direction.RIGHT)
                 {
                     tempRect.isTouch = false;
                     tempObj2         = (TouchEvent)objBlock[i].GetComponent("TouchEvent");
                     if (tempObj2.column != num - 1)
                     {
                         tempObj2.moveR();
                         arrNum = i;
                         isMove = true;
                         break;
                     }
                 }
                 if (dir == Direction.UP)
                 {
                     tempRect.isTouch = false;
                     tempObj2         = (TouchEvent)objBlock[i].GetComponent("TouchEvent");
                     if (tempObj2.row != num - 1)
                     {
                         tempObj2.moveU();
                         arrNum = i;
                         isMove = true;
                         break;
                     }
                 }
                 if (dir == Direction.DOWN)
                 {
                     tempRect.isTouch = false;
                     tempObj2         = (TouchEvent)objBlock[i].GetComponent("TouchEvent");
                     if (tempObj2.row != 0)
                     {
                         tempObj2.moveD();
                         arrNum = i;
                         isMove = true;
                         break;
                     }
                 }
             }
         }
         if (isMove)
         {
             for (int j = 0; j < objBlock.Length; j++)
             {
                 if (arrNum != j)
                 {
                     TouchEvent tempEvent = (TouchEvent)objBlock[j].GetComponent("TouchEvent");
                     if (objBlock[j].transform.position == tempObj2.transform.position)
                     {
                         if (dir == Direction.LEFT)
                         {
                             tempEvent.moveR();
                             isMove = false;
                             Match();
                         }
                         if (dir == Direction.RIGHT)
                         {
                             tempEvent.moveL();
                             isMove = false;
                             Match();
                         }
                         if (dir == Direction.UP)
                         {
                             tempEvent.moveD();
                             isMove = false;
                             Match();
                         }
                         if (dir == Direction.DOWN)
                         {
                             tempEvent.moveU();
                             isMove = false;
                             Match();
                         }
                         break;
                     }
                 }
             }
         }
     }
 }