Maya Pythonでオブジェクト名を取得する
oSelはリストで,このままprintするとunicodeせ出力される
そこで,oSel[0].decode
でoSelの1番目のをデコードしてmojiに代入する
import maya.cmds as cmds cmds.select() oSel = cmds.ls(sl=True) print oSel moji = oSel[0].decode() print moji
Maya Pythonでオブジェクト名を取得する
oSelはリストで,このままprintするとunicodeせ出力される
そこで,oSel[0].decode
でoSelの1番目のをデコードしてmojiに代入する
import maya.cmds as cmds cmds.select() oSel = cmds.ls(sl=True) print oSel moji = oSel[0].decode() print moji
配置確認(未完成)2017/10/25 AM11時変更
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;//必ず必要
public class dicPractice : MonoBehaviour {
public GameObject ballPre;//ボールプレファブ用
public InputField numInput;//インプットフィールド用
public InputField scnNumInput;//インプットフィールド用
public Button subBtn;//シーン戻るボタン
public Button addBtn;//シーン次ボタン
Dictionary<int, List<string>> timeList1;//多重化Dictionary
List<string> tempList ;//テンポラリ用のList
List<GameObject> goList;//生成したゲームオブジェクトの全リスト
int scenceNum;//現在のシーン番号用変数
void Start () {
//Dictionary,Listの追加
timeList1 = new Dictionary<int, List<string>> ();
tempList = new List<string>();
goList = new List<GameObject> ();
//※※シーン番号ゼロはシーンが空の意味に変更
scenceNum = 0;//現在のシーン番号初期化//保存データ読み込み時にはシーン番号を1以上にする
//シーン数がいくつかあるかチェックする空なら0を,
int scnDicCount = timeList1.Count;
if(scnDicCount < 1){
scnNumInput.text = scnDicCount .ToString ();//シーン番号の数字を文字に変換
}else{
scnNumInput.text = scenceNum.ToString ();//Dictionaryが空でなかったらシーン番号を表示させる(保存機能追加後に機能する)
}
//シーン番号0以下なら次シーンボタンオフに
if (scenceNum <= 1) {
subBtn.interactable = false;
}
//シーン番号がゼロで戻るボタンオフに
addBtn.interactable = false;
//json用オブジェクトを作成
myData jdata = new myData();
//キャラ10体作成
for (int i = 0; i < 10; i++) {
GameObject go = Instantiate (ballPre, new Vector3 (i * 2.0f, 0, 0), Quaternion.identity) as GameObject;
string myAIname = "AI" + i.ToString ();
go.name = myAIname;
//goListに 生成したgoをgoListに追加
goList.Add(go);
}
}
//番号で呼び出す用
public void numDel(){
int objNum = int.Parse (numInput.text);//インプットフィールドで受け取った番号をintに変換
int scnNum = int.Parse (scnNumInput.text);//インプットフィールドで受け取った番号をintに変換
scnNum--;//Dictionaryには0から収納されているので1引く
List<string> temp2List = new List<string> ();//一時的なList作成
Debug.Log ("呼び出し番号_" + objNum);
Debug.Log ("シーン番号_" + scnNum);
temp2List = timeList1 [scnNum];//シーン番号scnNumのJSONをLISTに読み込む
var myObject = JsonUtility.FromJson<myData>(temp2List [objNum]);//シーンゼロのobjNum番のJSONのみをオブジェクトに変換
Debug.Log ("X=" + myObject.posx);//デバッグ用
Debug.Log ("Z=" + myObject.posz);
Debug.Log ("name=" + myObject.name);
//Debug.Log ("time=" + myObject.time);
}
// シーン追加用
public void dicAdd(){
// int dicCount = timeList1.Count;//シーン番号の最大値確認用
// scnNumInput.text = dicCount.ToString ();//シーン番号の数字を文字に変換
//記録する準備
myData jdata = new myData ();
int i = 0;
//goListの中身をJSONにするforeach
foreach (var n in goList) {
jdata.id = i;
jdata.name = n.name;
jdata.posx = n.transform.position.x;
jdata.posy = n.transform.position.y;
jdata.posz = n.transform.position.z;
jdata.time = i * 10;//dummy data
string json = JsonUtility.ToJson (jdata);//オブジェクトをJSON文字列に変更
// Debug.Log(n.name);
tempList.Add (json);//LISTにJSONを追加
i++;
}
//timeList1に書き換えなのか追加なのかチェック
if (timeList1.ContainsKey(scenceNum ) )//現在のシーン番号がtimeList1に含まれているとき
{
timeList1[ scenceNum ] = tempList;//timeList1のscenceNumのリストを入れ替え
}
else
{ //現在のシーン番号がtimeList1に含まれていないとき
timeList1.Add( scenceNum , tempList );//timeList1に新規追加
//シーンが増えたので現在のシーンも追加
scenceNum++;
}
//ボタン関連処理
//現在のシーン番号が0より大きければ<ボタン表示
if (scenceNum > 1) {
subBtn.interactable = true;
}
//現在のシーン番号がtimeList1と同じなら>ボタン隠す
if (scenceNum == timeList1.Count) {
addBtn.interactable = false;
}
//現在のシーン番号がtimeList1より小さいなら>ボタン表示
if (scenceNum < timeList1.Count) {
addBtn.interactable = true;
}
scnNumInput.text = scenceNum.ToString ();//シーン番号の数字を文字に変換し表示
}
//シーン番号次へボタン
public void scnNumAdd(){
//現在のシーン番号を1足す
scenceNum++;
//シーン番号をInputFileldに表示書き換え
scnNumInput.text = scenceNum.ToString ();
//現在のシーン番号が0より大きければ<ボタン表示
if (scenceNum > 1) {
subBtn.interactable = true;
}
//現在のシーン番号がtimeList1より大きければ>ボタン隠す
if (scenceNum >= timeList1.Count) {
addBtn.interactable = false;
}
}
//シーン番号戻るボタン
public void scnNumSub(){
//現在のシーン番号を1減らす
scenceNum--;
//シーン番号をInputFileldに表示書き換え
scnNumInput.text = scenceNum.ToString ();
//現在のシーン番号が0以下であれば<ボタン隠す
if (scenceNum <= 1) {
subBtn.interactable = false;
}
//現在のシーン番号がtimeList1より小さければ>ボタン表示
if (scenceNum < timeList1.Count) {
addBtn.interactable = true;
}
}
}
[System.Serializable]
public class myData {
public int id;
public string name;
public int time;
public float posx;
public float posy;
public float posz;
}
動画のような動きを実現します
2017/11/02更新,次々タップしてゴールをどんどん変更できるようにした
ここからダウンロードできます
using UnityEngine;
using System.Collections;
using System;
public class tapMove : MonoBehaviour {
//AIの変数用
UnityEngine.AI.NavMeshAgent agent;
//hit情報(タップ先)情報の格納用
RaycastHit hit;
//タップ用レイの準備
Ray ray;
[SerializeField, HeaderAttribute ("circlePrefabをここにアサイン")]
public GameObject circlePre;
//レイヤーマスクでタップを無視するレイヤー設定用
LayerMask mylayerMask;
//アニメーターの変数用
Animator animator;
//初期化
void Start () {
agent = GetComponent<UnityEngine.AI.NavMeshAgent>();//AIをこのスクリプトがあるゲームオブジェクトから探す
animator = GetComponent<Animator> ();//このゲームオブジェクトからアニメーターを探す
int layerMask = LayerMask.GetMask(new string[] {"Default"});//レイヤーマスクの設定
mylayerMask = layerMask;//これ何だっけ?
}
//毎回処理します
void Update () {
// 左クリックしたときに、
if (Input.GetMouseButtonDown (0)) {
// マウスの位置からRayを発射して、
ray = Camera.main.ScreenPointToRay (Input.mousePosition);
// 物体にあたったら、
if (Physics.Raycast (ray, out hit, 30f, mylayerMask)) {
// その場所に、Nav Mesh Agentをアタッチしたオブジェクトを移動させる
agent.SetDestination (hit.point);
// "Run"アニメーションに遷移
// animator.SetBool ("Wak", true);
spawnPrefab ();
}
}
// 目的地とプレイヤーとの距離が1以下になったら、
if (Vector3.Distance(hit.point, transform.position) < 1.0f) {
}
}
//ターゲットマーカーを表示
void spawnPrefab(){
string delPreviusGO = circlePre.name;//Prefabの名前を取得する
try{
GameObject deathObj = GameObject.Find (delPreviusGO);//Prefab名のゲームオブジェクトがあったら
Destroy(deathObj);//それを消す=つまり目的地に到着前にタップして行き先を変更した時用
}catch(NullReferenceException e) {//見つからなかった時の処理(特に何もしていない)
Debug.Log ("noGO");
}
Vector3 mypos ;//行き先の座標設定用
float myPosy = hit.point.y + 0.1f;//若干高い位置にマーカー表示させる
mypos = new Vector3 (hit.point.x, myPosy, hit.point.z);//Yだけ少し高くした座標作成
GameObject circleGO = Instantiate(circlePre, mypos, circlePre.transform.rotation) as GameObject;//Prefabを生成する
circleGO.name = circlePre.name;//Prefabでなくゲームオブジェクトにして名前を設定する(上で名前で検索して消すために設定いている)
}
}
元ネタはこちらのスクリプトを参考にしています
また,Prefab側にはこのスクリプトをあてて,IsTriggerをONにしています
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class triggerDestroy : MonoBehaviour {
Animation anim;
bool animCheck;
// Use this for initialization
void Start () {
anim = gameObject.GetComponent<Animation> ();
animCheck = false;//noPlayning
}
// Update is called once per frame
void Update () {
if (animCheck) {
if (!anim.isPlaying) {
print ("end");
animCheck = false;//noanimPlay
Destroy(this.gameObject);
}
}
}
void OnTriggerEnter(Collider other) {
//Debug.Log ("ON");
if (!anim.isPlaying) {
anim.Play ();
animCheck = true;//Playing
}
}
}
ターゲットの赤い輪はPhotoshopで作成し,Planeにテクスチャで貼付
パッケージのダウンロード(ここ)