Exemplo n.º 1
0
    private void ManualInitGrid()
    {
        gridSystem.Init(new Int2(sizeX, sizeZ), cellSize, new Int2(goalX, goalZ));
        //gridSizeX = 7
        //gridSizeZ = 20
        if (gridSystem.gridSizeX != 7 || gridSystem.gridSizeZ != 22)
        {
            throw new UnityException("gridSystem has a different size  than that of manual initialization ");
        }

        int[,] map = new int[7, 22]
        {
            { 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1 },
            { 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0 },
            { 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0 },
            { 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1 },
            { 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0 },
            { 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1 },
            { 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0 }
        };


        HashSet <PlatformGroup> init = new HashSet <PlatformGroup>();

        for (int x = 0; x < 7; x++)
        {
            for (int z = 0; z < 22; z++)
            {
                if (map[x, z] == 1)
                {
                    init.Add(gridSystem.PlacePlatform(x, z));
                }
            }
        }

        PlatformGroup.Restructure(init, gridSystem.ComputeIdx(new Vector2(robotController.transform.position.x, robotController.transform.position.z)));
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (PSMoveInput.IsConnected)
        {
            MoveData moveData = new MoveData();
            if (controllerNumber != -1 && PSMoveInput.MoveControllers [controllerNumber].Connected)
            {
                moveData = PSMoveInput.MoveControllers [controllerNumber].Data;
            }
            else
            {
                bool found = false;
                for (int i = 0; i < PSMoveInput.MoveControllers.Length; i++)
                {
                    if (PSMoveInput.MoveControllers[i].Connected)
                    {
                        moveData         = PSMoveInput.MoveControllers[i].Data;
                        controllerNumber = i;
                        found            = true;
                        break;
                    }
                }
                if (!found)
                {
                    return;
                }
            }

            handlePos = moveData.HandlePosition * handlePositionSensitivity + handlePositionOffset;
            handle.transform.localPosition = new Vector3(handlePos.x, handlePos.y, -handlePos.z);
            handle.transform.localRotation = Quaternion.Euler(-moveData.Orientation);

            if (moveData.ValueT > 0)
            {
                //If tractor beam is not lit up, light it up
                if (!beamOn)
                {
                    Debug.Log("Beam on!");
                    //beam.SetActive(true);
                    beamOn = true;

                    //add sound effect here (modified by Yang)
                    handle.GetComponent <TrackbeamSound>().PlaySound();
                }

                //If speed is above speed threshold
                if (moveData.Velocity.magnitude >= speedThreshold && activePlatform != null &&
                    activePlatform.gameObject.layer == Utility.ToLayerNumber(gridSystem.movablePfLayer))
                {
                    float   xVel = moveData.Velocity.x;
                    Vector3 oVec = activePlatform.gameObject.transform.position;
                    Vector3 pVec = robot.transform.position;
                    Int2    pIdx = gridSystem.ComputeIdx(new Vector2(pVec.x, pVec.z));
                    Debug.Log(pVec);
                    Debug.Log(oVec);
                    int dX = Mathf.RoundToInt(pVec.x) - Mathf.RoundToInt(oVec.x);
                    int dZ = Mathf.RoundToInt(pVec.z) - Mathf.RoundToInt(oVec.z);
                    if (dX == 0)
                    {
                        activePlatform.group.StartMoveGroup(PlatformMoveType.AxisZ, pIdx);
                    }
                    else if (dZ == 0)
                    {
                        activePlatform.group.StartMoveGroup(PlatformMoveType.AxisX, pIdx);
                    }
                    else
                    {
                        if (dX < 0)
                        {
                            if (dZ > 0)
                            {
                                if (xVel > angledSpeedThreshold)
                                {
                                    activePlatform.group.StartMoveGroup(PlatformMoveType.AxisX, pIdx);
                                }
                                else if (xVel < -angledSpeedThreshold)
                                {
                                    activePlatform.group.StartMoveGroup(PlatformMoveType.AxisZ, pIdx);
                                }
                            }
                            else
                            {
                                if (xVel > angledSpeedThreshold)
                                {
                                    activePlatform.group.StartMoveGroup(PlatformMoveType.AxisZ, pIdx);
                                }
                                else if (xVel < -angledSpeedThreshold)
                                {
                                    activePlatform.group.StartMoveGroup(PlatformMoveType.AxisX, pIdx);
                                }
                            }
                        }
                        else
                        {
                            if (dZ > 0)
                            {
                                if (xVel > angledSpeedThreshold)
                                {
                                    activePlatform.group.StartMoveGroup(PlatformMoveType.AxisZ, pIdx);
                                }
                                else if (xVel > -angledSpeedThreshold)
                                {
                                    activePlatform.group.StartMoveGroup(PlatformMoveType.AxisX, pIdx);
                                }
                            }
                            else
                            {
                                if (xVel > angledSpeedThreshold)
                                {
                                    activePlatform.group.StartMoveGroup(PlatformMoveType.AxisX, pIdx);
                                }
                                else if (xVel > -angledSpeedThreshold)
                                {
                                    activePlatform.group.StartMoveGroup(PlatformMoveType.AxisZ, pIdx);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                if (beamOn)
                {
                    Debug.Log("Beam off!");
                    beamOn = false;
                    if (activePlatform != null)
                    {
                        if (activePlatform.group != null)
                        {
                            activePlatform.group.Deactivate();
                        }
                        activePlatform = null;
                    }
                }
            }
        }
    }