protected void OnAdRewarded(object _sender, Reward _args) { Debug.Log("AdRewarded!!!"); if (_args != null) { Debug.Log("AdRewardedRewardType[" + _args.Type + "]"); Debug.Log("AdRewardedRewardAmount[" + _args.Amount.ToString() + "]"); } json = File.ReadAllText(Application.persistentDataPath + "/data.json");//読み取ってるよ json = encryption.DecryptString(json); savedata sv = new savedata(); JsonUtility.FromJsonOverwrite(json, sv);//読み取ったのを変換してるよ sv._yobi1 = sv._yobi1 + 250; json = JsonUtility.ToJson(sv); json = encryption.EncryptString(json); File.WriteAllText(Application.persistentDataPath + "/data.json", json);//結局これでよかった mypoint mp = scriptbox.GetComponent <mypoint>(); mp.Load(); // DailyBonusData.Instance.addSpecialBonusNotice("AD_REWARD_1"); IsActive = true; }
public XInputController() { controller = new Controller(UserIndex.One); //controller = new Controller(UserIndex.Two); connected = controller.IsConnected; leftThumb = new mypoint(0, 0); rightThumb = new mypoint(0, 0); }
// Use this for initialization public void DoGasha() { sum = 0; // jikidata_json jd = GetComponent<jikidata_json>(); for (int i = 0; i < jd.rarelity.Length; i++) { sum = sum + jd.rarelity[i]; } Debug.Log("sum=" + sum); rand = Random.Range(0, sum); Debug.Log("rand=" + rand); num = 0; int j = jd.rarelity[0]; //ちなみに最初の登場確率はゼロ while (j <= sum) { if (rand < j) { Debug.Log(num + "が当選"); enshutu d1 = scriptbox.GetComponent <enshutu>(); d1.ReadytoGasha(num); break; } Debug.Log(rand + "は" + num + "の該当番号である" + j + "より大きい"); num++; j = j + jd.rarelity[num]; } //358 Debug.Log(num); json = File.ReadAllText(Application.persistentDataPath + "/data.json"); //読み取ってるよ json = encryption.DecryptString(json); JsonUtility.FromJsonOverwrite(json, sv); //読み取ったのを変換してるよ if (sv._jikiflag[num] == false) { sv._jikiflag[num] = true; json = JsonUtility.ToJson(sv); Debug.Log(json); json = encryption.EncryptString(json); File.WriteAllText(Application.persistentDataPath + "/data.json", json);//結局これでよかった unlock ul = scriptbox.GetComponent <unlock>(); ul.rainbow(); } mypoint mp = scriptbox.GetComponent <mypoint>(); mp.PointUsed(); }
// Call this method to update all class values public void Update() { if (!connected) { return; } gamepad = controller.GetState().Gamepad; leftThumb = new mypoint(0, 0); rightThumb = new mypoint(0, 0); leftThumb.X = (Math.Abs((float)gamepad.LeftThumbX) < deadband) ? 0 : (float)gamepad.LeftThumbX / short.MinValue * -100; leftThumb.Y = (Math.Abs((float)gamepad.LeftThumbY) < deadband) ? 0 : (float)gamepad.LeftThumbY / short.MaxValue * 100; rightThumb.Y = (Math.Abs((float)gamepad.RightThumbX) < deadband) ? 0 : (float)gamepad.RightThumbX / short.MaxValue * 100; rightThumb.X = (Math.Abs((float)gamepad.RightThumbY) < deadband) ? 0 : (float)gamepad.RightThumbY / short.MaxValue * 100; leftTrigger = gamepad.LeftTrigger; rightTrigger = gamepad.RightTrigger; }
/// <summary> /// 读取方向键信息 /// </summary> /// <returns></returns> public void GetDirection(out float tLeft, out float tRight, out mypoint pLeft, out mypoint pRight, out string returnFlag) { pLeft = new mypoint(0, 0); pRight = new mypoint(0, 0); if (!controller.IsConnected) { returnFlag = null; } gamepad = controller.GetState().Gamepad; leftThumb.X = (Math.Abs((float)gamepad.LeftThumbX) < deadband) ? 0 : (float)gamepad.LeftThumbX / short.MinValue * -100; leftThumb.Y = (Math.Abs((float)gamepad.LeftThumbY) < deadband) ? 0 : (float)gamepad.LeftThumbY / short.MaxValue * 100; rightThumb.Y = (Math.Abs((float)gamepad.RightThumbX) < deadband) ? 0 : (float)gamepad.RightThumbX / short.MinValue * -100; rightThumb.X = (Math.Abs((float)gamepad.RightThumbY) < deadband) ? 0 : (float)gamepad.RightThumbY / short.MaxValue * 100; pLeft = leftThumb; pRight = rightThumb; leftTrigger = (float)Math.Ceiling((float)gamepad.LeftTrigger / 256 * 90); rightTrigger = (float)Math.Ceiling((float)gamepad.RightTrigger / 256 * 90); tLeft = leftTrigger; tRight = rightTrigger; GamepadButtonFlags flag = gamepad.Buttons; int resultStart = ((int)flag) & 0x10; int resultBack = ((int)flag) & 0x20; int resultUp = ((int)flag) & 0x01; int resultDown = ((int)flag) & 0x02; int resultLeft = ((int)flag) & 0x04; int resultRight = ((int)flag) & 0x08; int resultLS = ((int)flag) & 0x40; int resultRS = ((int)flag) & 0x80; int resultLB = ((int)flag) & 0x100; int resultRB = ((int)flag) & 0x200; int resultA = ((int)flag) & 0x1000; int resultB = ((int)flag) & 0x2000; int resultX = ((int)flag) & 0x4000; int resultY = ((int)flag) & 0x8000; // int result if (resultStart != 0) { returnFlag = "start"; } else if (resultBack != 0) { returnFlag = "back"; } else if (resultUp != 0) { returnFlag = "up"; } else if (resultDown != 0) { returnFlag = "down"; } else if (resultLeft != 0) { returnFlag = "left"; } else if (resultRight != 0) { returnFlag = "right"; } else if (resultLS != 0) { returnFlag = "LS"; } else if (resultRS != 0) { returnFlag = "RS"; } else if (resultLB != 0) { returnFlag = "OL"; } else if (resultRB != 0) { returnFlag = "OR"; } else if (resultA != 0) { returnFlag = "sa"; } else if (resultB != 0) { returnFlag = "sr"; } else if (resultX != 0) { returnFlag = "st"; } else if (resultY != 0) { returnFlag = "li"; } else { returnFlag = flag.ToString(); } }
/// <summary> /// 定时器处理 /// </summary> private void Timer1_Tick(object sender, EventArgs e) { string input = null; mypoint pLeft = null; mypoint pRight = null; float tLeft; float tRight; controller.GetDirection(out tLeft, out tRight, out pLeft, out pRight, out input); if (input == null) { this.textBox1.Text += "the handle disconnect...\r\n"; return; } // this.textBox4.Text += input + "\r\n"; Console.WriteLine("888:" + input); Console.WriteLine("leftx:" + pLeft.X + " lefty:" + pLeft.Y); Console.WriteLine("rightx:" + pRight.X + " righty:" + pRight.Y); Console.WriteLine("leftt:" + tLeft + " rightt:" + tRight); //向下位机发送控制指令 byte li = 0xFF; string str4 = ""; string lastInput = ""; bool locker = false; if (input == "li") { //if (!locker) //{ // li = Convert.ToByte(liCount); // locker = true; //} liCount++; if (liCount == 1) { li = Convert.ToByte(0); } else { li = Convert.ToByte(1); liCount = 0; } str4 = "li"; //lastInput = input; } else if (input == "sr") { li = Convert.ToByte(1); str4 = "st"; } else if (input == "st") { li = Convert.ToByte(0); str4 = "st"; } else if (input == "sa") { li = Convert.ToByte(2); str4 = "st"; //}else if(input == "None") //{ // if (locker) // { // if (liCount == 1) // { // liCount = 0; // } // else // { // liCount = 1; // } // locker = false; // } } if (input != "None") { sendOrder(li, 0, 0, str4); } //Console.WriteLine("liCount="+ liCount); //Console.WriteLine("locker=" + locker); //字符串指令 string str1 = "ot"; tLeft = 128 - tLeft; tRight = tRight + 128; byte data_ol = Convert.ToByte(tLeft); byte data_or = Convert.ToByte(tRight); byte[] data2_ol = new byte[] { data_ol, 0, 0 }; byte[] data2_or = new byte[] { data_or, 0, 0 }; byte[] data1_ol = Encoding.Default.GetBytes(str1); if (tLeft != 128) { sendOrder(data_ol, 0, 0, str1); } else { sendOrder(data_or, 0, 0, str1); } sendOrder(pRight.Y + 128, pRight.X + 128, pLeft.X + 128, "mv"); //向小车发送控制指令 //byte[] buffer = Encoding.UTF8.GetBytes(input); //streamToServer.Write(buffer, 0, buffer.Length); //if (input == "back") //{ // //关闭 // this.timer1.Stop(); // streamToServer.Close(); // client.Close(); // streamToServer = null; // client = null; // this.button1.Enabled = true; // this.textBox1.Text += "shut down the connection...\r\n"; //} }