ボタンがクリックされたら、csvに書き込むようにしたいのですができなくて困っています。
ここ↓ と2か所書いた場所でできると思っていたのですが、なにがおかしいでしょうか?それとも、unityのボタンのほうに原因があるのでしょうか?
c#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using Enflux.SDK.Core; 5using UnityEngine.UI; 6using System; 7using System.Linq; 8using Enflux.Common.DataTypes; 9using Enflux.SDK.Core.Devices; 10using Enflux.SDK.DataTypes; 11using Enflux.SDK.Extensions; 12using Enflux.SDK.Utils; 13using Enflux.Shim.Utils; 14using System.IO; 15 16public class math : MonoBehaviour 17{ 18 // Assign these in the editor. 19 public EnfluxManager EnfluxManager; 20 public Humanoid Humanoid; 21 // Retrieve limb orientations as Unity local space quaternions. 22 private void GetLocalSpaceOrientations() 23 { 24 var chest = Humanoid.LocalOrientations.Chest.Orientation; 25 var leftUpperArm = Humanoid.LocalOrientations.LeftUpperArm.Orientation; 26 var leftLowerArm = Humanoid.LocalOrientations.LeftLowerArm.Orientation; 27 var rightUpperArm = Humanoid.LocalOrientations.RightUpperArm.Orientation; 28 var rightLowerArm = Humanoid.LocalOrientations.RightLowerArm.Orientation; 29 var pelvis = Humanoid.LocalOrientations.Pelvis.Orientation; 30 var leftUpperLeg = Humanoid.LocalOrientations.LeftUpperLeg.Orientation; 31 var leftLowerLeg = Humanoid.LocalOrientations.LeftLowerLeg.Orientation; 32 var rightUpperLeg = Humanoid.LocalOrientations.RightUpperLeg.Orientation; 33 var rightLowerLeg = Humanoid.LocalOrientations.RightLowerLeg.Orientation; 34 } 35 36 // Retrieve limb orientations as real world NED (North-East-Down) space quaternions. 37 private string GetNedSpaceOrientations() 38 { 39 40 var chest = EnfluxManager.NedOrientations.Chest.Orientation; 41 var leftUpperArm = EnfluxManager.NedOrientations.LeftUpperArm.Orientation; 42 var leftLowerArm = EnfluxManager.NedOrientations.LeftLowerArm.Orientation; 43 var rightUpperArm = EnfluxManager.NedOrientations.RightUpperArm.Orientation; 44 var rightLowerArm = EnfluxManager.NedOrientations.RightLowerArm.Orientation; 45 var pelvis = EnfluxManager.NedOrientations.Pelvis.Orientation; 46 var leftUpperLeg = EnfluxManager.NedOrientations.LeftUpperLeg.Orientation; 47 var leftLowerLeg = EnfluxManager.NedOrientations.LeftLowerLeg.Orientation; 48 var rightUpperLeg = EnfluxManager.NedOrientations.RightUpperLeg.Orientation; 49 var rightLowerLeg = EnfluxManager.NedOrientations.RightLowerLeg.Orientation; 50 51 52 return "胸 " + chest + "\n左肘 " + leftUpperArm + "\n左手首 " + leftLowerArm + "\n右肘 " + rightUpperArm + "\n右手首 " + rightLowerArm + 53 "\n腰 " + pelvis + "\n左膝 " + leftUpperLeg + "\n左足首 " + leftLowerLeg + "\n右膝 " + rightUpperLeg + "\n右足首 " + rightLowerLeg + "\n\n"; 54 } 55 56 //時間 57 void FindSundayOfTheWeek() 58 { 59 System.DateTime work = System.DateTime.Now; 60 Debug.Log(work.ToString()); 61 } 62 63 //書き出し準備 64 private int i = 1; 65 StreamWriter sw; 66 FileInfo fi; 67 68 69 bool aa; 70 public void Push() 71 { 72 aa = true; 73 } 74 public void noPush() 75 { 76 aa = false; 77 } 78 79 void Start() 80 { 81 82 FindSundayOfTheWeek(); 83 84 //ファイル準備 85 fi = new FileInfo(Application.dataPath + "/" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".csv"); 86 sw = fi.AppendText(); 87 88 } 89 90 private float timeleft; 91 int log; 92 93 void Update() 94 { 95 96 if (i > 10000) 97 { 98 sw.Close(); 99 return; 100 } 101 timeleft -= Time.deltaTime; 102 if (timeleft <= 0.0) 103 { 104 timeleft = 1.0f; 105 106 //処理 107 Debug.Log(GetNedSpaceOrientations()); 108 this.GetComponent<Text>().text = GetNedSpaceOrientations(); 109 110 //書き出す 111 112 sw.WriteLine(GetNedSpaceOrientations()); 113 sw.Flush(); 114 115 i++; 116 } 117 } 118}
c#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using Enflux.SDK.Core; 5using UnityEngine.UI; 6using System; 7using System.Linq; 8using Enflux.Common.DataTypes; 9using Enflux.SDK.Core.Devices; 10using Enflux.SDK.DataTypes; 11using Enflux.SDK.Extensions; 12using Enflux.SDK.Utils; 13using Enflux.Shim.Utils; 14using System.IO; 15 16public class math : MonoBehaviour 17{ 18 // Assign these in the editor. 19 public EnfluxManager EnfluxManager; 20 public Humanoid Humanoid; 21 // Retrieve limb orientations as Unity local space quaternions. 22 private void GetLocalSpaceOrientations() 23 { 24 var chest = Humanoid.LocalOrientations.Chest.Orientation; 25 var leftUpperArm = Humanoid.LocalOrientations.LeftUpperArm.Orientation; 26 var leftLowerArm = Humanoid.LocalOrientations.LeftLowerArm.Orientation; 27 var rightUpperArm = Humanoid.LocalOrientations.RightUpperArm.Orientation; 28 var rightLowerArm = Humanoid.LocalOrientations.RightLowerArm.Orientation; 29 var pelvis = Humanoid.LocalOrientations.Pelvis.Orientation; 30 var leftUpperLeg = Humanoid.LocalOrientations.LeftUpperLeg.Orientation; 31 var leftLowerLeg = Humanoid.LocalOrientations.LeftLowerLeg.Orientation; 32 var rightUpperLeg = Humanoid.LocalOrientations.RightUpperLeg.Orientation; 33 var rightLowerLeg = Humanoid.LocalOrientations.RightLowerLeg.Orientation; 34 } 35 36 // Retrieve limb orientations as real world NED (North-East-Down) space quaternions. 37 private string GetNedSpaceOrientations() 38 { 39 var chest = EnfluxManager.NedOrientations.Chest.Orientation; 40 var leftUpperArm = EnfluxManager.NedOrientations.LeftUpperArm.Orientation; 41 var leftLowerArm = EnfluxManager.NedOrientations.LeftLowerArm.Orientation; 42 var rightUpperArm = EnfluxManager.NedOrientations.RightUpperArm.Orientation; 43 var rightLowerArm = EnfluxManager.NedOrientations.RightLowerArm.Orientation; 44 var pelvis = EnfluxManager.NedOrientations.Pelvis.Orientation; 45 var leftUpperLeg = EnfluxManager.NedOrientations.LeftUpperLeg.Orientation; 46 var leftLowerLeg = EnfluxManager.NedOrientations.LeftLowerLeg.Orientation; 47 var rightUpperLeg = EnfluxManager.NedOrientations.RightUpperLeg.Orientation; 48 var rightLowerLeg = EnfluxManager.NedOrientations.RightLowerLeg.Orientation; 49 50 51 return "胸 " + chest + "\n左肘 " + leftUpperArm + "\n左手首 " + leftLowerArm + "\n右肘 " + rightUpperArm + "\n右手首 " + rightLowerArm + 52 "\n腰 " + pelvis + "\n左膝 " + leftUpperLeg + "\n左足首 " + leftLowerLeg + "\n右膝 " + rightUpperLeg + "\n右足首 " + rightLowerLeg + "\n\n"; 53 } 54 55 //時間 56 void FindSundayOfTheWeek() 57 { 58 System.DateTime work = System.DateTime.Now; 59 Debug.Log(work.ToString()); 60 } 61 62 //書き出し準備 63 private int i = 1; 64 StreamWriter sw; 65 FileInfo fi; 66 67 int x = 0; 68 public void OnClick() 69 { 70 x++; 71 Debug.Log(x); 72 Debug.Log("Button click!"); 73 } 74 75void Start() 76 { 77 78 FindSundayOfTheWeek(); 79 80 //ファイル準備 81 fi = new FileInfo(Application.dataPath + "/" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".csv"); 82 sw = fi.AppendText(); 83 84 } 85 86 private float timeleft; 87 int log; 88 89 void Update() 90 { 91 if (i > 10000) 92 { 93 sw.Close(); 94 return; 95 } 96 timeleft -= Time.deltaTime; 97 if (timeleft <= 0.0) 98 { 99 timeleft = 1.0f; 100 101 //処理 102 Debug.Log(GetNedSpaceOrientations()); 103 this.GetComponent<Text>().text = GetNedSpaceOrientations(); 104 105 //書き出す 106 107 sw.WriteLine(GetNedSpaceOrientations()); 108 sw.Flush(); 109 110 i++; 111 } 112 } 113 } 114
出ていないなら出ていないと書きましょう。「できません」で済ませていいのははおじいさんおばあさんです。具体的にどうなるのかという記述がありません。以上を「エラーメッセージがありません」の一言で理解できると思っていました。
すみません。現在ボタンをクリックした際に書き込みをしたいのですが、On Click時に書き込みをしたいと考えています。しかし、ボタンを押しても変化がないのと、下記で指摘していただいているno functionのところでつまずいています。