2014年7月17日木曜日

Bluetooth TextViewに書き込めない件 thread exiting with uncaught exception

Bluetooth通信のテストをしてるときに、現在の状態をTextViewに出したくなった。
(LogCatは慣れなくて嫌い・・・なんて言ってられないんだろうけど。)

で、ClientThreadとかServerThreadとかAcceptThreadとかなんかそういう感じの名前のThreadが
皆さんのコードの中にもあると思うけど、そこからtextviewを編集しようとすると
thread exiting with uncaught exception

とかいってエラーになってる。


なんだよクソッ!とおもって色々調べてみると、ThreadからUIの編集が出来ないんだって。
詳しくは知らない。

だから、新しいHandlerを作ってその中でtextviewを書き換えればいいらしい。

ということをきっかけにして各位ググるといいんじゃないでしょうか。

2014年5月28日水曜日

Bluetoothで通信を行う

Bluetoothで通信を行うって記事を参考にbluetooth通信を行うアプリを作ろうと思ってるんだけど、
さっきからぜんぜんエラーが消えなくて何かと思ってた

元記事Bluetoothで通信を行う(2)

ACTION_DISCOVERY_STARTED
ACTION_DISCOVERY_FINISHED

の2つは、頭にBluetoothAdapter.  ってつける必要があって、

ACTION_FOUND
ACTION_NAME_CHANGED

の2つは、頭にBluetoothDevice.   ってつける必要があった。


だから、その部分のコードは、
private final BroadcastReceiver DevieFoundReceiver = new BroadcastReceiver(){
   //検出されたデバイスからのブロードキャストを受ける
   @Override
   public void onReceive(Context context, Intent intent){
       String action = intent.getAction();
       String dName = null;
       BluetoothDevice foundDevice;
       ListView nonpairedList = (ListView)findViewById(R.id.listview);
       if(BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)){
        Log.d("ACTION_DISCOVERY_STARTED","スキャン開始");
       }
       if(BluetoothDevice.ACTION_FOUND.equals(action)){
           //デバイスが検出された
           foundDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
           if((dName = foundDevice.getName()) != null){
               if(foundDevice.getBondState() != BluetoothDevice.BOND_BONDED){
                   //接続したことのないデバイスのみアダプタに詰める
                connectableDeviceAdapter.add(dName + "\n" + foundDevice.getAddress());
                   Log.d("ACTION_FOUND", dName);
               }
           }
           nonpairedList.setAdapter(connectableDeviceAdapter);
       }
       if(BluetoothDevice.ACTION_NAME_CHANGED.equals(action)){
           //名前が検出された
           Log.d("ACTION_NAME_CHANGED", dName);
           foundDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
           if(foundDevice.getBondState() != BluetoothDevice.BOND_BONDED){
               //接続したことのないデバイスのみアダプタに詰める
               connectableDeviceAdapter.add(dName + "\n" + foundDevice.getAddress());
           }
           nonpairedList.setAdapter(connectableDeviceAdapter);
       }

       if(BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)){
           Log.d("ACTION_DISCOVERY?FINISHED","スキャン終了");
       }
   }

};

ってなる。

本来はならないのかな?
よくわかりません。

分かる人教えてください。
おわり

2014年2月1日土曜日

くりっくしたらでっかくなる

カメラのprojectionをperspectiveにしていると、ゲームオブジェクトの描画に奥行きが出来る。
その状態で、オブジェクトの位置を変更することで、クリック中にオブジェクトを大きく表示させたかった。


純粋にz座標の位置を変化させると、マウスと位置がずれる。
this.transform.Translate(Vector3.back * 0.5f);

カメラとオブジェクトを結ぶ直線上でキャラクターを動かすと、描画がちゃんとする
this.transform.Translate((game_camera.transform.position - this.transform.position).normalized * 0.5f);

2014年1月5日日曜日

unityをまたいじっている

試作追いかけシステム

馬車を剣士が追いかける。

ドラッグドロップで場所移動



このなんか良く分からんスクリプト間の値のやり取りのやり方をうまい事理解できると結構簡単。

using UnityEngine;
using System.Collections;

public class follow : MonoBehaviour {
private GameObject leader;
private float follow_speed;

// Use this for initialization
void Start () {
this.leader = GameObject.FindGameObjectWithTag("leader");
follow_speed = (float)this.GetComponent<parsonal_parameter>().walk_speed;
}

// Update is called once per frame
void Update () {

Vector3 velo = this.leader.transform.position - this.transform.position;

if(Vector3.Distance(this.leader.transform.position,this.transform.position) > 1.0f){
this.rigidbody.velocity = velo.normalized * follow_speed;
}else{
this.rigidbody.velocity = Vector3.zero;
}
//this.rigidbody.velocity = velo.normalized * 2.0f;

}
}

追いかけるところ。
this.leader = GameObject.FindGameObjectWithTag("leader");
ここと
follow_speed = (float)this.GetComponent<parsonal_parameter>().walk_speed;
ここがめんどっちい。
なんか特殊な関数使ってゲーム内のオブジェクトを区別して値を呼び出してるっていうイメージ。



using UnityEngine;
using System.Collections;

public class parsonal_parameter : MonoBehaviour {

public double walk_speed;

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {

}
}

キャラの持ってる数値。
まだ速度だけ。