示例#1
0
    static void AddSpriteCollectionFromIndex(tk2dSpriteCollectionIndex indexEntry)
    {
        string path = AssetDatabase.GUIDToAssetPath(indexEntry.spriteCollectionDataGUID);
        tk2dSpriteCollectionData data = AssetDatabase.LoadAssetAtPath(path, typeof(tk2dSpriteCollectionData)) as tk2dSpriteCollectionData;

        if (data == null)
        {
            CustomDebug.LogError(string.Format("Unable to load sprite collection '{0}' at path '{1}'", indexEntry.name, path));
            return;
        }
        MakeLoadableAsset(data, indexEntry.managedSpriteCollection ? " " : data.assetName);
        data = null;
    }
    public void AddSpriteCollectionData(tk2dSpriteCollectionData sc)
    {
#if UNITY_EDITOR
        // prune list
        GetSpriteCollectionIndex();
        spriteCollectionIndex.RemoveAll(item => item == null);
        string guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(sc));

        bool existing = false;
        tk2dSpriteCollectionIndex indexEntry = null;
        foreach (var v in spriteCollectionIndex)
        {
            if (v.spriteCollectionDataGUID == guid)
            {
                indexEntry = v;
                existing   = true;
                break;
            }
        }
        if (indexEntry == null)
        {
            indexEntry = new tk2dSpriteCollectionIndex();
        }

        indexEntry.name = sc.spriteCollectionName;
        indexEntry.spriteCollectionDataGUID = guid;
        indexEntry.spriteCollectionGUID     = sc.spriteCollectionGUID;
        indexEntry.spriteNames        = new string[sc.spriteDefinitions.Length];
        indexEntry.spriteTextureGUIDs = new string[sc.spriteDefinitions.Length];
        indexEntry.version            = sc.version;
        for (int i = 0; i < sc.spriteDefinitions.Length; ++i)
        {
            var s = sc.spriteDefinitions[i];
            if (s != null)
            {
                indexEntry.spriteNames[i]        = sc.spriteDefinitions[i].name;
                indexEntry.spriteTextureGUIDs[i] = sc.spriteDefinitions[i].sourceTextureGUID;
            }
            else
            {
                indexEntry.spriteNames[i]        = "";
                indexEntry.spriteTextureGUIDs[i] = "";
            }
        }

        if (!existing)
        {
            spriteCollectionIndex.Add(indexEntry);
        }
#endif
    }
示例#3
0
    public void AddSpriteCollectionData(tk2dSpriteCollectionData sc)
    {
        #if UNITY_EDITOR
        // prune list
        GetSpriteCollectionIndex();
        spriteCollectionIndex.RemoveAll(item => item == null);
        string guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(sc));

        bool existing = false;
        tk2dSpriteCollectionIndex indexEntry = null;
        foreach (var v in spriteCollectionIndex)
        {
            if (v.spriteCollectionDataGUID == guid)
            {
                indexEntry = v;
                existing = true;
                break;
            }
        }
        if (indexEntry == null)
            indexEntry = new tk2dSpriteCollectionIndex();

        indexEntry.name = sc.spriteCollectionName;
        indexEntry.spriteCollectionDataGUID = guid;
        indexEntry.spriteCollectionGUID = sc.spriteCollectionGUID;
        indexEntry.spriteNames = new string[sc.spriteDefinitions.Length];
        indexEntry.spriteTextureGUIDs = new string[sc.spriteDefinitions.Length];
        indexEntry.version = sc.version;
        for (int i = 0; i < sc.spriteDefinitions.Length; ++i)
        {
            var s = sc.spriteDefinitions[i];
            if (s != null)
            {
                indexEntry.spriteNames[i] = sc.spriteDefinitions[i].name;
                indexEntry.spriteTextureGUIDs[i] = sc.spriteDefinitions[i].sourceTextureGUID;
            }
            else
            {
                indexEntry.spriteNames[i] = "";
                indexEntry.spriteTextureGUIDs[i] = "";
            }
        }

        if (!existing)
            spriteCollectionIndex.Add(indexEntry);
        #endif
    }
示例#4
0
        /// <summary>
        /// Is this a 2dToolkit collection?
        /// </summary>
        /// <returns>Yes or no</returns>
        bool AttemptTk2dCollection()
        {
#if PS2D_TK2D
            tk2dSpriteCollectionIndex[] collectionIndexes = tk2dEditorUtility.GetOrCreateIndex().GetSpriteCollectionIndex();
            if (collectionIndexes == null || collectionIndexes.Length == 0)
            {
                return(false);
            }

            List <tk2dSpriteCollectionIndex> collections = new List <tk2dSpriteCollectionIndex>(collectionIndexes);

            // look for identical names
            string basename = layout.GetFriendlyDocumentName();
            tk2dSpriteCollectionIndex foundIndex = collections.Find(each => each.name.Equals(basename, System.StringComparison.CurrentCultureIgnoreCase));
            if (foundIndex == null)
            {
                return(false);
            }

            // found it ... load it
            GameObject go = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(foundIndex.spriteCollectionDataGUID), typeof(GameObject)) as GameObject;
            if (go == null)
            {
                return(false);
            }

            // grab the data from it
            tk2dSpriteCollectionData spriteCollectionData = go.GetComponent <tk2dSpriteCollectionData>();
            if (spriteCollectionData == null)
            {
                return(false);
            }

            // all good.
            layout.imageSource        = TextureSource.Tk2dSpriteCollection;
            this.spriteCollectionData = spriteCollectionData;

            return(true);
#else
            return(false);
#endif
        }
示例#5
0
	static void AddSpriteCollectionFromIndex(tk2dSpriteCollectionIndex indexEntry)
	{
		string path = AssetDatabase.GUIDToAssetPath( indexEntry.spriteCollectionDataGUID );
		tk2dSpriteCollectionData data = AssetDatabase.LoadAssetAtPath(path, typeof(tk2dSpriteCollectionData)) as tk2dSpriteCollectionData;
		if (data == null)
		{
			Debug.LogError(string.Format("Unable to load sprite collection '{0}' at path '{1}'", indexEntry.name, path));
			return;
		}
		MakeLoadableAsset(data, indexEntry.managedSpriteCollection ? " " : data.assetName);
		data = null;
	}
示例#6
0
    public void AddSpriteCollectionData(tk2dSpriteCollectionData sc)
    {
#if UNITY_EDITOR
        // prune list
        GetSpriteCollectionIndex();
        spriteCollectionIndex.RemoveAll(item => item == null);
        string guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(sc));

        bool existing = false;
        tk2dSpriteCollectionIndex indexEntry = null;
        foreach (var v in spriteCollectionIndex)
        {
            if (v.spriteCollectionDataGUID == guid)
            {
                indexEntry = v;
                existing   = true;
                break;
            }
        }
        if (indexEntry == null)
        {
            indexEntry = new tk2dSpriteCollectionIndex();
        }

        indexEntry.name = sc.spriteCollectionName;
        indexEntry.spriteCollectionDataGUID = guid;
        indexEntry.spriteCollectionGUID     = sc.spriteCollectionGUID;
        indexEntry.spriteNames             = new string[sc.spriteDefinitions.Length];
        indexEntry.spriteTextureGUIDs      = new string[sc.spriteDefinitions.Length];
        indexEntry.spriteTextureTimeStamps = new string[sc.spriteDefinitions.Length];
        indexEntry.version = sc.version;
        indexEntry.managedSpriteCollection = sc.managedSpriteCollection;
        indexEntry.loadable  = sc.loadable;
        indexEntry.assetName = sc.assetName;
        for (int i = 0; i < sc.spriteDefinitions.Length; ++i)
        {
            var s = sc.spriteDefinitions[i];
            if (s != null)
            {
                indexEntry.spriteNames[i]        = sc.spriteDefinitions[i].name;
                indexEntry.spriteTextureGUIDs[i] = sc.spriteDefinitions[i].sourceTextureGUID;
                string assetPath = AssetDatabase.GUIDToAssetPath(indexEntry.spriteTextureGUIDs[i]);
                if (assetPath.Length > 0 && System.IO.File.Exists(assetPath))
                {
                    indexEntry.spriteTextureTimeStamps[i] = (System.IO.File.GetLastWriteTime(assetPath) - new System.DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalSeconds.ToString();
                }
                else
                {
                    indexEntry.spriteTextureTimeStamps[i] = "0";
                }
            }
            else
            {
                indexEntry.spriteNames[i]             = "";
                indexEntry.spriteTextureGUIDs[i]      = "";
                indexEntry.spriteTextureTimeStamps[i] = "";
            }
        }

        if (sc.spriteCollectionPlatforms.Length > 0)
        {
            indexEntry.spriteNames             = new string[] { "dummy" };
            indexEntry.spriteTextureGUIDs      = new string[] { "" };
            indexEntry.spriteTextureTimeStamps = new string[] { "0" };
        }

        if (!existing)
        {
            spriteCollectionIndex.Add(indexEntry);
        }
#endif
    }