private UIDrawCall.Iterator GetDrawCall(UIMaterial mat, bool createIfMissing) { for (UIDrawCall.Iterator i = (UIDrawCall.Iterator) this.mDrawCalls; i.Has; i = i.Next) { if (i.Current.material == mat) { return(i); } } UIDrawCall uIDrawCall = null; if (createIfMissing) { GameObject gameObject = new GameObject(string.Concat("_UIDrawCall [", mat.name, "]")) { hideFlags = HideFlags.DontSave, layer = base.gameObject.layer }; uIDrawCall = gameObject.AddComponent <UIDrawCall>(); uIDrawCall.material = mat; uIDrawCall.LinkedList__Insert(ref this.mDrawCalls); UIPanel uIPanel = this; uIPanel.mDrawCallCount = uIPanel.mDrawCallCount + 1; } return((UIDrawCall.Iterator)uIDrawCall); }
protected override TileSheet Load(UITileSheetInfo info) { using var bitmap = UIBitmap.LoadMaskedBitmap(resourcePool, info.Name); var tileSheet = new TileSheet(info.Name, bitmap, info.IsFont); var texture = resourceFactory.CreateTexture( new TextureDescription( (uint)bitmap.Width, (uint)(bitmap.Height - 1), depth: 1, mipLevels: 1, arrayLayers: 1, PixelFormat.R8_G8_B8_A8_UNorm, TextureUsage.Sampled, TextureType.Texture2D)); UploadTileSheet(bitmap, texture, info.IsFont); var material = new UIMaterial(diContainer, info.IsFont); material.Texture.Texture = texture; material.Sampler.Sampler = info.IsFont? fontSampler : linearSampler; material.ScreenSize.Buffer = ui.ProjectionBuffer; materials.Add(tileSheet, material); return(tileSheet); }
void OnRenderImage(RenderTexture source, RenderTexture destination) { if (blurMaterial == null || UIMaterial == null) { return; } int tw = source.width >> downsample; int th = source.height >> downsample; var rt = RenderTexture.GetTemporary(tw, th, 0, source.format); Graphics.Blit(source, rt); if (renderMode == RenderMode.Screen) { Blur(rt, destination); } else if (renderMode == RenderMode.UI) { Blur(rt, rt); UIMaterial.SetTexture(Uniforms._BackgroundTexture, rt); Graphics.Blit(source, destination); } else if (renderMode == RenderMode.OnlyUI) { Blur(rt, rt); UIMaterial.SetTexture(Uniforms._BackgroundTexture, rt); } RenderTexture.ReleaseTemporary(rt); }
void OnPostRender() { if (blurMaterial == null || UIMaterial == null) { return; } m_Camera.targetTexture = null; if (renderMode == RenderMode.Screen) { Blur(rt, null); } else if (renderMode == RenderMode.UI) { Blur(rt, rt); UIMaterial.SetTexture(Uniforms._BackgroundTexture, rt); Graphics.Blit(rt, null, blurMaterial, 0); } else if (renderMode == RenderMode.OnlyUI) { Blur(rt, rt); UIMaterial.SetTexture(Uniforms._BackgroundTexture, rt); } RenderTexture.ReleaseTemporary(rt); }
protected new void OnDestroy() { base.OnDestroy(); if (this.material) { UnityEngine.Object.Destroy(this.material); this.material = null; } }
protected void OnDestroy() { base.OnDestroy(); if (this.material != null) { UnityEngine.Object.Destroy(this.material); this.material = null; } }
public UIMaterial Clone() { Material material = new Material(this.key) { hideFlags = HideFlags.DontSave }; return(UIMaterial.Create(material, true)); }
public Batcher(ITagContainer diContainer) : base(diContainer.GetTag <DefaultEcs.World>(), CreateEntityContainer, useBuffer: false) { ui = diContainer.GetTag <UI>(); graphicsDevice = diContainer.GetTag <GraphicsDevice>(); resourceFactory = diContainer.GetTag <ResourceFactory>(); instanceBuffer = null !; emptyTexture = resourceFactory.CreateTexture( new TextureDescription(1, 1, 1, 1, 1, PixelFormat.R8_G8_B8_A8_UNorm, TextureUsage.Sampled, TextureType.Texture2D)); untexturedMaterial = new UIMaterial(diContainer, isFont: false); untexturedMaterial.Texture.Texture = emptyTexture; untexturedMaterial.ScreenSize.Buffer = diContainer.GetTag <UI>().ProjectionBuffer; }
private void Fill(UIMaterial mat) { int count = this.mWidgets.Count; while (count > 0) { int num = count - 1; count = num; if (this.mWidgets[num] != null) { continue; } this.mWidgets.RemoveAt(count); } int num1 = 0; int count1 = this.mWidgets.Count; while (num1 < count1) { UIWidget item = this.mWidgets[num1]; if (item.visibleFlag == 1 && item.material == mat) { if (this.GetNode(item.cachedTransform) == null) { Debug.LogError(string.Concat("No transform found for ", NGUITools.GetHierarchy(item.gameObject)), this); } else { item.WriteToBuffers(this.mCacheBuffer); } } num1++; } if (this.mCacheBuffer.vSize <= 0) { UIDrawCall.Iterator drawCall = this.GetDrawCall(mat, false); if (drawCall.Has) { this.Delete(ref drawCall); } } else { UIDrawCall current = this.GetDrawCall(mat, true).Current; current.depthPass = this.depthPass; current.panelPropertyBlock = this.propertyBlock; current.Set(this.mCacheBuffer); } this.mCacheBuffer.Clear(); }
public void MarkMaterialAsChanged(UIMaterial mat, bool sort) { if (mat != null) { if (sort) { this.mDepthChanged = true; } if (this.mChanged.Add(mat)) { this.mChangedLastFrame = true; } } }
private void Start() { this.startingIconColor = this._icon.color; this._icon.enabled = false; GUIHeldItem._guiHeldItem = this; this._myMaterial = this._icon.material.Clone(); this._icon.material = this._myMaterial; this.mTrans = base.transform; if (this.uiCamera == null) { this.uiCamera = NGUITools.FindCameraForLayer(base.gameObject.layer); } this.planeTest = new Plane(this.uiCamera.transform.forward * 1f, new Vector3(0f, 0f, 2f)); this.started = true; }
private void Fill(UIMaterial mat) { int count = this.mWidgets.Count; while (count > 0) { if (this.mWidgets[--count] == null) { this.mWidgets.RemoveAt(count); } } int num2 = 0; int num3 = this.mWidgets.Count; while (num2 < num3) { UIWidget widget = this.mWidgets[num2]; if ((widget.visibleFlag == 1) && (widget.material == mat)) { if (this.GetNode(widget.cachedTransform) != null) { widget.WriteToBuffers(this.mCacheBuffer); } else { Debug.LogError("No transform found for " + NGUITools.GetHierarchy(widget.gameObject), this); } } num2++; } if (this.mCacheBuffer.vSize > 0) { UIDrawCall current = this.GetDrawCall(mat, true).Current; current.depthPass = this.depthPass; current.panelPropertyBlock = this.propertyBlock; current.Set(this.mCacheBuffer); } else { UIDrawCall.Iterator drawCall = this.GetDrawCall(mat, false); if (drawCall.Has) { this.Delete(ref drawCall); } } this.mCacheBuffer.Clear(); }
private void UpdateMaterials() { if (this.mDepthPass) { if (this.mDepthMat == null) { Material material = new Material(Shader.Find("Depth")) { hideFlags = HideFlags.DontSave, mainTexture = this.mSharedMat.mainTexture }; this.mDepthMat = UIMaterial.Create(material, true, this.mClipping); } } else if (this.mDepthMat != null) { NGUITools.Destroy(this.mDepthMat); this.mDepthMat = null; } Material item = this.mSharedMat[this.mClipping]; if (this.mDepthMat != null) { UIDrawCall.materialBuffer2[0] = this.mDepthMat[this.mClipping]; UIDrawCall.materialBuffer2[1] = item; this.mRen.sharedMaterials = UIDrawCall.materialBuffer2; object obj = null; Material material1 = (Material)obj; UIDrawCall.materialBuffer2[1] = (Material)obj; UIDrawCall.materialBuffer2[0] = material1; } else if (this.mRen.sharedMaterial != item) { UIDrawCall.materialBuffer1[0] = item; this.mRen.sharedMaterials = UIDrawCall.materialBuffer1; UIDrawCall.materialBuffer1[0] = null; } }
private UIDrawCall.Iterator GetDrawCall(UIMaterial mat, bool createIfMissing) { for (UIDrawCall.Iterator iterator = (UIDrawCall.Iterator) this.mDrawCalls; iterator.Has; iterator = iterator.Next) { if (iterator.Current.material == mat) { return(iterator); } } UIDrawCall call = null; if (createIfMissing) { call = new GameObject("_UIDrawCall [" + mat.name + "]") { hideFlags = HideFlags.DontSave, layer = base.gameObject.layer }.AddComponent <UIDrawCall>(); call.material = mat; call.LinkedList__Insert(ref this.mDrawCalls); this.mDrawCallCount++; } return((UIDrawCall.Iterator)call); }
private void UpdateMaterials() { if (this.mDepthPass) { if (this.mDepthMat == null) { Material key = new Material(Shader.Find("Depth")) { hideFlags = HideFlags.DontSave, mainTexture = this.mSharedMat.mainTexture }; this.mDepthMat = UIMaterial.Create(key, true, this.mClipping); } } else if (this.mDepthMat != null) { NGUITools.Destroy(this.mDepthMat); this.mDepthMat = null; } Material material2 = this.mSharedMat[this.mClipping]; if (this.mDepthMat != null) { Material material3; materialBuffer2[0] = this.mDepthMat[this.mClipping]; materialBuffer2[1] = material2; this.mRen.sharedMaterials = materialBuffer2; materialBuffer2[1] = (Material)(material3 = null); materialBuffer2[0] = material3; } else if (this.mRen.sharedMaterial != material2) { materialBuffer1[0] = material2; this.mRen.sharedMaterials = materialBuffer1; materialBuffer1[0] = null; } }
private void Awake() { this.startTime = NetCull.time; this.material = this.texture.material.Clone(); this.texture.material = this.material; }
private void UpdateTransforms() { this.mChangedLastFrame = false; bool flag = false; bool flag2 = Time.realtimeSinceStartup > this.mCullTime; if (!this.widgetsAreStatic || (flag2 != this.mCulled)) { int num = 0; int count = this.mChildren.Count; while (num < count) { UINode node = (UINode)this.mChildren[num]; if (node.trans == null) { this.mRemoved.Add(node.trans); } else if (node.HasChanged()) { node.changeFlag = 1; flag = true; } else { node.changeFlag = -1; } num++; } int num3 = 0; int num4 = this.mRemoved.Count; while (num3 < num4) { this.mChildren.Remove(this.mRemoved[num3]); num3++; } this.mRemoved.Clear(); } if (!this.mCulled && flag2) { this.mCheckVisibility = true; } if ((this.mCheckVisibility || flag) || this.mRebuildAll) { int num5 = 0; int num6 = this.mChildren.Count; while (num5 < num6) { UINode start = (UINode)this.mChildren[num5]; if (start.widget != null) { int num7 = 1; if (flag2 || flag) { if (start.changeFlag == -1) { start.changeFlag = this.GetChangeFlag(start); } if (flag2) { num7 = (!this.mCheckVisibility && (start.changeFlag != 1)) ? start.visibleFlag : (!this.IsVisible(start.widget) ? 0 : 1); } } if (start.visibleFlag != num7) { start.changeFlag = 1; } if ((start.changeFlag == 1) && ((num7 == 1) || (start.visibleFlag != 0))) { start.visibleFlag = num7; UIMaterial item = start.widget.material; if (!this.mChanged.Contains(item)) { this.mChanged.Add(item); this.mChangedLastFrame = true; } } } num5++; } } this.mCulled = flag2; this.mCheckVisibility = false; }
private static Shader GetClippingShader(Shader original, UIDrawCall.Clipping clipping) { if (!original) { return(null); } string str = original.name; switch (clipping) { case UIDrawCall.Clipping.None: { string str1 = str.Replace(" (HardClip)", string.Empty).Replace(" (AlphaClip)", string.Empty).Replace(" (SoftClip)", string.Empty); if (str1 == str) { return(original); } str = str1; break; } case UIDrawCall.Clipping.HardClip: { if (!UIMaterial.ShaderNameDecor(ref str, " (AlphaClip)", " (SoftClip)", " (HardClip)")) { return(original); } break; } case UIDrawCall.Clipping.AlphaClip: { if (!UIMaterial.ShaderNameDecor(ref str, " (SoftClip)", " (HardClip)", " (AlphaClip)")) { return(original); } break; } case UIDrawCall.Clipping.SoftClip: { if (!UIMaterial.ShaderNameDecor(ref str, " (HardClip)", " (AlphaClip)", " (SoftClip)")) { return(original); } break; } default: { throw new NotImplementedException(); } } Shader shader = Shader.Find(str); if (!shader) { throw new MissingReferenceException(string.Concat("Theres no shader named ", str)); } return(shader); }
private UIDrawCall.Iterator GetDrawCall(UIMaterial mat, bool createIfMissing) { for (UIDrawCall.Iterator i = (UIDrawCall.Iterator)this.mDrawCalls; i.Has; i = i.Next) { if (i.Current.material == mat) { return i; } } UIDrawCall uIDrawCall = null; if (createIfMissing) { GameObject gameObject = new GameObject(string.Concat("_UIDrawCall [", mat.name, "]")) { hideFlags = HideFlags.DontSave, layer = base.gameObject.layer }; uIDrawCall = gameObject.AddComponent<UIDrawCall>(); uIDrawCall.material = mat; uIDrawCall.LinkedList__Insert(ref this.mDrawCalls); UIPanel uIPanel = this; uIPanel.mDrawCallCount = uIPanel.mDrawCallCount + 1; } return (UIDrawCall.Iterator)uIDrawCall; }
private void MakeDefaultMaterial() { this.MakeMaterial(UIMaterial.ShaderClipping(this.key.shader.name)); }
public static UIMaterial Create(Material key, bool manageKeyDestruction, UIDrawCall.Clipping useAsClipping) { UIMaterial uIMaterial; if (!manageKeyDestruction) { return(UIMaterial.Create(key)); } if (!key) { return(null); } if (UIMaterial.g.keyedMaterials.TryGetValue(key, out uIMaterial)) { throw new InvalidOperationException("That material is registered and cannot be used with manageKeyDestruction"); } if (UIMaterial.g.generatedMaterials.TryGetValue(key, out uIMaterial)) { return(uIMaterial); } uIMaterial = ScriptableObject.CreateInstance <UIMaterial>(); uIMaterial.key = key; int num = UIMaterial.g.hashCodeIterator + 1; UIMaterial.g.hashCodeIterator = num; uIMaterial.hashCode = num; if (uIMaterial.hashCode == 2147483647) { UIMaterial.g.hashCodeIterator = -2147483648; } UIMaterial.g.generatedMaterials.Add(key, uIMaterial); uIMaterial.matFirst = key; switch (useAsClipping) { case UIDrawCall.Clipping.None: { uIMaterial.matNone = key; break; } case UIDrawCall.Clipping.HardClip: { uIMaterial.matHardClip = key; break; } case UIDrawCall.Clipping.AlphaClip: { uIMaterial.matAlphaClip = key; break; } case UIDrawCall.Clipping.SoftClip: { uIMaterial.matSoftClip = key; break; } default: { throw new NotImplementedException(); } } uIMaterial.madeMats = (UIMaterial.ClippingFlags)((int)UIDrawCall.Clipping.HardClip << (int)(useAsClipping & (UIDrawCall.Clipping.HardClip | UIDrawCall.Clipping.AlphaClip | UIDrawCall.Clipping.SoftClip))); return(uIMaterial); }
private void UpdateTransforms() { int num; this.mChangedLastFrame = false; bool flag = false; bool flag1 = Time.realtimeSinceStartup > this.mCullTime; if (!this.widgetsAreStatic || flag1 != this.mCulled) { int num1 = 0; int count = this.mChildren.Count; while (num1 < count) { UINode item = (UINode)this.mChildren[num1]; if (item.trans == null) { this.mRemoved.Add(item.trans); } else if (!item.HasChanged()) { item.changeFlag = -1; } else { item.changeFlag = 1; flag = true; } num1++; } int num2 = 0; int count1 = this.mRemoved.Count; while (num2 < count1) { this.mChildren.Remove(this.mRemoved[num2]); num2++; } this.mRemoved.Clear(); } if (!this.mCulled && flag1) { this.mCheckVisibility = true; } if (this.mCheckVisibility || flag || this.mRebuildAll) { int num3 = 0; int count2 = this.mChildren.Count; while (num3 < count2) { UINode changeFlag = (UINode)this.mChildren[num3]; if (changeFlag.widget != null) { int num4 = 1; if (flag1 || flag) { if (changeFlag.changeFlag == -1) { changeFlag.changeFlag = this.GetChangeFlag(changeFlag); } if (flag1) { if (this.mCheckVisibility || changeFlag.changeFlag == 1) { num = (!this.IsVisible(changeFlag.widget) ? 0 : 1); } else { num = changeFlag.visibleFlag; } num4 = num; } } if (changeFlag.visibleFlag != num4) { changeFlag.changeFlag = 1; } if (changeFlag.changeFlag == 1 && (num4 == 1 || changeFlag.visibleFlag != 0)) { changeFlag.visibleFlag = num4; UIMaterial uIMaterial = changeFlag.widget.material; if (!this.mChanged.Contains(uIMaterial)) { this.mChanged.Add(uIMaterial); this.mChangedLastFrame = true; } } } num3++; } } this.mCulled = flag1; this.mCheckVisibility = false; }
public static UIMaterial Create(Material key, bool manageKeyDestruction) { return(UIMaterial.Create(key, manageKeyDestruction, UIDrawCall.Clipping.None)); }
public void MarkMaterialAsChanged(UIMaterial mat, bool sort) { if (mat) { if (sort) { this.mDepthChanged = true; } if (this.mChanged.Add(mat)) { this.mChangedLastFrame = true; } } }
private Material MakeMaterial(UIDrawCall.Clipping clipping) { Material material; Material material1; Shader clippingShader; Material material2; bool flag = (int)this.madeMats == 0; switch (clipping) { case UIDrawCall.Clipping.None: { clippingShader = this.key.shader; material1 = this.matNone; Material material3 = UIMaterial.CreateMaterial(clippingShader); material2 = material3; this.matNone = material3; material = material2; UIMaterial uIMaterial = this; uIMaterial.madeMats = uIMaterial.madeMats | UIMaterial.ClippingFlags.None; break; } case UIDrawCall.Clipping.HardClip: { clippingShader = UIMaterial.GetClippingShader(this.key.shader, UIDrawCall.Clipping.HardClip); material1 = this.matHardClip; Material material4 = UIMaterial.CreateMaterial(clippingShader); material2 = material4; this.matHardClip = material4; material = material2; UIMaterial uIMaterial1 = this; uIMaterial1.madeMats = uIMaterial1.madeMats | UIMaterial.ClippingFlags.HardClip; break; } case UIDrawCall.Clipping.AlphaClip: { clippingShader = UIMaterial.GetClippingShader(this.key.shader, UIDrawCall.Clipping.AlphaClip); material1 = this.matAlphaClip; Material material5 = UIMaterial.CreateMaterial(clippingShader); material2 = material5; this.matAlphaClip = material5; material = material2; UIMaterial uIMaterial2 = this; uIMaterial2.madeMats = uIMaterial2.madeMats | UIMaterial.ClippingFlags.AlphaClip; break; } case UIDrawCall.Clipping.SoftClip: { clippingShader = UIMaterial.GetClippingShader(this.key.shader, UIDrawCall.Clipping.SoftClip); material1 = this.matSoftClip; Material material6 = UIMaterial.CreateMaterial(clippingShader); material2 = material6; this.matSoftClip = material6; material = material2; UIMaterial uIMaterial3 = this; uIMaterial3.madeMats = uIMaterial3.madeMats | UIMaterial.ClippingFlags.SoftClip; break; } default: { throw new NotImplementedException(); } } UIMaterial.g.generatedMaterials.Add(material, this); if (!flag) { material.CopyPropertiesFromMaterial(this.matFirst); } else { this.matFirst = material; material.CopyPropertiesFromMaterial(this.key); } if (material1) { UnityEngine.Object.DestroyImmediate(material1); } return(material); }