mirror of
https://github.com/maxartz15/TextureCombiner.git
synced 2025-06-27 12:46:05 +02:00
Init.
P4 -> GitHub sync.
This commit is contained in:
53
Assets/Scripts/UI/ButtonHandlerWeb.cs
Normal file
53
Assets/Scripts/UI/ButtonHandlerWeb.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace TextureCombiner
|
||||
{
|
||||
[RequireComponent(typeof(Button))]
|
||||
public class ButtonHandlerWeb : MonoBehaviour, IPointerDownHandler
|
||||
{
|
||||
public enum ButtonType
|
||||
{
|
||||
Load,
|
||||
Save
|
||||
}
|
||||
|
||||
#pragma warning disable CS0414
|
||||
[SerializeField]
|
||||
private ButtonType m_buttonType = ButtonType.Load;
|
||||
#pragma warning restore CS0414
|
||||
|
||||
#if UNITY_WEBGL
|
||||
private TextureCombiner m_textureCombiner = null;
|
||||
private Button m_button = null;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
m_textureCombiner = FindObjectOfType<TextureCombiner>();
|
||||
m_button = this.GetComponent<Button>();
|
||||
}
|
||||
#endif
|
||||
|
||||
public void OnPointerDown(UnityEngine.EventSystems.PointerEventData eventData)
|
||||
{
|
||||
#if UNITY_WEBGL
|
||||
m_button.onClick.RemoveAllListeners();
|
||||
|
||||
switch (m_buttonType)
|
||||
{
|
||||
case ButtonType.Load:
|
||||
m_textureCombiner.Load();
|
||||
break;
|
||||
case ButtonType.Save:
|
||||
m_textureCombiner.Save();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/UI/ButtonHandlerWeb.cs.meta
Normal file
11
Assets/Scripts/UI/ButtonHandlerWeb.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c1fd32c98211f8744bbb554e3fd928d7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
39
Assets/Scripts/UI/FitRect.cs
Normal file
39
Assets/Scripts/UI/FitRect.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace TextureCombiner
|
||||
{
|
||||
[RequireComponent(typeof(RectTransform)), ExecuteInEditMode]
|
||||
public class FitRect : MonoBehaviour
|
||||
{
|
||||
public bool m_fitHeight = false;
|
||||
public bool m_fitWidth = false;
|
||||
public RectTransform m_rectToFit = null;
|
||||
|
||||
private RectTransform m_rectTransform = null;
|
||||
private Rect m_prevRect = new Rect();
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
m_rectTransform = GetComponent<RectTransform>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if(!m_rectToFit)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(m_prevRect != m_rectToFit.rect)
|
||||
{
|
||||
m_prevRect = m_rectToFit.rect;
|
||||
|
||||
m_rectTransform.sizeDelta = new Vector2(
|
||||
m_fitWidth ? m_rectToFit.rect.width : m_rectTransform.rect.width,
|
||||
m_fitHeight ? m_rectToFit.rect.height : m_rectToFit.rect.height
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/UI/FitRect.cs.meta
Normal file
11
Assets/Scripts/UI/FitRect.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3df6f29a361ab574789d62241d8f0310
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
21
Assets/Scripts/UI/HoverInfo.cs
Normal file
21
Assets/Scripts/UI/HoverInfo.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace TextureCombiner
|
||||
{
|
||||
public class HoverInfo : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
|
||||
{
|
||||
[SerializeField, Multiline]
|
||||
private string m_text = "";
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
HoverInfoBox.s_hoverInfoBox.Show(m_text, eventData.position);
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
HoverInfoBox.s_hoverInfoBox.Hide();
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/UI/HoverInfo.cs.meta
Normal file
11
Assets/Scripts/UI/HoverInfo.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4777ae165e0fc384c9b2f40261e50fb0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
82
Assets/Scripts/UI/HoverInfoBox.cs
Normal file
82
Assets/Scripts/UI/HoverInfoBox.cs
Normal file
@ -0,0 +1,82 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace TextureCombiner
|
||||
{
|
||||
public class HoverInfoBox : MonoBehaviour
|
||||
{
|
||||
public static HoverInfoBox s_hoverInfoBox { get; private set; } = null;
|
||||
|
||||
[SerializeField]
|
||||
private RectTransform m_infoBoxParent = null;
|
||||
[SerializeField]
|
||||
private Text m_text = null;
|
||||
[SerializeField]
|
||||
private Vector2 m_offset = new Vector2(0, 0);
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if(s_hoverInfoBox)
|
||||
{
|
||||
DestroyImmediate(gameObject);
|
||||
}
|
||||
|
||||
s_hoverInfoBox = this;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
Hide();
|
||||
}
|
||||
|
||||
public void Show(string a_text, Vector2 a_position)
|
||||
{
|
||||
if(!enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Set text.
|
||||
m_text.text = a_text;
|
||||
m_text.SetLayoutDirty();
|
||||
|
||||
// Flip when above 50% of the screen.
|
||||
if(Input.mousePosition.y < (Screen.height / 2))
|
||||
{
|
||||
a_position += new Vector2(m_offset.x - (m_infoBoxParent.rect.width / 2), m_offset.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
a_position += new Vector2(m_offset.x - (m_infoBoxParent.rect.width / 2), -m_offset.y - m_infoBoxParent.rect.height);
|
||||
}
|
||||
|
||||
// Clamp borders.
|
||||
if(a_position.x < 0)
|
||||
{
|
||||
a_position.x = 0;
|
||||
}
|
||||
else if (a_position.x + m_infoBoxParent.rect.width > Screen.width)
|
||||
{
|
||||
a_position.x = Screen.width - m_infoBoxParent.rect.width;
|
||||
}
|
||||
|
||||
if (a_position.y < 0)
|
||||
{
|
||||
a_position.y = 0;
|
||||
}
|
||||
else if (a_position.y + m_infoBoxParent.rect.height > Screen.height)
|
||||
{
|
||||
a_position.y = Screen.height - m_infoBoxParent.rect.height;
|
||||
}
|
||||
|
||||
// Enable object.
|
||||
m_infoBoxParent.gameObject.SetActive(true);
|
||||
m_infoBoxParent.position = a_position;
|
||||
}
|
||||
|
||||
public void Hide()
|
||||
{
|
||||
m_infoBoxParent.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/UI/HoverInfoBox.cs.meta
Normal file
11
Assets/Scripts/UI/HoverInfoBox.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f517fa6682ad6dd4ebec0f35cd3cfc1a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
24
Assets/Scripts/UI/OpenURL.cs
Normal file
24
Assets/Scripts/UI/OpenURL.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace TextureCombiner
|
||||
{
|
||||
public class OpenURL : MonoBehaviour, IPointerClickHandler
|
||||
{
|
||||
[SerializeField]
|
||||
private string m_url = "";
|
||||
[SerializeField]
|
||||
private bool m_httpsOnly = true;
|
||||
|
||||
public void OnPointerClick(UnityEngine.EventSystems.PointerEventData eventData)
|
||||
{
|
||||
if(m_httpsOnly && !m_url.StartsWith("https://"))
|
||||
{
|
||||
m_url = "https://" + m_url;
|
||||
}
|
||||
|
||||
Application.OpenURL(m_url);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
11
Assets/Scripts/UI/OpenURL.cs.meta
Normal file
11
Assets/Scripts/UI/OpenURL.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0de3abbefbab004458d0b32fa4794c61
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
23
Assets/Scripts/UI/ToggleInvoke.cs
Normal file
23
Assets/Scripts/UI/ToggleInvoke.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace TextureCombiner
|
||||
{
|
||||
[RequireComponent(typeof(Toggle))]
|
||||
public class ToggleInvoke : MonoBehaviour
|
||||
{
|
||||
private Toggle m_toggle = null;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
m_toggle = GetComponent<Toggle>();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
m_toggle.onValueChanged.Invoke(m_toggle.isOn);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/UI/ToggleInvoke.cs.meta
Normal file
11
Assets/Scripts/UI/ToggleInvoke.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9695356589cdfd24f9058351ac2f48e3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user