Skip to content
This repository has been archived by the owner on Mar 11, 2024. It is now read-only.

Commit

Permalink
Prevent usage of mp3 files in audio interactions. Unity licensing issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Saticmotion committed Jul 7, 2020
1 parent 7e2cfb2 commit 61b2769
Showing 1 changed file with 107 additions and 107 deletions.
214 changes: 107 additions & 107 deletions Assets/Scripts/InteractionPanels/AudioPanelEditor.cs
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;
}
}

0 comments on commit 61b2769

Please sign in to comment.