Hi
Code is made.
I want to control and playmaker.
-----------------------------------------------------------------------------------
using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;
using System.Threading;
[StructLayout(LayoutKind.Sequential)]
public class CR2_shotdata_t
{
public int ballspeedX10;
public int clubspeed_BX10;
public int clubspeed_AX10;
public int clubpathX10;
public int clubfaceangleX10;
public int sidespin;
public int backspin;
public int azimuthX10;
public int inclineX10;
}
public class Sensor : MonoBehaviour {
static BallInformation bm;
static void Thread_Proc()
{
active();
}
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate bool CallBackDelegate(int h, uint status, CR2_shotdata_t psd, int userparam);
[DllImport("sensor4cs.dll", CallingConvention=CallingConvention.StdCall)]
static extern void RegCallback(CallBackDelegate pCB);
[DllImport("sensor4cs.dll")]
public static extern void reStartShot();
[DllImport("sensor4cs.dll")]
static extern int init();
[DllImport("sensor4cs.dll")]
static extern void setTee(int use);
[DllImport("sensor4cs.dll")]
static extern void setClub(int useClub);
[DllImport("sensor4cs.dll")]
static extern void setWind();
[DllImport("sensor4cs.dll")]
static extern int active();
[DllImport("sensor4cs.dll")]
static extern void close();
[DllImport("sensor4cs.dll")]
static extern void deActivation();
[DllImport("sensor4cs.dll")]
static extern int getStatus();
[DllImport("sensor4cs.dll")]
static extern uint getSensorVersion();
public static bool ShotCallFunc(int h, uint status, CR2_shotdata_t psd, int userparam) {
ForceToBall ftb = GameObject.Find ("/Ball").GetComponent<ForceToBall>();
bm.SetAngle(psd.inclineX10/10.0f);
bm.SetBallSpeed(psd.ballspeedX10/10.0f);
bm.SetHeadSpeed(psd.clubspeed_AX10/10.0f);
ftb.sensorForce(psd.ballspeedX10, psd.inclineX10, psd.azimuthX10);
return true;
}
//Thread sub_thread = new Thread(new ThreadStart(Thread_Proc));
Thread sub_thread;
CallBackDelegate callFunc;
void Start() {
bm = GameObject.Find ("/BallInformations").GetComponent<BallInformation>();
sub_thread = new Thread(new ThreadStart(Thread_Proc));
callFunc = new CallBackDelegate(ShotCallFunc);
RegCallback(callFunc);
sub_thread.Start ();
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown(KeyCode.Q)) {
dispose();
System.Diagnostics.Process.GetCurrentProcess().Kill();
}
}
void dispose()
{
if(sub_thread != null)
{
sub_thread.Abort();
sub_thread = null;
}
deActivation();
close();
if(callFunc != null) {
callFunc = null;
}
//System.AppDomain.Unload(System.AppDomain.CurrentDomain);
System.GC.Collect();
}
void OnDestroy() {
dispose();
}
void OnApplicationQuit() {
dispose();
if(Application.isEditor == false) {
System.Diagnostics.Process.GetCurrentProcess().Kill();
}
/* deActivation();
close ();
sub_thread.Abort ();
*/
}
}
-----------------------------------------------------------------------------------