Пример #1
0
    void OnMouseDrag()
    {
        if (Lerping)
        {
            return;
        }
        float MouseY = Input.mousePosition.y - _mouseOffsetY;
        float NewAngle;
        float AngleIncrement;

        if (_dragHandle == "L")
        {
            AngleIncrement = -Mathf.Atan2(MouseY, Screen.width / 2) * Mathf.Rad2Deg;
        }
        else
        {
            AngleIncrement = Mathf.Atan2(MouseY, Screen.width / 2) * Mathf.Rad2Deg;
        }
        NewAngle = _startAngle + AngleIncrement;
        Bez.CtrlPts[Mrkr.Index].BankAngle = NewAngle;
        //Rotate the marker - We do this by rotating the transform about the kerb pivot
        Vector3 _markerPos = Bez.CtrlPts[Mrkr.Index].Pos;

        AttachedTransform.position = _startPos;
        AttachedTransform.rotation = _startRot;
        AttachedTransform.RotateAround(_pivot, AttachedTransform.forward, AngleIncrement);        //this function was depreciated but I really struggled to do it any other way
        Bez.CtrlPts[Mrkr.Index].Pos = AttachedTransform.position;
        Bez.Interp(Mrkr.Index - 1);
        Bez.Interp(Mrkr.Index);
        Bez.Interp(Mrkr.Index + 1);
        Bez.DrawLine();
    }
Пример #2
0
 // Update is called once per frame
 void Update()
 {
     // Get target in attack range
     if (_target == null)
     {
         _target = GridManager.Instance.GetNearestTargetInRange((int)MapPosition.x, (int)MapPosition.y, _attackRange, GridType.Enemy);
         if (_target != null)
         {
             _attackLine.ShowLine();
             _attackLine.EndObject = _target;
             _attackLine.DrawLine();
         }
         else
         {
             _attackLine.HideLine();
         }
     }
     else // Hide attack line when target out of attack range
     {
         Vector2 sub      = _target.GetComponent <Grid>().MapPosition - MapPosition;
         float   distance = Mathf.Max(Mathf.Abs(sub.x), Mathf.Abs(sub.y));
         if (distance > _attackRange)
         {
             _target = null;
             _attackLine.HideLine();
         }
     }
 }
Пример #3
0
    void OnMouseDrag()
    {
        if (Lerping)
        {
            return;
        }
        float NewAngle;
        float MouseAngle = Mathf.Atan2(Input.mousePosition.y - Screen.height / 2, Input.mousePosition.x - Screen.width / 2) * Mathf.Rad2Deg;

        //Signed angle measured anticlockwise from the right
        MouseAngle = MouseAngle - _mouseOffsetAngle;
        if (MouseAngle > 180)
        {
            MouseAngle = MouseAngle - 360;
        }
        if (MouseAngle < -180)
        {
            MouseAngle = MouseAngle + 360;
        }
        if (_viewFromFront)
        {
            MouseAngle = -MouseAngle;
        }

        NewAngle = _startAngle + MouseAngle;
        if (_hand == "R")
        {
            if (NewAngle > 0)
            {
                transform.localRotation = Quaternion.Euler(0, 0, NewAngle); _oppositeGizmoBank.localRotation = Quaternion.identity;
            }
            else
            {
                _oppositeGizmoBank.localRotation = Quaternion.Euler(0, 0, NewAngle); transform.localRotation = Quaternion.identity;
            }
        }
        else
        {
            if (NewAngle > 0)
            {
                _oppositeGizmoBank.localRotation = Quaternion.Euler(0, 0, NewAngle); transform.localRotation = Quaternion.identity;
            }
            else
            {
                transform.localRotation = Quaternion.Euler(0, 0, NewAngle); _oppositeGizmoBank.localRotation = Quaternion.identity;
            }
        }
        Bez.CtrlPts[Mrkr.Index].BankAngle = NewAngle;
        //transform.RotateAround(_pivot, AttachedTransform.forward, AngleIncrement);
        //Bez.CtrlPts[Mrkr.Index].Pos = AttachedTransform.position;
        Bez.Interp(Mrkr.Index - 1);
        Bez.Interp(Mrkr.Index);
        Bez.Interp(Mrkr.Index + 1);
        Bez.DrawLine();
    }
    void OnMouseDrag()
    {
        if (Lerping)
        {
            return;
        }
        float MouseY = Input.mousePosition.y - _mouseOffsetY;
        float NewAngle;

        if (_hand == "L")
        {
            NewAngle = _startAngle + Mathf.Atan2(MouseY, Screen.width / 2);
        }
        else
        {
            NewAngle = _startAngle - Mathf.Atan2(MouseY, Screen.width / 2);
        }
        NewAngle = NewAngle * Mathf.Rad2Deg;
        //Debug.Log("New angle = " + NewAngle);
        Vector3 NewPos;
        Vector3 _bankDirection = AttachedTransform.forward * NewAngle;

        NewPos = VectGeom.RotatePointAroundPivot(_untiltedPos, OtherHandGizmo.position, _bankDirection);
        Bez.CtrlPts[Mrkr.Index].Pos       = (NewPos + _otherHandStartPos) / 2;
        AttachedTransform.position        = Bez.CtrlPts[Mrkr.Index].Pos;
        Bez.CtrlPts[Mrkr.Index].BankAngle = NewAngle;
        Bez.Interp(Mrkr.Index - 1);
        Bez.Interp(Mrkr.Index);
        Bez.Interp(Mrkr.Index + 1);
        Bez.DrawLine();
        AttachedTransform.rotation = Quaternion.identity;
        try
        {
            AttachedTransform.LookAt(BezierLine.Instance.Path[Bez.CtrlPts[Mrkr.Index].SegStartIdx + 1]);
            AttachedTransform.Rotate(Vector3.forward, NewAngle);
        }
        catch (System.Exception e)
        {    //Todo Find something for it to look at
        }
        transform.position      = NewPos;
        OtherHandGizmo.position = _otherHandStartPos;
        transform.LookAt(OtherHandGizmo, AttachedTransform.up);
        OtherHandGizmo.LookAt(transform, AttachedTransform.up);
    }
Пример #5
0
    // Use this for initialization
    void Start()
    {
        _canvas    = GameObject.Find("BuilderGUICanvas(Clone)");
        BuilderCam = GameObject.Find("BuilderCamera").GetComponent <Camera>();
        Toolbox    = _canvas.GetComponent <ToolboxController>();
        Toolbox.ToolOptionChanged += ToolChange;
        Bez = BezierLine.Instance;
        Rd  = Road.Instance;
        if (Road.Instance.Segments.Count == 0 || Road.Instance.Segments[0].goSeg == null)    //Cos When they might already be built
        {
            if (Road.Instance.StartingLinePos != null)
            {
                PlaceStartingLine(Road.Instance.StartingLineSegIdx);
            }
        }
        Bez.CreateGameObject();
        Bez.DrawLine();
        if (GameData.current.MacId == SystemInfo.deviceUniqueIdentifier)
        {
            Bez.CreateRoadMarkers();
        }
        //Open the tutorial if building first track
        if (SaveLoadModel.savedGames.Count < 3)     //!!!!!change to 3
        {
            UnityEngine.Object objPnl1 = Resources.Load("Prefabs/pnlTutorialBuild1");
            GameObject         goVid   = (GameObject)(GameObject.Instantiate(objPnl1, _canvas.transform));
            goVid.transform.localScale = Vector3.one;
            goVid.GetComponent <RectTransform>().anchoredPosition = Vector2.zero;
        }

        //Open the turorial panel so you can say how many cones left
        UnityEngine.Object objPnl = Resources.Load("Prefabs/pnlTutorialBuild2");
        GameObject         goTut  = (GameObject)(GameObject.Instantiate(objPnl, _canvas.transform));

        Tut = goTut.GetComponent <Tutorial>();
        Tut.transform.localScale = Vector3.one;
        Tut.GetComponent <RectTransform>().anchoredPosition = Vector2.zero;
        Tut.gameObject.SetActive(false);
    }
Пример #6
0
    // Update is called once per frame
    void Update()
    {
        //Check we're not clicking on a UI element
        if (Input.GetMouseButtonDown(0))
        {
            foreach (RectTransform RT in _canvas.GetComponentsInChildren <RectTransform>(false))
            {
                if (RT.name == "RR")
                {
                    break;                    //because RR covers the whole screen
                }
                if (RT.name.StartsWith("BuilderGUI"))
                {
                    continue;                                      //So does the canvas but we just want to skip this
                }
                Vector3[] worldCorners = new Vector3[4];
                RT.GetWorldCorners(worldCorners);
                if (Input.mousePosition.x >= worldCorners[0].x && Input.mousePosition.x < worldCorners[2].x &&
                    Input.mousePosition.y >= worldCorners[0].y && Input.mousePosition.y < worldCorners[2].y)
                {
                    _mouseDownOnUI = true;
                    break;
                }
            }
        }

        if (Input.GetMouseButtonUp(0))
        {
            //Check we didn't drag the mouse onto the terrain
            if (Dragging == false && _mouseDownOnUI == false)
            {
                //If you've clicked on a UI element then you didn't mean to click the terrain

                foreach (RectTransform RT in _canvas.GetComponentsInChildren <RectTransform>(false))
                {
                    if (RT.name == "RR")
                    {
                        break;                    //because RR covers the whole screen
                    }
                    if (RT.name.StartsWith("BuilderGUI"))
                    {
                        continue;
                    }
                    Vector3[] worldCorners = new Vector3[4];
                    RT.GetWorldCorners(worldCorners);
                    if (Input.mousePosition.x >= worldCorners[0].x && Input.mousePosition.x < worldCorners[2].x &&
                        Input.mousePosition.y >= worldCorners[0].y && Input.mousePosition.y < worldCorners[2].y)
                    {
                        return;
                    }
                }
                RaycastHit Hit;
                Ray        R = BuilderCam.ScreenPointToRay(Input.mousePosition);
                if (Physics.Raycast(R, out Hit))
                {
                    if (Hit.collider.name.Contains("Terrain"))
                    {
                        if (Toolbox.SelectedTool == "RoadSectn")// && BezCurr.CtrlPts.Count - BezCtrlPt.Current.CtrlPtId ==2)
                        {
                            AddSection(Hit.point);
                        }
                        if (Toolbox.SelectedTool == "Scenery")
                        {
                            AddScenery(Hit.point);
                        }
                        Game.current.Dirty = true;
                    }
                    if (Hit.collider.name.Contains("RoadSeg"))
                    {
                        if (Toolbox.SelectedTool == "StartingLine")
                        {
                            int SegNo = int.Parse(Hit.collider.name.Substring(7));
                            //InsertMarker(SegNo)
                            PlaceStartingLine(SegNo);
                        }
                        if (Toolbox.SelectedTool == "Scenery")
                        {
                            AddScenery(Hit.point);
                        }
                        Game.current.Dirty = true;
                    }
                }
            }

            //Draw the line
            Bez.DrawLine();

            //GetComponent<BuilderCamController>().FreezeTilt = false;
            _mouseDownOnUI = false;
            Dragging       = false;
        }
    }