Ejemplo n.º 1
0
    private void SnapToNearestRailPoint()
    {
        List <(RailNode, RailNode)> currentRails = RailManager.GetRails();

        if (currentRails == null)
        {
            return;
        }

        float    distanceRecord = Vector3.Distance(currentRails[0].Item1.transform.position, this.transform.position);
        RailNode closestRail    = currentRails[0].Item1;

        foreach ((RailNode, RailNode)rail in currentRails)
        {
            if (Vector3.Distance(rail.Item1.transform.position, this.transform.position) < distanceRecord)
            {
                closestRail = rail.Item1;
            }
            if (Vector3.Distance(rail.Item2.transform.position, this.transform.position) < distanceRecord)
            {
                closestRail = rail.Item2;
            }
        }

        if (closestRail == null)
        {
            return;
        }

        //this.transform.position = closestRail.transform.position;
        this.currentNearestRailPoint = closestRail;
    }
Ejemplo n.º 2
0
    // Use this for initialization
    void Start()
    {
        rm = Object.FindObjectOfType <RailManager>();
        Button myselfButton = GetComponent <Button>();

        myselfButton.onClick.AddListener(() => doIt());
    }
Ejemplo n.º 3
0
    private void FindRailwayOnDirection()
    {
        List <(RailNode, RailNode)> currentRails = RailManager.GetRails();

        if (currentRails == null)
        {
            return;
        }

        foreach ((RailNode, RailNode)rail in currentRails)
        {
            if (rail.Item1.Equals(this.currentNearestRailPoint))
            {
                if ((rail.Item2.transform.position - rail.Item1.transform.position).normalized == this.transform.forward)
                {
                    this.movementDirection = (rail.Item2.transform.position - rail.Item1.transform.position).normalized;
                    this.SetSpeed(0.1f);
                    this.canTurn            = false;
                    this.switchedToEndpoint = false;
                }
            }
            else if (rail.Item2.Equals(this.currentNearestRailPoint))
            {
                if ((rail.Item1.transform.position - rail.Item2.transform.position).normalized == this.transform.forward)
                {
                    this.movementDirection = (rail.Item1.transform.position - rail.Item2.transform.position).normalized;
                    this.SetSpeed(0.1f);
                    this.canTurn            = false;
                    this.switchedToEndpoint = false;
                }
            }
        }
    }
Ejemplo n.º 4
0
        /// <summary>Creates a Button that adds a child object with a Rail component to the game object</summary>
        /// <param name="railManager">The RailManager component selected in the Inspector</param>
        private void AddNewRailButton(RailManager railManager)
        {
            // Disallows rails being added when Editor in Play Mode
            if (EditorApplication.isPlaying)
            {
                GUI.enabled = false;
            }

            // Button to add a rail
            _content = new GUIContent("Add New Rail", "");
            if (GUILayout.Button(_content, GUILayout.Height(24f)))
            {
                // Checks for next available index to append to rail object name
                var railNames = new List <string>();
                for (int i = 0; i < _rails.Count; i++)
                {
                    railNames.Add(_rails[i].gameObject.name);
                }
                var newRailIndex = GUIUtilities.GetUniqueChildObjectIndex(railNames, "Rail ");

                // Adds the rail object
                GUIUtilities.AddRailObjectAsChild(railManager.gameObject, newRailIndex);
                _repaintScene = true;
            }

            if (EditorApplication.isPlaying)
            {
                GUI.enabled = true;
            }
        }
Ejemplo n.º 5
0
    public override void Start()
    {
        base.Start();

        RailManager rm    = GameManager.Instance.RailManager;
        int         index = Random.Range(0, RailManager.NumRails);

        // List<int> availableRails = Enumerable.Range(0, 3).ToList();

        ConnectToRail(rm.GetRail(index));
        for (int i = 0; i < AttachedRail.RailSegmentPositions.Count - 1; i++)
        {
            var screenPos = mainCamera.Camera.WorldToViewportPoint(AttachedRail.RailSegmentPositions[i + 1]);
            if (screenPos.x > 0 && screenPos.y > 0 && screenPos.x < 1 && screenPos.y < 1)
            {
                RailIndex = AttachedRail.FindIndex(AttachedRail.RailSegmentPositions[i]);
                break;
            }
        }
        RailNode nextPosition = AttachedRail.GetTargetRailNode(RailIndex);

        transform.position = nextPosition.Position;

        if (!nextPosition.Valid)
        {
            StartFreeMovement();
        }
        else
        {
            target = nextPosition;
        }

        child = transform.GetChild(0);
    }
Ejemplo n.º 6
0
 // Use this for initialization
 void Awake()
 {
     lastRailSpawnPosition = transform.position;
     railManager           = GetComponentInParent <RailManager>();
     seed  = Mathf.RoundToInt(UnityEngine.Random.value * 1000000);
     nodes = new List <RailNode>();
     RailSegmentPositions = new List <Vector3>();
 }
Ejemplo n.º 7
0
    public void Initialize(RailManager rail)
    {
        this.rail = rail;

        distanceUnitToFrontBogie = Train.GetZDistance(transform.position.z, bogies[0].transform.position.z);
        distanceUnitToRearBogie  = -Train.GetZDistance(transform.position.z, bogies[1].transform.position.z);

        distanceToFrontAttach = Train.GetZDistance(transform.position.z, FrontAttachPoint.position.z);
        distanceToRearAttach  = Train.GetZDistance(transform.position.z, RearAttachPoint.position.z);

        transform.position = Vector3.zero;
        transform.rotation = Quaternion.identity;
    }
Ejemplo n.º 8
0
 private void Awake()
 {
     Instance = this;
     Cursor.lockState = CursorLockMode.Locked;
     Cursor.visible = true;
     inputManager = GetComponent<InputManager>();
     railManager = GetComponent<RailManager>();
     uiManager = GetComponent<UIManager>();
     scoreManager = GetComponent<ScoreManager>();
     
     //Debug
     scoreManager.CurrentScore = 0;
 }
Ejemplo n.º 9
0
    private void Awake()
    {
        if (Instance == null)
        {
            Instance = this;
        }
        else
        {
            Destroy(this);
        }

        if (m_inversePath)
        {
            m_currentPathElementIdx = m_rails[0].GetPathPoints().Length - 1;
        }
    }
Ejemplo n.º 10
0
        /// <summary>Sets the currently displayed rail and text in the main editor</summary>
        /// <param name="railManager">The RailManager component selected in the Inspector</param>
        private void InitializeMainEditor(RailManager railManager)
        {
            // Default values
            var  heading     = "NO RAILS FOUND";
            Rail currentRail = null;

            // If a rail is supposed to be displayed
            if (_currentRailIndex != -1 && _rails[_currentRailIndex] != null)
            {
                currentRail = _rails[_currentRailIndex];
                heading     = currentRail.gameObject.name.ToUpper();
            }

            // If no rail is displayed, but rails are available
            else if (_rails.Count > 0)
            {
                heading = "SELECT RAIL TO EDIT";
            }

            DrawMainEditor(currentRail, heading);
        }
Ejemplo n.º 11
0
    private RailManager rm;             // reference to rail manager

    // Set up the singleton design pattern
    private void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }
        // Set up the speedometer
        speedometer.minValue = GameManager.MIN_SPEED;
        speedometer.maxValue = GameManager.MAX_SPEED / 2;

        //Setup the tiltometer
        tiltometer.minValue = -GameManager.TILT_THRESHHOLD;
        tiltometer.maxValue = GameManager.TILT_THRESHHOLD;

        // Hide game over panel and get the reference to the image on it
        gameOverPanel.gameObject.SetActive(false);
        gameOverPanelBG       = gameOverPanel.GetComponent <Image>();
        gameOverPanelBG.color = new Color(gameOverPanelBG.color.r, gameOverPanelBG.color.g, gameOverPanelBG.color.b, 0);

        rm   = GameObject.FindObjectOfType <RailManager>();
        audi = GetComponent <AudioSource>();
    }
Ejemplo n.º 12
0
 void Start()
 {
     railmanager = GetComponentInChildren <RailManager>();
 }
Ejemplo n.º 13
0
 void Start()
 {
     rm = Object.FindObjectOfType <RailManager>();
     processing.gameObject.SetActive(false);
 }
Ejemplo n.º 14
0
 public int whereToActivate; // which location will movement activate?
 // Start is called before the first frame update
 void Start()
 {
     rmove   = FindObjectOfType <RailMovement>();
     rManage = FindObjectOfType <RailManager>();
 }
 // Start is called before the first frame update
 void Start()
 {
     anim    = GetComponent <Animator>();
     rmove   = FindObjectOfType <RailMovement>();
     rManage = FindObjectOfType <RailManager>();
 }
Ejemplo n.º 16
0
 private void OnEnable()
 {
     m_target = (RailManager)target;
 }