using System; using System.Collections.Generic; using UnityEngine; public class MaterialMgr { public MaterialMgr(TBodySkin tbskin) { this.m_tbSkin = tbskin; this.m_SlotId = tbskin.SlotId; this.m_tbody = tbskin.body; this.m_bMan = tbskin.body.boMAN; } public void Init(GameObject obj, Material[] mats) { this.m_materials = mats; } public void Remove() { this.m_materials = null; this.m_tbSkin.body.GetSlot(0).MaterialMgr.RemoveSkinMask(this.m_SlotId, this.m_tbSkin.m_subNo); this.RemoveSkinMaskAll(); } public Material GetMaterial(int f_nMatNo) { if (this.m_materials == null) { return null; } foreach (Transform transform in this.m_tbSkin.obj.transform.GetComponentsInChildren(true)) { Renderer component = transform.GetComponent(); if (component != null && component.material != null) { if (f_nMatNo < component.materials.Length) { return component.materials[f_nMatNo]; } NDebug.Assert(string.Concat(new object[] { "マテリアル番号指定が ", component.name, " のマテリアル数を超えています。", this.m_SlotId.ToString(), " / ", f_nMatNo }), false); } } return null; } public int materialCount { get { if (this.m_materials == null) { return -1; } return this.m_materials.Length; } } public float MayuThick { set { if (this.m_tbSkin.m_bMan) { return; } if (this.m_SlotId == TBody.SlotID.head && 120 <= this.m_tbSkin.PartsVersion) { Material material = this.m_materials[3]; float num = 0.5f * (value - 0.5f) / -0.5f; material.SetTextureScale("_MainTex", new Vector2(1f, 1f + num)); material.SetTextureOffset("_MainTex", new Vector2(0f, -(num / 2f))); } } } public float FutaePosX { set { if (this.m_tbSkin.m_bMan) { return; } if (this.m_SlotId == TBody.SlotID.head && 120 <= this.m_tbSkin.PartsVersion) { Material material = this.m_materials[9]; float x = 0.05f * (value - 0.5f) / 0.5f; material.SetTextureOffset("_MainTex", new Vector2(x, material.GetTextureOffset("_MainTex").y)); } } } public float FutaePosY { set { if (this.m_tbSkin.m_bMan) { return; } if (this.m_SlotId == TBody.SlotID.head && 120 <= this.m_tbSkin.PartsVersion) { Material material = this.m_materials[9]; float num = 0.1f * (value - 0.5f) / 0.5f; material.SetTextureOffset("_MainTex", new Vector2(material.GetTextureOffset("_MainTex").x, -num)); } } } public float FutaeRot { set { if (this.m_tbSkin.m_bMan) { return; } if (this.m_SlotId == TBody.SlotID.head && 120 <= this.m_tbSkin.PartsVersion) { Material material = this.m_materials[9]; float value2 = 0.4f * (value - 0.5f) / 0.5f; material.EnableKeyword("USE_UV_ROT"); material.SetFloat("_UVRotAngle", value2); } } } public float HitomiHiPosX { set { if (this.m_tbSkin.m_bMan) { return; } if (this.m_SlotId == TBody.SlotID.head && 120 <= this.m_tbSkin.PartsVersion) { Material material = this.m_materials[2]; Material material2 = this.m_materials[7]; float num = 0.05f * (value - 0.5f) / 0.5f; Vector2 textureOffset = material.GetTextureOffset("_MainTex"); material.SetTextureOffset("_MainTex", new Vector2(-num, textureOffset.y)); material2.SetTextureOffset("_MainTex", new Vector2(-num, textureOffset.y)); } } } public float HitomiHiPosY { set { if (this.m_tbSkin.m_bMan) { return; } if (this.m_SlotId == TBody.SlotID.head && 120 <= this.m_tbSkin.PartsVersion) { Material material = this.m_materials[2]; Material material2 = this.m_materials[7]; float num = 0.1f * (value - 0.5f) / 0.5f; Vector2 textureOffset = material.GetTextureOffset("_MainTex"); material.SetTextureOffset("_MainTex", new Vector2(textureOffset.x, -num + this.m_hitomiHiSclYOffsY)); material2.SetTextureOffset("_MainTex", new Vector2(textureOffset.x, -num + this.m_hitomiHiSclYOffsY)); this.m_hitomiHiPosYOffsY = -num; } } } public float HitomiHiSclY { set { if (this.m_tbSkin.m_bMan) { return; } if (this.m_SlotId == TBody.SlotID.head && 120 <= this.m_tbSkin.PartsVersion) { Material material = this.m_materials[2]; Material material2 = this.m_materials[7]; float num = -1f * (value - 0.5f) / 0.5f; Vector2 textureOffset = material.GetTextureOffset("_MainTex"); material.SetTextureScale("_MainTex", new Vector2(1f, 1f + num)); material2.SetTextureScale("_MainTex", new Vector2(1f, 1f + num)); material.SetTextureOffset("_MainTex", new Vector2(textureOffset.x, -(num / 2f) + this.m_hitomiHiPosYOffsY)); material2.SetTextureOffset("_MainTex", new Vector2(textureOffset.x, -(num / 2f) + this.m_hitomiHiPosYOffsY)); this.m_hitomiHiSclYOffsY = -(num / 2f); } } } public void AddSkinMask(TBody.SlotID slot, int subNo, string texFileName) { NDebug.Assert(this.m_SlotId == TBody.SlotID.body, "skin mask destination is must be body."); if (this.m_skinMaskTexs == null) { this.m_skinMaskTexs = new Dictionary(); } if (this.m_skinMaskDestTex == null) { this.m_skinMaskDestTex = new Texture2D(512, 512, TextureFormat.ARGB32, false); } TextureResource textureResource = ImportCM.LoadTexture(null, texFileName, false); NDebug.Assert(textureResource != null, "skin mask tex is not found. -> " + texFileName); Texture2D value = textureResource.CreateTexture2D(); this.m_skinMaskTexs.Add((uint)(((uint)slot << 16) + subNo), value); this.m_isSkinMaskBody = true; } public void RemoveSkinMask(TBody.SlotID slot, int subNo) { if (!this.m_isSkinMaskBody) { return; } uint key = (uint)(((uint)slot << 16) + subNo); Texture2D obj; if (this.m_skinMaskTexs.TryGetValue(key, out obj)) { UnityEngine.Object.Destroy(obj); this.m_skinMaskTexs.Remove(key); } } public void RemoveSkinMaskAll() { if (!this.m_isSkinMaskBody) { return; } foreach (KeyValuePair keyValuePair in this.m_skinMaskTexs) { if (keyValuePair.Value != null) { UnityEngine.Object.Destroy(keyValuePair.Value); } } this.m_skinMaskTexs = null; if (this.m_skinMaskDestTex != null) { UnityEngine.Object.Destroy(this.m_skinMaskDestTex); } this.m_isSkinMaskBody = false; } public bool FixSkinMask() { if (!this.m_isSkinMaskBody) { return false; } RenderTexture active = RenderTexture.active; RenderTexture temporary = RenderTexture.GetTemporary(this.m_skinMaskDestTex.width, this.m_skinMaskDestTex.height, 0, RenderTextureFormat.ARGB32); RenderTexture.active = temporary; GL.Clear(false, true, Color.white); Material systemMaterial = GameUty.GetSystemMaterial(GameUty.SystemMaterial.Multiply); foreach (KeyValuePair keyValuePair in this.m_skinMaskTexs) { TBodySkin slot = this.m_tbody.GetSlot((int)(keyValuePair.Key >> 16), (int)(keyValuePair.Key & 16U)); if (slot.boVisible) { Graphics.Blit(keyValuePair.Value, temporary, systemMaterial); } } this.m_skinMaskDestTex.ReadPixels(new Rect(0f, 0f, (float)temporary.width, (float)temporary.height), 0, 0); this.m_skinMaskDestTex.Apply(); RenderTexture.ReleaseTemporary(temporary); RenderTexture.active = active; return true; } public bool CheckSkinMaskUV(Vector2 uv) { return this.m_isSkinMaskBody && this.m_skinMaskDestTex.GetPixel((int)((float)this.m_skinMaskDestTex.width * uv.x + 0.5f), (int)((float)this.m_skinMaskDestTex.height * uv.y + 0.5f)).r < 0.5f; } private Material[] m_materials; private TBody m_tbody; private TBodySkin m_tbSkin; private TBody.SlotID m_SlotId; private bool m_bMan; private float m_hitomiHiPosYOffsY; private float m_hitomiHiSclYOffsY; private Dictionary m_skinMaskTexs; private Texture2D m_skinMaskDestTex; private bool m_isSkinMaskBody; }