当前位置: 首页>>代码示例>>C#>>正文


C# SpriteRenderer.GetComponent方法代码示例

本文整理汇总了C#中UnityEngine.SpriteRenderer.GetComponent方法的典型用法代码示例。如果您正苦于以下问题:C# SpriteRenderer.GetComponent方法的具体用法?C# SpriteRenderer.GetComponent怎么用?C# SpriteRenderer.GetComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEngine.SpriteRenderer的用法示例。


在下文中一共展示了SpriteRenderer.GetComponent方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SpawnPlatform

        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);
        }
开发者ID:Pavelko007,项目名称:InfiniteBall,代码行数:10,代码来源:Spawner.cs

示例2: FadeSprite

        /** 
         * 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;
        }
开发者ID:KRUR,项目名称:NotJustASheep,代码行数:50,代码来源:SpriteFader.cs

示例3: Initialize

        /// <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 );
            }
        }
开发者ID:yabos,项目名称:BattleHit,代码行数:81,代码来源:AutoTileMap.cs

示例4: Initialize

        /// <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 );
            }
        }
开发者ID:JumberlackCoding,项目名称:TopDownRPG,代码行数:66,代码来源:AutoTileMap.cs

示例5: Initialize

        /// <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 );
			}
		}
开发者ID:pmer,项目名称:zombie-ninja-attack-craft,代码行数:74,代码来源:AutoTileMap.cs


注:本文中的UnityEngine.SpriteRenderer.GetComponent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。