using UnityEngine; using UnityEngine.UI; using System.Collections; using System.Collections.Generic; using System; using System.Threading.Tasks; #if UNITY_IOS using AOT; using System.Runtime.InteropServices; #endif [Serializable] public class User { public int id; //用户id public string nickname; // 昵称 public string avatar; // 头像 http地址 public int gender; // 0: 未设置, 1:男 ,2:女 public string address; // 地址 } [Serializable] public class UserFriend { public User user; //用户id public string status; // 状态 [ONLINE,OFFLINE,GAME] public int rank; // 排名 public int score; // 分数 } public class Response { public List list; } enum CMD_MOTION { MOTION_STOP = 0, MOTION_RUN, // 跑 MOTION_JUMP, // 跳 MOTION_DOWN, // 蹲 MOTION_LEFT, // 滑左 MOTION_RIGHT, // 滑右 MOTION_FRONT, // 滑前 MOTION_BACK, // 滑后 MOTION_LEFT_UP, // 点击-左上 MOTION_LEFT_DOWN, // 点击-左下 MOTION_RIGHT_UP, // 点击-右上 MOTION_RIGHT_DOWN, // 点击-右下 MOTION_STEP, // 点击-原地踩 NUMBERS_OF_MOTION, MOTION_CANCEL = 0x0100, } enum BLE_STATE { STATE_DISCONNECTED = 0, STATE_CONNECTING, // 连接中 STATE_CONNECTED, // 连接成功 STATE_DISCONNECTING, // 断开连接 } [Serializable] public class Shoe { public string name, address; public int status, electricity; public int stepLeftStatus, stepLeftFrag, stepRightStatus, stepRightFrag; public short lx, ly, lz, rx, ry, rz; public int[] cmd = new int[2]; public int[] motion = new int[4 * 2]; public bool Valid(int ts) { return (DateTime.Now.Millisecond - ts) >= (1000 / Application.targetFrameRate); } public int GetCmd() { if (Valid(cmd[1])) { return cmd[0]; } return -1; } public int GetMotionLeft() { if (Valid(motion[1])) { return motion[0]; } return -1; } public int GetMotionRight() { if (Valid(motion[3])) { return motion[2]; } return -1; } } class NativeResponse { public int code; public string result; } class NativeCallback : AndroidJavaProxy { public NativeCallback() : base("com.ouj.shoe.sdklibrary.interface.IntergrationInterface") { } public void Callback(int code, string result) { Debug.Log(result); NativeResponse resp = new NativeResponse { code = code, result = result }; onCallback(resp); } public Action onCallback; } public class MessageHandler : MonoBehaviour { private static bool _debug = true; private Transform left, right; private Transform cameraTransform; private static Vector3 lv = new Vector3(0, 0, 0), rv = new Vector3(0, 0, 0); private static Quaternion lqo = new Quaternion(0, 0, 0, 0), rqo = new Quaternion(0, 0, 0, 0); private static Quaternion lq = new Quaternion(0, 0, 0, 0), rq = new Quaternion(0, 0, 0, 0); private static Text montionTextPos, montionTextAtt, montionTextAttConver, montionTextStep; private static int motionLeftCode_0 = -1, motionRightCode_0 = -1; private static int motionLeftCode_1 = -1, motionRightCode_1 = -1; private static Text textDeviceOne, textDeviceOneStatus, textDeviceOneElectricity; private static Text textDeviceTwo, textDeviceTwoStatus, textDeviceTwoElectricity; private static Text textGetUserFriends; private static Text textGameMode; private static Text textDeviceOneMotion, textDeviceTwoMotion; private static Response friends; private static string _name_0, _address_0; private static int _status_0, _electricity_0; private static string _name_1, _address_1; private static int _status_1, _electricity_1; private static bool _gameMode = false; private static int _leftStatus, _leftFrag, _rightStatus, _rightFrag; private static short _lx, _ly, _lz, _rx, _ry, _rz; private static Shoe[] shoes = new Shoe[2]; /** * 获取鞋子数据信息 */ public Shoe GetShoe(int id) { return shoes[id]; } /** * 测试 或 使用方法参考 * * */ void test() { Debug.Log("test start"); GameObject.Find("btnGameStart").GetComponent