コード例 #1
0
 // used for the custom event handlers
 public void PlatformDataNode_OnUpdatePlatformDataNodeUI(PlatformDataNode pdn)
 {
     //UI is updated when a tile is selected
     SelectedNodeName.text     = string.Format("Node [{0},{1}]", pdn.i, pdn.j);
     SelectedNodePosition.text = string.Format("Height: {0:0.00}f", pdn.NextPosition);
     HeightSlider.value        = pdn.NextPosition;
 }
コード例 #2
0
    // used to create that one instance of the platform
    public void BuildPlatform()
    {
        platform = new GameObject[configurationData.M, configurationData.N];
        for (int i = 0; i < configurationData.M; i++)
        {
            for (int j = 0; j < configurationData.N; j++)
            {
                // create the actual cubes that will be used as nodes
                GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
                cube.transform.position   = new Vector3(i + (i * configurationData.deltaSpacing), 0, j + (j * configurationData.deltaSpacing));
                cube.transform.rotation   = Quaternion.identity;
                cube.transform.localScale = new Vector3(1, 0.1f, 1);
                cube.name = string.Format("Cube-{0}-{1}", i, j);
                cube.GetComponent <Renderer>().material = myMaterial;

                // set the i, j, next position, and next color of each node
                cube.AddComponent <PlatformDataNode>();
                PlatformDataNode pdn = cube.GetComponent <PlatformDataNode>();
                pdn.NextColor    = Color.white;
                pdn.NextPosition = cube.transform.position.y;
                pdn.node         = cube;

                pdn.i = i;
                pdn.j = j;

                // finally add it to the game object platform
                platform[i, j] = cube;
            }
        }
    }
コード例 #3
0
    // updating Programming scene UI using data from node
    private void PlatformDataNode_OnUpdatePlatformDataNodeUI(PlatformDataNode pdn)
    {
        GameObject.Find("TextNodeName").GetComponent<Text>().text = string.Format("Node [ {0}, {1} ]", pdn.iPosition, pdn.jPosition);
        GameObject.Find("TextHeightNum").GetComponent<Text>().text = "" + pdn.yPosition;

        heightSlider.maxValue = PlatformManager.Instance.configData.height; // set maxValue to the slider
        heightSlider.value = pdn.yPosition;
    }
コード例 #4
0
    private void PlatformDataNode_OnUpdatePlatformDataNodeUI(PlatformDataNode dataNode)
    {
        dataNode.sliderSelectedProgramNodeHeight = sliderYRange;

        // update the min/max values for slider
        dataNode.sliderSelectedProgramNodeHeight.minValue = 0;
        dataNode.sliderSelectedProgramNodeHeight.maxValue = PlatformManager.Instance.configurationData.RandomHeight;

        dataNode.txtSelectedNodeName     = txtSelectedNodeName;
        dataNode.txtSelectedNodePosition = txtSelectedNodePosition;
    }
コード例 #5
0
    // read from the text file
    public void ReadFile()
    {
        Debug.Log("Reader reached");
        StreamReader reader = new StreamReader(Path.Combine(Application.dataPath, "WriteLines.txt"));

        using (reader)
        {
            // prep the reader
            string   line = reader.ReadLine();
            string[] entries;
            entries = line.Split(',');

            // 1st line is configuration data
            Debug.Log(entries[0] + "," + entries[1] + "," + entries[2] + "," + entries[3]);

            // Configure
            PlatformConfigurationData pcd = new PlatformConfigurationData();
            pcd.M            = Convert.ToInt32(entries[0]);
            pcd.N            = Convert.ToInt32(entries[1]);
            pcd.deltaSpacing = (float)Convert.ToDouble(entries[2]);
            pcd.RandomHeight = (float)Convert.ToDouble(entries[3]);

            // set global configurationData to local pcd
            // so we can access the correct information
            configurationData = pcd;

            // used to map each node accordingly
            platformData = new PlatformDataNode[pcd.M, pcd.N];

            // read through the text until complete
            while ((line = reader.ReadLine()) != null)
            {
                // create a new pdn to access i, j, and next position
                PlatformDataNode pdn = new PlatformDataNode();
                entries = line.Split(',');

                // rest of lines are now platform data nodes
                Debug.Log(entries[0] + "," + entries[1] + "," + entries[2]);

                // grab the i, j and next position of each node
                pdn.i            = Convert.ToInt32(entries[0]);
                pdn.j            = Convert.ToInt32(entries[1]);
                pdn.NextPosition = (float)Convert.ToDouble(entries[2]);

                // assign it accordingly to the platformData array
                platformData[pdn.i, pdn.j] = pdn;
            }
        }
        reader.Close();
    }
コード例 #6
0
        public void BuildPlatform()
        {
            DestroyPlatform();

            platformNode = new GameObject[configurationData.M, configurationData.N];

            spaceX = 0;
            spaceZ = 0;

            for (int i = 0; i < configurationData.M; i++)
            {
                spaceZ = 0.0f;
                for (int j = 0; j < configurationData.N; j++)
                {
                    float x = (i * 1) + spaceX;
                    float z = (j * 1) + spaceZ;

                    //Debug.Log(string.Format("x={0} z={1}", x, z));
                    // create a platform pref ...
                    var platformBase = Instantiate(PlatformBasePref,
                                                   new Vector3(x, 0, z),
                                                   Quaternion.identity);

                    platformBase.name = string.Format("Node[{0},{1}]", i, j);

                    platformBase.AddComponent <PlatformDataNode>();

                    platformNode[i, j] = platformBase;
                    platformNode[i, j].transform.SetParent(transform, true);//becomes child of PlatformManager, added by Moses

                    PlatformDataNode pdn = platformBase.transform.GetComponent <PlatformDataNode>();
                    pdn.Program = Program;
                    pdn.i       = i;
                    pdn.j       = j;

                    spaceZ += configurationData.deltaSpace;
                }
                spaceX += configurationData.deltaSpace;
            }

            if (OnPlatformManagerChanged != null)
            {
                OnPlatformManagerChanged(configurationData);
            }

            oldM = configurationData.M;
            oldN = configurationData.N;
        }
コード例 #7
0
    // initializing platform here
    public void BuildPlatform()
    {
        // destroy all the cubes first if it's already initialized
        DestroyCube();

        // initializing arrays' size to given m and n value
        allCube = new GameObject[configData.mSize, configData.nSize];

        // creating all the cubes (platform)
        for (int i = 0; i < configData.mSize; i++)
        {
            for (int j = 0; j < configData.nSize; j++)
            {
                // instantiate cube prefab
                GameObject cube = Instantiate(
                    cubePrefab,                                                                        // original object
                    new Vector3(i + (i * configData.deltaSpace), 0f, j + (j * configData.deltaSpace)), // position
                    Quaternion.identity                                                                // rotation
                    );
                cube.name = string.Format("Node[{0},{1}]", i, j);

                allCube[i, j] = cube;                   // keep all initialized cubes into 2d GameObject array

                cube.AddComponent <PlatformDataNode>(); // adding PlatformDataNode script to the cube

                PlatformDataNode pdn = cube.transform.GetComponent <PlatformDataNode>();
                pdn.iPosition    = i;
                pdn.jPosition    = j;
                pdn.isProgrammed = programmingScene; // toggle programming flag on each cube
                pdn.isSimulated  = simulatingScene;  // toggle simulating flag on each cube
            }
        }

        // updating UI after building platform
        if (OnPlatformManagerChanged != null)
        {
            // if subscribed, update data and UI
            OnPlatformManagerChanged(configData);
        }
    }
コード例 #8
0
        // Update is called once per frame
        void Update()
        {
            // check to see if platform has been build
            if (platformNode == null)
            {
                return;
            }

            if (Input.GetKeyUp(KeyCode.Space))
            {
                StartSimulationButtonClick();
            }
            //if (Input.GetKeyUp(KeyCode.T))
            //    SimulateTest = !SimulateTest;
            //if (Input.GetKeyUp(KeyCode.H))
            //    shade = ColorShade.GrayScale;
            //if (Input.GetKeyUp(KeyCode.R))
            //    shade = ColorShade.RedScale;
            //if (Input.GetKeyUp(KeyCode.G))
            //    shade = ColorShade.GreenScale;
            //if (Input.GetKeyUp(KeyCode.B))
            //    shade = ColorShade.BlueScale;
            //if (Input.GetKeyUp(KeyCode.E))
            //    shade = ColorShade.Random;
            //if (Input.GetKeyUp(KeyCode.W))
            //{
            //    RandomHeight += 1;
            //    txtPlatformYAxisRange.text = string.Format("{0}", RandomHeight);
            //}
            //if (Input.GetKeyUp(KeyCode.S))
            //{
            //    RandomHeight -= 1;
            //    if (RandomHeight < 0)
            //        RandomHeight = 0;
            //    txtPlatformYAxisRange.text = string.Format("{0}", RandomHeight);
            //}
            if (Input.GetKey(KeyCode.Q))
            {
                Application.Quit();
            }

            #region Object Selection
            // you can select only if in program mode/scene
            if (Program)
            {
                if (Input.GetMouseButtonUp(0))
                {
                    if (IsPointerOverUIObject())
                    {
                        return;
                    }

                    #region Screen To World
                    RaycastHit hitInfo = new RaycastHit();
                    bool       hit     = Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hitInfo);
                    if (hit)
                    {
                        #region COLOR

                        if (currentSelection != null)
                        {
                            PlatformDataNode pdn = currentSelection.transform.GetComponent <PlatformDataNode>();
                            pdn.ResetDataNode();
                        }

                        currentSelection = hitInfo.transform.gameObject;
                        PlatformDataNode newPdn = currentSelection.transform.GetComponent <PlatformDataNode>();
                        newPdn.SelectNode();

                        #endregion
                    }
                    else
                    {
                        Debug.Log("No hit");
                    }
                    #endregion
                }
            }
            #endregion

            if (Simulate)//added by Moses
            {
                float[] tempRow;

                if (nodeCounter == totalNodes) //do not update control until all platforms reach their destinations

                //when each node reaches height, add 1 to nodeCounter
                //this is handled by PlatformDataNode_OnNodeReachedPosition()

                {
                    for (int i = 0; i < configurationData.M; i++)
                    {
                        tempRow = rows.Dequeue();

                        //Debug.Log("Row "+i+": "+tempRow[0]+", "+tempRow[1]+", "+tempRow[2]+", "+tempRow[3]);//  <---  <---  <---  <---  <---  <---Remove later(for testing)

                        for (int j = 0; j < configurationData.N; j++)
                        {
                            platformNode[i, j].GetComponent <PlatformDataNode>().NextPosition = tempRow[j]; //may want to
                            platformNode[i, j].GetComponent <PlatformDataNode>().Simulate     = true;       //use a delegate for these?
                        }

                        rows.Enqueue(tempRow);//return to queue
                    }

                    tempRow = rows.Dequeue(); //shift the rows by one
                    rows.Enqueue(tempRow);    //will start with the next row

                    nodeCounter = 0;          //reset to repeat process
                }
            }
        }