This repository has been archived by the owner on Mar 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent usage of mp3 files in audio interactions. Unity licensing issue
- Loading branch information
1 parent
7e2cfb2
commit 61b2769
Showing
1 changed file
with
107 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,107 +1,107 @@ | ||
using System; | ||
using UnityEngine; | ||
using UnityEngine.UI; | ||
|
||
public class AudioPanelEditor : MonoBehaviour | ||
{ | ||
public Button done; | ||
|
||
public InputField url; | ||
public InputField title; | ||
public AudioControl audioControl; | ||
|
||
public bool answered; | ||
public string answerTitle; | ||
public string answerURL; | ||
|
||
public bool allowCancel => explorerPanel == null; | ||
|
||
private ExplorerPanel explorerPanel; | ||
private bool fileOpening; | ||
|
||
private static Color errorColor = new Color(1, 0.8f, 0.8f, 1f); | ||
|
||
public void OnEnable() | ||
{ | ||
StartCoroutine(UIAnimation.FadeIn(GetComponent<RectTransform>(), GetComponent<CanvasGroup>())); | ||
} | ||
|
||
void Update() | ||
{ | ||
if (fileOpening) | ||
{ | ||
if (explorerPanel != null) | ||
{ | ||
if (Input.GetKeyDown(KeyCode.Escape)) | ||
{ | ||
Destroy(explorerPanel.gameObject); | ||
} | ||
} | ||
|
||
if (explorerPanel != null && explorerPanel.answered) | ||
{ | ||
url.text = explorerPanel.answerPath; | ||
|
||
Destroy(explorerPanel.gameObject); | ||
audioControl.enabled = true; | ||
audioControl.Init(explorerPanel.answerPath); | ||
} | ||
} | ||
} | ||
|
||
public void Init(string initialTitle, string initialUrl) | ||
{ | ||
title.onValueChanged.AddListener(_ => OnInputChange(title)); | ||
url.onValueChanged.AddListener(_ => OnInputChange(url)); | ||
|
||
title.text = initialTitle; | ||
url.text = initialUrl; | ||
if (String.IsNullOrEmpty(initialUrl)) | ||
{ | ||
audioControl.enabled = false; | ||
} | ||
else | ||
{ | ||
audioControl.Init(initialUrl); | ||
} | ||
} | ||
|
||
public void Answer() | ||
{ | ||
bool errors = false; | ||
if (String.IsNullOrEmpty(title.text)) | ||
{ | ||
title.image.color = errorColor; | ||
errors = true; | ||
} | ||
|
||
if (String.IsNullOrEmpty(url.text)) | ||
{ | ||
url.image.color = errorColor; | ||
errors = true; | ||
} | ||
|
||
if (!errors) | ||
{ | ||
answered = true; | ||
answerURL = url.text; | ||
answerTitle = title.text; | ||
} | ||
} | ||
|
||
public void Browse() | ||
{ | ||
var searchPattern = "*.mp3;*.wav;*.aif;*.ogg"; | ||
|
||
explorerPanel = Instantiate(UIPanels.Instance.explorerPanel); | ||
explorerPanel.transform.SetParent(Canvass.main.transform, false); | ||
explorerPanel.GetComponent<ExplorerPanel>().Init("", searchPattern, "Select audio"); | ||
|
||
fileOpening = true; | ||
} | ||
|
||
public void OnInputChange(InputField input) | ||
{ | ||
input.image.color = Color.white; | ||
} | ||
} | ||
using System; | ||
using UnityEngine; | ||
using UnityEngine.UI; | ||
|
||
public class AudioPanelEditor : MonoBehaviour | ||
{ | ||
public Button done; | ||
|
||
public InputField url; | ||
public InputField title; | ||
public AudioControl audioControl; | ||
|
||
public bool answered; | ||
public string answerTitle; | ||
public string answerURL; | ||
|
||
public bool allowCancel => explorerPanel == null; | ||
|
||
private ExplorerPanel explorerPanel; | ||
private bool fileOpening; | ||
|
||
private static Color errorColor = new Color(1, 0.8f, 0.8f, 1f); | ||
|
||
public void OnEnable() | ||
{ | ||
StartCoroutine(UIAnimation.FadeIn(GetComponent<RectTransform>(), GetComponent<CanvasGroup>())); | ||
} | ||
|
||
void Update() | ||
{ | ||
if (fileOpening) | ||
{ | ||
if (explorerPanel != null) | ||
{ | ||
if (Input.GetKeyDown(KeyCode.Escape)) | ||
{ | ||
Destroy(explorerPanel.gameObject); | ||
} | ||
} | ||
|
||
if (explorerPanel != null && explorerPanel.answered) | ||
{ | ||
url.text = explorerPanel.answerPath; | ||
|
||
Destroy(explorerPanel.gameObject); | ||
audioControl.enabled = true; | ||
audioControl.Init(explorerPanel.answerPath); | ||
} | ||
} | ||
} | ||
|
||
public void Init(string initialTitle, string initialUrl) | ||
{ | ||
title.onValueChanged.AddListener(_ => OnInputChange(title)); | ||
url.onValueChanged.AddListener(_ => OnInputChange(url)); | ||
|
||
title.text = initialTitle; | ||
url.text = initialUrl; | ||
if (String.IsNullOrEmpty(initialUrl)) | ||
{ | ||
audioControl.enabled = false; | ||
} | ||
else | ||
{ | ||
audioControl.Init(initialUrl); | ||
} | ||
} | ||
|
||
public void Answer() | ||
{ | ||
bool errors = false; | ||
if (String.IsNullOrEmpty(title.text)) | ||
{ | ||
title.image.color = errorColor; | ||
errors = true; | ||
} | ||
|
||
if (String.IsNullOrEmpty(url.text)) | ||
{ | ||
url.image.color = errorColor; | ||
errors = true; | ||
} | ||
|
||
if (!errors) | ||
{ | ||
answered = true; | ||
answerURL = url.text; | ||
answerTitle = title.text; | ||
} | ||
} | ||
|
||
public void Browse() | ||
{ | ||
var searchPattern = "*.wav;*.aif;*.ogg"; | ||
|
||
explorerPanel = Instantiate(UIPanels.Instance.explorerPanel); | ||
explorerPanel.transform.SetParent(Canvass.main.transform, false); | ||
explorerPanel.GetComponent<ExplorerPanel>().Init("", searchPattern, "Select audio"); | ||
|
||
fileOpening = true; | ||
} | ||
|
||
public void OnInputChange(InputField input) | ||
{ | ||
input.image.color = Color.white; | ||
} | ||
} |