예제 #1
0
    private void updatePanels()
    {
        updatePanelsBehaviourList();
        resetPanels();
        List <int> panelsToActivate = new List <int>();

        for (int i = 0; i < NbOfPanelsToActivate; i++)
        {
            panelsToActivate.Add(getPanelIndex(panelsToActivate));
        }
        panelsToActivate.ForEach((index) =>
        {
            int panelType               = Random.Range(0, panelPrefabs.Length);
            GameObject currentPanel     = panels[index].transform.parent.gameObject;
            GameObject newPanel         = Instantiate(panelPrefabs[panelType], currentPanel.transform.position, currentPanel.transform.rotation);
            newPanel.transform.parent   = currentPanel.transform.parent;
            newPanel.transform.position = currentPanel.transform.position;
            newPanel.transform.rotation = currentPanel.transform.rotation;
            newPanel.transform.SetSiblingIndex(currentPanel.transform.GetSiblingIndex());
            Destroy(currentPanel);
            PanelBehaviour newPanelBehaviour = newPanel.GetComponentInChildren <PanelBehaviour>();
            newPanelBehaviour.addListener(TriggerPanel);
            newPanelBehaviour.Activate();
        });
    }
예제 #2
0
    // Use this for initialization
    void Start()
    {
        moveDirection = this.randomMoveDirection ();

        GameObject go = GameObject.Find("Tile Map");
        if (go != null) terrain = go.GetComponent<PATileTerrain>();
        plantDistance = 2;
        meatDistance = 2;
        strength = 0;
        maxHealth = 100;
        health = 100;
        poisoningToHealth = 0.1f;
        alcoholTolerance = 0;
        poisoning = 0;
        poisoningFall = 1;
        panel = (PanelBehaviour) FindObjectOfType(typeof(PanelBehaviour));
        state = State.Searching;
    }
예제 #3
0
        /// <summary>
        /// Moves the gameObject from its current panel to the panel at the given position.
        /// </summary>
        /// <param name="targetPanel">The panel on the grid that the gameObject will travel to.</param>
        /// <param name="snapPosition">If true, teh gameObject will immediately teleport to its destination without a smooth transition.</param>
        /// <returns>Returns false if the panel is occupied or not in the grids array of panels.</returns>
        public bool MoveToPanel(PanelBehaviour targetPanel, bool snapPosition = false, GridAlignment tempAlignment = GridAlignment.NONE)
        {
            if (tempAlignment == GridAlignment.NONE)
            {
                tempAlignment = _defaultAlignment;
            }
            else
            {
                _tempAlignment = tempAlignment;
            }

            if (!targetPanel)
            {
                return(false);
            }

            if (IsMoving && !canCancelMovement || targetPanel.Alignment != tempAlignment && tempAlignment != GridAlignment.ANY || !_canMove)
            {
                return(false);
            }

            _previousPanel = _currentPanel;
            _targetPanel   = targetPanel;

            //Sets the new position to be the position of the panel added to half the gameOgjects height.
            //Adding the height ensures the gameObject is not placed inside the panel.
            float offset = 0;

            if (!_meshFilter)
            {
                offset = transform.localScale.y / 2;
            }
            else
            {
                offset = (_meshFilter.mesh.bounds.size.y * transform.localScale.y) / 2;
            }

            Vector3 newPosition = _targetPanel.transform.position + new Vector3(0, offset, 0);

            _targetPosition = newPosition;


            MoveDirection = targetPanel.Position - _position;

            SetIsMoving(true);

            //If snap position is true, hard set the position to the destination. Otherwise smoothly slide to destination.
            if (snapPosition)
            {
                transform.position = newPosition;
                SetIsMoving(false);
            }
            else
            {
                _MoveRoutine = StartCoroutine(LerpPosition(newPosition));
            }

            //Sets the current panel to be unoccupied if it isn't null
            if (_currentPanel)
            {
                _currentPanel.Occupied = false;
            }

            //Updates the current panel
            _currentPanel          = _targetPanel;
            _currentPanel.Occupied = !_canBeWalkedThrough;
            _position = _currentPanel.Position;

            return(true);
        }
예제 #4
0
        /// <summary>
        /// Moves the gameObject from its current panel to the panel at the given position.
        /// </summary>
        /// <param name="panelPosition">The position of the panel on the grid that the gameObject will travel to.</param>
        /// <param name="snapPosition">If true, the gameObject will immediately teleport to its destination without a smooth transition.</param>
        /// <returns>Returns false if the panel is occupied or not in the grids array of panels.</returns>
        public bool MoveToPanel(Vector2 panelPosition, bool snapPosition = false, GridAlignment tempAlignment = GridAlignment.NONE, bool canBeOccupied = false, bool reservePanel = true)
        {
            if (tempAlignment == GridAlignment.NONE)
            {
                tempAlignment = _defaultAlignment;
            }
            else
            {
                _tempAlignment = tempAlignment;
            }

            if (IsMoving && !canCancelMovement || !_canMove)
            {
                return(false);
            }
            else if (canCancelMovement && IsMoving)
            {
                StopAllCoroutines();
            }

            //If it's not possible to move to the panel at the given position, return false.
            if (!BlackBoardBehaviour.Instance.Grid.GetPanel(panelPosition, out _targetPanel, _position == panelPosition || canBeOccupied, tempAlignment))
            {
                return(false);
            }

            _previousPanel = _currentPanel;

            //Sets the new position to be the position of the panel added to half the gameObjects height.
            //Adding the height ensures the gameObject is not placed inside the panel.
            float offset = 0;

            if (!_meshFilter)
            {
                offset = transform.localScale.y / 2;
            }
            else
            {
                offset = (_meshFilter.mesh.bounds.size.y * transform.localScale.y) / 2;
            }

            Vector3 newPosition = _targetPanel.transform.position + new Vector3(0, offset, 0);

            _targetPosition = newPosition;

            MoveDirection = panelPosition - _position;

            SetIsMoving(true);

            //If snap position is true, hard set the position to the destination. Otherwise smoothly slide to destination.
            if (snapPosition)
            {
                transform.position = newPosition;
                SetIsMoving(false);
            }
            else
            {
                _MoveRoutine = StartCoroutine(LerpPosition(newPosition));
            }

            //Sets the current panel to be unoccupied if it isn't null
            if (_currentPanel)
            {
                _currentPanel.Occupied = false;
            }

            //Updates the current panel
            _currentPanel = _targetPanel;
            if (reservePanel)
            {
                _currentPanel.Occupied = !_canBeWalkedThrough;
            }
            _position = _currentPanel.Position;

            return(true);
        }