質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

Q&A

解決済

1回答

334閲覧

unityのDebug.LogやGetComponentの使い方。

daityann

総合スコア7

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

0グッド

0クリップ

投稿2017/12/13 00:39

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Enflux.SDK.Core;
using UnityEngine.UI;
using System;
using System.Linq;
using Enflux.Common.DataTypes;
using Enflux.SDK.Core.Devices;
using Enflux.SDK.DataTypes;
using Enflux.SDK.Extensions;
using Enflux.SDK.Utils;
using Enflux.Shim.Utils;
using System.IO;

public class example0 : MonoBehaviour
{
// Assign these in the editor.
public EnfluxManager EnfluxManager;
public Humanoid Humanoid;
// Retrieve limb orientations as Unity local space quaternions.
private void GetLocalSpaceOrientations()
{
var chest = Humanoid.LocalOrientations.Chest.Orientation;
var leftUpperArm = Humanoid.LocalOrientations.LeftUpperArm.Orientation;
var leftLowerArm = Humanoid.LocalOrientations.LeftLowerArm.Orientation;
var rightUpperArm = Humanoid.LocalOrientations.RightUpperArm.Orientation;
var rightLowerArm = Humanoid.LocalOrientations.RightLowerArm.Orientation;
var pelvis = Humanoid.LocalOrientations.Pelvis.Orientation;
var leftUpperLeg = Humanoid.LocalOrientations.LeftUpperLeg.Orientation;
var leftLowerLeg = Humanoid.LocalOrientations.LeftLowerLeg.Orientation;
var rightUpperLeg = Humanoid.LocalOrientations.RightUpperLeg.Orientation;
var rightLowerLeg = Humanoid.LocalOrientations.RightLowerLeg.Orientation;
}

// Retrieve limb orientations as real world NED (North-East-Down) space quaternions. private void GetNedSpaceOrientations() { var chest = EnfluxManager.NedOrientations.Chest.Orientation; var leftUpperArm = EnfluxManager.NedOrientations.LeftUpperArm.Orientation; var leftLowerArm = EnfluxManager.NedOrientations.LeftLowerArm.Orientation; var rightUpperArm = EnfluxManager.NedOrientations.RightUpperArm.Orientation; var rightLowerArm = EnfluxManager.NedOrientations.RightLowerArm.Orientation; var pelvis = EnfluxManager.NedOrientations.Pelvis.Orientation; var leftUpperLeg = EnfluxManager.NedOrientations.LeftUpperLeg.Orientation; var leftLowerLeg = EnfluxManager.NedOrientations.LeftLowerLeg.Orientation; var rightUpperLeg = EnfluxManager.NedOrientations.RightUpperLeg.Orientation; var rightLowerLeg = EnfluxManager.NedOrientations.RightLowerLeg.Orientation; Debug.Log("胸 " + chest); Debug.Log("<color=blue>" + "左肘 " + leftUpperArm + "</color>"); Debug.Log("<color=blue>" + "左手首 " + leftLowerArm + "</color>"); Debug.Log("<color=red>" + "右肘 " + rightUpperArm + "</color>"); Debug.Log("<color=red>" + "右手首 " + rightLowerArm + "</color>"); } void Start() { } private float timeleft; int log;

void Update()
{

timeleft -= Time.deltaTime; if (timeleft <= 0.0) { timeleft = 1.0f; log++; Debug.Log("Log : " + log); // textSave(GetNedSpaceOrientations); GetNedSpaceOrientations(); // Debug.Log(GetNedSpaceOrientations()); // this.GetComponent<Text>().text = GetNedSpaceOrientations(); }

}

/* public void logSave(int num, string txt) { StreamWriter sw; FileInfo fi; fi = new FileInfo(Application.dataPath + "/FileName.csv"); sw = fi.AppendText(); sw.WriteLine("test output"); sw.Flush(); sw.Close(); } */ public void textSave(int log) { StreamWriter sw = new StreamWriter("../aaaaa.txt", true); //true=追記 false=上書き sw.WriteLine(log); sw.Flush(); sw.Close(); }

}

unityを使って現在開発中なのですが、GetNedSpaceOrientations()の値を
console上と画面にだしたいのですがエラーになり足止め状態になっています。

また、consoleで出力した内容をテキスト上に書き出したいのですがそれもわからなくて困っています。

Update内の//の部分が主なわからない内容です。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

GetNedSpaceOrientations()はvoid型なので、返り値はありません。
以下のようにすれば、文字列を取得することが出来るようになります。

C#

1// void → string に変更 2private string GetNedSpaceOrientations() 3{ 4 var chest = EnfluxManager.NedOrientations.Chest.Orientation; 5 var leftUpperArm = EnfluxManager.NedOrientations.LeftUpperArm.Orientation; 6 var leftLowerArm = EnfluxManager.NedOrientations.LeftLowerArm.Orientation; 7 var rightUpperArm = EnfluxManager.NedOrientations.RightUpperArm.Orientation; 8 var rightLowerArm = EnfluxManager.NedOrientations.RightLowerArm.Orientation; 9 var pelvis = EnfluxManager.NedOrientations.Pelvis.Orientation; 10 var leftUpperLeg = EnfluxManager.NedOrientations.LeftUpperLeg.Orientation; 11 var leftLowerLeg = EnfluxManager.NedOrientations.LeftLowerLeg.Orientation; 12 var rightUpperLeg = EnfluxManager.NedOrientations.RightUpperLeg.Orientation; 13 var rightLowerLeg = EnfluxManager.NedOrientations.RightLowerLeg.Orientation; 14 15 // 返り値の文字列を指定 16 return "胸 " + chest + "\n左肘 " + leftUpperArm + "\n左手首 " + leftLowerArm + "\n右肘 " + rightUpperArm + "\n右手首 " + rightLowerArm; 17}

ソースコードは「```」×2で囲うと見やすくなります。
また、エラーが出たのであれば、基本的にはその内容をコピペしてください。

投稿2017/12/13 00:52

fiveHundred

総合スコア9797

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

daityann

2017/12/13 01:11

ありがとうございます。できるようになりました! あともう一つ今console上に数値が出るようになったのですがその数値をpython上に渡してグラフ化したいと考えています。よろしければ教えていただけると助かります。 ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー private float timeleft; void Update() { timeleft -= Time.deltaTime; if (timeleft <= 0.0) { timeleft = 1.0f; Debug.Log(GetNedSpaceOrientations()); this.GetComponent<Text>().text = GetNedSpaceOrientations(); } } /* public void logSave(int num, string txt) { StreamWriter sw; FileInfo fi; fi = new FileInfo(Application.dataPath + "/FileName.csv"); sw = fi.AppendText(); sw.WriteLine("test output"); sw.Flush(); sw.Close(); } */ public void textSave(float GetNedSpaceOrientations) { StreamWriter sw = new StreamWriter("../aaaaa.txt", true); //true=追記 false=上書き sw.WriteLine(GetNedSpaceOrientations); sw.Flush(); sw.Close(); } } ーーーーーーーーーーーーーーーーーーーーーーーーー 現在テキストに書き出したいのですが、それもできていなくて。 エラーは出ていないのですが、うまくいっていなくて。 直接pythonに書き込むことができるならテキストに書き出す必要はないのですが。。。
fiveHundred

2017/12/13 01:57

「GetNedSpaceOrientations()」を数字の文字列(カンマかスペースで区切る)を出力するようにするか、そのような関数を作成し、その文字列を「textSave()」で保存する。 Python側では、その保存したファイルから値を取得し、グラフ化させる、というのはどうでしょうか? ちなみに、一応Unity上からPythonのスクリプトを実行する方法はあるそうですが、私は試したことがないので、よく分かりません。
daityann

2017/12/13 02:06

ありがとうございますやってみます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問