示例#1
0
    // 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>();
    }
    } // Awake()

    void Start()
    {
        //initialize others
        m_boids = this.gameObject.GetComponent <SimpleBoidsTreeOfVoice>();


        //m_BoidBuffer = m_boids.m_BoidBuffer;

        if (m_boids == null)
        {
            Debug.LogError("SimpleBoidsTreeOfVoice component should be added to CommHub");
            // Application.Quit();
#if UNITY_EDITOR
            // Application.Quit() does not work in the editor so
            //  UnityEditor.EditorApplication.isPlaying = false;
            //UnityEditor.EditorApplication.Exit(0);
#else
            //Application.Quit();
#endif
        }


        m_BoidLEDComputeShader.SetFloat("_CeilingInnerRadius", m_startingRadiusOfInnerChain);
        m_BoidLEDComputeShader.SetFloat("_MaxChainRadius", m_endingRadiusOfOuterChainThreeTurns);

        m_BoidLEDComputeShader.SetFloat("_Hemisphere", m_Hemisphere);

        m_BoidLEDComputeShader.SetFloat("_MaxDomainRadius", m_boids.m_MaxDomainRadius);
        // m_BoidLEDComputeShader.SetFloat("_MinDomainRadius", m_boids.m_MinDomainRadius);
        m_BoidLEDComputeShader.SetFloat("_CeilingInnerRadius", m_boids.m_CeilingInnerRadius);

        //m_BoidsNum = (int)m_boids.m_BoidsNum;

        m_BoidLEDComputeShader.SetInt("_BoidsNum", (int)m_boids.m_BoidsNum);

        m_BoidLEDComputeShader.SetBuffer(m_kernelIDLED, "_BoidBuffer", m_boids.m_BoidBuffer);

        m_BoidLEDComputeShader.SetInt("_ColorSamplingMethod", m_colorSamplingMethod);

        m_BoidLEDComputeShader.SetFloat("_SamplingRadius", m_samplingRadius);


        //define BoidLED Buffer

        m_BoidLEDBuffer = new ComputeBuffer(m_totalNumOfLEDs, Marshal.SizeOf(typeof(BoidLEDData)));

        m_BoidLEDArray = new BoidLEDData[m_totalNumOfLEDs];

        //For each kernel we are setting the buffers that are used by the kernel, so it would read and write to those buffers

        // For the part of boidArray that is set by data are filled by null.
        // When the array boidArray is created each element is set by null.

        // create a m_BoidLEDArray to link to m_BoidLEDBuffer:
        SetBoidLEDArray(m_BoidLEDArray);         // THe Boid LEDs array is defined without their colors

        m_BoidLEDBuffer.SetData(m_BoidLEDArray); // buffer is R or RW

        m_BoidLEDComputeShader.SetBuffer(m_kernelIDLED, "_BoidLEDBuffer", m_BoidLEDBuffer);
    }// void Start()
示例#3
0
    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()
    } // Awake()

    void Start()
    {
        //initialize others
        m_boids = this.gameObject.GetComponent <SimpleBoidsTreeOfVoice>();


        //m_BoidBuffer = m_boids.m_BoidBuffer;

        if (m_boids == null)
        {
            Debug.LogError("impleBoidsTreeOfVoice component should be added to CommHub");
            // Application.Quit();
            return;
        }



        m_BoidLEDComputeShader.SetFloat("_MaxDomainRadius", m_boids.m_MaxDomainRadius);
        m_BoidLEDComputeShader.SetFloat("_MinDomainRadius", m_boids.m_MinDomainRadius);

        //m_BoidsNum = (int)m_boids.m_BoidsNum;

        m_BoidLEDComputeShader.SetInt("_BoidsNum", (int)m_boids.m_BoidsNum);

        m_BoidLEDComputeShader.SetBuffer(m_kernelIDLED, "_BoidBuffer", m_boids.m_BoidBuffer);


        m_BoidLEDComputeShader.SetFloat("_SamplingRadius", m_samplingRadius);


        //define BoidLED Buffer

        m_BoidLEDBuffer = new ComputeBuffer(m_totalNumOfLEDs, Marshal.SizeOf(typeof(BoidLEDData)));

        m_BoidLEDArray = new BoidLEDData[m_totalNumOfLEDs];

        //For each kernel we are setting the buffers that are used by the kernel, so it would read and write to those buffers

        // For the part of boidArray that is set by data are filled by null.
        // When the array boidArray is created each element is set by null.

        // create a m_BoidLEDArray to link to m_BoidLEDBuffer:
        SetBoidLEDArray(m_BoidLEDArray);         // THe Boid LEDs array is defined without their colors

        m_BoidLEDBuffer.SetData(m_BoidLEDArray); // buffer is R or RW

        m_BoidLEDComputeShader.SetBuffer(m_kernelIDLED, "_BoidLEDBuffer", m_BoidLEDBuffer);
    }// void Start()
示例#5
0
    } // Awake()

    void Start()
    {
        //initialize others
        m_boids = this.gameObject.GetComponent <SimpleBoidsTreeOfVoice>();

        //m_BoidBuffer = m_boids.m_BoidBuffer;

        if (m_boids == null)
        {
            Debug.LogError("impleBoidsTreeOfVoice component should be added to CommHub");
            // Application.Quit();
            return;
        }

        m_BoidsNum = (int)m_boids.m_BoidsNum;


        m_BoidLEDComputeShader.SetInt("_BoidsNum", (int)m_BoidsNum);

        m_BoidLEDComputeShader.SetBuffer(m_kernelIDLED, "_BoidBuffer", m_boids.m_BoidBuffer);
    }// void Start()
    void Start()
    {       // initialize others
        // get the reference to SimpleBoidsTreeOfVoice

        m_boids = this.gameObject.GetComponent <SimpleBoidsTreeOfVoice>();


        if (m_boids == null)
        {
            Debug.LogError("SimpleBoidsTreeOfVoice component should be attached to CommHub");
            //EditorApplication.Exit(0);
            // Application.Quit();
            return;
        }



        // check if _boids.BoidBuffer is not null
        if (m_boids.m_BoidBuffer is null)
        {
            return;                               // nothing to render;
        }
        // _boids.BoidBuffer.GetData(boidArray);
        // https://unity3d.com/kr/learn/tutorials/topics/graphics/gentle-introduction-shaders

        //Debug.Log("Current Num of Boids=");
        //Debug.Log(_boids.BoidsNum);


        //https://answers.unity.com/questions/979080/how-to-pass-an-array-to-a-shader.html
        //_instanceMaterial.SetFloatArray("GroundMaxCorner", GroundMaxCornerF);
        //_instanceMaterial.SetFloatArray("GroundMinCorner", GroundMinCornerF);

        // _instanceMaterial.SetFloatArray("CeilingMaxCorner", CeilingMaxCornerF);
        // _instanceMaterial.SetFloatArray("CeilingMinCorner", CeilingMinCornerF);

        // // Shader vectors are always Vector4s.
        // But the value here is converted to a Vector3.
        //Vector3 value = Vector3.one;
        //Renderer renderer = GetComponent<Renderer>();
        //renderer.material.SetVector("_SomeVariable", value);

        // Use SetVector() rather than setFloatArray


        // BOIDS Drawing

        numIndices = m_boidInstanceMesh ? m_boidInstanceMesh.GetIndexCount(0) : 0;
        //GetIndexCount(submesh = 0)



        m_boidArgs[0] = numIndices;               // the number of indices in the set of triangles
        m_boidArgs[1] = (uint)m_boids.m_BoidsNum; // the number of instances

        m_boidArgsBuffer.SetData(m_boidArgs);


        m_boidInstanceMaterial.SetVector("_Scale", new Vector3(m_scale, m_scale, m_scale));

        //m_boidInstanceMaterial.SetVector("GroundMaxCorner", m_boids.GroundMaxCorner);
        //m_boidInstanceMaterial.SetVector("GroundMinCorner", m_boids.GroundMinCorner);

        //m_boidInstanceMaterial.SetVector("CeilingMaxCorner", m_boids.CeilingMaxCorner);
        //m_boidInstanceMaterial.SetVector("CeilingMinCorner", m_boids.CeilingMinCorner);

        m_boidInstanceMaterial.SetBuffer("_BoidBuffer", m_boids.m_BoidBuffer);
        // m_boids.BoidBuffer is ceated in SimpleBoids.cs
        // This buffer is shared between CPU and GPU
    } // Start()
    } // Awake()

    void SetupButtonGUI()
    {
        Debug.Log("I am in Canvas Test");



        //"initialize my connections to others, which have been initialized by their own Awake()

        // Check if global components are defined
        m_boidsController = this.gameObject.GetComponent <SimpleBoidsTreeOfVoice>();

        if (m_boidsController == null)
        {
            Debug.LogError("The component SimpleBoidsTreeOfVoice should be added to CommHub");
            //Application.Quit();
        }
        // m_actionPlan = m_boidsController.m_actionPlan; // m_actionPlan is created in this script

        float m_AnimationCycle = m_boidsController.m_AnimationCycle;


        // set the sizes of the canvas, the scrollRect, and the content Rect

        m_canvasHeight = (int)m_canvas.pixelRect.height;

        //The pixel size of the canvas is set to the resolution of the game view,
        //  which is the target display of the Event Camera (Screen Space-Camera mode);
        // We will change the canvas mode to WorldSpace later. But we will use this
        // canvas size to set the size of the scrollView

        m_canvasWidth = (int)m_canvas.pixelRect.width;

        //m_scrollRectWidth = m_canvasWidth;
        //m_scrollRectHeight = m_canvasHeight;


        // The content is displayed on the scroll view rect which includes the view port, the horizontal scrollbar, and the
        // vertial scroll bar at the bottom most part and the right most part of the scroll view. The right most part of
        // the content will be occluded by the vertical scroll bar. So, the extra empty area is added to the content panel.


        m_canvasObj.GetComponent <RectTransform>().sizeDelta
            = new Vector2(m_canvasWidth, m_canvasHeight);

        // Make the size of the canvas (to which the Event Camera's view volume is defined) equal to the size of the
        // content panel onto which the contents of the UI are specified. The part of which defined by the viewport
        // will be displayed on the screen

        // m_canvasObj.GetComponent<RectTransform>().localPosition =  new Vector3(0,0,0);
        //  m_canvasObj.GetComponent<RectTransform>().sizeDelta
        //                            = new Vector2(m_contentWidth, m_contentHeight);
        // This does not change the size of the  canvas in Screen Space mode. It is fixed to the gameview screen size at the beginning.
        // To use the custom size canvas, use "World Space" canvas mode: https://forum.unity.com/threads/setting-custom-canvas-size.263788/



        // Set the Event Camera so that its view volume covers the entire content panel

        // The canvas for the event camera is located at z =0; The size of the canvas is the same as the size of
        // the world in which boids move. The event camera for the canvas is set in UISetActionPlan.cs

        //m_canvasObj.GetComponent<RectTransform>().transform.localScale)

        Camera eventCamera;

        // Get the reference to the Event Camera
        eventCamera = GameObject.Find("EventCamera").GetComponent <Camera>();


        Debug.Log(eventCamera.name + ": camera pos=");
        Debug.Log(eventCamera.transform.position);

        Vector3 targetPos = m_canvas.GetComponent <RectTransform>().position;


        Debug.Log("camera targetPos=");
        Debug.Log(targetPos);


        Debug.Log("computed target vector:");

        Vector3 vecToTarget = targetPos - eventCamera.transform.position;

        Debug.Log(vecToTarget);

        float canvasWidth  = m_canvas.GetComponent <RectTransform>().sizeDelta[0];
        float canvasHeight = m_canvas.GetComponent <RectTransform>().sizeDelta[1];

        float heightOfFOV = canvasHeight;
        float fieldOfView = 2.0f * Mathf.Rad2Deg *
                            Mathf.Atan(heightOfFOV / vecToTarget.magnitude);


        Debug.Log("computed field of view:");
        Debug.Log(fieldOfView);

        Debug.Log("computed aspect (width/height):");

        float aspect = canvasWidth / canvasHeight;

        Debug.Log(aspect);



        // Define save Buttons:


        //GameObject saveButtonObj = new GameObject("Action Save Button");
        //GameObject saveButtonTextObj = new GameObject("Action  Button Text");

        //saveButtonObj.transform.SetParent(m_canvasObj.transform, false);

        //saveButtonTextObj.transform.SetParent(saveButtonObj.transform, false);

        //        m_canvasObj = this.gameObject.transform.GetChild(0).gameObject;

        //GameObject saveButtonObj = m_canvasObj.transform.GetChild(1).gameObject;

        GameObject saveButtonObj = m_canvasObj.transform.GetChild(0).gameObject;

        //saveButtonObj.AddComponent<RectTransform>();
        //saveButtonObj.AddComponent<CanvasRenderer>(); // CanvasRenderer component is used to render Button
        //saveButtonObj.AddComponent<Button>();
        //saveButtonObj.layer = 5;

        // save the saveButton to used by other components and places
        m_saveButton = saveButtonObj.GetComponent <Button>();

        //anchorMin: The normalized position in the parent RectTransform that the upper right corner of this Rect is anchored to.
        //anchorMin: The normalized position in the parent RectTransform that the lower left corner of this Rect is anchored to.
        saveButtonObj.GetComponent <RectTransform>().anchorMin = new Vector2(0, 1);
        saveButtonObj.GetComponent <RectTransform>().anchorMax = new Vector2(0, 1);
        saveButtonObj.GetComponent <RectTransform>().pivot     = new Vector2(0, 1);
        //anchoredPosition:   The position of the left top pivot of this RectTransform relative to the left top anchor reference point.
        // m_timeTopBarContainer[0].GetComponent<RectTransform>().anchoredPosition = new Vector3(0, 0, 0);


        //  Set the pivot of this Rect ( m_timeTopBarContainer[0] Rect) relative to the anchor frame
        //  which is the left top of the ContentTitle Rect
        //  saveButtonObj.GetComponent<RectTransform>().anchoredPosition = new Vector3(m_paramTextWidth, m_canvasHeight-m_paramTextHeight, 0.0f);

        saveButtonObj.GetComponent <RectTransform>().anchoredPosition3D = new Vector3(0, m_canvasHeight - m_paramTextHeight, -1);
        //saveButtonObj.GetComponent<RectTransform>().anchoredPosition = new Vector3(m_paramTextWidth, m_canvasHeight-m_paramTextHeight, 0.0f);

        saveButtonObj.GetComponent <RectTransform>().sizeDelta = new Vector2(m_paramTextWidth, m_paramTextHeight);
        //NOTE:

        //m_scrollRectWidth = m_canvasWidth;
        //m_scrollRectHeight = m_canvasHeight - (int)m_paramTextHeight;
        //// The scrollView contains the viewport and the horizotal and vertical bar;
        //// Make space for the save and load buttons just below the scrollView
        //// within the canvas => Make the vertical size of the scrollView shorter.

        //saveButtonTextObj.layer = 5;
        //saveButtonTextObj.AddComponent<RectTransform>();
        ////m_textContainer[i][j].AddComponent<CanvasRenderer>();  // // canvasRender is added automatically

        //saveButtonTextObj.AddComponent<Text>();
        //saveButtonTextObj.AddComponent<CanvasRenderer>();

        //saveButtonTextObj.GetComponent<RectTransform>().anchorMin = new Vector2(0, 1);
        //saveButtonTextObj.GetComponent<RectTransform>().anchorMax = new Vector2(0, 1);
        //saveButtonTextObj.GetComponent<RectTransform>().pivot = new Vector2(0, 1);
        //saveButtonTextObj.GetComponent<RectTransform>().anchoredPosition = new Vector3(0.0f, 0.0f, 0.0f);
        //// the center pivot position wrt its left top frame
        //saveButtonTextObj.GetComponent<RectTransform>().sizeDelta = new Vector2(m_paramTextWidth, m_paramTextHeight);


        String saveButtonLablel = "Save Action Plan";

        // set the properties of the textComponent Field of the input field
        //saveButtonTextObj.GetComponent<Text>().supportRichText = false;
        //saveButtonTextObj.GetComponent<Text>().color = new Color(0f, 0f, 0f);

        //Font ArialFontField = (Font)Resources.GetBuiltinResource(typeof(Font), "Arial.ttf");
        // text.font = ArialFont;
        // text.material = ArialFont.material;


        //saveButtonTextObj.GetComponent<Text>().font = ArialFont;
        //saveButtonTextObj.GetComponent<Text>().material = ArialFont.material;

        //saveButtonTextObj.GetComponent<Text>().fontSize = 12;
        //saveButtonTextObj.GetComponent<Text>().lineSpacing = 1;
        //saveButtonTextObj.GetComponent<Text>().alignment = TextAnchor.MiddleCenter;
        //saveButtonTextObj.GetComponent<Text>().horizontalOverflow = HorizontalWrapMode.Overflow;
        //saveButtonTextObj.GetComponent<Text>().verticalOverflow = VerticalWrapMode.Overflow;

        // _textComponentField.horizontalOverflow = HorizontalWrapMode.Wrap;
        // _textComponentField.verticalOverflow = VerticalWrapMode.Truncate;

        //saveButtonTextObj.GetComponent<Text>().text = saveButtonLablel;

        // Button has a child gameObject called "Text" which has a Text Component.

        saveButtonObj.transform.GetChild(0).gameObject.GetComponent <Text>().text = saveButtonLablel;

        // Define load Buttons:

        // GameObject loadButtonObj = m_canvasObj.transform.GetChild(2).gameObject;
        GameObject loadButtonObj = m_canvasObj.transform.GetChild(1).gameObject;


        //GameObject loadButtonObj = new GameObject("Load Save Button");
        //GameObject loadButtonTextObj = new GameObject("Action  Button Text");

        //loadButtonObj.transform.SetParent(m_canvasObj.transform, false);

        //loadButtonTextObj.transform.SetParent(loadButtonObj.transform, false);

        //loadButtonObj.AddComponent<RectTransform>();
        //loadButtonObj.AddComponent<CanvasRenderer>();
        //loadButtonObj.AddComponent<Button>();
        //loadButtonObj.layer = 5;

        // save the loadButton to used by other components and places
        m_loadButton = loadButtonObj.GetComponent <Button>();

        //anchorMin: The normalized position in the parent RectTransform that the upper right corner of this Rect is anchored to.
        //anchorMin: The normalized position in the parent RectTransform that the lower left corner of this Rect is anchored to.
        loadButtonObj.GetComponent <RectTransform>().anchorMin = new Vector2(0, 1);
        loadButtonObj.GetComponent <RectTransform>().anchorMax = new Vector2(0, 1);
        loadButtonObj.GetComponent <RectTransform>().pivot     = new Vector2(0, 1);
        //anchoredPosition:   The position of the left top pivot of this RectTransform relative to the left top anchor reference point.
        // m_timeTopBarContainer[0].GetComponent<RectTransform>().anchoredPosition = new Vector3(0, 0, 0);


        //  Set the pivot of this Rect ( m_timeTopBarContainer[0] Rect) relative to the anchor frame which is the left top of the ContentTitle Rect
        loadButtonObj.GetComponent <RectTransform>().anchoredPosition3D = new Vector3(m_paramTextWidth, m_canvasHeight - m_paramTextHeight, -1);

        // saveButtonObj.GetComponent<RectTransform>().anchoredPosition = new Vector3(0, m_canvasHeight - m_paramTextHeight, 0.0f);

        //loadButtonObj.GetComponent<RectTransform>().anchoredPosition = new Vector3(0, m_canvasHeight - m_paramTextHeight, 0.0f);
        loadButtonObj.GetComponent <RectTransform>().sizeDelta = new Vector2(m_paramTextWidth, m_paramTextHeight);


        //loadButtonTextObj.layer = 5;
        //loadButtonTextObj.AddComponent<RectTransform>();
        ////m_textContainer[i][j].AddComponent<CanvasRenderer>();  // // canvasRender is added automatically

        //loadButtonTextObj.AddComponent<Text>();

        //loadButtonTextObj.AddComponent<CanvasRenderer>();
        //loadButtonTextObj.GetComponent<RectTransform>().anchorMin = new Vector2(0, 1);
        //loadButtonTextObj.GetComponent<RectTransform>().anchorMax = new Vector2(0, 1);
        //loadButtonTextObj.GetComponent<RectTransform>().pivot = new Vector2(0, 1);
        //loadButtonTextObj.GetComponent<RectTransform>().anchoredPosition = new Vector3(0.0f, 0.0f, 0.0f);
        //// the center pivot position wrt its left top frame
        //loadButtonTextObj.GetComponent<RectTransform>().sizeDelta = new Vector2(m_paramTextWidth, m_paramTextHeight);


        String loadButtonLablel = "load Action Plan";

        //// set the properties of the textComponent Field of the input field
        //loadButtonTextObj.GetComponent<Text>().supportRichText = false;
        //loadButtonTextObj.GetComponent<Text>().color = new Color(0f, 0f, 0f);

        ////Font ArialFontField = (Font)Resources.GetBuiltinResource(typeof(Font), "Arial.ttf");
        //// text.font = ArialFont;
        //// text.material = ArialFont.material;


        //loadButtonTextObj.GetComponent<Text>().font = ArialFont;
        //loadButtonTextObj.GetComponent<Text>().material = ArialFont.material;

        //loadButtonTextObj.GetComponent<Text>().fontSize = 12;
        //loadButtonTextObj.GetComponent<Text>().lineSpacing = 1;
        //loadButtonTextObj.GetComponent<Text>().alignment = TextAnchor.MiddleCenter;
        //loadButtonTextObj.GetComponent<Text>().horizontalOverflow = HorizontalWrapMode.Overflow;
        //loadButtonTextObj.GetComponent<Text>().verticalOverflow = VerticalWrapMode.Overflow;

        //// _textComponentField.horizontalOverflow = HorizontalWrapMode.Wrap;
        //// _textComponentField.verticalOverflow = VerticalWrapMode.Truncate;

        loadButtonObj.transform.GetChild(0).gameObject.GetComponent <Text>().text = loadButtonLablel;

        //loadButtonTextObj.GetComponent<Text>().text = loadButtonLablel;
    } //   void SetupButtonGUI()