コード例 #1
0
        /// <summary>
        /// Initialize the map
        /// </summary>
        public void Initialize()
        {
            //Debug.Log("AutoTileMap:Initialize");

            if( MapData == null )
            {
                Debug.LogError(" AutoTileMap.Initialize called when MapData was null");
            }
            else if( Tileset == null || Tileset.AtlasTexture == null )
            {
                Debug.LogError(" AutoTileMap.Initialize called when Tileset or Tileset.TilesetsAtlasTexture was null");
            }
            else
            {
                //Set the instance if executed in editor where Awake is not called
                if( Instance == null ) Instance = this;

                Tileset.GenerateAutoTileData();

                MinimapTexture = new Texture2D(MapTileWidth, MapTileHeight);
                MinimapTexture.anisoLevel = 0;
                MinimapTexture.filterMode = FilterMode.Point;
                MinimapTexture.name = "MiniMap";

                m_minimapTilesTexture = new Texture2D( 64, 64 );
                m_minimapTilesTexture.anisoLevel = 0;
                m_minimapTilesTexture.filterMode = FilterMode.Point;
                m_minimapTilesTexture.name = "MiniMapTiles";

                _GenerateMinimapTilesTexture();

                if( Application.isEditor )
                {
                    if( EditorMinimapRender == null )
                    {
                        GameObject objMinimap = new GameObject();
                        objMinimap.name = "Minimap";
                        objMinimap.transform.parent = transform;
                        EditorMinimapRender = objMinimap.AddComponent<SpriteRenderer>();
                        EditorMinimapRender.GetComponent<Renderer>().enabled = false;
                    }
                    Rect rMinimap = new Rect(0f, 0f, MinimapTexture.width, MinimapTexture.height);
                    Vector2 pivot = new Vector2(0f, 1f);
                    EditorMinimapRender.sprite = Sprite.Create(MinimapTexture, rMinimap, pivot, AutoTileset.PixelToUnits);
                    EditorMinimapRender.transform.localScale = new Vector3(Tileset.TileWidth, Tileset.TileHeight);
                }

                MapLayers = new List<MapLayer>();
                TileLayers = new List<AutoTile[]>();

                AutoTileMapGui = GetComponent<AutoTileMapGui>();

                if( m_tileChunkPoolNode == null )
                {
                    string nodeName = name+" Data";
                    GameObject obj = GameObject.Find( nodeName );
                    if( obj == null ) obj = new GameObject();
                    obj.name = nodeName;
                    m_tileChunkPoolNode = obj.AddComponent<TileChunkPool>();
                }
                m_tileChunkPoolNode.Initialize( this );
            }
        }
コード例 #2
0
ファイル: AutoTileMap.cs プロジェクト: yabos/BattleHit
        /// <summary>
        /// Initialize the map
        /// </summary>
        public void Initialize()
        {
            //Debug.Log("AutoTileMap:Initialize");

            if( MapData == null )
            {
                Debug.LogError(" AutoTileMap.Initialize called when MapData was null");
            }
            else if( Tileset == null || Tileset.AtlasTexture == null )
            {
                Debug.LogError(" AutoTileMap.Initialize called when Tileset or Tileset.TilesetsAtlasTexture was null");
            }
            else
            {
                //Set the instance if executed in editor where Awake is not called
                if( Instance == null ) Instance = this;

                Tileset.GenerateAutoTileData();

                //TODO: Allow changing minimap offset to allow minimaps smaller than map size
                int minimapWidth = Mathf.Min(MapTileWidth, 2048); //NOTE: 2048 is a maximum safe size for a texture
                int minimapHeigh = Mathf.Min(MapTileHeight, 2048);
                if( MinimapTexture != null )
                {
                    DestroyImmediate( MinimapTexture );
                }
                MinimapTexture = new Texture2D(minimapWidth, minimapHeigh);
                MinimapTexture.anisoLevel = 0;
                MinimapTexture.filterMode = FilterMode.Point;
                MinimapTexture.name = "MiniMap";
                MinimapTexture.hideFlags = HideFlags.DontSave;

                int tileNb = m_autoTileset.TilesCount;
                int minimapSize = Mathf.CeilToInt( (float)Math.Sqrt( tileNb ) );
                if (m_minimapTilesTexture != null)
                {
                    DestroyImmediate(m_minimapTilesTexture);
                }
                m_minimapTilesTexture = new Texture2D(minimapSize, minimapSize);
                m_minimapTilesTexture.anisoLevel = 0;
                m_minimapTilesTexture.filterMode = FilterMode.Point;
                m_minimapTilesTexture.name = "MiniMapTiles";
                m_minimapTilesTexture.hideFlags = HideFlags.DontSave;

                _GenerateMinimapTilesTexture();

                if( Application.isEditor )
                {
                    if( EditorMinimapRender == null )
                    {
                        GameObject objMinimap = new GameObject();
                        objMinimap.name = "Minimap";
                        objMinimap.transform.parent = transform;
                        EditorMinimapRender = objMinimap.AddComponent<SpriteRenderer>();
                        EditorMinimapRender.GetComponent<Renderer>().enabled = false;
                    }
                    Rect rMinimap = new Rect(0f, 0f, MinimapTexture.width, MinimapTexture.height);
                    Vector2 pivot = new Vector2(0f, 1f);
                    EditorMinimapRender.sprite = Sprite.Create(MinimapTexture, rMinimap, pivot, AutoTileset.PixelToUnits);
                    EditorMinimapRender.transform.localScale = new Vector3(Tileset.TileWidth, Tileset.TileHeight);
                }

                MapLayers = new List<MapLayer>();
                TileLayers = new List<AutoTile[]>();

                AutoTileMapGui = GetComponent<AutoTileMapGui>();

                if( m_tileChunkPoolNode == null )
                {
                    string nodeName = name+" Data";
                    GameObject obj = GameObject.Find( nodeName );
                    if( obj == null ) obj = new GameObject();
                    obj.name = nodeName;
                    m_tileChunkPoolNode = obj.AddComponent<TileChunkPool>();
                }
                m_tileChunkPoolNode.Initialize( this );
            }
        }
コード例 #3
0
        /// <summary>
        /// Initialize the map
        /// </summary>
		public void Initialize()
		{
			//Debug.Log("AutoTileMap:Initialize");

			if( MapData == null )
			{
				Debug.LogError(" AutoTileMap.Initialize called when MapData was null");
			}
			else if( Tileset == null || Tileset.AtlasTexture == null )
			{
				Debug.LogError(" AutoTileMap.Initialize called when Tileset or Tileset.TilesetsAtlasTexture was null");
			}
			else
			{
				Tileset.GenerateAutoTileData();

				MinimapTexture = new Texture2D(MapTileWidth, MapTileHeight);
				MinimapTexture.anisoLevel = 0;
				MinimapTexture.filterMode = FilterMode.Point;
				MinimapTexture.name = "MiniMap";

				m_minimapTilesTexture = new Texture2D( 64, 64 );
				m_minimapTilesTexture.anisoLevel = 0;
				m_minimapTilesTexture.filterMode = FilterMode.Point;
				m_minimapTilesTexture.name = "MiniMapTiles";
				
				_GenerateMinimapTilesTexture();

				if( Application.isEditor )
				{
					if( EditorMinimapRender == null )
					{
						GameObject objMinimap = new GameObject();
						objMinimap.name = "Minimap";
						objMinimap.transform.parent = transform;
						EditorMinimapRender = objMinimap.AddComponent<SpriteRenderer>();
						EditorMinimapRender.GetComponent<Renderer>().enabled = false;
					}
					Rect rMinimap = new Rect(0f, 0f, MinimapTexture.width, MinimapTexture.height);
					Vector2 pivot = new Vector2(0f, 1f);
					EditorMinimapRender.sprite = Sprite.Create(MinimapTexture, rMinimap, pivot, AutoTileset.PixelToUnits);
                    EditorMinimapRender.transform.localScale = new Vector3(Tileset.TileWidth, Tileset.TileHeight);
				}
				
				m_AutoTileLayers = new List<AutoTile[,]>( (int)eTileLayer._SIZE );
				for( int iLayer = 0; iLayer <  (int)eTileLayer._SIZE; ++iLayer )
				{
					m_AutoTileLayers.Add( new AutoTile[MapTileWidth, MapTileHeight] );
					for (int i = 0; i < MapTileWidth; ++i)
					{
						for (int j = 0; j < MapTileHeight; ++j)
						{
							m_AutoTileLayers[iLayer][i, j] = null;
						}
					}
				}
				
				AutoTileMapGui = GetComponent<AutoTileMapGui>();

				if( m_tileChunkPoolNode == null )
				{
					string nodeName = name+" Data";
					GameObject obj = GameObject.Find( nodeName );
					if( obj == null ) obj = new GameObject();
					obj.name = nodeName;
					obj.AddComponent<TileChunkPool>();
					m_tileChunkPoolNode = obj.AddComponent<TileChunkPool>();
				}
				m_tileChunkPoolNode.Initialize( this );
			}
		}