|
- using System;
- using Inno.DLC;
- using SUISS.Core;
- using SUISSEngine;
- using UnityEngine;
-
- public class JPEGLoader : MonoBehaviour
- {
- public static int TextureScalingFactor
- {
- get
- {
- if (JPEGLoader.MemorySize < 1024 || JPEGLoader.MaxTextureSize < 4096)
- {
- return 4;
- }
- if (JPEGLoader.MemorySize > 1500)
- {
- return 1;
- }
- return 2;
- }
- }
-
- public void DownloadCompleted(string group, string name)
- {
- if (group == this.dlcGroup && name == this.dlcName)
- {
- if (this.spriteRenderer != null)
- {
- this.spriteRenderer.sprite = null;
- }
- this.OnDestroy();
- this.Awake();
- }
- }
-
- protected void Awake()
- {
- byte[] array = null;
- if (!string.IsNullOrEmpty(this.dlcGroup) && !string.IsNullOrEmpty(this.dlcName))
- {
- DLCManager dlcmanager = ServiceLocator.Find<DLCManager>();
- if (dlcmanager != null && dlcmanager.IsEnabled)
- {
- DLCGroup dlcgroup = dlcmanager.GetGroup(this.dlcGroup).FileSelection("Type", "Background");
- if (dlcgroup.IsDownloaded)
- {
- DLCFile fileWithName = dlcgroup.GetFileWithName(this.dlcName);
- if (fileWithName != null)
- {
- array = fileWithName.GetContents();
- }
- else
- {
- UnityEngine.Debug.LogError(string.Format("No file with name {0} in group {1}", this.dlcName, this.dlcGroup));
- }
- }
- }
- else
- {
- UnityEngine.Debug.LogWarning("No DLC manager");
- }
- }
- if (array == null)
- {
- TextAsset textAsset = Resources.Load(this.jpegFileResourcePath) as TextAsset;
- array = textAsset.bytes;
- Resources.UnloadAsset(textAsset);
- }
- float pixelsPerUnit = 1f;
- this._texture = null;
- if (this._texture == null)
- {
- this._texture = new Texture2D(0, 0, TextureFormat.RGB24, false);
- this._texture.wrapMode = TextureWrapMode.Clamp;
- this._texture.LoadImage(array);
- this._texture.Apply(false, true);
- }
- this._sprite = Sprite.Create(this._texture, new Rect(0f, 0f, (float)this._texture.width, (float)this._texture.height), new Vector2(0f, 1f), pixelsPerUnit);
- if (this.spriteRenderer != null)
- {
- this.spriteRenderer.sprite = this._sprite;
- }
- else
- {
- UnityEngine.Debug.LogError(string.Format("JPEGLoading at {0} should have SpriteRenderer or UI2DSprite", base.name));
- }
- }
-
- protected void OnDestroy()
- {
- UnityEngine.Object.DestroyImmediate(this._sprite);
- UnityEngine.Object.DestroyImmediate(this._texture);
- }
-
- protected static int MemorySize
- {
- get
- {
- if (JPEGLoader._memorySize < 0)
- {
- JPEGLoader._memorySize = SystemInfo.graphicsMemorySize + SystemInfo.systemMemorySize;
- }
- return JPEGLoader._memorySize;
- }
- }
-
- protected static int MaxTextureSize
- {
- get
- {
- if (JPEGLoader._maxTextureSize < 0)
- {
- JPEGLoader._maxTextureSize = SystemInfo.maxTextureSize;
- }
- return JPEGLoader._maxTextureSize;
- }
- }
-
- [SerializeField]
- protected string jpegFileResourcePath;
-
- [SerializeField]
- [SelfReference(true)]
- protected SpriteRenderer spriteRenderer;
-
- [SerializeField]
- protected bool forceHighQuality;
-
- [SerializeField]
- protected string dlcGroup;
-
- [SerializeField]
- protected string dlcName;
-
- protected Texture2D _texture;
-
- protected Sprite _sprite;
-
- protected static int _memorySize = -1;
-
- protected static int _maxTextureSize = -1;
- }
|