InitDictionary() 공개 메소드

Initializes the lookup dictionary
public InitDictionary ( ) : void
리턴 void
예제 #1
0
        public static int AddSpriteToCollection(tk2dSpriteDefinition spriteDefinition, tk2dSpriteCollectionData collection)
        {
            tk2dSpriteDefinition[] spriteDefinitions = collection.spriteDefinitions;
            tk2dSpriteDefinition[] array             = spriteDefinitions.Concat(new tk2dSpriteDefinition[] { spriteDefinition }).ToArray();
            collection.spriteDefinitions = array;
            FieldInfo field = typeof(tk2dSpriteCollectionData).GetField("spriteNameLookupDict", BindingFlags.Instance | BindingFlags.NonPublic);

            field.SetValue(collection, null);
            collection.InitDictionary();
            return(array.Length - 1);
        }
        // Token: 0x0600000A RID: 10 RVA: 0x000026EC File Offset: 0x000008EC
        public static tk2dSpriteCollectionData ConstructCollection(GameObject obj, string name)
        {
            tk2dSpriteCollectionData tk2dSpriteCollectionData = obj.AddComponent <tk2dSpriteCollectionData>();

            UnityEngine.Object.DontDestroyOnLoad(tk2dSpriteCollectionData);
            tk2dSpriteCollectionData.assetName            = name;
            tk2dSpriteCollectionData.spriteCollectionGUID = name;
            tk2dSpriteCollectionData.spriteCollectionName = name;
            tk2dSpriteCollectionData.spriteDefinitions    = new tk2dSpriteDefinition[0];
            tk2dSpriteCollectionData.InitDictionary();
            return(tk2dSpriteCollectionData);
        }
예제 #3
0
        public static int AddSpriteToCollection(tk2dSpriteDefinition spriteDefinition, tk2dSpriteCollectionData collection)
        {
            //Add definition to collection
            var defs    = collection.spriteDefinitions;
            var newDefs = defs.Concat(new tk2dSpriteDefinition[] { spriteDefinition }).ToArray();

            collection.spriteDefinitions = newDefs;

            //Reset lookup dictionary
            spriteNameLookup.SetValue(collection, null); //Set dictionary to null
            collection.InitDictionary();                 //InitDictionary only runs if the dictionary is null
            return(newDefs.Length - 1);
        }
예제 #4
0
 private static int AddSpriteToCollection(tk2dSpriteDefinition spriteDefinition, tk2dSpriteCollectionData collection, bool InitDictionary = false)
 {
     tk2dSpriteDefinition[] spriteDefinitions = collection.spriteDefinitions;
     tk2dSpriteDefinition[] array             = spriteDefinitions.Concat(new tk2dSpriteDefinition[] { spriteDefinition }).ToArray();
     collection.spriteDefinitions = array;
     // Default is off. We never need to call specific definitions by name from newCollection since it's only a temperary object about to be serialized.
     if (InitDictionary)
     {
         FieldInfo field = typeof(tk2dSpriteCollectionData).GetField("spriteNameLookupDict", BindingFlags.Instance | BindingFlags.NonPublic);
         field.SetValue(collection, null);
         collection.InitDictionary();
     }
     return(array.Length - 1);
 }
예제 #5
0
        /// <summary>
        /// Adds a sprite from a definition to a collection
        /// </summary>
        /// <returns>The spriteID of the defintion in the collection</returns>
        public static int AddSpriteToCollection(tk2dSpriteDefinition spriteDefinition, tk2dSpriteCollectionData collection)
        {
            //Add definition to collection
            var defs    = collection.spriteDefinitions;
            var newDefs = defs.Concat(new tk2dSpriteDefinition[] { spriteDefinition }).ToArray();

            collection.spriteDefinitions = newDefs;

            //Reset lookup dictionary
            FieldInfo f = typeof(tk2dSpriteCollectionData).GetField("spriteNameLookupDict", BindingFlags.Instance | BindingFlags.NonPublic);

            f.SetValue(collection, null); //Set dictionary to null
            collection.InitDictionary();  //InitDictionary only runs if the dictionary is null
            return(newDefs.Length - 1);
        }
예제 #6
0
        private static tk2dSpriteCollectionData GenerateNewSpriteCollection(GameObject targetObject, string CollectionName = null, tk2dSpriteDefinition[] spriteDefinitions = null, bool initDictionary = false)
        {
            tk2dSpriteCollectionData newCollection = targetObject.AddComponent <tk2dSpriteCollectionData>();

            newCollection.version          = 3;
            newCollection.materialIdsValid = true;
            if (spriteDefinitions != null)
            {
                newCollection.spriteDefinitions = spriteDefinitions;
            }
            newCollection.spriteDefinitions  = new tk2dSpriteDefinition[0];
            newCollection.premultipliedAlpha = false;
            newCollection.shouldGenerateTilemapReflectionData = false;
            newCollection.materials            = new Material[0];
            newCollection.textures             = new Texture[0];
            newCollection.pngTextures          = new TextAsset[0];
            newCollection.textureFilterMode    = FilterMode.Point;
            newCollection.textureMipMaps       = false;
            newCollection.allowMultipleAtlases = false;
            newCollection.spriteCollectionGUID = Guid.NewGuid().ToString();
            if (!string.IsNullOrEmpty(CollectionName))
            {
                newCollection.spriteCollectionName = CollectionName;
            }
            else
            {
                newCollection.spriteCollectionName = targetObject.name + "_Collection";
            }
            newCollection.loadable = false;
            newCollection.buildKey = UnityEngine.Random.Range(800000000, 999999999);
            newCollection.dataGuid = Guid.NewGuid().ToString();
            newCollection.managedSpriteCollection       = false;
            newCollection.hasPlatformData               = false;
            newCollection.spriteCollectionPlatforms     = new string[0];
            newCollection.spriteCollectionPlatformGUIDs = new string[0];
            if (initDictionary)
            {
                newCollection.InitDictionary();
            }
            return(newCollection);
        }
예제 #7
0
        // Assigns a GameObject (loaded from an asset bundle in this version) with the attached tk2dSpriteCollectionData component to your chosen field.
        // Currently only setup a version that loads these assets from an asset bundle
        public static GameObject DeserializeSpriteCollectionFromAssetBundle(AssetBundle assetBundle, string GameObjectPath, string spriteAtlasPath, string serializedCollectionJSONName, bool addSpriteToObject = false, string spriteDefintionName = null, Material overrideMaterial = null)
        {
            GameObject targetObject = assetBundle.LoadAsset <GameObject>(GameObjectPath);
            Texture2D  spriteAtlas  = assetBundle.LoadAsset <Texture2D>(spriteAtlasPath);
            tk2dSpriteCollectionData m_CollectionData = targetObject.AddComponent <tk2dSpriteCollectionData>();

            JsonUtility.FromJsonOverwrite(DeserializeJSONDataFromAssetBundle(assetBundle, serializedCollectionJSONName), m_CollectionData);
            if (overrideMaterial)
            {
                m_CollectionData.materials = new Material[] { new Material(overrideMaterial) };
            }
            else
            {
                m_CollectionData.materials = new Material[] { new Material(ShaderCache.Acquire(PlayerController.DefaultShaderName)) };
            }
            m_CollectionData.materials[0].mainTexture = spriteAtlas;
            foreach (tk2dSpriteDefinition definition in m_CollectionData.spriteDefinitions)
            {
                definition.material = m_CollectionData.materials[0];
            }
            m_CollectionData.InitDictionary();
            m_CollectionData.inst.InitDictionary(); // Important you do this on inst (on a new collection) so that inst's init runs and the collection is in the correct state. Else things like items not having ammonocon sprites or GetBounds causing exceptiosn on instances spawned by SpawnVFX in some circumstances!
            if (addSpriteToObject)
            {
                tk2dSprite m_tk2dSprite = targetObject.AddComponent <tk2dSprite>();
                if (!string.IsNullOrEmpty(spriteDefintionName))
                {
                    m_tk2dSprite.SetSprite(m_CollectionData, spriteDefintionName);
                }
                else
                {
                    m_tk2dSprite.SetSprite(m_CollectionData, 0);
                }
                m_tk2dSprite.SortingOrder = 0;
                targetObject.GetComponent <BraveBehaviour>().sprite = m_tk2dSprite;
            }
            return(targetObject);
        }