using System; using System.Collections; using UnityEngine; public class ThumShot : MonoBehaviour { private void Start() { this.m_camMain = base.gameObject.GetComponent(); this.m_camMain.enabled = false; this.m_rtThumPreset = new RenderTexture(this.m_siPreSize.width, this.m_siPreSize.height, 24, RenderTextureFormat.ARGB32); this.m_rtThumPreset.filterMode = FilterMode.Bilinear; this.m_rtThumPreset.antiAliasing = 8; this.m_rtThumPreset2 = new RenderTexture(this.m_siPreSize.width, this.m_siPreSize.height, 0, RenderTextureFormat.ARGB32); this.m_rtThumIcon = new RenderTexture(this.m_siIconSize.width, this.m_siIconSize.height, 24, RenderTextureFormat.ARGB32); this.m_rtThumIcon.filterMode = FilterMode.Bilinear; this.m_rtThumIcon.antiAliasing = 8; this.m_rtThumIcon2 = new RenderTexture(this.m_siIconSize.width, this.m_siIconSize.height, 0, RenderTextureFormat.ARGB32); this.m_rtThumCard = new RenderTexture(this.m_siCardSize.width, this.m_siCardSize.height, 24, RenderTextureFormat.ARGB32); this.m_rtThumCard.filterMode = FilterMode.Bilinear; this.m_rtThumCard.antiAliasing = 8; this.m_rtThumCard2 = new RenderTexture(this.m_siCardSize.width, this.m_siCardSize.height, 0, RenderTextureFormat.ARGB32); } private void Update() { if (this.m_trParent != null) { base.transform.position = this.m_trParent.TransformPoint(this.m_trParent.localPosition + this.m_vecOffsetPos); base.transform.rotation = this.m_trParent.rotation * Quaternion.Euler(this.m_vecOffsetRot); } } public Texture2D RenderThum(Camera f_cam, RenderTexture f_rtMain, RenderTexture f_rtSub, Size f_size) { f_cam.targetTexture = f_rtMain; f_cam.enabled = true; f_cam.Render(); f_cam.enabled = false; Texture2D texture2D = new Texture2D(f_size.width, f_size.height, TextureFormat.ARGB32, false); RenderTexture active = RenderTexture.active; if (f_rtMain.antiAliasing != 0) { RenderTexture.active = f_rtSub; GL.Clear(true, true, new Color(0f, 0f, 0f, 0f)); GL.PushMatrix(); GL.LoadPixelMatrix(0f, (float)f_size.width, (float)f_size.height, 0f); Graphics.DrawTexture(new Rect(0f, 0f, (float)f_size.width, (float)f_size.height), f_rtMain); GL.PopMatrix(); } else { RenderTexture.active = f_rtMain; } texture2D.ReadPixels(new Rect(0f, 0f, (float)f_size.width, (float)f_size.height), 0, 0); texture2D.Apply(); RenderTexture.active = active; return texture2D; } public Texture2D ShotThumPreset(Maid f_maid) { if (f_maid.body0 == null || f_maid.body0.m_Bones == null) { return null; } Transform transform = CMT.SearchObjName(f_maid.body0.m_Bones.transform, "Bip01 HeadNub", true); if (transform == null) { return null; } base.transform.position = transform.TransformPoint(transform.localPosition + new Vector3(0.38f, 1.07f, 0f)); base.transform.rotation = transform.rotation * Quaternion.Euler(90f, 0f, 90f); this.m_camMain.fieldOfView = 30f; return this.RenderThum(this.m_camMain, this.m_rtThumPreset, this.m_rtThumPreset2, this.m_siPreSize); } public void MoveTargetThum(Maid f_maid) { Transform transform = CMT.SearchObjName(f_maid.body0.m_Bones.transform, "Bip01 HeadNub", true); if (transform != null) { base.transform.position = transform.TransformPoint(transform.localPosition + new Vector3(0.38f, 1.07f, 0f)); base.transform.rotation = transform.rotation * Quaternion.Euler(90f, 0f, 90f); } else { Debug.LogError("サムネイルを取ろうとしましたがメイドが居ません。"); } } public Texture2D ShotThumIcon(Maid f_maid) { this.MoveTargetThum(f_maid); this.m_camMain.fieldOfView = 30f; return this.RenderThum(this.m_camMain, this.m_rtThumIcon, this.m_rtThumIcon2, this.m_siIconSize); } public void MoveTargetCard(Maid f_maid) { Transform transform = CMT.SearchObjName(f_maid.body0.m_Bones.transform, "Bip01 HeadNub", true); if (transform != null) { base.transform.position = transform.TransformPoint(transform.localPosition + new Vector3(0.64f, 2.25f, 0f)); base.transform.rotation = transform.rotation * Quaternion.Euler(90f, 0f, 90f); } else { Debug.LogError("サムネイルを取ろうとしましたがメイドが居ません。"); } } public Texture2D ShotThumCard(Maid f_maid) { this.MoveTargetCard(f_maid); this.m_camMain.fieldOfView = 30f; return this.ShotThumCardOriginal(); } public Texture2D ShotThumCardOriginal() { return this.RenderThum(this.m_camMain, this.m_rtThumCard, this.m_rtThumCard2, this.m_siCardSize); } public void ShotSave(Maid f_maid) { UTY.SaveImage(this.ShotThumPreset(f_maid), null); } public void ShotStart() { base.StartCoroutine(this.CoShot()); } private IEnumerator CoShot() { yield return new WaitForEndOfFrame(); this.m_camMain.enabled = true; yield return new WaitForEndOfFrame(); this.m_camMain.enabled = false; Camera cam = base.gameObject.GetComponent(); if (cam != null) { UTY.SaveImage(this.m_rtThumPreset, null, TextureFormat.ARGB32); } yield break; } private Camera m_camMain; private RenderTexture m_rtThumPreset; private RenderTexture m_rtThumPreset2; private RenderTexture m_rtThumIcon; private RenderTexture m_rtThumIcon2; private RenderTexture m_rtThumCard; private RenderTexture m_rtThumCard2; public Transform m_trParent; public Vector3 m_vecOffsetPos; public Vector3 m_vecOffsetRot; private readonly Size m_siIconSize = new Size(90, 90); private readonly Size m_siPreSize = new Size(138, 200); private readonly Size m_siCardSize = new Size(630, 890); }