Esempio n. 1
0
        public MachineRasterSpeeds(string filename)
        {
            try
            {
                var fileList = FileIO.ReadDataTextFile(filename);

                string[] words = FileIO.Split(fileList[1]);
                words = FileIO.Split(fileList[1]);
                double jp = Convert.ToDouble(words[1]);

                _machiningParameters = new MachiningParameters();
                words = FileIO.Split(fileList[2]);
                double dn = Convert.ToDouble(words[1]);
                words = FileIO.Split(fileList[3]);
                double dm = Convert.ToDouble(words[1]);
                words = FileIO.Split(fileList[4]);
                double ma = Convert.ToDouble(words[1]);
                words = FileIO.Split(fileList[5]);
                string   ab  = words[1];
                Abrasive abr = new Abrasive(ab, ma);
                WaterJet wj  = new WaterJet(jp, dm, dn);
                _machiningParameters = new MachiningParameters(wj, abr, MachiningOpType.SingleChannel, 0);
                words              = FileIO.Split(fileList[6]);
                _xLocation         = Convert.ToDouble(words[1]);
                words              = FileIO.Split(fileList[7]);
                _targetPasses      = Convert.ToInt32(words[1]);
                words              = FileIO.Split(fileList[8]);
                _rasterOffsetAngle = GeometryLib.GeomUtilities.ToRadians(Convert.ToDouble(words[1]));
                for (int i = 10; i < fileList.Count; i++)
                {
                    words = FileIO.Split(fileList[i]);
                    if (words.Length == 4)
                    {
                        int    rasterIndex = Convert.ToInt32(words[0]);
                        double thetaRel    = GeometryLib.GeomUtilities.ToRadians(Convert.ToDouble(words[1]));
                        double speed       = Convert.ToDouble(words[2]);
                        double depth       = Convert.ToDouble(words[3]);
                        var    mrs         = new MachineRasterSpeed(rasterIndex, thetaRel, speed, depth);
                        this.Add(mrs);
                    }
                }
                _rasterCount = this.Count;
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 2
0
    void CheckInput()
    {
        if (isMoving || !GridManager.Instance)
        {
            return;
        }
        RaycastHit2D _hit;

        if (Input.GetKeyDown(KeyCode.Mouse0))
        {
            _hit = (Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero, 1, cellLayer));
            if (_hit)
            {
                Cell _destination = GridManager.Instance.GetClosestCell(_hit.point);
                if (_destination.State == CellState.NonNavigable)
                {
                    return;
                }
                Cell _origin = GridManager.Instance.GetClosestCell(transform.position);
                if (_destination == _origin)
                {
                    return;
                }
                List <Vector2> _cellPath = CalculatePath(_origin, _destination);
                if (_cellPath == null)
                {
                    return;
                }
                if (currentCell.State == CellState.House)
                {
                    renderer.sortingOrder = 2;
                }
                StartCoroutine(FollowPath(_cellPath));
            }
        }
        else if (Input.GetKeyDown(KeyCode.Mouse1) && energy > 0 && currentCell.State != CellState.House)
        {
            _hit = (Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero, 1, cellLayer));
            if (_hit)
            {
                Cell    _c   = GridManager.Instance.GetClosestCell(_hit.point);
                Vector3 _dir = GridManager.Instance.GetStraightLine(currentCell, _c);
                if (_dir == Vector3.zero)
                {
                    return;
                }
                UpdateOrientation(_dir);
                characterAnimator.SetTrigger("SprayWater");
                int   rand_son   = UnityEngine.Random.Range(1, 3);
                float rand_pitch = UnityEngine.Random.Range(0.5f, 1.5f);
                switch (rand_son)
                {
                case 1:

                    audio.Play("shot1", rand_pitch);
                    break;

                case 2:
                    audio.Play("shot2", rand_pitch);
                    break;
                }
                WaterJet _jet   = Instantiate(waterJetPrefab, transform.position, Quaternion.identity).GetComponent <WaterJet>();
                float    _angle = Mathf.Atan2(_dir.y, _dir.x) * Mathf.Rad2Deg;
                _jet.transform.rotation = Quaternion.AngleAxis(_angle, Vector3.forward);
                _jet.ApplyDirection(_dir, WaterJetRange);
                Energy -= waterJetCost;
            }
        }
    }