Exemplo n.º 1
0
        // Returns index of newly added layer
        public static int AddNewLayer(tk2dTileMap tileMap)
        {
            var existingLayers = tileMap.data.Layers;
            // find a unique hash
            bool duplicateHash = false;
            int hash;
            do
            {
                duplicateHash = false;
                hash = Random.Range(0, int.MaxValue);
                foreach (var layer in existingLayers)
                    if (layer.hash == hash)
                        duplicateHash = true;
            } while (duplicateHash == true);

            var newLayer = new tk2dRuntime.TileMap.LayerInfo();
            newLayer.name = "New Layer";
            newLayer.hash = hash;
            newLayer.z = 0.1f;
            tileMap.data.tileMapLayers.Add(newLayer);

            // remap tilemap
            tk2dRuntime.TileMap.BuilderUtil.InitDataStore(tileMap);

            return tileMap.data.NumLayers - 1;
        }
Exemplo n.º 2
0
        // Returns index of newly added layer
        public static int AddNewLayer(tk2dTileMap tileMap)
        {
            var existingLayers = tileMap.data.Layers;
            // find a unique hash
            bool duplicateHash = false;
            int  hash;

            do
            {
                duplicateHash = false;
                hash          = Random.Range(0, int.MaxValue);
                foreach (var layer in existingLayers)
                {
                    if (layer.hash == hash)
                    {
                        duplicateHash = true;
                    }
                }
            } while (duplicateHash == true);

            var newLayer = new tk2dRuntime.TileMap.LayerInfo();

            newLayer.name = "New Layer";
            newLayer.hash = hash;
            newLayer.z    = 0.1f;
            tileMap.data.tileMapLayers.Add(newLayer);

            // remap tilemap
            tk2dRuntime.TileMap.BuilderUtil.InitDataStore(tileMap);

            return(tileMap.data.NumLayers - 1);
        }
Exemplo n.º 3
0
    void InitLayers()
    {
        tileMapLayers = new List <tk2dRuntime.TileMap.LayerInfo>();
        var newLayer = new tk2dRuntime.TileMap.LayerInfo();

        newLayer      = new tk2dRuntime.TileMap.LayerInfo();
        newLayer.name = "Layer 0";
        newLayer.hash = 0x70d32b98;
        newLayer.z    = 0.0f;
        tileMapLayers.Add(newLayer);
    }
Exemplo n.º 4
0
        // Returns index of newly added layer
        public static int AddNewLayer(tk2dTileMap tileMap)
        {
            var existingLayers = tileMap.data.Layers;
            // find a unique hash
            bool duplicateHash = false;
            int  hash;

            do
            {
                duplicateHash = false;
                hash          = Random.Range(0, int.MaxValue);
                foreach (var layer in existingLayers)
                {
                    if (layer.hash == hash)
                    {
                        duplicateHash = true;
                    }
                }
            } while (duplicateHash == true);

            List <Object> objectsToUndo = new List <Object>();

            objectsToUndo.Add(tileMap);
            objectsToUndo.Add(tileMap.data);
            Undo.RegisterUndo(objectsToUndo.ToArray(), "Add layer");

            var newLayer = new tk2dRuntime.TileMap.LayerInfo();

            newLayer.name = "New Layer";
            newLayer.hash = hash;
            newLayer.z    = 0.1f;
            tileMap.data.tileMapLayers.Add(newLayer);

            // remap tilemap
            tk2dRuntime.TileMap.BuilderUtil.InitDataStore(tileMap);

            GameObject layerGameObject = new GameObject(newLayer.name);

            layerGameObject.transform.parent        = tileMap.renderData.transform;
            layerGameObject.transform.localPosition = Vector3.zero;
            layerGameObject.transform.localScale    = Vector3.one;
            layerGameObject.transform.localRotation = Quaternion.identity;
            tileMap.Layers[tileMap.Layers.Length - 1].gameObject = layerGameObject;

            Undo.RegisterCreatedObjectUndo(layerGameObject, "Add layer");

            return(tileMap.data.NumLayers - 1);
        }
Exemplo n.º 5
0
		// Returns index of newly added layer
		public static int AddNewLayer(tk2dTileMap tileMap)
		{
			var existingLayers = tileMap.data.Layers;
			// find a unique hash
			bool duplicateHash = false;
			int hash;
			do
			{
				duplicateHash = false;
				hash = Random.Range(0, int.MaxValue);
				foreach (var layer in existingLayers) 
					if (layer.hash == hash) 
						duplicateHash = true;
			} while (duplicateHash == true);

			List<Object> objectsToUndo = new List<Object>();
			objectsToUndo.Add(tileMap);
			objectsToUndo.Add(tileMap.data);
			tk2dUndo.RecordObjects(objectsToUndo.ToArray(), "Add layer");
			
			var newLayer = new tk2dRuntime.TileMap.LayerInfo();
			newLayer.name = "New Layer";
			newLayer.hash = hash;
			newLayer.z = 0.1f;
			tileMap.data.tileMapLayers.Add(newLayer);
			
			// remap tilemap
			tk2dRuntime.TileMap.BuilderUtil.InitDataStore(tileMap);

			GameObject layerGameObject = tk2dUtil.CreateGameObject(newLayer.name);
			layerGameObject.transform.parent = tileMap.renderData.transform;
			layerGameObject.transform.localPosition = Vector3.zero;
			layerGameObject.transform.localScale = Vector3.one;
			layerGameObject.transform.localRotation = Quaternion.identity;
			tileMap.Layers[tileMap.Layers.Length - 1].gameObject = layerGameObject;

			Undo.RegisterCreatedObjectUndo(layerGameObject, "Add layer");
			
			return tileMap.data.NumLayers - 1;
		}
Exemplo n.º 6
0
	void InitLayers()
	{
		tileMapLayers = new List<tk2dRuntime.TileMap.LayerInfo>();
		var newLayer = new tk2dRuntime.TileMap.LayerInfo();
		newLayer = new tk2dRuntime.TileMap.LayerInfo();
		newLayer.name = "Layer 0";
		newLayer.hash = 0x70d32b98;
		newLayer.z = 0.0f;
		tileMapLayers.Add(newLayer);
	}