Code: Select all
Application.DoEvents();
Code: Select all
using UnityEngine;
using System.Collections;
using System;
public class testscript : MonoBehaviour
{
private Phidget_script phid;
public bool okToQuit = false;
void Awake ()
{
phid = GetComponent<Phidget_script>();
}
void Start()
{
Debug.Log("Connecting to phidgets");
phid.connect("localhost","5001");
}
void OnApplicationQuit ()
{
Debug.Log("OnApplicationQuit() called.");
if (okToQuit==false) {
Debug.Log("Cancel quitting");
Application.CancelQuit();
phid.close();
}
}
public void complete_close()
{
Debug.Log("testscript Complete Close");
okToQuit=true;
Application.Quit();
}
}
Code: Select all
using System;
using System.Collections;
using System.Text;
using Phidgets;
using Phidgets.Events;
using UnityEngine;
public class Phidget_script: MonoBehaviour
{
InterfaceKit ifKit;
private string phidget_adres;
private int phidget_port;
public void connect(string phidgetadres,string phidgetport)
{
Debug.Log("interfaceKit Program connect : "+ phidgetadres + " / " + phidgetport);
phidget_adres = phidgetadres;
phidget_port = Convert.ToInt32(phidgetport);
try
{
Debug.Log("Initialize the InterfaceKit object");
ifKit = new InterfaceKit();
ifKit.Attach += new AttachEventHandler(ifKit_Attach);
ifKit.open(phidget_adres,phidget_port);
}
catch (PhidgetException ex)
{
Debug.Log("InterfaceKit Program connect exception: "+ex.Description);
}
}
void ifKit_Attach(object sender, AttachEventArgs e)
{
Debug.Log("InterfaceKit attached!"+e.Device.SerialNumber.ToString());
}
public void close() {
StartCoroutine(closeEnum());
}
private IEnumerator closeEnum () {
yield return StartCoroutine(WaitFunction (0.5f));
close_ifkit1();
yield return StartCoroutine(WaitFunction (1f));
close_ifkit2();
yield return StartCoroutine(WaitFunction (1f));
SendMessage("complete_close");
}
private void close_ifkit1() {
Debug.Log("close ifkit1");
if (ifKit!=null) {
ifKit.Attach -= new AttachEventHandler(ifKit_Attach);
}
}
private void close_ifkit2() {
if (ifKit!=null) {
Debug.Log("close ifkit2");
ifKit.close();
Debug.Log("after ifKit.close");
ifKit = null;
}
}
IEnumerator WaitFunction (float delay) {
float timer = Time.time + delay;
while (Time.time < timer) {
yield return null;
}
}
}
Users browsing this forum: Ahrefs [Bot] and 0 guests