123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- using System;
- using System.Collections;
- using UnityEngine;
- public class ThumShot : MonoBehaviour
- {
- private void Start()
- {
- this.m_camMain = base.gameObject.GetComponent<Camera>();
- 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<int> 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)
- {
- Transform transform = CMT.SearchObjName(f_maid.body0.m_Bones.transform, "Bip01 HeadNub", true);
- 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<Camera>();
- 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<int> m_siIconSize = new Size<int>(90, 90);
- private readonly Size<int> m_siPreSize = new Size<int>(138, 200);
- private readonly Size<int> m_siCardSize = new Size<int>(630, 890);
- }
|