前提・実現したいこと
Logは残せるのですがエラーが発生しています。
どのようなエラーか把握できません。
発生している問題・エラーメッセージ
IOException: Sharing violation on path C:\Users\surfa\Desktop\New Unity Project 9\Assets\Log\hannteiLog\hanntei00.csv System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/FileStream.cs:320) System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share) (wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare) System.IO.FileInfo.Open (FileMode mode, FileAccess access, FileShare share) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/FileInfo.cs:210) System.IO.FileInfo.Open (FileMode mode, FileAccess access) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/FileInfo.cs:205) System.IO.FileInfo.AppendText () (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/FileInfo.cs:178) (wrapper remoting-invoke-with-check) System.IO.FileInfo:AppendText () hannteiLog.Update () (at Assets/hannteiLog.cs:40)
該当のソースコード
C# using UnityEngine; using System.IO; public class hannteiLog : MonoBehaviour { public Light attachedLight; public FoveInterfaceBase foveInterface; private Collider my_collider; private Material material; private bool light_attached = false; private string datetimeStr; void Start() { my_collider = GetComponent<Collider>(); if (attachedLight == null) attachedLight = transform.GetComponentInChildren<Light>(); if (attachedLight) { light_attached = true; attachedLight.enabled = false; } material = gameObject.GetComponent<Renderer>().material; if (material == null) gameObject.SetActive(false); } void Update() { StreamWriter sw; FileInfo fi; fi = new FileInfo(Application.dataPath + "/Log/hannteiLog/hanntei00.csv"); sw = fi.AppendText(); if (foveInterface.Gazecast(my_collider)) { material.EnableKeyword("_EMISSION"); if (light_attached) { material.SetColor("_EmissionColor", attachedLight.color); attachedLight.enabled = true; DynamicGI.SetEmissive(GetComponent<Renderer>(), attachedLight.color); datetimeStr = System.DateTime.Now.Year.ToString() + "." + System.DateTime.Now.Month.ToString() + "." + System.DateTime.Now.Day.ToString() + "." + System.DateTime.Now.Hour.ToString() + "." + System.DateTime.Now.Minute.ToString() + "." + System.DateTime.Now.Second.ToString() + "." + System.DateTime.Now.Millisecond.ToString(); sw.WriteLine(datetimeStr); } sw.Close(); } else { gameObject.GetComponent<Renderer>().material.color = Color.white; material.DisableKeyword("_EMISSION"); if (light_attached) { attachedLight.enabled = false; DynamicGI.SetEmissive(GetComponent<Renderer>(), Color.black); } } } }