コード例 #1
0
ファイル: Spawner.cs プロジェクト: Pavelko007/InfiniteBall
        private void SpawnPlatform(Vector3 nextPos, PlatformType platformType)
        {
            lastPlatformSR = GameObjectUtil.Instantiate(platformPrefab.gameObject, nextPos)
                .GetComponent<SpriteRenderer>();

            lastPlatformSR.GetComponent<FallingPlatform>().SetupPlatform(platformType);
        
            int numCoins = Random.Range(0, maxNumCoins + 1);
            while (numCoins-- > 0) SpawnCoin(lastPlatformSR);
        }
コード例 #2
0
ファイル: SpriteFader.cs プロジェクト: KRUR/NotJustASheep
        /** 
         * Attaches a SpriteFader component to a sprite object to transition its color over time.
         */
        public static void FadeSprite(SpriteRenderer spriteRenderer, Color targetColor, float duration, Vector2 slideOffset, Action onComplete = null)
        {
            if (spriteRenderer == null)
            {
                Debug.LogError("Sprite renderer must not be null");
                return;
            }

            // Fade child sprite renderers
            SpriteRenderer[] children = spriteRenderer.gameObject.GetComponentsInChildren<SpriteRenderer>();
            foreach (SpriteRenderer child in children)
            {
                if (child == spriteRenderer)
                {
                    continue;
                }
                
                FadeSprite(child, targetColor, duration, slideOffset);
            }

            // Destroy any existing fader component
            SpriteFader oldSpriteFader = spriteRenderer.GetComponent<SpriteFader>();
            if (oldSpriteFader != null)
            {
                Destroy(oldSpriteFader);
            }

            // Early out if duration is zero
            if (duration == 0f)
            {
                spriteRenderer.color = targetColor;
                if (onComplete != null)
                {
                    onComplete();
                }
                return;
            }

            // Set up color transition to be applied during update
            SpriteFader spriteFader = spriteRenderer.gameObject.AddComponent<SpriteFader>();
            spriteFader.fadeDuration = duration;
            spriteFader.startColor = spriteRenderer.color;
            spriteFader.endColor = targetColor;
            spriteFader.endPosition = spriteRenderer.transform.position;
            spriteFader.slideOffset = slideOffset;
            spriteFader.onFadeComplete = onComplete;
        }
コード例 #3
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 );
            }
        }
コード例 #4
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 );
            }
        }
コード例 #5
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 );
			}
		}