Tanoda
PanoramaManager.cs
Go to the documentation of this file.
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using System.Runtime.Serialization;
5using GILES;
6using UnityEngine;
7using UnityEngine.UI;
8
9public class PanoramaManager : pb_MonoBehaviourSingleton<PanoramaManager>, ISerializable
10{
11 public float SavedRotation = 0;
12 private string textureName;
13 public RawImage PreviewImage;
14 internal Vector3 pos, scale = Vector3.one * 5;
15 internal float panoramaHeight = 7.0f;
16 private Material panoramaMaterial;
17 private bool loaded = false;
18
19 // Start is called before the first frame update
20 void Start()
21 {
22 panoramaMaterial = GetComponent<MeshRenderer>().material;
23 if (!loaded)
24 panoramaHeight = 7.0f;
25 }
26
27 public void SelectMe()
28 {
29 pb_Selection.SetSelection(gameObject);
30 }
31
32 public void SetRotation(float value)
33 {
34 if (panoramaMaterial.HasProperty("_PanoRotation"))
35 {
36 panoramaMaterial.SetFloat("_PanoRotation", value);
37 }
38 else
39 {
40 transform.eulerAngles = Vector3.up * value;
41 }
42 SavedRotation = value;
43 }
44
45 public void SetTextureName(string value)
46 {
47 textureName = value;
48 }
49
50 public void SetTexture(Texture value)
51 {
52 GetComponent<MeshRenderer>().material.mainTexture = value;
53 if (GetComponent<MeshRenderer>().material.HasProperty("_PanoTexture"))
54 GetComponent<MeshRenderer>().material.SetTexture("_PanoTexture", value);
55 PreviewImage.texture = value;
56 }
57
58 public void ClearImage()
59 {
60 GetComponent<MeshRenderer>().material.mainTexture = null;
61 if (GetComponent<MeshRenderer>().material.HasProperty("_PanoTexture"))
62 GetComponent<MeshRenderer>().material.SetTexture("_PanoTexture", null);
63 PreviewImage.texture = null;
64 }
65
66 private void Update()
67 {
68 if (panoramaMaterial.HasProperty("_PanoWorldPos"))
69 {
70 panoramaMaterial.SetVector("_PanoWorldPos", new Vector4(transform.position.x, transform.position.y + panoramaHeight, transform.position.z, 0));
71 }
72 }
73
74 public void SetHeight(string text)
75 {
76 panoramaHeight = Macro.StoF(text);
77 loaded = true;
78 }
79
80 internal void LoadPM(PanoramaManager pm)
81 {
82 if (panoramaMaterial == null)
83 {
84 Destroy(gameObject);
85 return;
86 }
88 textureName = pm.textureName;
89 transform.position = pm.pos;
90 transform.localScale = pm.scale;
92 panoramaHeight = pm.panoramaHeight;
93 loaded = true;
94 if (string.IsNullOrEmpty(textureName))
95 {
96 return;
97 }
98 StartCoroutine(LoadPic());
99 }
100
101 IEnumerator LoadPic()
102 {
103 yield return new WaitForEndOfFrame();
104 while (LoadingManager.instance.isLoading)
105 {
106 yield return new WaitForEndOfFrame();
107 }
108
109 try
110 {
111
112 if (GetComponent<MeshRenderer>().material.HasProperty("_PanoTexture"))
113 GetComponent<MeshRenderer>().material.SetTexture("_PanoTexture", GlobalTextureHolder.instance.GetFullRes(textureName));
114
115 GetComponent<MeshRenderer>().material.mainTexture = GlobalTextureHolder.instance.GetFullRes(textureName);
117 }
118 catch (Exception)
119 {
120 // ignored
121 }
122 }
123
124 [NaughtyAttributes.Button]
125 private void tesztLoad()
126 {
127 GetComponent<MeshRenderer>().material.SetTexture("_PanoTexture", PreviewImage.texture);
128 }
129
130 public void GetObjectData(SerializationInfo info, StreamingContext context)
131 {
132 info.AddValue("SavedRotation", SavedRotation);
133 info.AddValue("textureName", textureName);
134 info.AddValue("panoramaHeight", panoramaHeight);
135 info.AddValue("scale", (SerializableVector3)transform.localScale);
136 info.AddValue("pos", (SerializableVector3)transform.position);
137 }
138
139 public PanoramaManager(SerializationInfo info, StreamingContext context)
140 {
141 SavedRotation = info.GetSingle("SavedRotation");
142 textureName = info.GetString("textureName");
143 try
144 {
145 scale = (SerializableVector3)info.GetValue("scale", typeof(SerializableVector3));
146 pos = (SerializableVector3)info.GetValue("pos", typeof(SerializableVector3));
147 panoramaHeight = info.GetSingle("panoramaHeight");
148 }
149 catch (Exception)
150 {
151 // ignored, backward compatibility
152 }
153 }
154}
static void SetSelection(IEnumerable< GameObject > selection)
Definition: pb_Selection.cs:92
Texture2D GetFullRes(string filename)
static GlobalTextureHolder instance
Definition: Macro.cs:12
static float StoF(string value)
Definition: Macro.cs:24
RawImage PreviewImage
void GetObjectData(SerializationInfo info, StreamingContext context)
void SetRotation(float value)
void SetHeight(string text)
PanoramaManager(SerializationInfo info, StreamingContext context)
void SetTextureName(string value)
void SetTexture(Texture value)
Since unity doesn't flag the Vector3 as serializable, we need to create our own version....
Definition: SolveIK.cs:459