I found myself often with the problem that i need to add tons of items into a Array.
Normally you expect so see the same order you selected the items.
But Unity does not follow the order.
So i tinker a scrip that sort a Array by name in the editor.
In the inspector of the scrip in which the Array is needed to sort a button will appear.
Tested with textures, but should work for the most other stuff. You can easily add all the data type you need.
ArraySort.cs
using UnityEditor;
using UnityEngine;
using System.Collections;
[CustomEditor( typeof(name_of_script_which_contains_the_array) )]
public class ArraySort : Editor {
name_of_script_which_contains_the_array m_Instance;
public override void OnInspectorGUI () {
this.DrawDefaultInspector();
if(GUILayout.Button("Sort the array by name"))
{
name_of_script_which_contains_the_array current_target = target as name_of_script_which_contains_the_array;
Debug.Log("The Array name_of_sorted_array got sorted by Name.");
System.Array.Sort( current_target.name_of_sorted_array, CompareObNames );
}
}
int CompareObNames( Texture x, Texture y )
{
return x.name.CompareTo( y.name );
}
int CompareObNames( Texture2D x, Texture2D y )
{
return x.name.CompareTo( y.name );
}
int CompareObNames( GameObject x, GameObject y )
{
return x.name.CompareTo( y.name );
}
int CompareObNames( Transform x, Transform y )
{
return x.name.CompareTo( y.name );
}
int CompareObNames( GUIText x, GUIText y )
{
return x.name.CompareTo( y.name );
}
int CompareObNames( GUITexture x, GUITexture y )
{
return x.name.CompareTo( y.name );
}
int CompareObNames( Material x, Material y )
{
return x.name.CompareTo( y.name );
}
int CompareObNames( PhysicMaterial x, PhysicMaterial y )
{
return x.name.CompareTo( y.name );
}
int CompareObNames( ProceduralMaterial x, ProceduralMaterial y )
{
return x.name.CompareTo( y.name );
}
}