Exemplo n.º 1
0
    public void Start()
    {
        healthCanvas = GameObject.FindWithTag("HealthCanvas").GetComponent <Canvas>();
        GameObject hm = Instantiate(healthManagerPrefab, healthCanvas.transform);

        healthUI  = hm.GetComponent <HealthUI>();
        uiTracker = hm.GetComponent <UITrackObject>();

        Debug.Assert(uiTracker != null, "Failed to find UI Tracker component!");
        Debug.Assert(healthUI != null, "Health Manager Prefab needs a Health UI component");

        if (RandomStartingHealth)
        {
            MaxHealth     = Random.Range(MinStartHealth, MaxStartHealth);
            MaxHealth    -= MaxHealth % 2;
            CurrentHealth = MaxHealth;
        }

        // Set our tracking target and current health
        uiTracker.TrackTarget = gameObject;
        healthUI.SetHealth(CurrentHealth, MaxHealth);
    }
Exemplo n.º 2
0
    public void CloseInfoWindow(CanInspect _io, int _index = -1)
    {
        if (_index == -1)
        {
            _index = currentInfoWindows.FindIndex(x => x.User == _io);
            if (_index == -1)
            {
                return;
            }
        }

        currentInfoWindows[_index].Window.HideWindow();
        UITrackObject _tracker = currentInfoWindows[_index].Window.GetComponent <UITrackObject>();

        if (_tracker != null)
        {
            _tracker.trackTransform = null;
        }

        //trackedComponent = null;
        currentInfoWindows.RemoveAt(_index);
    }
Exemplo n.º 3
0
    //public void ToggleWindow(InteractiveObject _io, InteractiveObject.State _state, WindowType _type) { // currently only support for 1 window, but maybe more later?
    //    if (currentInfoWindow != null && currentInfoWindow.OwnerIO == _io)
    //        CloseCurrentInfoWindow();
    //    else
    //        OpenNewWindow(_io, _state, _type);
    //}

    public void OpenNewWindow(CanInspect _inspectable, CanInspect.State _state, WindowType _type)
    {
        int          _index         = currentInfoWindows.FindIndex(x => x.User == _inspectable);
        UIInfoWindow _currentWindow = null;

        if (_index > -1)
        {
            _currentWindow = currentInfoWindows[_index].Window;

            if (_currentWindow.OwnerInspectable == _inspectable)
            {
                if (_state != _currentWindow.State)
                {
                    _currentWindow.ChangeState(_state);
                }

                return;
            }

            CloseInfoWindow(_inspectable, _index); // not sure if needed
        }

        switch (_type)
        {
        case WindowType.Basic:
            _currentWindow = ComponentWindow_Main;
            break;

        case WindowType.Basic_SecondWindow:
            _currentWindow = ComponentWindow_Sub;
            break;

        case WindowType.ComponentHolder_x6:
            _currentWindow = ComponentHolderWindow_x6;
            break;

        case WindowType.ComponentHolder_x9:
            _currentWindow = ComponentHolderWindow_x9;
            break;

        case WindowType.ComponentHolder_15:
            _currentWindow = ComponentHolderWindow_x15;
            break;

        case WindowType.ComponentHolder_x24:
            _currentWindow = ComponentHolderWindow_x24;
            break;
        }

        // make sure no on else is using this window
        for (int i = 0; i < currentInfoWindows.Count; i++)
        {
            if (currentInfoWindows [i].Window == _currentWindow)
            {
                CloseInfoWindow(currentInfoWindows[i].User, i);
            }
        }

        ComponentObject _trackedComponent = null;

        switch (_type)
        {
        case WindowType.Basic:
        case WindowType.Basic_SecondWindow:
            _trackedComponent = _inspectable.GetComponent <ComponentObject>();
            break;

        case WindowType.ComponentHolder_x6:
        case WindowType.ComponentHolder_x9:
        case WindowType.ComponentHolder_15:
        case WindowType.ComponentHolder_x24:
            currentComponentHolder = _inspectable.GetComponent <ComponentHolder>();

            // set button-names to be the same as in the component-slots
            ComponentObject.ComponentType _compType;
            int _compTypeID;
            for (int i = 0; i < _currentWindow.Buttons.Length; i++)
            {
                _compType   = currentComponentHolder.ComponentSlots[i].SlotType;
                _compTypeID = currentComponentHolder.ComponentSlots[i].SlotTypeID;
                _currentWindow.Buttons[i].GetComponentInChildren <Text>().text = ComponentInfoManager.Instance.AllComponentsInfo[_compType][_compTypeID].Name;
            }
            break;
        }

        _currentWindow.UI_Image.sprite = _inspectable.Selected_Sprite;
        _currentWindow.UI_Name.text    = _inspectable.Selected_Name;
        _currentWindow.UI_Desc.text    = _inspectable.Selected_Desc;

        UITrackObject _tracker = _currentWindow.GetComponent <UITrackObject>();

        if (_tracker != null)
        {
            _tracker.trackTransform = _inspectable.transform;
        }

        _currentWindow.ChangeState(_state);
        _currentWindow.ShowWindow(_inspectable, _trackedComponent);
        currentInfoWindows.Add(new InfoWindowUser(_currentWindow, _inspectable));

        UpdateButtonGraphics(_inspectable);
    }