123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- using System;
- using System.IO;
- using UnityEngine;
- public class PhotoCustomObjectSphere : BasePhotoCustomObject
- {
- public override byte[] imageBinarys
- {
- get
- {
- return this.imageBinary;
- }
- }
- public override BasePhotoCustomObject.Type type
- {
- get
- {
- return BasePhotoCustomObject.Type.Sphere;
- }
- }
- public override Texture2D mainTexture
- {
- get
- {
- return this.texture;
- }
- }
- public bool isAlphaTexture
- {
- get
- {
- return this.isAlphaTexture_;
- }
- }
- public override void Awake()
- {
- base.Awake();
- this.material = new Material(Shader.Find("CM3D2/Unlit_Texture_Photo_MyObject"));
- foreach (Renderer renderer in this.texRenderers)
- {
- if (renderer != null)
- {
- renderer.material = this.material;
- }
- }
- this.material.SetFloat("_Cull", 0f);
- this.material.SetFloat("_ZWrite", 1f);
- this.material.renderQueue = 2980;
- this.scaleTransform.gameObject.SetActive(false);
- }
- public override void OnDestroy()
- {
- base.OnDestroy();
- this.ReleaseTexture();
- }
- public override void Clear()
- {
- base.Clear();
- if (this.material != null && this.material.mainTexture != null)
- {
- this.material.mainTexture = null;
- }
- if (this.scaleTransform != null)
- {
- this.scaleTransform.gameObject.SetActive(false);
- }
- this.ReleaseTexture();
- }
- protected override bool CreateTexture2D(byte[] imageBinary)
- {
- this.ReleaseTexture();
- this.texture = new Texture2D(16, 16);
- if (!this.texture.LoadImage(imageBinary))
- {
- this.ReleaseTexture();
- this.scaleTransform.gameObject.SetActive(false);
- return false;
- }
- if (this.alphaCheck)
- {
- this.isAlphaTexture_ = false;
- Color[] pixels = this.texture.GetPixels();
- for (int i = 0; i < pixels.Length; i++)
- {
- if (pixels[i].a != 1f)
- {
- this.isAlphaTexture_ = true;
- break;
- }
- }
- }
- this.material.SetFloat("_ZWrite", (float)((!this.isAlphaTexture_) ? 1 : 0));
- this.imageBinary = new byte[imageBinary.Length];
- Array.Copy(imageBinary, this.imageBinary, imageBinary.Length);
- this.material.mainTexture = this.texture;
- this.scaleTransform.gameObject.SetActive(true);
- return true;
- }
- protected override void SetTextureColor(Color setColor)
- {
- if (this.material != null)
- {
- this.material.SetColor("_Color", setColor);
- }
- }
- protected override void SetScale(float scale)
- {
- if (this.scaleTransform != null)
- {
- this.scaleTransform.localScale = new Vector3(scale, scale, scale);
- }
- }
- protected override void OnSerialize(BinaryWriter writer)
- {
- writer.Write(1001);
- writer.Write(this.isAlphaTexture_);
- writer.Write(this.imageBinary.Length);
- writer.Write(this.imageBinary);
- }
- protected override bool OnDesilialize(int gameVersion, BasePhotoCustomObject.Type type, BinaryReader reader)
- {
- if (type != BasePhotoCustomObject.Type.Sphere)
- {
- return false;
- }
- int num = 1000;
- if (1120 < gameVersion)
- {
- num = reader.ReadInt32();
- }
- if (1001 <= num)
- {
- this.isAlphaTexture_ = reader.ReadBoolean();
- this.alphaCheck = false;
- }
- int count = reader.ReadInt32();
- base.SetTexture(reader.ReadBytes(count));
- this.alphaCheck = true;
- return true;
- }
- private void ReleaseTexture()
- {
- if (this.texture != null)
- {
- UnityEngine.Object.DestroyImmediate(this.texture);
- this.texture = null;
- this.imageBinary = null;
- }
- }
- [SerializeField]
- protected Transform scaleTransform;
- [SerializeField]
- protected Renderer[] texRenderers;
- protected Texture2D texture;
- protected Material material;
- protected byte[] imageBinary = new byte[0];
- protected bool isAlphaTexture_;
- private bool alphaCheck = true;
- }
|