Exemplo n.º 1
0
    public void Close()
    {
        if (_state == CraftingMenuState.CraftingMenu_Closed)
        {
            return;
        }

        _state       = CraftingMenuState.CraftingMenu_Closing;
        _timeInState = 0.0f;
        //Play a sound effect
        _sound.Play(_sound.MenuDown, 1.0f);

        // destroy all cloned item quads placed into crafting slots
        _lastClickedQuad = null;
        _craftResult     = null;

        for (int i = 0; i <= _craftingSlots.Length - 1; i++)
        {
            if (_craftingSlots [i] != null)
            {
                Destroy(_craftingSlots [i]);
                _craftingSlots [i] = null;
            }
        }
    }
Exemplo n.º 2
0
    public void Open()
    {
        GameManager.UI.ShowMap(false);
        //Play a sound effect
        _sound.Play(_sound.MenuUp, 1.0f);

        _state       = CraftingMenuState.CraftingMenu_Opening;
        _timeInState = 0.0f;
    }
Exemplo n.º 3
0
    // animation of crafting menu
    void AnimateCraftingMenu()
    {
        _timeInState += Time.deltaTime; // TODO: ELAPSEDTIME

        if (_state == CraftingMenuState.CraftingMenu_Opening)
        {
            float alpha = Mathf.Min(_timeInState / FadeTime, 1.0f);

            ShowWithAlpha(_itemWheel, alpha);
            ShowWithAlpha(_craftingBackdrop, alpha);

            for (int i = 0; i < 5; i++)
            {
                ShowWithAlpha(_itemQuads [i], alpha);
                ShowWithAlpha(_itemCountQuads [i], alpha);
            }

            if (alpha == 1.0f)
            {
                _state = CraftingMenuState.CraftingMenu_Open;
            }
        }
        else if (_state == CraftingMenuState.CraftingMenu_Open)
        {
            // nothing
        }
        else if (_state == CraftingMenuState.CraftingMenu_Closing)
        {
            _craftingButton.GetComponent <Renderer>().enabled = false;

            float alpha = Mathf.Max(1.0f - (float)(_timeInState / FadeTime), 0.0f);

            ShowWithAlpha(_itemWheel, alpha);
            ShowWithAlpha(_craftingBackdrop, alpha);

            for (int i = 0; i < 5; i++)
            {
                ShowWithAlpha(_itemQuads [i], alpha);
                ShowWithAlpha(_itemCountQuads [i], alpha);
                ;
            }

            if (alpha == 0.0f)
            {
                _state = CraftingMenuState.CraftingMenu_Closed;
            }
        }
        else if (_state == CraftingMenuState.CraftingMenu_Closed)
        {
            for (int i = 0; i < 5; i++)
            {
                ShowWithAlpha(_itemQuads [i], 0.0f);
                ShowWithAlpha(_itemCountQuads [i], 0.0f);
            }
        }
    }
Exemplo n.º 4
0
    // --------------------------------
    void Start()
    {
        _uiCamera  = transform.root.GetComponentInChildren <Camera>();
        _inventory = GameManager.Player.GetComponent <InventoryManager>();

        // wheelcenter
        Vector3 wheelCenter = _uiCamera.ViewportToWorldPoint(new Vector3(1.0f, 1.0f, 7.0f));

        _weaponWheel = (GameObject)Instantiate(WeaponWheelPrefab, wheelCenter, Quaternion.identity);
        _weaponWheel.transform.parent = transform;
        _weaponWheel.GetComponent <Renderer>().enabled = true;


        _itemWheel = (GameObject)Instantiate(ItemWheelPrefab, wheelCenter, Quaternion.identity);
        _itemWheel.transform.parent = transform;
        _itemWheel.GetComponent <Renderer>().enabled = false;

        _craftingBackdrop = (GameObject)Instantiate(CraftingBackdropPrefab, Vector3.zero, Quaternion.identity);
        _craftingBackdrop.transform.parent = transform;
        _craftingBackdrop.GetComponent <Renderer>().enabled = false;

        // position crafting button in screen coords.
        CraftButtonPos  = _uiCamera.ViewportToWorldPoint(CraftButtonPos);
        _craftingButton = (GameObject)Instantiate(CraftButtonPrefab, CraftButtonPos, Quaternion.identity);
        _craftingButton.transform.parent = transform;
        _craftingButton.GetComponent <Renderer>().enabled = false;


        _currentItem = 0;

        _state       = CraftingMenuState.CraftingMenu_Closed;
        _timeInState = 0.0f;


        // *** position all item quads and their counts at proper rotations for texture replacement ***
        _itemQuads      = new GameObject[5];
        _itemCountQuads = new GameObject[5];

        Vector3 quadPos = wheelCenter + Vector3.left * ItemWheelRadius;

        _itemQuads [0] = (GameObject)Instantiate(ItemQuadPrefab, quadPos, Quaternion.identity);
        _itemQuads [0].transform.parent = _weaponWheel.transform;
        quadPos             = wheelCenter + Vector3.left * ItemCountRadius;
        _itemCountQuads [0] = (GameObject)Instantiate(ItemCountQuadPrefab, quadPos, Quaternion.identity);
        _itemCountQuads [0].transform.parent = _weaponWheel.transform;

        // pi/8
        quadPos        = wheelCenter + Vector3.RotateTowards(Vector3.left, Vector3.down, Mathf.PI / 8.0f, 0.0f) * ItemWheelRadius;
        _itemQuads [1] = (GameObject)Instantiate(ItemQuadPrefab, quadPos, Quaternion.identity);
        _itemQuads [1].transform.parent = _weaponWheel.transform;
        quadPos             = wheelCenter + Vector3.RotateTowards(Vector3.left, Vector3.down, Mathf.PI / 8.0f, 0.0f) * ItemCountRadius;
        _itemCountQuads [1] = (GameObject)Instantiate(ItemCountQuadPrefab, quadPos, Quaternion.identity);
        _itemCountQuads [1].transform.parent = _weaponWheel.transform;

        // pi/4
        quadPos        = wheelCenter + Vector3.RotateTowards(Vector3.left, Vector3.down, Mathf.PI / 4.0f, 0.0f) * ItemWheelRadius;
        _itemQuads [2] = (GameObject)Instantiate(ItemQuadPrefab, quadPos, Quaternion.identity);
        _itemQuads [2].transform.parent = _weaponWheel.transform;
        quadPos             = wheelCenter + Vector3.RotateTowards(Vector3.left, Vector3.down, Mathf.PI / 4.0f, 0.0f) * ItemCountRadius;
        _itemCountQuads [2] = (GameObject)Instantiate(ItemCountQuadPrefab, quadPos, Quaternion.identity);
        _itemCountQuads [2].transform.parent = _weaponWheel.transform;

        // 3 pi / 8
        quadPos        = wheelCenter + Vector3.RotateTowards(Vector3.left, Vector3.down, Mathf.PI * 3.0f / 8.0f, 0.0f) * ItemWheelRadius;
        _itemQuads [3] = (GameObject)Instantiate(ItemQuadPrefab, quadPos, Quaternion.identity);
        _itemQuads [3].transform.parent = _weaponWheel.transform;
        quadPos             = wheelCenter + Vector3.RotateTowards(Vector3.left, Vector3.down, Mathf.PI * 3.0f / 8.0f, 0.0f) * ItemCountRadius;
        _itemCountQuads [3] = (GameObject)Instantiate(ItemCountQuadPrefab, quadPos, Quaternion.identity);
        _itemCountQuads [3].transform.parent = _weaponWheel.transform;


        // pi / 2
        quadPos        = wheelCenter + Vector3.down * ItemWheelRadius;
        _itemQuads [4] = (GameObject)Instantiate(ItemQuadPrefab, quadPos, Quaternion.identity);
        _itemQuads [4].transform.parent = _weaponWheel.transform;
        quadPos             = wheelCenter + Vector3.down * ItemCountRadius;
        _itemCountQuads [4] = (GameObject)Instantiate(ItemCountQuadPrefab, quadPos, Quaternion.identity);
        _itemCountQuads [4].transform.parent = _weaponWheel.transform;



        _lastClickedQuad = null;
        _draggingQuad    = null;

        // *** translate GUI positionings into screen coords ***
        ItemDescriptionBounds = new Rect(ItemDescriptionBounds.x * Screen.width,
                                         ItemDescriptionBounds.y * Screen.height,
                                         ItemDescriptionBounds.width * Screen.width,
                                         ItemDescriptionBounds.height * Screen.height);

        // crafting points get translated into screen res coords for checking distance from mouse pointer
        for (int i = 0; i <= CraftingPoints.Length - 1; i++)
        {
            CraftingPoints [i] = new Vector3(CraftingPoints [i].x * Screen.width,
                                             CraftingPoints [i].y * Screen.height,
                                             7.0f);
        }

        _craftingSlots = new GameObject[CraftingPoints.Length];
        for (int i = 0; i <= _craftingSlots.Length - 1; i++)
        {
            _craftingSlots [i] = null;
        }

        CraftingDropDistance *= Screen.width;

        //instantiate sound
        _sound = gameObject.GetComponentInChildren <UIAudioPlayer>();
    }