public void DrawSprite(string textureName, int x, int y, int z, int alpha, int priority, float wait, bool isblocking) { iTween.Stop(base.gameObject); Texture2D texture2D = AssetManager.Instance.LoadTexture(textureName); if (!(texture2D == null)) { LayerAlignment align = LayerAlignment.AlignCenter; if (x != 0 || y != 0) { align = LayerAlignment.AlignTopleft; } Prepare(texture2D.width, texture2D.height, LayerShader, align, retainMainTexture: false); float num = 1f; if (z > 0) { num = 1f - (float)z / 100f; } if (z < 0) { num = 1f + (float)z / -100f; } base.transform.localPosition = new Vector3((float)x, (float)(y * -1), (float)priority * -0.1f); base.transform.localScale = new Vector3(num, num, 1f); material.SetTexture("_MainTex", texture2D); if (wait > 0f) { FadeInSprite(wait, isblocking); } else { material.SetFloat("_Alpha", 0f + (float)alpha / 256f); } } }
private void CreateMesh(int width, int height, LayerAlignment alignment) { int num = Mathf.Clamp(height, 1, 480); float num2 = (float)num / (float)height; int width2 = Mathf.RoundToInt(Mathf.Clamp((float)width, 1f, num2 * (float)width)); mesh = MGHelper.CreateMesh(width2, num, alignment); meshFilter.mesh = mesh; }
public void SetTextureImmediate(string textureName, LayerAlignment align) { Texture2D texture2D = AssetManager.Instance.LoadTexture(textureName); if (!(texture2D == null)) { Prepare(texture2D.width, texture2D.height, LayerShader, align, retainMainTexture: false); primary = texture2D; material.SetTexture("_MainTex", texture2D); material.SetFloat("_Alpha", 0f); } }
public void DrawLayerWithMask(string textureName, string maskName, int x, int y, Vector2?origin, bool isBustshot, int style, float wait, bool isBlocking) { Texture2D texture2D = AssetManager.Instance.LoadTexture(textureName); Texture2D maskTexture = AssetManager.Instance.LoadTexture(maskName); material.shader = shaderMasked; SetPrimaryTexture(texture2D); SetMaskTexture(maskTexture); PrimaryName = textureName; MaskName = maskName; startRange = 0f; targetRange = 1f; targetAlpha = 1f; targetAngle = 0f; shaderType = 0; if (mesh == null) { alignment = LayerAlignment.AlignCenter; if ((x != 0 || y != 0) && !isBustshot) { alignment = LayerAlignment.AlignTopleft; } if (origin.HasValue) { CreateMesh(texture2D.width, texture2D.height, origin.GetValueOrDefault()); } else { CreateMesh(texture2D.width, texture2D.height, alignment); } } SetRange(startRange); base.transform.localPosition = new Vector3((float)x, 0f - (float)y, (float)Priority * -0.1f); GameSystem.Instance.RegisterAction(delegate { meshRenderer.enabled = true; material.SetFloat("_Fuzziness", (style != 0) ? 0.15f : 0.45f); material.SetFloat("_Direction", 1f); FadeInLayer(wait); if (isBlocking) { GameSystem.Instance.AddWait(new Wait(wait, WaitTypes.WaitForMove, FinishAll)); } }); }
private void Prepare(int width, int height, Shader shader, LayerAlignment align, bool retainMainTexture) { if (meshFilter == null) { meshFilter = base.gameObject.AddComponent <MeshFilter>(); } if (meshRenderer == null) { meshRenderer = base.gameObject.AddComponent <MeshRenderer>(); } mesh = MGHelper.CreateMesh(width, height, align); if (material != null) { if (!retainMainTexture) { Object.Destroy(primary); } Object.Destroy(material); } material = new Material(shader); meshFilter.mesh = mesh; meshRenderer.material = material; }
public void SetTextureCrossFade(string textureName, float time, LayerAlignment align) { Texture2D texture2D = AssetManager.Instance.LoadTexture(textureName); if (!(texture2D == null)) { if (primary != null) { Prepare(texture2D.width, texture2D.height, LayerCrossfade, align, retainMainTexture: true); secondary = primary; primary = texture2D; material.SetTexture("_Primary", primary); material.SetTexture("_Secondary", secondary); material.SetFloat("_Range", 0f); iTween.Stop(base.gameObject); iTween.ValueTo(base.gameObject, iTween.Hash("from", 0f, "to", 1f, "time", time, "onupdate", "UpdateRange", "oncomplete", "FinalizeFade")); } else { SetTextureImmediate(textureName, align); FadeInSprite(time, isblocking: false); } } }
public static Mesh CreateMesh(int width, int height, LayerAlignment alignment) { Mesh mesh = new Mesh(); float num = Mathf.Round((float)width / 2f); float num2 = Mathf.Round((float)height / 2f); Vector3 vector; Vector3 vector2; Vector3 vector3; Vector3 vector4; switch (alignment) { case LayerAlignment.AlignTopleft: vector = new Vector3(0f, 0f, 0f); vector2 = new Vector3((float)width, 0f, 0f); vector3 = new Vector3((float)width, (float)(-height), 0f); vector4 = new Vector3(0f, (float)(-height), 0f); break; case LayerAlignment.AlignBottomCenter: vector = new Vector3(0f - num, (float)height, 0f); vector2 = new Vector3(num, (float)height, 0f); vector3 = new Vector3(num, 0f, 0f); vector4 = new Vector3(0f - num, 0f, 0f); break; case LayerAlignment.AlignCenter: vector = new Vector3(0f - num, num2, 0f); vector2 = new Vector3(num, num2, 0f); vector3 = new Vector3(num, 0f - num2, 0f); vector4 = new Vector3(0f - num, 0f - num2, 0f); break; default: Logger.LogError("Could not CreateMesh, unexpected alignment " + alignment); return(null); } Vector3[] vertices = new Vector3[4] { vector2, vector3, vector, vector4 }; Vector2[] uv = new Vector2[4] { new Vector2(1f, 1f), new Vector2(1f, 0f), new Vector2(0f, 1f), new Vector2(0f, 0f) }; int[] triangles = new int[6] { 0, 1, 2, 2, 1, 3 }; mesh.vertices = vertices; mesh.uv = uv; mesh.triangles = triangles; mesh.RecalculateNormals(); mesh.RecalculateBounds(); return(mesh); }
public void MODDrawLayer(string textureName, Texture2D tex2d, int x, int y, int z, Vector2?origin, float alpha, bool isBustshot, int type, float wait, bool isBlocking) { FinishAll(); if (textureName == string.Empty) { HideLayer(); } else if (tex2d == null) { Logger.LogError("Failed to load texture " + textureName); } else { startRange = 0f; targetRange = alpha; targetAlpha = alpha; meshRenderer.enabled = true; shaderType = type; PrimaryName = textureName; float num = 1f; if (z > 0) { num = 1f - (float)z / 400f; } if (z < 0) { num = 1f + (float)z / -400f; } if (mesh == null) { alignment = LayerAlignment.AlignCenter; if ((x != 0 || y != 0) && !isBustshot) { alignment = LayerAlignment.AlignTopleft; } if (!origin.HasValue) { CreateMesh(tex2d.width, tex2d.height, alignment); } else { CreateMesh(tex2d.width, tex2d.height, origin.GetValueOrDefault()); } } if (primary == null) { material.shader = shaderDefault; if (type == 3) { material.shader = shaderMultiply; } SetPrimaryTexture(tex2d); } else { material.shader = shaderCrossfade; SetSecondaryTexture(primary); SetPrimaryTexture(tex2d); startRange = 1f; targetRange = 0f; targetAlpha = 1f; } SetRange(startRange); base.transform.localPosition = new Vector3((float)x, 0f - (float)y, (float)Priority * -0.1f); base.transform.localScale = new Vector3(num, num, 1f); targetPosition = base.transform.localPosition; targetScale = base.transform.localScale; if (Mathf.Approximately(wait, 0f)) { FinishFade(); } } }