public static GameObject DropFramesToSceneToCreateGO(Sprite[] frames, Vector3 position)
{
if (frames.Length > 0)
{
Sprite sprite = frames[0];
string name = (!string.IsNullOrEmpty(sprite.name)) ? sprite.name : "Sprite";
name = GameObjectUtility.GetUniqueNameForSibling(null, name);
GameObject gameObject = new GameObject(name);
SpriteRenderer spriteRenderer = gameObject.AddComponent <SpriteRenderer>();
spriteRenderer.sprite = sprite;
gameObject.transform.position = position;
Selection.activeObject = gameObject;
if (frames.Length > 1)
{
Analytics.Event("Sprite Drag and Drop", "Drop multiple sprites to scene", "null", 1);
if (!SpriteUtility.CreateAnimation(gameObject, frames))
{
UnityEngine.Object.DestroyImmediate(gameObject);
return(null);
}
}
else
{
Analytics.Event("Sprite Drag and Drop", "Drop single sprite to scene", "null", 1);
}
return(gameObject);
}
return(null);
}