コード例 #1
0
 /// <summary>
 /// Set the path type for a newly activated moth.
 /// This initialises the moth path.
 /// </summary>
 public void SetPathType(MothPathTypes pathType)
 {
     _pathType  = pathType;
     _state     = PathStates.NorthWest;
     _pathTimer = 0f;
     _bLeft     = pathType != MothPathTypes.Figure8;
 }
コード例 #2
0
 public void ToggleAStar(bool isToggled)
 {
     if (isToggled)
     {
         pathSelected = PathStates.Astar;
     }
 }
コード例 #3
0
 public void ToggleDFS(bool isToggled)
 {
     if (isToggled)
     {
         pathSelected = PathStates.DFS;
     }
 }
コード例 #4
0
 public PathContext(
     DiagnosticMessages diagnosticMessages,
     FileSystemWatcher watcher,
     ApplicationEventsPresenter applicationEventsPresenter,
     PathStates pathStates)
 {
     _diagnosticMessages         = diagnosticMessages;
     _watcher                    = watcher;
     _applicationEventsPresenter = applicationEventsPresenter;
     _pathStates                 = pathStates;
     _currentState               = _pathStates.PathNotDetectedState();
 }
コード例 #5
0
    /// <summary>
    /// Chooses the next section the moth will travel on the clover,
    /// depending on its current trajectory.
    /// </summary>
    private void ChooseNextDirection()
    {
        _compensateX   = _displacementX;
        _compensateY   = _displacementY;
        _displacementX = 0;
        _displacementY = 0;

        // Update the state to the currect direction the moth is facing
        switch (_state)
        {
        case PathStates.NorthWest:
            _state = !_bLeft ? PathStates.SouthWest : PathStates.NorthEast;
            break;

        case PathStates.NorthEast:
            _state = !_bLeft ? PathStates.NorthWest : PathStates.SouthEast;
            break;

        case PathStates.SouthEast:
            _state = !_bLeft ? PathStates.NorthEast : PathStates.SouthWest;
            break;

        case PathStates.SouthWest:
            _state = !_bLeft ? PathStates.SouthEast : PathStates.NorthWest;
            break;
        }

        // Pick the next direction for the moth to travel
        switch (_pathType)
        {
        case MothPathTypes.Infinity:
            _bLeft = !_bLeft;
            break;

        case MothPathTypes.Clover:
            _bLeft = Random.Range(0f, 1f) > 0.5f;
            break;

        case MothPathTypes.Figure8:
            _bLeft = !_bLeft;
            break;

        case MothPathTypes.Spiral:
            _bLeft = true;
            break;

        default:
            _bLeft = Random.Range(0f, 1f) > 0.5f;
            break;
        }
    }
コード例 #6
0
 IEnumerator DoDraw(float timeRate)
 {
     //Debug.Log("ENTER");
     while (true)
     {
         //Debug.Log("ENTER Corutine");
         if (Input.GetMouseButton(0))
         {
             DrawPath(drawTime);
         }
         else
         {
             pathStates = PathStates.destroy;
             destoryPath();
         }
         pathStates = PathStates.idle;
         destoryPathConditions();
         yield return(new WaitForSeconds(timeRate));
     }
 }
コード例 #7
0
    public void destoryPath()
    {
        addPathToPathPositions();

        if (path != null)
        {
            foreach (GameObject go in path)
            {
                pathStates = PathStates.destroy;
                Destroy(go);
            }

            foreach (GameObject go in mainPathCalc)
            {
                pathStates = PathStates.destroy;
                Destroy(go);
            }
            mainPathCalc.Clear();

            path.Clear();
        }
    }
コード例 #8
0
    public void destoryPathConditions()
    {
        if (path != null)
        {
            if (path.Count >= maxNumberOfPath)
            {
                addPathToPathPositions();
                foreach (GameObject go in path)
                {
                    pathStates = PathStates.destroy;
                    Destroy(go);
                }
                path.Clear();

                foreach (GameObject go in mainPathCalc)
                {
                    pathStates = PathStates.destroy;
                    Destroy(go);
                }
                mainPathCalc.Clear();
            }
        }
    }
コード例 #9
0
    void DrawPath(float timeRate)
    {
        pathStates = PathStates.draw;
        //Debug.Log("ENTER DRAW");
        RaycastHit hit;
        Ray        ray = camera.ScreenPointToRay(Input.mousePosition);

        if (!Physics.Raycast(ray, out hit))
        {
            Vector3 mousePosition = new Vector3(Input.mousePosition.x, Input.mousePosition.y, mouse_z_distance);
            mousePosition = Camera.main.ScreenToWorldPoint(mousePosition);
            if (path.Count == 0)
            {
                GameObject goP = Instantiate(objectToDraw, mousePosition, Quaternion.identity);

                Ray downRay = new Ray(goP.transform.position, -Vector3.up);

                if (Physics.Raycast(downRay, out hit))
                {
                    Vector3 forward = goP.transform.TransformDirection(-Vector3.up) * hit.distance;
                    Debug.DrawRay(goP.transform.position, forward, Color.green);
                    //Debug.Log("hit distance = " + hit.distance);
                    Vector3 drawPathPosistion = hit.point;
                    drawPathPosistion.y = drawPathPosistion.y + maxDistanceToDrawPath;;
                    addPathPoint(drawPathPosistion);
                }

                path.Add(goP);
            }
            else
            {
                if (Vector3.Distance(path[path.Count - 1].transform.position, mousePosition) > drawTrashold)
                {
                    Vector3 drawPos   = mousePosition;
                    Vector3 direction = mousePosition - path[path.Count - 1].transform.position;
                    float   angle     = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;

                    if (Vector3.Distance(path[path.Count - 1].transform.position, mousePosition) > (drawTrashold + drawTrasholdMaxDistance))
                    {
                        drawPos = path[path.Count - 1].transform.position + direction / 2.0f;
                    }
                    else
                    {
                        drawPos = mousePosition;
                    }

                    GameObject goP = Instantiate(objectToDraw, drawPos, Quaternion.identity);

                    Ray downRay = new Ray(goP.transform.position, -Vector3.up);

                    if (Physics.Raycast(downRay, out hit))
                    {
                        Vector3 forward = goP.transform.TransformDirection(-Vector3.up) * hit.distance;
                        Debug.DrawRay(goP.transform.position, forward, Color.green);

                        Vector3 drawPathPosistion = hit.point;
                        drawPathPosistion.y = drawPathPosistion.y + maxDistanceToDrawPath;
                        addPathPoint(drawPathPosistion);
                    }

                    goP.transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
                    path.Add(goP);
                }
            }
        }
    }