59 lines
1.6 KiB
C#
59 lines
1.6 KiB
C#
using System.Text;
|
|
using UnityEngine;
|
|
using UnityEngine.Networking;
|
|
using UnityEngine.UI;
|
|
|
|
public enum URL_Type{tg, whats }
|
|
public class QR_viewer : MonoBehaviour
|
|
{
|
|
public URL_Type urlType;
|
|
[SerializeField] private Image image;
|
|
|
|
[SerializeField] private string prefix = "https://wa.me/";
|
|
[SerializeField] private string prefsDatakey = "Number";
|
|
private string suffix;
|
|
|
|
|
|
private void Start()
|
|
{
|
|
if (!PlayerPrefs.HasKey(prefsDatakey)) return;
|
|
|
|
string data = PlayerPrefs.GetString(prefsDatakey);
|
|
|
|
suffix = $"Здравствуйте! Я победил на аппарате {PlayerPrefs.GetString("Serial")}. Жду приз!";
|
|
suffix = workOnSuffix(suffix);
|
|
//suffix = suffix.Replace(" ", "%20");
|
|
|
|
|
|
string message = $"{prefix}{data}?text={suffix}";
|
|
Debug.Log(message);
|
|
|
|
|
|
|
|
var tex = QrMaker.MakeTexture(message, 1, drawQuietZones: true);
|
|
tex.filterMode = FilterMode.Point;
|
|
var sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f));
|
|
|
|
image.sprite = sprite;
|
|
}
|
|
|
|
string workOnSuffix(string suffix)
|
|
{
|
|
if (urlType== URL_Type.tg)
|
|
{
|
|
suffix = suffix.Replace("%", "%25")
|
|
.Replace("?", "%3F")
|
|
.Replace(" ", "%20")
|
|
.Replace("!", "%21")
|
|
.Replace("\"", "%22");
|
|
return suffix;
|
|
|
|
}
|
|
else
|
|
{
|
|
return UnityWebRequest.EscapeURL(suffix, Encoding.UTF8);
|
|
}
|
|
}
|
|
|
|
}
|