コード例 #1
0
    public void CSVSave(int x, string fileName)
    {
        StreamWriter sw;

        sw = new StreamWriter(Application.dataPath + "/Data/" + fileName + ".csv", true);

        int TestID  = ExperimentID.getTestID();
        int TrialID = TestID;

        if (TestID <= 2)
        {
            TrialID = TestID;
        }
        else
        {
            TrialID = ExperimentID.getTrialID();
        }
        int    AromaID   = ExperimentID.getAromaID();
        string Condition = ExperimentID.getCondition();

        string[] s1 = { TrialID.ToString(), AromaID.ToString(), Condition, x.ToString() };
        string   s2 = string.Join(",", s1);

        sw.WriteLine(s2);
        //sw.WriteLine(x.ToString());
        // 書き込みデータが配列の場合

        /*
         * for (int i = 0; i < x.Length; i++)
         * {
         *  sw.WriteLine(x[i].ToString());
         * }*/
        sw.Flush();
        sw.Close();
    }
コード例 #2
0
    // Start is called before the first frame update
    void Start()
    {
        //信号を受信したときに、そのメッセージの処理を行う
        serialHandler.OnDataReceived += OnDataReceived;

        totalTime = 15;

        TestID = ExperimentID.getTestID();

        //準備する香料の表示、鼻部皮膚温度制御の信号をArduinoへ送信
        string Condition = ExperimentID.getCondition();

        if (Condition == "A")
        {
            serialHandler.Write("h");
            Debug.Log("Hot command!");  // ログを出力
        }
        else if (Condition == "B" || Condition == "C")
        {
            serialHandler.Write("c");
            Debug.Log("Cool command!");  // ログを出力
        }

        int AromaID = ExperimentID.getAromaID();

        Debug.Log("Aroma ID : " + AromaID.ToString());
    }
コード例 #3
0
 //ArduinoからOKサインを受け取ったら、次のシーンに遷移する
 void OnDataReceived(string message)
 {
     try
     {
         Debug.Log("sign recieved");
         Debug.Log(message);
         string[] sign = message.Split(',');
         if (int.Parse(sign[0]) == 1)
         {
             Debug.Log("Scene Change");
             serialHandler.GetComponent <SerialHandler>().enabled = false;
             int TrialID = ExperimentID.getTrialID();
             if (TrialID == 1)
             {
                 SceneManager.LoadScene("Real_Scene");
             }
             else
             {
                 SceneManager.LoadScene("Explanation_Scene");
             }
         }
     }
     catch (System.Exception e)
     {
         Debug.LogWarning(e.Message);
     }
 }
コード例 #4
0
    // Start is called before the first frame update
    void Start()
    {
        //信号を受信したときに、そのメッセージの処理を行う
        serialHandler.OnDataReceived += OnDataReceived;

        totalTime = 15;

        //TestID, TrialIDの更新
        ExperimentID.addNumberOfTestID();
        TestID = ExperimentID.getTestID();
        if (TestID > 2)
        {
            ExperimentID.addNumberOfTrialID();
        }

        //準備する香料の表示、鼻部皮膚温度制御の信号をArduinoへ送信
        string Condition = ExperimentID.getCondition();

        if (Condition == "A" || Condition == "B")
        {
            serialHandler.Write("r");
            Debug.Log("Room Temperature command!");  // ログを出力
        }
        else if (Condition == "C")
        {
            serialHandler.Write("h");
            Debug.Log("Hot command!");  // ログを出力
        }

        int AromaID = ExperimentID.getAromaID();

        Debug.Log("Aroma ID : " + AromaID.ToString());
    }
コード例 #5
0
    // Start is called before the first frame update
    void Start()
    {
        //serialHandler.GetComponent<SerialHandler>().enabled = true;
        //信号を受信したときに、そのメッセージの処理を行う
        serialHandler.OnDataReceived += OnDataReceived;

        totalTime     = 15;
        GoFromArduino = false;

        //TestIDの更新
        ExperimentID.addNumberOfTestID();
        TestID  = ExperimentID.getTestID();
        TrialID = ExperimentID.getTrialID();

        //36試行まで終わったら、一度休憩
        if (TrialID == 36)
        {
            //ペルチェ素子にかかる電圧を0にする
            serialHandler.Write("o");
            Debug.Log("Off Command!");
            Debug.Log("Scene Change");
            //serialHandler.GetComponent<SerialHandler>().enabled = false;
            SceneManager.LoadScene("Intermission_Scene");
        }
        //72試行で実験終了
        else if (TrialID == 72)
        {
            //ペルチェ素子にかかる電圧を0にする
            serialHandler.Write("o");
            Debug.Log("Off Command!");
            Debug.Log("Scene Change");
            //serialHandler.GetComponent<SerialHandler>().enabled = false;
            SceneManager.LoadScene("End_Scene");
        }
        else
        {
            if (TestID > 2)
            {
                ExperimentID.addNumberOfTrialID();
            }
            TrialID = ExperimentID.getTrialID();
            //準備する香料の表示、鼻部皮膚温度制御の信号をArduinoへ送信
            string Condition = ExperimentID.getCondition();
            Debug.Log(Condition);
            if (Condition == "A" || Condition == "B")
            {
                serialHandler.Write("r");
                Debug.Log("Room Temperature command!");  // ログを出力
            }
            else if (Condition == "C")
            {
                serialHandler.Write("h");
                Debug.Log("Hot command!");  // ログを出力
            }

            int AromaID = ExperimentID.getAromaID();
            Debug.Log("Aroma ID : " + AromaID.ToString());
        }
    }
コード例 #6
0
    // Start is called before the first frame update
    void Start()
    {
        int TestID = ExperimentID.getTestID();

        if (TestID <= 2)
        {
            Debug.Log("Test : " + TestID.ToString());
        }
        else
        {
            int TrialID = ExperimentID.getTrialID();
            Debug.Log("Trial : " + TrialID.ToString());
        }
    }
コード例 #7
0
        /* ************************************************************************************************
        * Function Name: DoScience
        * Input: Position of the target, whether or not we're dealing with the FungEye or CactEye optics,
        *          the current field of view, and a screenshot.
        * Output: None
        * Purpose: This function will generate a science report based on the input parameters. This is an
        * override of a function prototype. This will generate a science report based on the target
        * celestial body. Science reports will only be generated if the target is a celestial body,
        * if the target is not the sun, if the target is visible in the scope, and if the telescope
        * is zoomed in far enough.
        * ************************************************************************************************/
        public override string DoScience(Vector3 TargetPosition, float scienceMultiplier, float FOV, Texture2D Screenshot)
        {
            CelestialBody Target = FlightGlobals.Bodies.Find(n => n.GetName() == FlightGlobals.fetch.VesselTarget.GetName());
            CelestialBody Home   = this.vessel.mainBody;

            //Sandbox or Career mode logic handled by gui.
            //if (HighLogic.CurrentGame.Mode == Game.Modes.SANDBOX)
            //{
            //    //CactEyeGUI.DisplayText("Science experiments unavailable in sandbox mode!");
            //    return;
            //}
            if (FlightGlobals.fetch.VesselTarget.GetType().Name != "CelestialBody")
            {
                //Invalid target type
                if (CactEyeConfig.DebugMode)
                {
                    Debug.Log("CactEye 2: Wide Field Camera: Invalid Target Type.");
                }
                return(Type + ": Invalid Target Type.");
            }
            else if (Target == FlightGlobals.Bodies[0])
            {
                //Cannot target the sun
                if (CactEyeConfig.DebugMode)
                {
                    Debug.Log("CactEye 2: Wide Field Camera: Cannot target the sun.");
                }
                return(Type + ": Cannot target the sun.");
            }
            else if (TargetPosition == new Vector3(-1, -1, 0))
            {
                //target not in scope
                if (CactEyeConfig.DebugMode)
                {
                    Debug.Log("CactEye 2: Wide Field Camera: Target not in scope.");
                }
                return(Type + ": Target not in scope field of view.");
            }

            //This has a tendency to be rather tempermental. If a player is getting false "Scope not zoomed in far enough" errors,
            //then the values here will need to be adjusted.
            else if (FOV > CactEyeAPI.bodySize[Target] * 50f)
            {
                //Scope not zoomed in far enough
                if (CactEyeConfig.DebugMode)
                {
                    Debug.Log("CactEye 2: Wide Field Camera: Scope not zoomed in far enough.");
                    Debug.Log("CactEye 2: Wide Field Camera: " + FOV.ToString());
                    Debug.Log("CactEye 2: Wide Field Camera: " + (CactEyeAPI.bodySize[Target] * 50f).ToString());
                }
                return(Type + ": Scope not zoomed in far enough.");
            }

            //Check to see if target is blocked.
            else if (CactEyeAPI.CheckOccult(Target) != "")
            {
                if (CactEyeConfig.DebugMode)
                {
                    Debug.Log("CactEye 2: Target is occulted by another body.");
                }
                return(Type + ": Target is occulted by another body.");
            }

            else
            {
                float             SciencePoints = 0f;
                string            TargetName    = Target.name;
                ScienceExperiment WideFieldExperiment;
                ScienceSubject    WideFieldSubject;

                bool          withParent;
                CelestialBody parentBody;


                ExperimentID = "CactEyePlanetary" + TargetName;
                try
                {
                    WideFieldExperiment = ResearchAndDevelopment.GetExperiment(ExperimentID);
                    WideFieldSubject    = ResearchAndDevelopment.GetExperimentSubject(WideFieldExperiment, ExperimentSituations.InSpaceHigh, Home, "");
                    SciencePoints       = WideFieldExperiment.baseValue * WideFieldExperiment.dataScale * maxScience * scienceMultiplier;
                    if (CactEyeConfig.DebugMode)
                    {
                        Debug.Log("CactEye 2: SciencePoints: " + SciencePoints.ToString());
                    }

                    //Different scopes have different multipliers for the science gains.
//                    SciencePoints *= scienceMultiplier;

                    ScienceData Data = new ScienceData(SciencePoints, 1f, 0f, WideFieldSubject.id, Type + " " + TargetName + " Observation");
                    StoredData.Add(Data);
                    ReviewData(Data, Screenshot);
                    if (RBWrapper.APIRBReady)
                    {
                        Debug.Log("CactEye 2: Wrapper ready");

                        RBWrapper.CelestialBodyInfo cbi;

                        RBWrapper.RBactualAPI.CelestialBodies.TryGetValue(Target, out cbi);
                        if (!cbi.isResearched)
                        {
                            int RBFoundScience = (int)(8f * WideFieldExperiment.dataScale);
                            RBWrapper.RBactualAPI.FoundBody(RBFoundScience, Target, out withParent, out parentBody);
                        }
                        else
                        {
                            System.Random rnd = new System.Random();
                            RBWrapper.RBactualAPI.Research(Target, rnd.Next(1, 11));
                        }
                    }
                    else
                    {
                        Debug.Log("CactEye 2: Wrapper not ready");
                    }
                }

                catch (Exception e)
                {
                    Debug.Log("CactEye 2: Excpetion 5: Was not able to find Experiment with ExperimentID: " + ExperimentID.ToString());
                    Debug.Log(e.ToString());

                    return("An error occurred. Please post on the Official CactEye 2 thread on the Kerbal Forums.");
                }

                return("");
            }
        }
コード例 #8
0
        /* ************************************************************************************************
        * Function Name: DoScience
        * Input: Position of the target, whether or not we're dealing with the FungEye or CactEye optics,
        *          the current field of view, and a screenshot.
        * Output: None
        * Purpose: This function will generate a science report based on the input parameters. This is an
        * override of a function prototype. This will generate a science report based on the target
        * celestial body. Science reports will only be generated if the target is a celestial body,
        * if the target is not the sun, if the target is visible in the scope, and if the telescope
        * is zoomed in far enough.
        * ************************************************************************************************/
        public override string DoScience(Vector3 TargetPosition, bool IsSmallOptics, float FOV, Texture2D Screenshot)
        {
            CelestialBody Target = FlightGlobals.Bodies.Find(n => n.GetName() == FlightGlobals.fetch.VesselTarget.GetName());

            //Sandbox or Career mode logic handled by gui.
            //if (HighLogic.CurrentGame.Mode == Game.Modes.SANDBOX)
            //{
            //    //CactEyeGUI.DisplayText("Science experiments unavailable in sandbox mode!");
            //    return;
            //}
            if (FlightGlobals.fetch.VesselTarget.GetType().Name != "CelestialBody")
            {
                //Invalid target type
                if (CactEyeConfig.DebugMode)
                {
                    Debug.Log("CactEye 2: Wide Field Camera: Invalid Target Type.");
                }
                return(Type + ": Invalid Target Type.");
            }
            else if (Target == FlightGlobals.Bodies[0])
            {
                //Cannot target the sun
                if (CactEyeConfig.DebugMode)
                {
                    Debug.Log("CactEye 2: Wide Field Camera: Cannot target the sun.");
                }
                return(Type + ": Cannot target the sun.");
            }
            else if (TargetPosition == new Vector3(-1, -1, 0))
            {
                //target not in scope
                if (CactEyeConfig.DebugMode)
                {
                    Debug.Log("CactEye 2: Wide Field Camera: Target not in scope.");
                }
                return(Type + ": Target not in scope field of view.");
            }

            //This has a tendency to be rather tempermental. If a player is getting false "Scope not zoomed in far enough" errors,
            //then the values here will need to be adjusted.
            else if (FOV > CactEyeAPI.bodySize[Target] * 50f)
            {
                //Scope not zoomed in far enough
                if (CactEyeConfig.DebugMode)
                {
                    Debug.Log("CactEye 2: Wide Field Camera: Scope not zoomed in far enough.");
                    Debug.Log("CactEye 2: Wide Field Camera: " + FOV.ToString());
                    Debug.Log("CactEye 2: Wide Field Camera: " + (CactEyeAPI.bodySize[Target] * 50f).ToString());
                }
                return(Type + ": Scope not zoomed in far enough.");
            }

            //Check to see if target is blocked.
            else if (CactEyeAPI.CheckOccult(Target) != "")
            {
                if (CactEyeConfig.DebugMode)
                {
                    Debug.Log("CactEye 2: Target is occulted by another body.");
                }
                return(Type + ": Target is occulted by another body.");
            }

            else
            {
                float             SciencePoints = 0f;
                string            TargetName    = Target.name;
                ScienceExperiment WideFieldExperiment;
                ScienceSubject    WideFieldSubject;

                try
                {
                    WideFieldExperiment = ResearchAndDevelopment.GetExperiment(ExperimentID);
                    WideFieldSubject    = ResearchAndDevelopment.GetExperimentSubject(WideFieldExperiment, ExperimentSituations.InSpaceHigh, Target, "");

                    SciencePoints += WideFieldExperiment.baseValue * WideFieldExperiment.dataScale * maxScience;

                    if (CactEyeConfig.DebugMode)
                    {
                        Debug.Log("CactEye 2: SciencePoints: " + SciencePoints.ToString());
                    }

                    if (IsSmallOptics)
                    {
                        SciencePoints *= 0.1f;
                    }

                    ScienceData Data = new ScienceData(SciencePoints, 1f, 0f, WideFieldSubject.id, Type + " " + TargetName + " Observation");
                    StoredData.Add(Data);
                    ReviewData(Data, Screenshot);
                }

                catch (Exception e)
                {
                    Debug.Log("CactEye 2: Excpetion 5: Was not able to find Experiment with ExperimentID: " + ExperimentID.ToString());
                    Debug.Log(e.ToString());

                    return("An error occurred. Please post on the Official CactEye 2 thread on the Kerbal Forums.");
                }

                return("");
            }
        }