private void doDragDrop(dfAnimationClip animation) { var atlas = animation.Atlas; if (atlas == null) { return; } var failed = new List <string>(); var textures = DragAndDrop.objectReferences .OrderBy(x => formatName(x.name)) .Select(x => x.name) .ToList(); if (textures.Count > 0) { dfEditorUtil.MarkUndo(animation, "Add frames"); } Debug.Log("Textures dropped: " + textures.Count); for (int i = 0; i < textures.Count; i++) { var name = textures[i]; if (atlas[name] == null) { failed.Add(name); } else { animation.Sprites.Add(name); } } if (failed.Count > 0) { var message = "The following textures are not in the Atlas:\r\n" + string.Join("\r\n", failed.ToArray()); EditorUtility.DisplayDialog("Texture not found", message, "OK"); } }
private void autoFill(dfAnimationClip animation) { var spriteName = animation.Sprites.Last(); var prefix = stripSuffix(spriteName); if (string.IsNullOrEmpty(prefix)) { EditorUtility.DisplayDialog("Auto-Fill Animation Clip", "Unable to determine a valid sprite prefix based on the name " + spriteName, "CANCEL"); return; } dfEditorUtil.MarkUndo(animation, "Auto-fill animation frames"); var results = new List <string>(); for (int i = 0; i < animation.Atlas.Items.Count; i++) { var item = animation.Atlas.Items[i].name; if (item.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)) { if (!animation.Sprites.Contains(item)) { results.Add(item); } } } if (results.Count == 0) { EditorUtility.DisplayDialog("Auto-Fill Animation Clip", "No additional sprites matching '" + prefix + "' could be found", "OK"); return; } results .OrderBy(x => formatName(x)) .ToList() .ForEach(x => animation.Sprites.Add(x)); }
private void editFrames( dfAnimationClip animation ) { EditorGUILayout.Separator(); var collectionModified = false; var showDialog = false; var sprites = animation.Sprites; for( int i = 0; i < sprites.Count && !collectionModified; i++ ) { EditorGUILayout.BeginHorizontal(); { EditorGUILayout.LabelField( "Frame " + i, "", GUILayout.Width( dfEditorUtil.LabelWidth - 6 ) ); GUILayout.Space( 2 ); var value = sprites[ i ]; var displayText = string.IsNullOrEmpty( value ) ? "[none]" : value; GUILayout.Label( displayText, "TextField" ); if( GUILayout.Button( new GUIContent( " ", "Select Frame" ), "IN ObjectField", GUILayout.Width( 14 ) ) ) { var index = i; dfEditorUtil.DelayedInvoke( (System.Action)( () => { dfSpriteSelectionDialog.Show( "Select Sprite", animation.Atlas, value, ( spriteName ) => { dfEditorUtil.MarkUndo( animation, "Select animation frame" ); sprites[ index ] = spriteName; } ); } ) ); } GUI.enabled = i > 0; if( GUILayout.Button( "\u25B2", "minibutton", GUILayout.Width( 22 ) ) && i > 0 ) { dfEditorUtil.MarkUndo( animation, "Reorder animation frames" ); var temp = sprites[ i - 1 ]; sprites[ i - 1 ] = sprites[ i ]; sprites[ i ] = temp; } GUI.enabled = i < sprites.Count - 1; if( GUILayout.Button( "\u25BC", "minibutton", GUILayout.Width( 22 ) ) && i < sprites.Count - 1 ) { dfEditorUtil.MarkUndo( animation, "Reorder animation frames" ); var temp = sprites[ i + 1 ]; sprites[ i + 1 ] = sprites[ i ]; sprites[ i ] = temp; } GUI.enabled = true; if( GUILayout.Button( "x", "minibutton", GUILayout.Width( 20 ) ) ) { dfEditorUtil.MarkUndo( animation, "Remove animation frame" ); sprites.RemoveAt( i ); collectionModified = true; } } EditorGUILayout.EndHorizontal(); } EditorGUILayout.Separator(); GUILayout.BeginHorizontal(); { if( sprites.Count > 0 ) { if( GUILayout.Button( "Auto Fill '" + stripSuffix( sprites.Last() ) + "*'" ) ) { autoFill( animation ); } } if( GUILayout.Button( "Add Frame" ) ) { showDialog = true; } } GUILayout.EndHorizontal(); if( showDialog ) { dfEditorUtil.DelayedInvoke( (System.Action)( () => { dfSpriteSelectionDialog.Show( "Select Sprite", animation.Atlas, null, ( selected ) => { if( !string.IsNullOrEmpty( selected ) ) { dfEditorUtil.MarkUndo( animation.gameObject, "Add new animation frame" ); sprites.Add( selected ); } } ); } ) ); } }
private void doDragDrop( dfAnimationClip animation ) { var atlas = animation.Atlas; if( atlas == null ) return; var failed = new List<string>(); var textures = DragAndDrop.objectReferences .OrderBy( x => formatName( x.name ) ) .Select( x => x.name ) .ToList(); if( textures.Count > 0 ) { dfEditorUtil.MarkUndo( animation, "Add frames" ); } Debug.Log( "Textures dropped: " + textures.Count ); for( int i = 0; i < textures.Count; i++ ) { var name = textures[ i ]; if( atlas[ name ] == null ) { failed.Add( name ); } else { animation.Sprites.Add( name ); } } if( failed.Count > 0 ) { var message = "The following textures are not in the Atlas:\r\n" + string.Join( "\r\n", failed.ToArray() ); EditorUtility.DisplayDialog( "Texture not found", message, "OK" ); } }
private void autoFill( dfAnimationClip animation ) { var spriteName = animation.Sprites.Last(); var prefix = stripSuffix( spriteName ); if( string.IsNullOrEmpty( prefix ) ) { EditorUtility.DisplayDialog( "Auto-Fill Animation Clip", "Unable to determine a valid sprite prefix based on the name " + spriteName, "CANCEL" ); return; } dfEditorUtil.MarkUndo( animation, "Auto-fill animation frames" ); var results = new List<string>(); for( int i = 0; i < animation.Atlas.Items.Count; i++ ) { var item = animation.Atlas.Items[ i ].name; if( item.StartsWith( prefix, StringComparison.OrdinalIgnoreCase ) ) { if( !animation.Sprites.Contains( item ) ) { results.Add( item ); } } } if( results.Count == 0 ) { EditorUtility.DisplayDialog( "Auto-Fill Animation Clip", "No additional sprites matching '" + prefix + "' could be found", "OK" ); return; } results .OrderBy( x => formatName( x ) ) .ToList() .ForEach( x => animation.Sprites.Add( x ) ); }
protected internal static void SelectTextureAtlas( string label, dfAnimationClip clip ) { var savedColor = GUI.color; var showDialog = false; try { var atlas = clip.Atlas; if( atlas == null ) GUI.color = Color.red; dfPrefabSelectionDialog.SelectionCallback selectionCallback = delegate( GameObject item ) { var newAtlas = ( item == null ) ? null : item.GetComponent<dfAtlas>(); dfEditorUtil.MarkUndo( clip, "Change Atlas" ); clip.Atlas = newAtlas; }; var value = clip.Atlas; EditorGUILayout.BeginHorizontal(); { EditorGUILayout.LabelField( label, "", GUILayout.Width( dfEditorUtil.LabelWidth - 6 ) ); GUILayout.Space( 2 ); var displayText = value == null ? "[none]" : value.name; GUILayout.Label( displayText, "TextField" ); var evt = Event.current; if( evt != null ) { Rect textRect = GUILayoutUtility.GetLastRect(); if( evt.type == EventType.mouseDown && evt.clickCount == 2 ) { if( textRect.Contains( evt.mousePosition ) ) { if( GUI.enabled && value != null ) { Selection.activeObject = value; EditorGUIUtility.PingObject( value ); } } } else if( evt.type == EventType.DragUpdated || evt.type == EventType.DragPerform ) { if( textRect.Contains( evt.mousePosition ) ) { var draggedObject = DragAndDrop.objectReferences.First() as GameObject; var draggedFont = draggedObject != null ? draggedObject.GetComponent<dfAtlas>() : null; DragAndDrop.visualMode = ( draggedFont != null ) ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.None; if( evt.type == EventType.DragPerform ) { selectionCallback( draggedObject ); } evt.Use(); } } } if( GUI.enabled && GUILayout.Button( new GUIContent( " ", "Edit Atlas" ), "IN ObjectField", GUILayout.Width( 14 ) ) ) { showDialog = true; } } EditorGUILayout.EndHorizontal(); GUILayout.Space( 2 ); if( showDialog ) { var dialog = dfPrefabSelectionDialog.Show( "Select Texture Atlas", typeof( dfAtlas ), selectionCallback, dfTextureAtlasInspector.DrawAtlasPreview, null ); dialog.previewSize = 200; } } finally { GUI.color = savedColor; } }
protected internal static void SelectTextureAtlas(string label, dfAnimationClip clip) { var savedColor = GUI.color; var showDialog = false; try { var atlas = clip.Atlas; if (atlas == null) { GUI.color = EditorGUIUtility.isProSkin ? Color.yellow : Color.red; } dfPrefabSelectionDialog.SelectionCallback selectionCallback = delegate(GameObject item) { var newAtlas = (item == null) ? null : item.GetComponent <dfAtlas>(); dfEditorUtil.MarkUndo(clip, "Change Atlas"); clip.Atlas = newAtlas; }; var value = clip.Atlas; EditorGUILayout.BeginHorizontal(); { EditorGUILayout.LabelField(label, "", GUILayout.Width(dfEditorUtil.LabelWidth - 6)); GUILayout.Space(2); var displayText = value == null ? "[none]" : value.name; GUILayout.Label(displayText, "TextField"); var evt = Event.current; if (evt != null) { Rect textRect = GUILayoutUtility.GetLastRect(); if (evt.type == EventType.mouseDown && evt.clickCount == 2) { if (textRect.Contains(evt.mousePosition)) { if (GUI.enabled && value != null) { Selection.activeObject = value; EditorGUIUtility.PingObject(value); } } } else if (evt.type == EventType.DragUpdated || evt.type == EventType.DragPerform) { if (textRect.Contains(evt.mousePosition)) { var draggedObject = DragAndDrop.objectReferences.First() as GameObject; var draggedFont = draggedObject != null?draggedObject.GetComponent <dfAtlas>() : null; DragAndDrop.visualMode = (draggedFont != null) ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.None; if (evt.type == EventType.DragPerform) { selectionCallback(draggedObject); } evt.Use(); } } } if (GUI.enabled && GUILayout.Button(new GUIContent(" ", "Edit Atlas"), "IN ObjectField", GUILayout.Width(14))) { showDialog = true; } } EditorGUILayout.EndHorizontal(); GUILayout.Space(2); if (showDialog) { var dialog = dfPrefabSelectionDialog.Show("Select Texture Atlas", typeof(dfAtlas), selectionCallback, dfTextureAtlasInspector.DrawAtlasPreview, null); dialog.previewSize = 200; } } finally { GUI.color = savedColor; } }
private void editFrames(dfAnimationClip animation) { EditorGUILayout.Separator(); var collectionModified = false; var showDialog = false; var sprites = animation.Sprites; for (int i = 0; i < sprites.Count && !collectionModified; i++) { EditorGUILayout.BeginHorizontal(); { EditorGUILayout.LabelField("Frame " + i, "", GUILayout.Width(dfEditorUtil.LabelWidth - 6)); GUILayout.Space(2); var value = sprites[i]; var displayText = string.IsNullOrEmpty(value) ? "[none]" : value; GUILayout.Label(displayText, "TextField"); if (GUILayout.Button(new GUIContent(" ", "Select Frame"), "IN ObjectField", GUILayout.Width(14))) { var index = i; dfEditorUtil.DelayedInvoke((System.Action)(() => { dfSpriteSelectionDialog.Show("Select Sprite", animation.Atlas, value, (spriteName) => { dfEditorUtil.MarkUndo(animation, "Select animation frame"); sprites[index] = spriteName; }); })); } GUI.enabled = i > 0; if (GUILayout.Button("\u25B2", "minibutton", GUILayout.Width(22)) && i > 0) { dfEditorUtil.MarkUndo(animation, "Reorder animation frames"); var temp = sprites[i - 1]; sprites[i - 1] = sprites[i]; sprites[i] = temp; } GUI.enabled = i < sprites.Count - 1; if (GUILayout.Button("\u25BC", "minibutton", GUILayout.Width(22)) && i < sprites.Count - 1) { dfEditorUtil.MarkUndo(animation, "Reorder animation frames"); var temp = sprites[i + 1]; sprites[i + 1] = sprites[i]; sprites[i] = temp; } GUI.enabled = true; if (GUILayout.Button("x", "minibutton", GUILayout.Width(20))) { dfEditorUtil.MarkUndo(animation, "Remove animation frame"); sprites.RemoveAt(i); collectionModified = true; } } EditorGUILayout.EndHorizontal(); } EditorGUILayout.Separator(); GUILayout.BeginHorizontal(); { if (sprites.Count > 0) { if (GUILayout.Button("Auto Fill '" + stripSuffix(sprites.Last()) + "*'")) { autoFill(animation); } } if (GUILayout.Button("Add Frame")) { showDialog = true; } } GUILayout.EndHorizontal(); if (showDialog) { dfEditorUtil.DelayedInvoke((System.Action)(() => { dfSpriteSelectionDialog.Show("Select Sprite", animation.Atlas, null, (selected) => { if (!string.IsNullOrEmpty(selected)) { dfEditorUtil.MarkUndo(animation.gameObject, "Add new animation frame"); sprites.Add(selected); } }); })); } }