Example #1
0
 public override void OnGUI(Rect position, UnityEditor.SerializedProperty p, GUIContent label)
 {
     UnityEditor.EditorGUI.BeginProperty(position, label, p);
     Rect[] controls = new Rect[2];
     controls[0] = new Rect(position.x, position.y, position.width / 2, position.height);
     controls[1] = new Rect(controls[0].xMax, position.y, position.width / 2, position.height);
     p.Next(true);
     UnityEditor.EditorGUI.PropertyField(controls[0], p);
     p.Next(true);
     //p.colorValue = UnityEditor.EditorGUI.ColorField(controls[1], p.colorValue);
     UnityEditor.EditorGUI.PropertyField(controls[1], p);
     UnityEditor.EditorGUI.EndProperty();
 }
        public override void OnGUI(Rect position, SerializedProperty prop, GUIContent label)
        {
            Rect textFieldPosition = position;
            textFieldPosition.height = 16;
            textFieldPosition.width -= 64;

            // Get the path field
            prop.Next(true);

            EditorGUI.LabelField(textFieldPosition, label);

            Rect buttonPosition = position;
            buttonPosition.height = 16;
            buttonPosition.x += buttonPosition.width - 128;
            buttonPosition.width = 128;

            List<string> mapNames = new List<string>();

            for(int i = 0; i < EditorBuildSettings.scenes.Length; i++)
            {
                string name = Path.GetFileNameWithoutExtension(EditorBuildSettings.scenes[i].path);

                mapNames.Add(name);
            }

            prop.intValue = EditorGUI.Popup(buttonPosition, prop.intValue, mapNames.ToArray());

            prop.serializedObject.ApplyModifiedProperties();
        }
        public override void OnGUI(Rect position, SerializedProperty prop, GUIContent label)
        {
            Rect textFieldPosition = position;
            textFieldPosition.height = 16;
            textFieldPosition.width -= 64;

            // Get the path field
            prop.Next(true);

            string pathLabel = prop.stringValue;

            if(string.IsNullOrEmpty(pathLabel))
            {
                pathLabel = "(none)";
            }

            EditorGUI.LabelField(textFieldPosition, label, new GUIContent(pathLabel));

            Rect buttonPosition = position;
            buttonPosition.height = 16;
            buttonPosition.x += buttonPosition.width - 48;
            buttonPosition.width = 48;

            DataTool.Log(prop);

            prop.serializedObject.ApplyModifiedProperties();
        }
 //Get property height.
 public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
 {
     SpriteRenderer spriteRenderer = ((SpriteShatter.Shatter) property.serializedObject.targetObject).gameObject.GetComponent<SpriteRenderer>();
     if (spriteRenderer == null || spriteRenderer.sprite == null)
         return base.GetPropertyHeight(property, label) * 2;
     bool textureIsReadable = ((TextureImporter) AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(spriteRenderer.sprite))).isReadable;
     for (int i = 0; i < 3; i++)
         property.Next(true);
     return (base.GetPropertyHeight(property, label) + EditorGUIUtility.standardVerticalSpacing) * ((textureIsReadable ? 15 : 21) +
             (property.boolValue ? 0 : 1)) + (textureIsReadable ? (int) (((float) (int) spriteRenderer.sprite.rect.height /
             (float) (int) spriteRenderer.sprite.rect.width) * Screen.width * 0.75f) : 0);
 }
        /// <summary>
        /// Copies value of <paramref name="sourceProperty"/> into <pararef name="destProperty"/>.
        /// </summary>
        /// <param name="destProperty">Destination property.</param>
        /// <param name="sourceProperty">Source property.</param>
        public static void CopyPropertyValue(SerializedProperty destProperty, SerializedProperty sourceProperty)
        {
            if (destProperty == null)
                throw new ArgumentNullException("destProperty");
            if (sourceProperty == null)
                throw new ArgumentNullException("sourceProperty");

            sourceProperty = sourceProperty.Copy();
            destProperty = destProperty.Copy();

            CopyPropertyValueSingular(destProperty, sourceProperty);

            if (sourceProperty.hasChildren) {
                int elementPropertyDepth = sourceProperty.depth;
                while (sourceProperty.Next(true) && destProperty.Next(true) && sourceProperty.depth > elementPropertyDepth)
                    CopyPropertyValueSingular(destProperty, sourceProperty);
            }
        }
        public override void OnGUI(Rect position, SerializedProperty prop, GUIContent label)
        {
            Rect textFieldPosition = position;
            textFieldPosition.height = 16;
            textFieldPosition.width -= 64;

            // Get the path field
            prop.Next(true);

            string pathLabel = prop.stringValue;

            if(string.IsNullOrEmpty(pathLabel))
            {
                pathLabel = "(none)";
            }

            EditorGUI.LabelField(textFieldPosition, label, new GUIContent(pathLabel));

            Rect buttonPosition = position;
            buttonPosition.height = 16;
            buttonPosition.x += buttonPosition.width - 48;
            buttonPosition.width = 48;

            if(GUI.Button(buttonPosition, "..."))
            {
                string newPath = EditorUtility.OpenFilePanel("Load a conversation file", prop.stringValue, "convo");

                if(!string.IsNullOrEmpty(newPath))
                {
                    newPath = newPath.Replace(Application.dataPath, "");

                    prop.stringValue = newPath;

                    prop.serializedObject.ApplyModifiedProperties();
                }
            }
        }
    private static void DrawRemainingProp(SerializedProperty prop) {
        int depth = prop.depth;

        while (true) {
            bool child = EditorGUILayout.PropertyField(prop, true);

            if (!prop.Next(child) || prop.depth < depth)
                break;
        }
    }
Example #8
0
        internal static void DisplayObjectContextMenu(Rect position, Object[] context, int contextUserData)
        {
            // Don't show context menu if we're inside the side-by-side diff comparison.
            if (EditorGUIUtility.comparisonViewMode != EditorGUIUtility.ComparisonViewMode.None)
            {
                return;
            }

            Vector2 temp = GUIUtility.GUIToScreenPoint(new Vector2(position.x, position.y));

            position.x = temp.x;
            position.y = temp.y;

            GenericMenu pm = new GenericMenu();

            if (context != null && context.Length == 1 && context[0] is Component)
            {
                Object    targetObject    = context[0];
                Component targetComponent = (Component)targetObject;

                // Do nothing if component is not on a prefab instance.
                if (PrefabUtility.GetCorrespondingConnectedObjectFromSource(targetComponent.gameObject) == null)
                {
                }
                // Handle added component.
                else if (PrefabUtility.GetCorrespondingObjectFromSource(targetObject) == null && targetComponent != null)
                {
                    GameObject instanceGo = targetComponent.gameObject;
                    PrefabUtility.HandleApplyRevertMenuItems(
                        "Added Component",
                        instanceGo,
                        (menuItemContent, sourceGo) =>
                    {
                        TargetChoiceHandler.ObjectInstanceAndSourcePathInfo info = new TargetChoiceHandler.ObjectInstanceAndSourcePathInfo();
                        info.instanceObject   = targetComponent;
                        info.assetPath        = AssetDatabase.GetAssetPath(sourceGo);
                        GameObject rootObject = PrefabUtility.GetRootGameObject(sourceGo);
                        if (!PrefabUtility.IsPartOfPrefabThatCanBeAppliedTo(rootObject))
                        {
                            pm.AddDisabledItem(menuItemContent);
                        }
                        else
                        {
                            pm.AddItem(menuItemContent, false, TargetChoiceHandler.ApplyPrefabAddedComponent, info);
                        }
                    },
                        (menuItemContent) =>
                    {
                        pm.AddItem(menuItemContent, false, TargetChoiceHandler.RevertPrefabAddedComponent, targetComponent);
                    }
                        );
                }
                else
                {
                    SerializedObject   so       = new SerializedObject(targetObject);
                    SerializedProperty property = so.GetIterator();
                    bool hasPrefabOverride      = false;
                    while (property.Next(property.hasChildren))
                    {
                        if (property.isInstantiatedPrefab && property.prefabOverride && !property.isDefaultOverride)
                        {
                            hasPrefabOverride = true;
                            break;
                        }
                    }

                    // Handle modified component.
                    if (hasPrefabOverride)
                    {
                        bool defaultOverrides =
                            PrefabUtility.IsObjectOverrideAllDefaultOverridesComparedToAnySource(targetObject);

                        PrefabUtility.HandleApplyRevertMenuItems(
                            "Modified Component",
                            targetObject,
                            (menuItemContent, sourceObject) =>
                        {
                            TargetChoiceHandler.ObjectInstanceAndSourcePathInfo info = new TargetChoiceHandler.ObjectInstanceAndSourcePathInfo();
                            info.instanceObject   = targetObject;
                            info.assetPath        = AssetDatabase.GetAssetPath(sourceObject);
                            GameObject rootObject = PrefabUtility.GetRootGameObject(sourceObject);
                            if (!PrefabUtility.IsPartOfPrefabThatCanBeAppliedTo(rootObject))
                            {
                                pm.AddDisabledItem(menuItemContent);
                            }
                            else
                            {
                                pm.AddItem(menuItemContent, false, TargetChoiceHandler.ApplyPrefabObjectOverride, info);
                            }
                        },
                            (menuItemContent) =>
                        {
                            pm.AddItem(menuItemContent, false, TargetChoiceHandler.RevertPrefabObjectOverride, targetObject);
                        },
                            defaultOverrides
                            );
                    }
                }
            }

            pm.ObjectContextDropDown(position, context, contextUserData);

            ResetMouseDown();
        }
	private bool PropsInArrayMismatched(SerializedProperty props) {
		string original = props.propertyPath;

		props.Next(true);
		props.Next(true);
		props.Next(true);

		//some weird unity behaviour where it collapses the array 
		if (!props.propertyPath.Contains(original)) {
			return true;
		}

		do {
			var nameProp = props.FindPropertyRelative("first.name");

			if (nameProp.hasMultipleDifferentValues) {
				return true;
			}
		} while (props.NextVisible(false) && props.propertyPath.Contains(original));



		return false;
	}
 //removes rect from the font settings and lists
 void RemoveRect()
 {
     ReFocusBlank = true;
     CharCount -= 1;
     SO = new SerializedObject( FontList[Rects[ClickedRectInd].fontIndex] );
     p = SO.FindProperty( "m_CharacterRects" );
     p.Next( true );
     p.DeleteArrayElementAtIndex( Rects[ClickedRectInd].CIIndex );
     SO.ApplyModifiedProperties(); //remove it from the actual font
     for ( int i = 0; i < Rects.Count; i++ ) { //Shift down all the CIindex for all rects in this font
         if ( Rects[i].fontIndex == Rects[ClickedRectInd].fontIndex && Rects[i].CIIndex > Rects[ClickedRectInd].CIIndex ) {
             Rects[i].CIIndex--;
         }
     }
     Rects.RemoveAt( ClickedRectInd ); //delete from the rect list
     if ( SpriteEditor ) { //check if removing has changed dupes
         CheckSprites();
     } else {
         CheckDupeChars();
     }
     ClickedRectInd--;
     ChrL--;
     if ( Rects.Count > 0 && ClickedRectInd == -1 ) {
         ClickedRectInd = 0;
     }
     if ( Rects.Count > 0 ) {
         GetFontInfoToGUI( Rects[ClickedRectInd].CIIndex, Rects[ClickedRectInd].fontIndex );
     } else {
         SpriteIndex = 0;
         SpriteIndexOld = 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();
    }
Example #12
0
        public void FillNodeInfos()
        {
            m_NodeInfos = new NodeInfo[m_TransformMask.arraySize];
            if (m_TransformMask.arraySize == 0)
            {
                return;
            }

            string[] paths = new string[m_TransformMask.arraySize];

            SerializedProperty prop = m_TransformMask.GetArrayElementAtIndex(0);

            prop.Next(false);

            for (int i = 1; i < m_NodeInfos.Length; i++)
            {
                m_NodeInfos[i].m_Path   = prop.FindPropertyRelative("m_Path");
                m_NodeInfos[i].m_Weight = prop.FindPropertyRelative("m_Weight");

                paths[i] = m_NodeInfos[i].m_Path.stringValue;
                string fullPath = paths[i];
                if (m_CanImport)
                {
                    // in avatar mask inspector UI,everything is enabled.
                    m_NodeInfos[i].m_State = NodeInfo.State.enabled;
                }
                else if (humanTransforms != null)
                {
                    //  Enable only transforms that are not human. Human transforms in this case are handled by muscle curves and cannot be imported.
                    if (ArrayUtility.FindIndex(humanTransforms, s => fullPath == s) == -1)
                    {
                        if (m_TransformPaths != null && ArrayUtility.FindIndex(m_TransformPaths, s => fullPath == s) == -1)
                        {
                            m_NodeInfos[i].m_State = NodeInfo.State.invalid;
                        }
                        else
                        {
                            m_NodeInfos[i].m_State = NodeInfo.State.enabled;
                        }
                    }
                    else
                    {
                        m_NodeInfos[i].m_State = NodeInfo.State.disabled;
                    }
                }
                else if (m_TransformPaths != null && ArrayUtility.FindIndex(m_TransformPaths, s => fullPath == s) == -1)
                {
                    // mask does not map to an existing hierarchy node. It's invalid.
                    m_NodeInfos[i].m_State = NodeInfo.State.invalid;
                }
                else
                {
                    m_NodeInfos[i].m_State = NodeInfo.State.enabled;
                }


                m_NodeInfos[i].m_Expanded     = true;
                m_NodeInfos[i].m_ParentIndex  = -1;
                m_NodeInfos[i].m_ChildIndices = new List <int>();

                m_NodeInfos[i].m_Depth = i == 0 ? 0 : fullPath.Count(f => f == '/');

                string parentPath = "";
                int    lastIndex  = fullPath.LastIndexOf('/');
                if (lastIndex > 0)
                {
                    parentPath = fullPath.Substring(0, lastIndex);
                }

                lastIndex             = lastIndex == -1 ? 0 : lastIndex + 1;
                m_NodeInfos[i].m_Name = fullPath.Substring(lastIndex);

                for (int j = 1; j < i; j++) // parents are already processed
                {
                    string otherPath = paths[j];
                    if (parentPath != "" && otherPath == parentPath)
                    {
                        m_NodeInfos[i].m_ParentIndex = j;
                        m_NodeInfos[j].m_ChildIndices.Add(i);
                    }
                }

                prop.Next(false);
            }
        }
Example #13
0
        private static string GetLogString(SerializedObject serializerObject)
        {
            string serializedObjectStr = "";

            SerializedProperty property = serializerObject.GetIterator();

            while (property.Next(property.hasVisibleChildren))
            {
                string propertyValue = "";
                switch (property.propertyType)
                {
                case SerializedPropertyType.Generic:
                    propertyValue = "Generic type value";
                    break;

                case SerializedPropertyType.Integer:
                    propertyValue = $"{property.intValue}";
                    break;

                case SerializedPropertyType.Boolean:
                    propertyValue = $"{property.boolValue}";
                    break;

                case SerializedPropertyType.Float:
                    propertyValue = $"{property.floatValue}";
                    break;

                case SerializedPropertyType.String:
                    propertyValue = property.stringValue;
                    break;

                case SerializedPropertyType.Color:
                    propertyValue = $"{property.colorValue}";
                    break;

                case SerializedPropertyType.ObjectReference:
                    propertyValue = $"{{instanceID: {property.objectReferenceInstanceIDValue} ({property.objectReferenceStringValue})}}";
                    break;

                case SerializedPropertyType.LayerMask:
                    propertyValue = $"{property.layerMaskBits}";
                    break;

                case SerializedPropertyType.Enum:
                    propertyValue = $"{property.enumValueIndex}";
                    break;

                case SerializedPropertyType.Vector2:
                    propertyValue = $"{property.vector2Value}";
                    break;

                case SerializedPropertyType.Vector3:
                    propertyValue = $"{property.vector3Value}";
                    break;

                case SerializedPropertyType.Vector4:
                    propertyValue = $"{property.vector4Value}";
                    break;

                case SerializedPropertyType.Rect:
                    propertyValue = $"{property.rectValue}";
                    break;

                case SerializedPropertyType.ArraySize:
                    propertyValue = $"{property.intValue}";
                    break;

                case SerializedPropertyType.Character:
                    propertyValue = $"{(char)property.intValue}";
                    break;

                case SerializedPropertyType.AnimationCurve:
                    propertyValue = $"{property.animationCurveValue}";
                    break;

                case SerializedPropertyType.Bounds:
                    propertyValue = $"{property.boundsValue}";
                    break;

                case SerializedPropertyType.Gradient:
                    propertyValue = $"{property.gradientValue}";
                    break;

                case SerializedPropertyType.Quaternion:
                    propertyValue = $"{property.quaternionValue}";
                    break;

                case SerializedPropertyType.ExposedReference:
                    propertyValue = $"{{instanceID: {property.objectReferenceInstanceIDValue} ({property.objectReferenceStringValue})}}";
                    break;

                case SerializedPropertyType.FixedBufferSize:
                    propertyValue = $"{property.fixedBufferSize}";
                    break;

                case SerializedPropertyType.Vector2Int:
                    propertyValue = $"{property.vector2IntValue}";
                    break;

                case SerializedPropertyType.Vector3Int:
                    propertyValue = $"{property.vector3IntValue}";
                    break;

                case SerializedPropertyType.RectInt:
                    propertyValue = $"{property.rectIntValue}";
                    break;

                case SerializedPropertyType.BoundsInt:
                    propertyValue = $"{property.boundsIntValue}";
                    break;

                case SerializedPropertyType.ManagedReference:
                    propertyValue = $"{{instanceID: {property.objectReferenceInstanceIDValue} ({property.objectReferenceStringValue})}}";
                    break;

                case SerializedPropertyType.Hash128:
                    propertyValue = $"{property.hash128Value}";
                    break;
                }

                if (property.prefabOverride)
                {
                    propertyValue += "(Prefab Override)";
                }

                serializedObjectStr += $"{property.propertyPath}: {propertyValue}\n";
            }

            return(serializedObjectStr);
        }
        private SerializedNodeInfo FillNodeInfos()
        {
            var rootNode = new SerializedNodeInfo()
            {
                depth = -1, displayName = "", id = 0, children = new List <TreeViewItem>(0)
            };

            if (m_TransformMask == null || m_TransformMask.arraySize == 0)
            {
                return(rootNode);
            }

            var nodesCount = m_TransformMask.arraySize;
            var nodeInfos  = new List <SerializedNodeInfo>(nodesCount);

            string[]           paths = new string[nodesCount];
            SerializedProperty prop  = m_TransformMask.GetArrayElementAtIndex(0);

            prop.Next(false);

            for (int i = 1; i < nodesCount; i++)
            {
                var newNode = new SerializedNodeInfo();
                newNode.id       = i;
                newNode.m_Path   = prop.FindPropertyRelative("m_Path");
                newNode.m_Weight = prop.FindPropertyRelative("m_Weight");

                paths[i] = newNode.m_Path.stringValue;
                string fullPath = paths[i];
                if (m_CanImport)
                {
                    // in avatar mask inspector UI,everything is enabled.
                    newNode.m_State = SerializedNodeInfo.State.Enabled;
                }
                else if (humanTransforms != null)
                {
                    //  Enable only transforms that are not human. Human transforms in this case are handled by muscle curves and cannot be imported.
                    if (ArrayUtility.FindIndex(humanTransforms, s => fullPath == s) == -1)
                    {
                        if (m_TransformPaths != null && ArrayUtility.FindIndex(m_TransformPaths, s => fullPath == s) == -1)
                        {
                            newNode.m_State = SerializedNodeInfo.State.Invalid;
                        }
                        else
                        {
                            newNode.m_State = SerializedNodeInfo.State.Enabled;
                        }
                    }
                    else
                    {
                        newNode.m_State = SerializedNodeInfo.State.Disabled;
                    }
                }
                else if (m_TransformPaths != null && ArrayUtility.FindIndex(m_TransformPaths, s => fullPath == s) == -1)
                {
                    // mask does not map to an existing hierarchy node. It's invalid.
                    newNode.m_State = SerializedNodeInfo.State.Invalid;
                }
                else
                {
                    newNode.m_State = SerializedNodeInfo.State.Enabled;
                }

                newNode.depth = i == 0 ? 0 : fullPath.Count(f => f == '/');

                int lastIndex = fullPath.LastIndexOf('/');
                lastIndex           = lastIndex == -1 ? 0 : lastIndex + 1;
                newNode.displayName = fullPath.Substring(lastIndex);

                nodeInfos.Add(newNode);
                prop.Next(false);
            }

            TreeViewUtility.SetChildParentReferences(nodeInfos.Cast <TreeViewItem>().ToList(), rootNode);
            return(rootNode);
        }
    //On GUI.
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        //Set the row height and initial position.
        float rowHeight = base.GetPropertyHeight(property, label);
        position = new Rect(position.xMin, position.yMin, position.width, rowHeight);
        rowHeight += EditorGUIUtility.standardVerticalSpacing;

        //If the sprite doesn't have its "readable" flag set, warn the user and given them the option to set it.
        SpriteRenderer spriteRenderer = ((SpriteShatter.Shatter) property.serializedObject.targetObject).gameObject.GetComponent<SpriteRenderer>();
        if (spriteRenderer == null || spriteRenderer.sprite == null) {
            position.height *= 2;
            EditorGUI.HelpBox(position, "Sprite Renderer does not have a sprite!", MessageType.Error);
            return;
        }
        string assetPath = AssetDatabase.GetAssetPath(spriteRenderer.sprite);
        TextureImporter textureImporter = (TextureImporter) AssetImporter.GetAtPath(assetPath);
        if (!textureImporter.isReadable) {
            addRow(ref position, rowHeight);
            position.height *= 2;
            EditorGUI.HelpBox(position, "Texture \"Read/Write\" flag not set!", MessageType.Error);
            position.height /= 2;
            addRow(ref position, rowHeight * 2);
            if (GUI.Button(position, new GUIContent("Set Texture Read/Write Flag", "Sprite Shatter requires that the sprite's texture has its \"Read/Write\"" +
                    "flag set. This is to ensure that the pixels can be read from the texture in order to shatter it. The flag is not currently set on the " +
                    "texture associated with this sprite, but you can click the button below to set it."))) {
                textureImporter.isReadable = true;
                AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate);
                EditorUtility.DisplayDialog("Texture Read/Write Flag Set", "The \"Read/Write\" flag has been set on the texture associated with this sprite.",
                        "OK");
            }
            addRow(ref position, rowHeight);
        }

        //Display the property fields.
        addRow(ref position, rowHeight);
        EditorGUI.LabelField(position, "Create Shatter Objects", EditorStyles.boldLabel);
        addRow(ref position, rowHeight);
        property.Next(true);
        EditorGUI.BeginProperty(position, label, property);
        property.intValue = EditorGUI.IntSlider(position, new GUIContent("Horizontal Cuts", "The number of cuts to make going horizontally across the " +
                "sprite. More cuts will shatter the sprite into smaller pieces, but will require more game objects and may affect performance."),
                property.intValue, 1, 32);
        EditorGUI.EndProperty();
        int horizontalCuts = property.intValue;
        addRow(ref position, rowHeight);
        property.Next(false);
        EditorGUI.BeginProperty(position, label, property);
        property.intValue = EditorGUI.IntSlider(position, new GUIContent("Vertical Cuts", "The number of cuts to make going vertically down the sprite. More " +
                "cuts will shatter the sprite into smaller pieces, but will require more game objects and may affect performance."), property.intValue, 1, 32);
        EditorGUI.EndProperty();
        int verticalCuts = property.intValue;
        addRow(ref position, rowHeight);
        property.Next(false);
        EditorGUI.BeginProperty(position, label, property);
        property.boolValue = EditorGUI.Toggle(position, new GUIContent("Randomize at Runtime", "Generate a completely random seed at runtime, meaning the " +
                "layout of the shattered sprite pieces will be different every time the game is run. This only has any effect if \"Randomness\" is set to " +
                "greater than zero."), property.boolValue);
        EditorGUI.EndProperty();
        bool randomizeAtRuntime = property.boolValue;
        addRow(ref position, rowHeight);
        property.Next(false);
        if (!randomizeAtRuntime) {
            EditorGUI.BeginProperty(position, label, property);
            property.intValue = EditorGUI.IntField(position, new GUIContent("Random Seed", "The seed value to use when generating random numbers. The same " +
                    "seed will always generate cuts in the same way, which is useful if you want multiple objects to shatter in an identical way. Otherwise " +
                    "you can select \"Randomize at Runtime\" below to generate a different random set of cuts each time the game runs. The random seed only " +
                    "has any effect if \"Randomness\" is set to greater than zero."), property.intValue);
            EditorGUI.EndProperty();
            addRow(ref position, rowHeight);
        }
        int randomSeed = property.intValue;
        property.Next(false);
        EditorGUI.BeginProperty(position, label, property);
        property.floatValue = EditorGUI.Slider(position, new GUIContent("Randomness", "The amount of randomness to apply to the cuts. A value of zero will " +
                "result in perfectly straight cuts, whereas a value of one will result in cuts that potentially could be almost touching each other."),
                property.floatValue, 0, 1);
        EditorGUI.EndProperty();
        float randomness = property.floatValue;
        addRow(ref position, rowHeight);
        property.Next(false);
        EditorGUI.BeginProperty(position, label, property);
        property.floatValue = EditorGUI.Slider(position, new GUIContent("Zigzag Frequency", "This property, along with \"Zigzag Amplitude\" allows for a " +
                "zigzag shape to be added to the cuts to make more jagged edges and more random-looking pieces. \"Zigzag Frequency\" specifies the number of " +
                "jagged edges across or down the cuts, but will have no effect if \"Zigzag Amplitude\" is zero."), property.floatValue, 0, 1);
        EditorGUI.EndProperty();
        float zigzagFrequency = property.floatValue;
        addRow(ref position, rowHeight);
        property.Next(false);
        EditorGUI.BeginProperty(position, label, property);
        property.floatValue = EditorGUI.Slider(position, new GUIContent("Zigzag Amplitude", "This property, along with \"Zigzag Amplitude\" allows for a " +
                "zigzag shape to be added to the cuts to make more jagged edges and more random-looking pieces. \"Zigzag Frequency\" specifies the number of " +
                "jagged edges across or down the cuts, but will have no effect if \"Zigzag Amplitude\" is zero."), property.floatValue, 0, 1);
        EditorGUI.EndProperty();
        float zigzagAmplitude = property.floatValue;
        addRow(ref position, rowHeight);
        property.Next(false);
        EditorGUI.BeginProperty(position, label, property);
        property.intValue = EditorGUI.IntPopup(position, new GUIContent("Collider Types", "The collider type to add to each of the shattered pieces of the " +
                "sprite. Having no collider is the most efficient way of shattering a sprite, but the shattered pieces will not collide with anything. A " +
                "polygon collider is the least-efficient collider, but produces the most accurate collisions."), property.intValue, new GUIContent[] {
                new GUIContent("None", "Do not apply any any colliders to the shattered pieces."),
                new GUIContent("Circle", "Apply circle colliders to the shattered pieces."),
                new GUIContent("Box", "Apply box colliders to the shattered pieces."),
                new GUIContent("Polygon", "Apply polygon colliders to the shattered pieces that match the shape each piece.") },
                new int[] { 0, 1, 2, 3 });
        EditorGUI.EndProperty();
        addRow(ref position, rowHeight);
        addRow(ref position, rowHeight);
        EditorGUI.LabelField(position, "Sprite Shattering Properties", EditorStyles.boldLabel);
        addRow(ref position, rowHeight);
        property.Next(false);
        EditorGUI.BeginProperty(position, label, property);
        property.vector2Value = EditorGUI.Vector2Field(position, new GUIContent("Explode From", "The position from which to apply the explosion force when " +
                "exploding the shattered pieces of the sprite. The X co-ordinate should be 0 for the left edge of the sprite and 1 for the right edge, and " +
                "the Y co-ordinate should be 0 for bottom of the sprite and 1 for the top, although the values can be outside this range. For example to " +
                "make the sprite explode up from the bottom, co-ordinates of (0.5, 0) could be used."), property.vector2Value);
        EditorGUI.EndProperty();
        addRow(ref position, rowHeight);
        property.Next(false);
        EditorGUI.BeginProperty(position, label, property);
        property.vector2Value = EditorGUI.Vector2Field(position, new GUIContent("Explosion Force", "The force to apply in the X and Y direction when " +
                "exploding the shattered pieces of the sprite. A force of zero will make the sprite just collapse in its current position"),
                property.vector2Value);
        EditorGUI.EndProperty();
        addRow(ref position, rowHeight);

        //Display a preview texture with the cuts made. First display a "Preview" header.
        addRow(ref position, rowHeight);
        EditorGUI.LabelField(position, "Preview", EditorStyles.boldLabel);
        addRow(ref position, rowHeight);
        if (!textureImporter.isReadable) {
            position.height *= 2;
            EditorGUI.HelpBox(position, "Texture \"Read/Write\" flag not set!", MessageType.Error);
        }
        else {
            int textureWidth = (int) spriteRenderer.sprite.rect.width;
            int textureHeight = (int) spriteRenderer.sprite.rect.height;

            //Calculate the texture width and height from the window width.
            int previewTextureWidth = (int) (position.width * 0.75f);
            int previewTextureHeight = (int) (((float) textureHeight / (float) textureWidth) * position.width * 0.75f);
            Color[] sourcePixels = spriteRenderer.sprite.texture.GetPixels((int) spriteRenderer.sprite.rect.xMin, (int) spriteRenderer.sprite.rect.yMin,
                    (int) spriteRenderer.sprite.rect.width, (int) spriteRenderer.sprite.rect.height);

            //If the preview texture is at least two pixels wide...
            if (previewTextureWidth > 1) {

                //Call the method that makes the cuts as these will be drawn onto the texture.
                int[,] horizontalCutTop, verticalCutLeft;
                ((SpriteShatter.Shatter) property.serializedObject.targetObject).makeCuts(spriteRenderer.sprite, horizontalCuts, verticalCuts, randomSeed,
                        randomness, zigzagFrequency, zigzagAmplitude, out horizontalCutTop, out verticalCutLeft);

                //Create the preview texture and set its pixels from the main texture.
                Texture2D previewTexture = new Texture2D(previewTextureWidth, previewTextureHeight, TextureFormat.RGBA32, false);
                previewTexture.hideFlags = HideFlags.HideAndDontSave;
                Color[] previewTexturePixels = new Color[previewTextureWidth * previewTextureHeight];
                for (int i = 0; i < previewTextureWidth; i++)
                    for (int j = 0; j < previewTextureHeight; j++)
                        previewTexturePixels[(j * previewTextureWidth) + i] = sourcePixels[(((j * textureHeight) / previewTextureHeight) * textureWidth) +
                                ((i * textureWidth) / previewTextureWidth)];

                //Loop over the cuts and draw them on the texture (white with a black outline to cover all texture colours).
                Color[] originalPreviewTexturePixels = (Color[]) previewTexturePixels.Clone();
                for (int l = 0; l < 2; l++) {
                    for (int i = 0; i < horizontalCuts; i++)
                        for (int j = 0; j < textureWidth; j++) {
                            int previewTextureX = (j * previewTextureWidth) / textureWidth;
                            int previewTextureY = (horizontalCutTop[i, j] * previewTextureHeight) / textureHeight;
                            if (originalPreviewTexturePixels[(previewTextureY * previewTextureWidth) + previewTextureX].a > 0.001f) {
                                for (int m = l == 0 ? -1 : 0; m <= (l == 0 ? 1 : 0); m++)
                                    for (int k = l == 0 ? -1 : 0; k <= (l == 0 ? 1 : 0); k++) {
                                        if (previewTextureX + m >= 0 && previewTextureX + m < previewTextureWidth && previewTextureY + k >= 0 &&
                                                previewTextureY + k < previewTextureHeight)
                                            previewTexturePixels[((previewTextureY + k) * previewTextureWidth) + previewTextureX + m] = l == 0 ? Color.black :
                                                    Color.white;
                                    }
                            }
                        }
                    for (int i = 0; i < verticalCuts; i++)
                        for (int j = 0; j < textureHeight; j++) {
                            int previewTextureX = (verticalCutLeft[i, j] * previewTextureWidth) / textureWidth;
                            int previewTextureY = (j * previewTextureHeight) / textureHeight;
                            if (originalPreviewTexturePixels[(previewTextureY * previewTextureWidth) + previewTextureX].a > 0.001f) {
                                for (int m = l == 0 ? -1 : 0; m <= (l == 0 ? 1 : 0); m++)
                                    for (int k = l == 0 ? -1 : 0; k <= (l == 0 ? 1 : 0); k++)
                                        if (previewTextureX + m >= 0 && previewTextureX + m < previewTextureWidth && previewTextureY + k >= 0 &&
                                                previewTextureY + k < previewTextureHeight)
                                            previewTexturePixels[((previewTextureY + k) * previewTextureWidth) + previewTextureX + m] = l == 0 ? Color.black :
                                                    Color.white;
                            }
                        }
                }
                previewTexture.SetPixels(previewTexturePixels);
                previewTexture.Apply();

                //Draw the texture in the editor window.
                position.xMin += position.width * 0.125f;
                position.xMax -= position.width * 0.125f;
                position.height = previewTextureHeight;
                GUIStyle style = new GUIStyle();
                style.normal.background = previewTexture;
                EditorGUI.LabelField(position, GUIContent.none, style);
            }
        }
    }
		internal static void MultiPropertyField(Rect position, GUIContent[] subLabels, SerializedProperty valuesIterator, float labelWidth = 13)
		{
			int num = subLabels.Length;
			float num2 = (position.width - (float)(num - 1) * 2) / (float)num;
			Rect position2 = new Rect(position);
			position2.width = num2;
			float labelWidth2 = EditorGUIUtility.labelWidth;
			int indentLevel = EditorGUI.indentLevel;
			EditorGUIUtility.labelWidth = labelWidth;
			EditorGUI.indentLevel = 0;
			for (int i = 0; i < subLabels.Length; i++)
			{
				EditorGUI.PropertyField(position2, valuesIterator, subLabels[i]);
				position2.x += num2 + 2;
				valuesIterator.Next(false);
			}
			EditorGUIUtility.labelWidth = labelWidth2;
			EditorGUI.indentLevel = indentLevel;
		}
		static public bool PropertyField(Rect position, SerializedProperty property, GUIContent label, bool includeChildren)
		{
			//if (!includeChildren)
			{
				switch (property.propertyType)
				{
					case SerializedPropertyType.Vector2:
					case SerializedPropertyType.Vector3:
						property = property.Copy();
						var labels = property.propertyType == SerializedPropertyType.Vector2 ? v2Labels : v3Labels;
						if (label == null)
							label = new GUIContent(GetDisplayName(property));

						property.Next(true);

						MultiPropertyField(position, labels, property, label);
						return false;
				}
			}

			return EditorGUI.PropertyField(position, property, label, includeChildren);
		}
Example #18
0
        // Given an object structure from JSON encoding, apply that to a serialized property.
        internal static void ParseGenericSerializedProperty(SerializedProperty prop, Dictionary <string, object> obj)
        {
            if (prop == null)
            {
                return;
            }
            if (!obj.TryGetValue("name", out var oName))
            {
                return;
            }
            var name = oName as string;

            if (string.IsNullOrEmpty(name))
            {
                return;
            }

            if (!obj.TryGetValue("type", out var oType))
            {
                return;
            }
            if (!(oType is long))
            {
                return;
            }
            try
            {
                var propertyType = (SerializedPropertyType)Convert.ToInt32(oType);
                if (propertyType != prop.propertyType)
                {
                    return;
                }
                obj.TryGetValue("val", out var oval);

                switch (propertyType)
                {
                case SerializedPropertyType.Integer:
                case SerializedPropertyType.LayerMask:
                case SerializedPropertyType.Character:
                    prop.intValue = Convert.ToInt32(oval);
                    break;

                case SerializedPropertyType.Boolean:
                    prop.boolValue = Convert.ToBoolean(oval);
                    break;

                case SerializedPropertyType.Float:
                    prop.floatValue = Convert.ToSingle(oval);
                    break;

                case SerializedPropertyType.String:
                    prop.stringValue = Convert.ToString(oval);
                    break;

                case SerializedPropertyType.ObjectReference:
                    if (ParseCustom <ObjectWrapper>(Convert.ToString(oval), out var objectWrapper))
                    {
                        prop.objectReferenceValue = objectWrapper.ToObject();
                    }
                    break;

                case SerializedPropertyType.ArraySize:
                    prop.arraySize = Convert.ToInt32(oval);
                    break;

                case SerializedPropertyType.AnimationCurve:
                    if (ParseCustom <AnimationCurveWrapper>(Convert.ToString(oval), out var animWrapper))
                    {
                        prop.animationCurveValue = animWrapper.curve;
                    }
                    break;

                case SerializedPropertyType.Enum:
                    ParseEnumProperty(Convert.ToString(oval), prop);
                    break;

                case SerializedPropertyType.Bounds:
                    if (ParseBounds(Convert.ToString(oval), out var boundsValue))
                    {
                        prop.boundsValue = boundsValue;
                    }
                    break;

                case SerializedPropertyType.Gradient:
                    if (ParseCustom <GradientWrapper>(Convert.ToString(oval), out var gradientWrapper))
                    {
                        prop.gradientValue = gradientWrapper.gradient;
                        UnityEditorInternal.GradientPreviewCache.ClearCache();
                    }
                    break;

                case SerializedPropertyType.Quaternion:
                    if (ParseQuaternion(Convert.ToString(oval), out var quaternionValue))
                    {
                        prop.quaternionValue = quaternionValue;
                    }
                    break;

                case SerializedPropertyType.Vector2Int:
                    if (ParseVector2(Convert.ToString(oval), out var v2Value))
                    {
                        prop.vector2IntValue = new Vector2Int((int)v2Value.x, (int)v2Value.y);
                    }
                    break;

                case SerializedPropertyType.Vector3Int:
                    if (ParseVector3(Convert.ToString(oval), out var v3Value))
                    {
                        prop.vector3IntValue = new Vector3Int((int)v3Value.x, (int)v3Value.y, (int)v3Value.z);
                    }
                    break;

                case SerializedPropertyType.RectInt:
                    if (ParseRect(Convert.ToString(oval), out var rectValue))
                    {
                        prop.rectIntValue = new RectInt((int)rectValue.x, (int)rectValue.y, (int)rectValue.width, (int)rectValue.height);
                    }
                    break;

                case SerializedPropertyType.BoundsInt:
                    if (ParseBounds(Convert.ToString(oval), out var biValue))
                    {
                        prop.boundsIntValue = new BoundsInt(
                            new Vector3Int((int)biValue.center.x, (int)biValue.center.y, (int)biValue.center.z),
                            new Vector3Int((int)biValue.size.x, (int)biValue.size.y, (int)biValue.size.z));
                    }
                    break;

                // Copy/Paste of these for generic serialized properties is not implemented yet.
                case SerializedPropertyType.FixedBufferSize: break;

                case SerializedPropertyType.ExposedReference: break;

                case SerializedPropertyType.ManagedReference: break;

                default:
                    if (prop.isArray)
                    {
                        if (!obj.TryGetValue("arraySize", out var oArraySize))
                        {
                            return;
                        }
                        if (!obj.TryGetValue("arrayType", out var oArrayType))
                        {
                            return;
                        }
                        if (Convert.ToString(oArrayType) != prop.arrayElementType)
                        {
                            return;
                        }
                        prop.arraySize = Convert.ToInt32(oArraySize);
                    }

                    if (prop.hasChildren)
                    {
                        if (!obj.TryGetValue("children", out var oChildren))
                        {
                            return;
                        }
                        if (!(oChildren is List <object> children))
                        {
                            return;
                        }

                        SerializedProperty chit = prop.Copy();
                        var end = chit.GetEndProperty();
                        chit.Next(true);
                        var index = 0;
                        while (!SerializedProperty.EqualContents(chit, end) && index < children.Count)
                        {
                            if (!(children[index] is Dictionary <string, object> ch))
                            {
                                return;
                            }
                            ParseGenericSerializedProperty(chit, ch);
                            if (!chit.Next(false))
                            {
                                break;
                            }
                            ++index;
                        }
                    }

                    break;
                }
            }
            catch (InvalidCastException)
            {
            }
        }
Example #19
0
        // Given a serialized property, produce an object structure for JSON encoding of it.
        internal static Dictionary <string, object> WriteGenericSerializedProperty(SerializedProperty p)
        {
            var res = new Dictionary <string, object>
            {
                ["name"] = p.name,
                ["type"] = (int)p.propertyType
            };

            switch (p.propertyType)
            {
            case SerializedPropertyType.Integer:
            case SerializedPropertyType.LayerMask:
            case SerializedPropertyType.Character:
                res["val"] = p.intValue; break;

            case SerializedPropertyType.Boolean: res["val"] = p.boolValue; break;

            case SerializedPropertyType.Float: res["val"] = p.floatValue; break;

            case SerializedPropertyType.String: res["val"] = p.stringValue; break;

            case SerializedPropertyType.ObjectReference: res["val"] = WriteCustom(new ObjectWrapper(p.objectReferenceValue)); break;

            case SerializedPropertyType.ArraySize: res["val"] = p.intValue; break;

            case SerializedPropertyType.AnimationCurve: res["val"] = WriteCustom(new AnimationCurveWrapper(p.animationCurveValue)); break;

            case SerializedPropertyType.Enum: res["val"] = WriteEnumProperty(p); break;

            case SerializedPropertyType.Bounds: res["val"] = WriteBounds(p.boundsValue); break;

            case SerializedPropertyType.Gradient: res["val"] = WriteCustom(new GradientWrapper(p.gradientValue)); break;

            case SerializedPropertyType.Quaternion: res["val"] = WriteQuaternion(p.quaternionValue); break;

            case SerializedPropertyType.Vector2Int: res["val"] = WriteVector2(p.vector2IntValue); break;

            case SerializedPropertyType.Vector3Int: res["val"] = WriteVector3(p.vector3IntValue); break;

            case SerializedPropertyType.RectInt:
                var ri = p.rectIntValue;
                res["val"] = WriteRect(new Rect(ri.x, ri.y, ri.width, ri.height));
                break;

            case SerializedPropertyType.BoundsInt:
                var bi = p.boundsIntValue;
                res["val"] = WriteBounds(new Bounds(bi.center, bi.size));
                break;

            // Copy/Paste of these for generic serialized properties is not implemented yet.
            case SerializedPropertyType.ExposedReference: break;

            case SerializedPropertyType.FixedBufferSize: break;

            case SerializedPropertyType.ManagedReference: break;

            default:
                if (p.isArray)
                {
                    res["arraySize"] = p.arraySize;
                    res["arrayType"] = p.arrayElementType;
                }
                if (p.hasChildren)
                {
                    var children            = new List <object>();
                    SerializedProperty chit = p.Copy();
                    var end = chit.GetEndProperty();
                    chit.Next(true);
                    while (!SerializedProperty.EqualContents(chit, end))
                    {
                        children.Add(WriteGenericSerializedProperty(chit));
                        if (!chit.Next(false))
                        {
                            break;
                        }
                    }
                    res["children"] = children;
                }
                break;
            }
            return(res);
        }
	private void AddPropsFromArray(PropType type, SerializedProperty props) {
		string original = props.propertyPath;

		props.Next(true);
		props.Next(true);
		props.Next(true);

		do {
			var valueProp = props.FindPropertyRelative("second");
			var nameProp = props.FindPropertyRelative("first.name");



			string propName = nameProp.stringValue;

			AddProperty(propName, type, valueProp);
		} while (props.NextVisible(false) && props.propertyPath.Contains(original));
	}
Example #21
0
 static SerializedProperty FirstOrDefault(SerializedProperty prop, Predicate<SerializedProperty> predicate, bool descendIntoChildren = false)
 {
     while (prop.Next(descendIntoChildren))
     {
         if (predicate(prop))
             return prop.Copy();
     }
     return null;
 }
        private SerializedNodeInfo FillNodeInfos()
        {
            var rootNode = new SerializedNodeInfo()
            {
                depth = -1, displayName = "", id = 0, children = new List <TreeViewItem>(0)
            };

            if (m_TransformMask == null || m_TransformMask.arraySize == 0)
            {
                return(rootNode);
            }

            var nodesCount          = m_TransformMask.arraySize;
            var nodeInfos           = new List <SerializedNodeInfo>(nodesCount);
            SerializedProperty prop = m_TransformMask.GetArrayElementAtIndex(0);

            prop.Next(false);
            Stack <string> depth       = new Stack <string>(nodesCount);
            string         currentPath = String.Empty;

            for (int i = 1; i < nodesCount; i++)
            {
                var newNode = new SerializedNodeInfo();
                newNode.id       = i;
                newNode.m_Path   = prop.FindPropertyRelative("m_Path");
                newNode.m_Weight = prop.FindPropertyRelative("m_Weight");

                var newPath = newNode.m_Path.stringValue;
                while (!string.IsNullOrEmpty(currentPath) && !newPath.StartsWith(currentPath + "/"))
                {
                    // we are in a new node, lets unstack until we reach the correct hierarchy
                    var oldParent = depth.Pop();
                    var index     = currentPath.LastIndexOf(oldParent);
                    if (index > 0)
                    {
                        index--;
                    }
                    currentPath = currentPath.Remove(index);
                }
                var nodeName = newPath;
                if (!string.IsNullOrEmpty(currentPath))
                {
                    nodeName = nodeName.Remove(0, currentPath.Length + 1);
                }

                if (m_CanImport)
                {
                    // in avatar mask inspector UI,everything is enabled.
                    newNode.m_State = SerializedNodeInfo.State.Enabled;
                }
                else if (humanTransforms != null)
                {
                    //  Enable only transforms that are not human. Human transforms in this case are handled by muscle curves and cannot be imported.
                    if (ArrayUtility.FindIndex(humanTransforms, s => newPath == s) == -1)
                    {
                        if (m_TransformPaths != null && ArrayUtility.FindIndex(m_TransformPaths, s => newPath == s) == -1)
                        {
                            newNode.m_State = SerializedNodeInfo.State.Invalid;
                        }
                        else
                        {
                            newNode.m_State = SerializedNodeInfo.State.Enabled;
                        }
                    }
                    else
                    {
                        newNode.m_State = SerializedNodeInfo.State.Disabled;
                    }
                }
                else if (m_TransformPaths != null && ArrayUtility.FindIndex(m_TransformPaths, s => newPath == s) == -1)
                {
                    // mask does not map to an existing hierarchy node. It's invalid.
                    newNode.m_State = SerializedNodeInfo.State.Invalid;
                }
                else
                {
                    newNode.m_State = SerializedNodeInfo.State.Enabled;
                }

                newNode.depth       = depth.Count;
                newNode.displayName = nodeName;
                depth.Push(nodeName);
                currentPath = newPath;
                nodeInfos.Add(newNode);
                prop.Next(false);
            }

            TreeViewUtility.SetChildParentReferences(nodeInfos.Cast <TreeViewItem>().ToList(), rootNode);
            return(rootNode);
        }