コード例 #1
0
    void HandleDroppedPayload(Object[] objects)
    {
        List <int> addedIndices = new List <int>();

        foreach (var obj in objects)
        {
            Texture2D tex  = obj as Texture2D;
            string    name = spriteCollectionProxy.FindUniqueTextureName(tex.name);
            int       slot = spriteCollectionProxy.FindOrCreateEmptySpriteSlot();
            spriteCollectionProxy.textureParams[slot].name         = name;
            spriteCollectionProxy.textureParams[slot].colliderType = tk2dSpriteCollectionDefinition.ColliderType.None;
            spriteCollectionProxy.textureRefs[slot] = (Texture2D)obj;
            addedIndices.Add(slot);
        }
        // And now select them
        searchFilter = "";
        PopulateEntries();
        foreach (var entry in entries)
        {
            if (entry.type == SpriteCollectionEditorEntry.Type.Sprite &&
                addedIndices.IndexOf(entry.index) != -1)
            {
                entry.selected = true;
            }
        }

        UpdateSelection();
    }
コード例 #2
0
    void HandleDroppedPayload(Object[] objects)
    {
        bool hasDuplicates = false;

        foreach (var obj in objects)
        {
            Texture2D tex = obj as Texture2D;
            if (tex != null)
            {
                if (spriteCollectionProxy.FindSpriteBySource(tex) != -1)
                {
                    hasDuplicates = true;
                }
            }
        }

        bool cloneDuplicates = false;

        if (hasDuplicates && EditorUtility.DisplayDialog("Duplicate textures detected.",
                                                         "One or more textures is already in the collection. What do you want to do with the duplicates?",
                                                         "Clone", "Ignore"))
        {
            cloneDuplicates = true;
        }

        List <int> addedIndices = new List <int>();

        foreach (var obj in objects)
        {
            Texture2D tex = obj as Texture2D;
            if ((tex != null) && (cloneDuplicates || spriteCollectionProxy.FindSpriteBySource(tex) == -1))
            {
                string name = spriteCollectionProxy.FindUniqueTextureName(tex.name);
                int    slot = spriteCollectionProxy.FindOrCreateEmptySpriteSlot();
                spriteCollectionProxy.textureParams[slot].name         = name;
                spriteCollectionProxy.textureParams[slot].colliderType = tk2dSpriteCollectionDefinition.ColliderType.UserDefined;
                spriteCollectionProxy.textureParams[slot].texture      = (Texture2D)obj;
                addedIndices.Add(slot);
            }
        }
        // And now select them
        searchFilter = "";
        PopulateEntries();
        foreach (var entry in entries)
        {
            if (entry.type == SpriteCollectionEditorEntry.Type.Sprite &&
                addedIndices.IndexOf(entry.index) != -1)
            {
                entry.selected = true;
            }
        }

        UpdateSelection();
    }