static void DoCreateClippedSpriteObject()
    {
        tk2dSpriteGuiUtility.GetSpriteCollectionAndCreate((sprColl) => {
            GameObject go            = tk2dEditorUtility.CreateGameObjectInScene("Clipped Sprite");
            tk2dClippedSprite sprite = go.AddComponent <tk2dClippedSprite>();
            sprite.SetSprite(sprColl, sprColl.FirstValidDefinitionIndex);
            sprite.Build();

            Selection.activeGameObject = go;
            Undo.RegisterCreatedObjectUndo(go, "Create Clipped Sprite");
        });
    }
Пример #2
0
    static void DoCreateClippedSpriteObject()
    {
        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 Clipped Sprite", "Unable to create clipped sprite as no SpriteCollections have been found.", "Ok");
                return;
            }
        }

        GameObject        go     = tk2dEditorUtility.CreateGameObjectInScene("Clipped Sprite");
        tk2dClippedSprite sprite = go.AddComponent <tk2dClippedSprite>();

        sprite.SwitchCollectionAndSprite(sprColl, sprColl.FirstValidDefinitionIndex);
        sprite.Build();

        Selection.activeGameObject = go;
        Undo.RegisterCreatedObjectUndo(go, "Create Clipped Sprite");
    }