예제 #1
0
    void Initialize()
    {
        supplyLines = new List <HexPath>();
        Name        = "UnnamedArmy";
        Food        = Mathf.Floor(Random.value * Global.MAXIMUM_FOOD);
        Manpower    = 100;
        roller      = new DiceRoller(6);
        // Create a drawer.
        drawer = new EntityDrawer(transform);

        //Attempt to wire the SelectionInterface.
        SelectionInterface = transform.GetComponent <SelectableObj>();
        if (SelectionInterface == null)
        {
            throw new UnityException("Failed to link Army Entity to a SelectionInterface.");
        }
        else
        {
            WireSelectionInterface();
        }

        //Wire up the GM
        Global.GM.NextTurn += OnStartTurn;

        //Present UI Components.
    }
예제 #2
0
    public void KeyDownSelect(KeyCode key)
    {
        if (Input.GetKeyDown(key))
        {
            if (SelectedObj != null)
            {
                Deselect();
                LastSelected = SelectedObj;
            }


            var        ray = UnityEngine.Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            Debug.DrawRay(ray.origin, ray.direction, Color.green, 100f); // only draws once. Re-clicking does nothing
            if (Physics.Raycast(ray, out hit))
            {
                var selectedTransform = hit.transform;
                SelectedObj = selectedTransform.GetComponent <SelectableObj>();
                // If the transform has a selectable Component, run the Selection logic.
                if (SelectedObj != null)
                {
                    SelectedObj.LastSelectKey = key;  // Better way to do this ? ?
                    Select();
                }
            }
        }
    }
예제 #3
0
    protected virtual void CheckResult()
    {
        m_answer = m_sObjs.FirstOrDefault(a => a.id == selectedId);

        bool result = CheckMatch(m_answer);

        if (onLevelComplete != null)
        {
            onLevelComplete(result);
        }

        AudioMng.PlayOneShot(m_answer.selectionData.clip);

        if (!result)
        {
            m_isRestarting = true;
            wallTrans.DOMoveY(m_wallStartPos.y, 1f)
            .SetEase(Ease.OutQuad)
            .OnComplete(() => m_isRestarting = false);

            CameraShake.ShakeAll();
        }
        else
        {
            GameOver();
        }
    }
예제 #4
0
    public GameObject ArmyPrefab;      //Remove this later.

    // Update is called once per frame.
    // Used to determine if something new has been selected.
    void Update()
    {
        // Left mouse will select a new SelectableObj.
        if (Input.GetKeyDown(KeyCode.Mouse0))
        {
            if (SelectedObj != null)
            {
                Deselect();
            }

            var        ray = UnityEngine.Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            Debug.DrawRay(ray.origin, ray.direction, Color.green, 100f);             // only draws once. Re-clicking does nothing
            if (Physics.Raycast(ray, out hit))
            {
                var selectedTransform = hit.transform;
                SelectedObj = selectedTransform.GetComponent <SelectableObj>();

                // If the transform has a selectable Component, run the Selection logic.
                if (SelectedObj != null)
                {
                    Select();
                }
            }
        }
        //Right keys will issue commands to selectableObj.
        //Army spawning key.Move code elsewhere at some point.
        //else if (Input.GetKeyDown(KeyCode.V)) {
        //	if (SelectedObj != null) {
        //		Vector3 position = SelectedObj.transform.position;
        //		Quaternion rotation = Quaternion.Euler(0, 0, 0);
        //		Instantiate(ArmyPrefab, position, rotation);
        //	}
        //}
    }
예제 #5
0
    private void Update()
    {
        RaycastHit hit;

        if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.rotation * Vector3.forward, out hit, Mathf.Infinity) && hit.transform.tag == "Menu")
        {
            //Debug.Log("Hitting a thing");
            if (currentMenuHit == null)
            {
                //Debug.Log("Forward!");
                //hit.transform.position = new Vector3(hit.transform.position.x, hit.transform.position.y, hit.transform.position.z - 0.05f);
                currentMenuHit = hit.transform.gameObject;
            }
        }
        else if (currentMenuHit != null)
        {
            //Debug.Log("Back you!");
            //currentMenuHit.transform.position = new Vector3(currentMenuHit.transform.position.x, currentMenuHit.transform.position.y, currentMenuHit.transform.position.z + 0.05f);
            currentMenuHit = null;
        }

        if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.rotation * Vector3.forward, out hit, Mathf.Infinity) && hit.transform.tag == "selectable")
        {
            currentSelection = hit.transform.gameObject.GetComponent <SelectableObj>();
            unhighlight.Invoke(); // unselect everything before selecting the new button
            currentSelection.onHighlight();
        }
        else if (currentSelection != null)
        {
            unhighlight.Invoke();
            currentSelection.onUnhighlight();
            currentSelection = null;
        }
    }
예제 #6
0
 public void ClearSelected()
 {
     if (SelectedObj != null)
     {
         Deselect();
         LastSelected = SelectedObj;
     }
 }
예제 #7
0
    void EndOfDay()
    {
        v_elect_stock += v_elect_prod;
        if (v_elect_stock > 100)
        {
            v_elect_stock = 100;
        }
        else if (v_elect_stock < 0)
        {
            v_elect_stock = 0;
        }

        v_food_stock += v_food_prod;

        if (v_food_stock < 0 && humans.Count > 0)
        {
            if (v_food_stock < v_food_prod / (float)humanCount)
            {
                humanCount = 0;
                Debug.Log("Kill 2 human =" + v_food_stock);

                foreach (SelectableObj so in _humans)
                {
                    so.Removed(0);
                }
                humans.Clear();
            }
            else
            {
                humanCount--;
                Debug.Log("Kill 1 human =" + v_food_stock);

                SelectableObj so = humans[humans.Keys.First()];
                humans.Remove(humans.Keys.First());
                so.Removed(0);
            }
        }

        if (v_food_stock < 0)
        {
            v_food_stock      = 0;
            _food_stock.color = Color.red;
        }
        else
        {
            _food_stock.color = Color.white;
        }
    }
예제 #8
0
    // Update is called once per frame.
    void Update()
    {
        // Move the responsibility of setting Map Viewing modes to another class later.

        // Shows the Food Map.
        if (Input.GetKeyDown(KeyCode.F))
        {
            drawer.Color = new Color(Food / 4f, 0, 0);
        }
        //Shows the Control Map.
        else if (Input.GetKeyDown(KeyCode.G))
        {
            if (Controller != null)
            {
                drawer.Color = Controller.Colour;
            }
            else
            {
                drawer.Color = Color.black;
            }
        }
        // Clears the map.
        else if (Input.GetKeyDown(KeyCode.R))
        {
            drawer.Color = Color.white;
        }

        //Attempt to wire the SelectionInterface.
        SelectionInterface = transform.GetComponent <SelectableObj>();
        if (SelectionInterface == null)
        {
            throw new UnityException("Failed to link Army Entity to a SelectionInterface.");
        }
        else
        {
            WireSelectionInterface();
        }

        //If Activated, run the extended activation methods.
        if (activated)
        {
            ActiveUpdate();
        }

        Draw();
    }
예제 #9
0
    private bool CheckMatch(SelectableObj answer)
    {
        if (answer.isNotAnswer)
        {
            return(false);
        }

        if (matchAnimState)
        {
            var clickToChangeState = heartObj.GetComponentInChildren <ClickToChangeState>();

            if (clickToChangeState == null || !clickToChangeState.IsEndState)
            {
                return(false);
            }
        }

        return(true);
    }
예제 #10
0
    void Initialize()
    {
        Name = "UnnamedArmy";
        Food = Mathf.Floor(Random.value * Global.MAXIMUM_FOOD);

        // Create a drawer.
        drawer = new EntityDrawer(transform);

        //Attempt to wire the SelectionInterface.
        SelectionInterface = transform.GetComponent <SelectableObj>();
        if (SelectionInterface == null)
        {
            throw new UnityException("Failed to link Army Entity to a SelectionInterface.");
        }
        else
        {
            WireSelectionInterface();
        }

        //Present UI Components.
    }
예제 #11
0
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out hit, _distance, _selectionLayer))
            {
                SelectableObj so = hit.collider.GetComponent <SelectableObj>();
                if (so != null && so != _lastSelected)
                {
                    if (_lastSelected != null)
                    {
                        _lastSelected.Diselect();
                    }
                    _lastSelected = so;
                    _lastSelected.Select();

                    Vector2 position = Camera.main.WorldToScreenPoint(_lastSelected.head.position);

                    position.x = (position.x / Screen.width) * 1350;
                    position.y = (position.y / Screen.height) * 1080;

                    _UI.SetPosition(position, so.robot, so);

                    //float _minDst = 270f, _maxDst = 480f;
                    //float scaleMul = 1f - (((transform.position - hit.point).sqrMagnitude - _minDst) / (_maxDst - _minDst)) * .2f;
                    //_UI.localScale = Vector2.one * scaleMul;

                    //Debug.Log(string.Format("{0} has been selected", _lastSelected.sName));
                }
            }
            else
            {
                _lastSelected = null;
                _UI.SetPosition(Vector2.one * -100, true, null);
            }
        }
    }
예제 #12
0
    protected virtual void CheckResult()
    {
        m_answer = m_sObjs.FirstOrDefault(a => a.id == selectedId);

        m_isWin = CheckMatch(m_answer);

        WallState += dialogDatas[ChatDialogState].wallStateEffect;

        chatDialogSpr.sprite = dialogDatas[m_chatDialogState].GetRandomSpr();

        AudioMng.PlayOneShot(dialogDatas[ChatDialogState].feedbackClip);

        if (onLevelComplete != null)
        {
            onLevelComplete(m_isWin);
        }

        // End game if no more try
        m_tryLeft--;

        if (m_tryLeft <= 0)
        {
            GameOver();
            return;
        }

        if (!m_isWin)
        {
            m_isRestarting = true;
            wallTrans.DOMoveY(m_wallStartPos.y, 1f)
            .SetEase(Ease.OutQuad)
            .OnComplete(() => m_isRestarting = false);
        }
        else
        {
            GameOver();
        }
    }
예제 #13
0
    // Update is called once per frame.
    void Update()
    {
        MapDrawingUpdater();

        //Attempt to wire the SelectionInterface.
        SelectionInterface = transform.GetComponent <SelectableObj>();
        if (SelectionInterface == null)
        {
            throw new UnityException("Failed to link Army Entity to a SelectionInterface.");
        }
        else
        {
            WireSelectionInterface();
        }

        //If Activated, run the extended activation methods.
        if (activated)
        {
            ActiveUpdate();
        }

        Draw();
    }
예제 #14
0
 public void SetPosition(Vector2 position, bool robot, SelectableObj so)
 {
     _rect.anchoredPosition = position;
     this.robot             = robot;
     this.so = so;
 }
예제 #15
0
 private bool CheckMatch(SelectableObj answer)
 {
     return(WallState == wallStateSprites.Length - 1);
 }