static void DoCreateSlicedSpriteObject()
 {
     tk2dSpriteGuiUtility.GetSpriteCollectionAndCreate((sprColl) => {
         GameObject go          = tk2dEditorUtility.CreateGameObjectInScene("Tiled Sprite");
         tk2dTiledSprite sprite = go.AddComponent <tk2dTiledSprite>();
         sprite.SetSprite(sprColl, sprColl.FirstValidDefinitionIndex);
         sprite.Build();
         Selection.activeGameObject = go;
         Undo.RegisterCreatedObjectUndo(go, "Create Tiled Sprite");
     });
 }
Beispiel #2
0
    static void DoCreateSlicedSpriteObject()
    {
        tk2dSpriteCollectionData sprColl = null;

        if (sprColl == null)
        {
            // try to inherit from other Sprites in scene
            tk2dSprite spr = GameObject.FindObjectOfType(typeof(tk2dSprite)) as tk2dSprite;
            if (spr)
            {
                sprColl = spr.Collection;
            }
        }

        if (sprColl == null)
        {
            tk2dSpriteCollectionIndex[] spriteCollections = tk2dEditorUtility.GetOrCreateIndex().GetSpriteCollectionIndex();
            foreach (var v in spriteCollections)
            {
                GameObject scgo = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(v.spriteCollectionDataGUID), typeof(GameObject)) as GameObject;
                var        sc   = scgo.GetComponent <tk2dSpriteCollectionData>();
                if (sc != null && sc.spriteDefinitions != null && sc.spriteDefinitions.Length > 0)
                {
                    sprColl = sc;
                    break;
                }
            }

            if (sprColl == null)
            {
                EditorUtility.DisplayDialog("Create Tiled Sprite", "Unable to create tiled sprite as no SpriteCollections have been found.", "Ok");
                return;
            }
        }

        GameObject      go     = tk2dEditorUtility.CreateGameObjectInScene("Tiled Sprite");
        tk2dTiledSprite sprite = go.AddComponent <tk2dTiledSprite>();

        sprite.SetSprite(sprColl, sprColl.FirstValidDefinitionIndex);
        sprite.Build();
        Selection.activeGameObject = go;
        Undo.RegisterCreatedObjectUndo(go, "Create Tiled Sprite");
    }