Exemple #1
0
 void Update()
 {
     for (int i = 0; i < actions.Length; i++)
     {
         bool keysPressed = true;
         if (actions[i].input.Length > 1)
         {
             for (int j = 0; j < actions[i].input.Length; j++)
             {
                 if (!Input.GetKey(actions[i].input[j]))
                 {
                     keysPressed = false;
                 }
             }
         }
         if (Input.GetKeyDown(actions[i].input[actions[i].input.Length - 1]) && keysPressed)
         {
             if ((actions[i].useInBuild && !PlayManager.GetIsPlay()) ||
                 (actions[i].useInPlay && PlayManager.GetIsPlay()))
             {
                 if ((actions[i].useInPaletteMenu && paletteMenuManager.IsPaletteMenuActive()) ||
                     !paletteMenuManager.IsPaletteMenuActive())
                 {
                     actions[i].evt.Invoke();
                 }
             }
         }
     }
 }
Exemple #2
0
 void Update()
 {
     if ((Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1)) && !PlayManager.GetIsPlay() &&
         !paletteMenuManager.IsPaletteMenuActive() && currentPalette != -1)
     {
         if (currentTool == Tools.Draw)
         {
             currMousePos = MouseUtilities.GridSpace(buildCam);
             prevMousePos = currMousePos;
         }
         else if (currentTool == Tools.Rect)
         {
             prevMousePos = MouseUtilities.GridSpace(buildCam);
         }
     }
     if ((Input.GetMouseButton(0) || Input.GetMouseButton(1)) && !PlayManager.GetIsPlay() &&
         !paletteMenuManager.IsPaletteMenuActive() && currentPalette != -1)
     {
         bool draw;
         draw = Input.GetMouseButton(0);
         if (currentTool == Tools.Draw)
         {
             currMousePos = MouseUtilities.GridSpace(buildCam);
             DrawTileLine(tileTypes[currentPalette], currMousePos, prevMousePos, draw);
             prevMousePos = MouseUtilities.GridSpace(buildCam);
         }
         else if (currentTool == Tools.Rect)
         {
             currMousePos = MouseUtilities.GridSpace(buildCam);
             rect.SetActive(true);
             rect.GetComponent <RectDraw>().Draw(currMousePos, prevMousePos);
         }
     }
     else
     {
         rect.SetActive(false);
     }
     if ((Input.GetMouseButtonUp(0) || Input.GetMouseButtonUp(1)) && !PlayManager.GetIsPlay() &&
         !paletteMenuManager.IsPaletteMenuActive() && currentPalette != -1)
     {
         bool draw;
         draw = Input.GetMouseButtonUp(0);
         if (currentTool == Tools.Rect)
         {
             DrawTileRect(tileTypes[currentPalette], currMousePos, prevMousePos, draw);
         }
     }
     if (PlayManager.GetIsPlay())
     {
         camBoundsRect.SetActive(false);
     }
     else
     {
         camBoundsRect.SetActive(true);
     }
 }
Exemple #3
0
 void Update()
 {
     if (PlayManager.GetIsPlay() || !isSelected)
     {
         lineRenderer.enabled = false;
         for (int i = 0; i < nodes.Length; i++)
         {
             nodes[i].SetActive(false);
         }
     }
     else
     {
         lineRenderer.enabled = true;
         for (int i = 0; i < nodes.Length; i++)
         {
             nodes[i].SetActive(true);
         }
     }
     isSelected = gameObject.name.Equals(draw.GetLayer());
     if (Input.GetMouseButtonDown(0) && isSelected)
     {
         mousePositionBuffer = MouseUtilities.WorldSpace(cam);
     }
     if (Input.GetMouseButton(0) && isSelected)
     {
         Vector3 positionChange = MouseUtilities.WorldSpace(cam) - mousePositionBuffer;
         for (int i = 0; i < nodes.Length; i++)
         {
             Vector3 normalizedPosition = new Vector3(nodes[i].transform.position.x, nodes[i].transform.position.y, 0);
             if ((Vector3.Distance(MouseUtilities.WorldSpace(cam), normalizedPosition) < 0.5f && currentlyDragged == -1) ||
                 currentlyDragged == i)
             {
                 nodes[i].transform.position += positionChange;
                 lineRenderer.SetPosition(i, nodes[i].transform.position + Vector3.forward);
                 currentlyDragged = i;
                 break;
             }
         }
         mousePositionBuffer = MouseUtilities.WorldSpace(cam);
     }
     if (Input.GetMouseButtonUp(0) && isSelected)
     {
         for (int i = 0; i < nodes.Length; i++)
         {
             Vector3 pos = nodes[i].transform.position;
             nodes[i].transform.position = new Vector3(Mathf.Round(pos.x), Mathf.Round(pos.y), pos.z);
             lineRenderer.SetPosition(i, nodes[i].transform.position + Vector3.forward);
         }
         currentlyDragged = -1;
     }
 }
    void Update()
    {
        if (PlayManager.GetIsPlay() && !isPlayBuffer)
        {
            transform.position = path.GetNodeLocation(0);
            movingForward      = true;
        }

        if (!PlayManager.GetIsPlay())
        {
            transform.position = (path.GetNodeLocation(0) + path.GetNodeLocation(1)) / 2f;
        }
        else
        {
            Vector3 posChange;
            if (movingForward)
            {
                posChange = Vector3.Normalize(path.GetNodeLocation(1) - path.GetNodeLocation(0)) * speed * Time.deltaTime;
            }
            else
            {
                posChange = Vector3.Normalize(path.GetNodeLocation(0) - path.GetNodeLocation(1)) * speed * Time.deltaTime;
            }
            transform.position += posChange;
            if (posChange.x > 0)
            {
                transform.localScale = new Vector3(1, 1, 1);
            }
            else if (posChange.x < 0)
            {
                transform.localScale = new Vector3(-1, 1, 1);
            }
            int index = movingForward ? 1 : 0;
            if (Vector2.Distance((Vector2)transform.position, (Vector2)path.GetNodeLocation(index)) <= speed * Time.deltaTime)
            {
                movingForward = !movingForward;
            }
        }
        isPlayBuffer = PlayManager.GetIsPlay();
    }