// Use Awake() to initialize field variables. public void Awake() { //It is assumed that all the necessary components are already attached to CommHub gameObject, which is referred to by // gameObject field of this object, the current instance of the current Class. m_displayController = this.gameObject.GetComponent <DisplayScriptTreeOfVoice>(); m_actionPlanController = this.gameObject.GetComponent <ActionPlanController>(); m_actionPlanUpdateController = this.gameObject.GetComponent <ActionPlanUpdateController>(); m_boidsController = this.gameObject.GetComponent <SimpleBoidsTreeOfVoice>(); m_boidsRenderer = this.gameObject.GetComponent <BoidRendererTreeOfVoice>(); m_actionPlanFileManager = this.gameObject.GetComponent <ActionPlanFileManager>(); //debugging m_LEDColorGenController = this.gameObject.GetComponent <LEDColorGenController>(); // compute Shader use if (m_LEDColorGenController == null) { Debug.LogError("The component LEDColorGenController should be added to CommHub"); // Application.Quit(); } m_pointerEventsController = this.gameObject.GetComponent <PointerEventsController>(); // this gets the reference to the instance of class PointerEventsController // The instance is automatically created (by new PointerEventsController() ) when the component is added to the gameObject // The gameboject will has the reference to that instance. m_IRSensorMasterController = this.gameObject.GetComponent <IRSensorMasterController>(); m_LEDMasterController = this.gameObject.GetComponent <LEDMasterController>(); m_neuroHeadSetController = this.gameObject.GetComponent <NeuroHeadSetController>(); }
private void Awake() { m_LEDColorGenController = this.gameObject.GetComponent <LEDColorGenController>(); m_boids = this.gameObject.GetComponent <SimpleBoidsTreeOfVoice>(); if (m_boidLEDInstanceMaterial == null) { Debug.LogError("The global Variable m_boidLEDInstanceMaterial is not defined in Inspector"); // EditorApplication.Exit(0); Application.Quit(); //return; } m_instanceMeshCircle = new CircleMesh(m_unitRadius); // m_instanceMeshCylinder = new CylinderMesh(m_unitHeight, m_cylinderRadiusScale, nbSides, nbHeightSeg); //m_boidInstanceMesh = m_instanceMeshCylinder.m_mesh; m_boidInstanceMesh = m_instanceMeshCircle.m_mesh; m_boidLEDArgsBuffer = new ComputeBuffer( 1, m_boidLEDArgs.Length * sizeof(uint), ComputeBufferType.IndirectArguments ); } // Awake()
// Use Awake() to initialize field variables. public void Awake() { //ActionPlanController m_actionPlanController; //ActionPlanUpdateController m_actionPlanUpdateController; //SimpleBoidsTreeOfVoice m_boidsController; //BoidsRendererTreeOfVoice m_boidsRenderer; //DictManager m_dictManager; //LEDColorGenController m_ledColorGenController; //ButtonEventController m_buttonEventController; //PointerEventsController m_pointerEventsController; //IRSensorMasterController m_irSensorMasterController; //LEDMasterController m_ledMasterController; //NeuroHeadSetController m_neuroHeadSetController; //m_actionPlanController = gameObject.GetComponent<ActionPlanController>(); m_actionPlanUpdateController = gameObject.GetComponent <ActionPlanUpdateController>(); //m_boidsController = gameObject.GetComponent<SimpleBoidsTreeOfVoice>(); // m_boidsRenderer = gameObject.GetComponent<BoidsRendererTreeOfVoice>(); m_dictManager = gameObject.GetComponent <DictManager>(); m_ledColorGenController = gameObject.GetComponent <LEDColorGenController>(); // compute Shader use m_pointerEventsController = gameObject.GetComponent <PointerEventsController>(); // this gets the reference to the instance of class PointerEventsController // The instance is automatically created (by new PointerEventsController() ) when the component is added to the gameObject // The gameboject will has the reference to that instance. //m_irSensorMasterController = gameObject.GetComponent<IRSensorMasterController>(); //IRSensorMasterControlle component should be added to CommHub game object m_ledMasterController = gameObject.GetComponent <LEDMasterController>(); //LEDMasterController component should be added to CommHub game object //m_neuroHeadSetController = gameObject.GetComponent<NeuroHeadSetController>(); //NeuroHeadSetController component should be added to CommHub game object //In Start(): call actionPlanController.InitActionPlan //pointerEventController.onDrag += actionPlanController.ChangeActionTimes; //pointerEventController.onDrag += actionPlanController.RedrawActionPlan ==> NO, NO: all drawings are controlled by the Renderer Components such as // CanvasRenderer and LineRenderer. All you need to change is to change the locations and properties of the gameobjects involved. //pointerEventController.onPointerClick += actionPlanController.MergeOrSplitActionFields;; // two right mouse clicks merge or split the fields based on the position of the mouse within the field //inputField.onEndEdit += actionPlanController.ChangeActionValues //neuroHeadSetController.onReceived += boidsController.ChangeColorOfElectrodeBoids //irsensorMasterController.onReceived += boidsController.ChangeBrightnessOfInnerCircleBoids; // In Update call boidsController.SampleColorsAtLEDPoints // In Update call ledMasterController.SendLEDData // uiMenuController.onLoadActionPlan += actionPlanController.LoadActionPlan // uiMenuController.onSaveActionPlan += actionPlanController.SaveActionPlan }
//https://www.codeproject.com/Questions/1178661/How-do-I-receive-a-byte-array-over-the-serial-port //That is most likely because you only read the first byte. //Serial ports are extremely slow and you need to keep checking whether there is any data ready to read, //you cannot assume that you will get the complete message on your first attempt. //int MyInt = 1; //byte[] b = BitConverter.GetBytes(MyInt); //serialPort1.Write(b,0,4); void Start() { //m_ledColorGenController.m_ledSenderHandler += UpdateLEDArray; // THis is moved to CommHub.cs // public delegate LEDSenderHandler (byte[] LEDArray); defined in LEDColorGenController // public event LEDSenderHandler m_ledSenderHandler; m_LEDColorGenController = this.gameObject.GetComponent<LEDColorGenController>(); //m_LEDCount = m_LEDColorGenController.m_totalNumOfLEDs + 2; m_LEDCount = m_LEDColorGenController.m_totalNumOfLEDs;
void Start() { //m_ledColorGenController = gameObject.GetComponent<LEDColorGenController>(); ////It is assumed that all the necessary components are already attached to CommHub gameObject, which is referred to by //// gameObject field variable. gameObject.GetComponent<LEDColorGenController>() == this.gameObject.GetComponent<LEDColorGenController>(); //if (m_ledColorGenController == null) //{ // Debug.LogError("The global Variable m_ledColorGenController is not defined"); // Application.Quit(); //} //m_ledColorGenController.m_ledSenderHandler += UpdateLEDArray; // THis is moved to CommHub.cs // public delegate LEDSenderHandler (byte[] LEDArray); defined in LEDColorGenController // public event LEDSenderHandler m_ledSenderHandler; m_LEDColorGenController = this.gameObject.GetComponent <LEDColorGenController>(); m_LEDCount = m_LEDColorGenController.m_totalNumOfLEDs; m_LEDArray = new byte[m_LEDCount * 3]; // 280*3 = 840 < 1024 // define an action m_updateArduino = () => { //Debug.Log("Thread Run Test"); //Write(byte[] buffer, int offset, int count); // for debugging, comment out: try { m_serialPort.Write(m_LEDArray, 0, m_LEDArray.Length); } catch (Exception ex) { Debug.Log("Error:" + ex.ToString()); } // The WriteBufferSize of the Serial Port is 1024, whereas that of Arduino is 64; m_LEDArray is 200 * 3 = 600 bytes less than // the Serial Port size. //https://stackoverflow.com/questions/22768668/c-sharp-cant-read-full-buffer-from-serial-port-arduino }; m_Thread = new Thread(new ThreadStart(m_updateArduino)); // ThreadStart() is a delegate (pointer type) // Thread state = unstarted }
//https://www.codeproject.com/Questions/1178661/How-do-I-receive-a-byte-array-over-the-serial-port //That is most likely because you only read the first byte. //Serial ports are extremely slow and you need to keep checking whether there is any data ready to read, //you cannot assume that you will get the complete message on your first attempt. //int MyInt = 1; //byte[] b = BitConverter.GetBytes(MyInt); //serialPort1.Write(b,0,4); void Start() { //m_ledColorGenController.m_ledSenderHandler += UpdateLEDArray; // THis is moved to CommHub.cs // public delegate LEDSenderHandler (byte[] LEDArray); defined in LEDColorGenController // public event LEDSenderHandler m_ledSenderHandler; m_LEDColorGenController = this.gameObject.GetComponent <LEDColorGenController>(); //m_LEDCount = m_LEDColorGenController.m_totalNumOfLEDs + 2; m_LEDCount = m_LEDColorGenController.m_totalNumOfLEDs; m_LEDArray = new byte[m_LEDCount * 3]; // 186*3 < 1024 // define an action m_updateArduino = () => { try { //https://social.msdn.microsoft.com/Forums/vstudio/en-US/93583332-d307-4552-bd61-9a2adfcf2480/serial-port-write-method-is-blocking-execution?forum=vbgeneral //Yes, the Write methods do block , until all data have been passed from the serial port driver to the UART FIFO. //Usually, this is not a problem.It will not block "forever," just for as long as it takes. //For example, if you were to send a 2K byte string, at 9600 bps, the write method would take about 2 seconds to return. //Write(byte[] buffer, int offset, int count); m_serialPort.Write(m_startByte, 0, 1); m_serialPort.Write(m_LEDArray, 0, m_LEDArray.Length); } catch (Exception ex) { Debug.Log("Error:" + ex.ToString()); } // The WriteBufferSize of the Serial Port is 1024, whereas that of Arduino is 64; m_LEDArray is 200 * 3 = 600 bytes less than // the Serial Port size. //https://stackoverflow.com/questions/22768668/c-sharp-cant-read-full-buffer-from-serial-port-arduino }; // m_Thread = new Thread(new ThreadStart(m_updateArduino)); // ThreadStart() is a delegate (pointer type) // Thread state = unstarted }// void Start()
private void Start() { if (m_actionPlanController == null) { Debug.LogError(" m_actionPlanController should be set before use"); Application.Quit(); } m_actionPlan = m_actionPlanController.m_actionPlan; m_inputFieldContainer = m_actionPlanController.m_inputFieldContainer; // In Start(): call actionPlanController.InitActionPlan m_pointerEventsController.onDrag += m_actionPlanUpdateController.ChangeActionTime; //pointerEventController.onDrag += actionPlanController.RedrawActionPlan ==> NO, NO: all drawings are controlled by the Renderer Components such as // CanvasRenderer and LineRenderer. All you need to change is to change the locations and properties of the gameobjects involved. m_pointerEventsController.onPointerClick += m_actionPlanUpdateController.MergeOrSplitActionField; //two right mouse clicks merge or split the fields based on the position of the mouse within the field // inputField.onEndEdit += actionPlanController.ChangeActionValues ==> This will be done within actionPlanController.initActionPlan //m_neuroHeadSetController.onAverageSignalReceived += m_ledColorGenController.UpdateLEDResponseParameter; //m_irSensorMasterController.onAverageSignalReceived += m_ledColorGenController.UpdateColorBrightnessParameter; //In Update call m_boidsController.SampleColorsAtLEDPoints //In Update call ledMasterController.SendLEDData // m_actionPlanController.loadButton.onClick.AddListener(m_dictManager.LoadActionPlan ) ; //m_actionPlanController.saveButton.onClick.AddListener( m_dictManager.SaveActionPlan) ; m_ledColorGenController = gameObject.GetComponent <LEDColorGenController>(); //It is assumed that all the necessary components are already attached to CommHub gameObject, which is referred to by // gameObject field variable. gameObject.GetComponent<LEDColorGenController>() == this.gameObject.GetComponent<LEDColorGenController>(); if (m_ledColorGenController == null) { Debug.LogError("The global Variable m_ledColorGenController is not defined"); Application.Quit(); } m_ledColorGenController.m_ledSenderHandler += m_ledMasterController.UpdateLEDArray; // Define Event Handlers for InputField Event for (int i = 0; i < m_actionPlan.Count; i++) { KeyValuePair <string, List <SimpleBoidsTreeOfVoice.Action> > dictItem = m_actionPlan.ElementAt(i); for (int j = 0; j < dictItem.Value.Count; j++) { // Get the reference to m_inputFieldContainer[i][j].GetComponent<InputField>() InputField _inputField = m_inputFieldContainer[i][j].GetComponent <InputField>(); int indexToTimedAction = j; m_inputFieldContainer[i][j].GetComponent <InputField>().onEndEdit.AddListener ( val => { //if (Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter)) // { // Debug.Log("End edit on enter"); OnValueInput(m_actionPlan, dictItem.Key, indexToTimedAction, _inputField); // } } ); } // for j } // for i } //Start()