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


C# Texture.GetInstanceID方法代码示例

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


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

示例1: GetFallbackMaterial

        /// <summary>
        /// This function returns a material instance using the material properties of a previous material but using the font atlas texture of the new font asset.
        /// </summary>
        /// <param name="sourceMaterial">The material containing the source material properties to be copied to the new material.</param>
        /// <param name="sourceAtlasTexture">The font atlas texture that should be assigned to the new material.</param>
        /// <returns></returns>
        public static Material GetFallbackMaterial(Material sourceMaterial, Texture sourceAtlasTexture)
        {
            int sourceID = sourceMaterial.GetInstanceID();
            int texID = sourceAtlasTexture.GetInstanceID();
            long key = (long)sourceID << 32 + texID;

            FallbackMaterial fallback;
            if (m_fallbackMaterials.TryGetValue(key, out fallback))
            {
                //Debug.Log("Material [" + fallback.fallbackMaterial.name + "] already exists.");
                return fallback.fallbackMaterial;
            }

            // Create new material from the source material
            Material fallbackMaterial = new Material(sourceMaterial);
            fallbackMaterial.hideFlags = HideFlags.HideAndDontSave;

            #if UNITY_EDITOR
                fallbackMaterial.name += " + " + sourceAtlasTexture.name;
            #endif

            fallbackMaterial.SetTexture(ShaderUtilities.ID_MainTex, sourceAtlasTexture);

            fallback = new FallbackMaterial();
            fallback.baseID = sourceID;
            fallback.baseMaterial = sourceMaterial;
            fallback.fallbackMaterial = fallbackMaterial;
            fallback.count = 0;

            m_fallbackMaterials.Add(key, fallback);
            m_fallbackMaterialLookup.Add(fallbackMaterial.GetInstanceID(), key);

            #if DEBUG_ON
                ListFallbackMaterials();
            #endif

            return fallbackMaterial;
        }
开发者ID:Reticulatas,项目名称:Embargo,代码行数:44,代码来源:TMP_MaterialManager.cs

示例2: GetMaterial

        static public System.WeakReference GetMaterial(SpriteRenderMode rm, Texture tex)
        {
            int idx = rm == SpriteRenderMode.None ? 0 : (int)rm;
            SpriteRenderModeGroup group = renderModeGroup[idx];
            System.WeakReference ret = null;

            int id = tex == null ? 0 : tex.GetInstanceID();

            if (group != null)
            {
                if (group.setting.IsAlive)
                {
                    ret = group.materials[id] as System.WeakReference;
                    if ( ret == null)
                    {
                        SpriteRenderModeSetting setting = group.setting.Target as SpriteRenderModeSetting;

                        Material mat = new Material(setting.shader);
                        mat.mainTexture = tex;

                        ret = new System.WeakReference(mat);
                        group.materials[id] = ret;
                        setting.materials.Add(ret);
                    }
                    else
                    {
                        if (!ret.IsAlive)
                        {
                            SpriteRenderModeSetting setting = group.setting.Target as SpriteRenderModeSetting;

                            Material mat = new Material(setting.shader);
                            mat.mainTexture = tex;

                            ret = new System.WeakReference(mat);
                            group.materials[id] = ret;
                            setting.materials.Add(ret);
                        }
                    }
                }
                else
                {
                    renderModeGroup[idx] = null;
                }
            }
            else
            {
                Debug.LogError("unknown RenderMode " + rm);
            }
            return ret;
        }
开发者ID:WaylandGod,项目名称:EasyMotion2D.Runtime,代码行数:50,代码来源:SpriteBatchRenderer.cs

示例3: UpdateSpriteSlices

		static public void UpdateSpriteSlices (Texture texture, Atlas atlas) {
			string texturePath = AssetDatabase.GetAssetPath(texture.GetInstanceID());
			var t = (TextureImporter)TextureImporter.GetAtPath(texturePath);
			t.spriteImportMode = SpriteImportMode.Multiple;
			var spriteSheet = t.spritesheet;
			var sprites = new List<SpriteMetaData>(spriteSheet);

			FieldInfo field = typeof(Atlas).GetField("regions", BindingFlags.Instance | BindingFlags.NonPublic);
			var regions = (List<AtlasRegion>)field.GetValue(atlas);
			int textureHeight = texture.height;
			char[] FilenameDelimiter = {'.'};
			int updatedCount = 0;
			int addedCount = 0;

			foreach (var r in regions) {
				int width, height;
				if (r.rotate) {
					width = r.height;
					height = r.width;
				} else {
					width = r.width;
					height = r.height;
				}

				int x = r.x;
				int y = textureHeight - height - r.y;

				string pageName = r.page.name.Split(FilenameDelimiter, StringSplitOptions.RemoveEmptyEntries)[0];
				string textureName = texture.name;
				bool pageMatch = string.Equals(pageName, textureName,StringComparison.Ordinal);
				int spriteIndex = pageMatch ? sprites.FindIndex(
					(s) => string.Equals(s.name, r.name, StringComparison.Ordinal)
				) : -1;
				bool matchFound = spriteIndex >= 0;

				if (matchFound) {
					var s = sprites[spriteIndex];
					s.rect = new Rect(x, y, width, height);
					sprites[spriteIndex] = s;
					updatedCount++;
				} else {
					if (pageMatch) {
						sprites.Add(new SpriteMetaData {
							name = r.name,
							pivot = new Vector2(0.5f, 0.5f),
							rect = new Rect(x, y, width, height)
						});
						addedCount++;
					}
				}
			}

			t.spritesheet = sprites.ToArray();
			EditorUtility.SetDirty(t);
			AssetDatabase.ImportAsset(texturePath, ImportAssetOptions.ForceUpdate);
			EditorGUIUtility.PingObject(texture);
			Debug.Log(string.Format("Applied sprite slices to {2}. {0} added. {1} updated.", addedCount, updatedCount, texture.name));
		}
开发者ID:Hinidu,项目名称:spine-runtimes,代码行数:58,代码来源:AtlasAssetInspector.cs

示例4: RenderTargetIdentifier

 /// <summary>
 /// <para>Creates a render target identifier.</para>
 /// </summary>
 /// <param name="type">Built-in temporary render texture type.</param>
 /// <param name="name">Temporary render texture name.</param>
 /// <param name="nameID">Temporary render texture name (as integer, see Shader.PropertyToID).</param>
 /// <param name="tex">RenderTexture or Texture object to use.</param>
 public RenderTargetIdentifier(Texture tex)
 {
     this.m_Type = ((tex != null) && !(tex is RenderTexture)) ? BuiltinRenderTextureType.BindableTexture : BuiltinRenderTextureType.None;
     this.m_NameID = -1;
     this.m_InstanceID = (tex == null) ? 0 : tex.GetInstanceID();
 }
开发者ID:CarlosHBC,项目名称:UnityDecompiled,代码行数:13,代码来源:RenderTargetIdentifier.cs

示例5: UpdateSpriteSlices

		static public void UpdateSpriteSlices (Texture texture, Atlas atlas) {
			string texturePath = AssetDatabase.GetAssetPath(texture.GetInstanceID());
			var t = (TextureImporter)TextureImporter.GetAtPath(texturePath);
			t.spriteImportMode = SpriteImportMode.Multiple;
			var spriteSheet = t.spritesheet;
			var sprites = new List<SpriteMetaData>(spriteSheet);

			var regions = AtlasAssetInspector.GetRegions(atlas);
			char[] FilenameDelimiter = {'.'};
			int updatedCount = 0;
			int addedCount = 0;

			foreach (var r in regions) {
				string pageName = r.page.name.Split(FilenameDelimiter, StringSplitOptions.RemoveEmptyEntries)[0];
				string textureName = texture.name;
				bool pageMatch = string.Equals(pageName, textureName, StringComparison.Ordinal);

//				if (pageMatch) {
//					int pw = r.page.width;
//					int ph = r.page.height;
//					bool mismatchSize = pw != texture.width || pw > t.maxTextureSize || ph != texture.height || ph > t.maxTextureSize;
//					if (mismatchSize)
//						Debug.LogWarningFormat("Size mismatch found.\nExpected atlas size is {0}x{1}. Texture Import Max Size of texture '{2}'({4}x{5}) is currently set to {3}.", pw, ph, texture.name, t.maxTextureSize, texture.width, texture.height);
//				}

				int spriteIndex = pageMatch ? sprites.FindIndex(
					(s) => string.Equals(s.name, r.name, StringComparison.Ordinal)
				) : -1;
				bool spriteNameMatchExists = spriteIndex >= 0;

				if (pageMatch) {
					Rect spriteRect = new Rect();

					if (r.rotate) {
						spriteRect.width = r.height;
						spriteRect.height = r.width;
					} else {
						spriteRect.width = r.width;
						spriteRect.height = r.height;
					}
					spriteRect.x = r.x;
					spriteRect.y = r.page.height - spriteRect.height - r.y;

					if (spriteNameMatchExists) {
						var s = sprites[spriteIndex];
						s.rect = spriteRect;
						sprites[spriteIndex] = s;
						updatedCount++;
					} else {
						sprites.Add(new SpriteMetaData {
							name = r.name,
							pivot = new Vector2(0.5f, 0.5f),
							rect = spriteRect
						});
						addedCount++;
					}
				}

			}

			t.spritesheet = sprites.ToArray();
			EditorUtility.SetDirty(t);
			AssetDatabase.ImportAsset(texturePath, ImportAssetOptions.ForceUpdate);
			EditorGUIUtility.PingObject(texture);
			Debug.Log(string.Format("Applied sprite slices to {2}. {0} added. {1} updated.", addedCount, updatedCount, texture.name));
		}
开发者ID:EsotericSoftware,项目名称:spine-runtimes,代码行数:66,代码来源:AtlasAssetInspector.cs


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