示例#1
0
    private void UpdateUI()
    {
        // Update targetUnit and targetTile
        hoverUnit  = battle.GetUnit(transform.position);
        targetTile = battle.GetTile(transform.position);

        // Update UI for targetUnit

        // UI: Unit Panel L
        Animator          uplAnim      = unitPanelL.GetComponent <Animator>();
        AnimatorStateInfo uplAnimState = uplAnim.GetCurrentAnimatorStateInfo(0);

        // Update targetUnit
        if (hoverUnit != targetUnit)
        {
            if (uplAnimState.IsName("SlideIn"))
            {
                // targetUnit = null;
                float animTime = Mathf.Max(1f - uplAnimState.normalizedTime, 0f);
                uplAnim.Play("SlideOut", -1, animTime);
            }

            if (uplAnimState.IsName("SlideOut") && uplAnimState.normalizedTime > 1f)
            {
                targetUnit = hoverUnit;
            }
        }

        // When targetUnit is updated
        if (hoverUnit == targetUnit)
        {
            bool showPanel = targetUnit != null && battle.ShowPanel();

            if (showPanel && uplAnimState.IsName("SlideOut") && uplAnimState.normalizedTime > 1f)
            {
                targetUnit.unit.SetPanelUI(unitPanelL);
                uplAnim.Play("SlideIn");
            }

            if (!showPanel && uplAnimState.IsName("SlideIn") && uplAnimState.normalizedTime > 1f)
            {
                targetUnit.unit.SetPanelUI(unitPanelL);
                uplAnim.Play("SlideOut");
            }
        }

        // UI: Unit Commands Menu
        Animator          ucmAnim      = unitCommandsMenu.GetComponent <Animator>();
        AnimatorStateInfo ucmAnimState = ucmAnim.GetCurrentAnimatorStateInfo(0);

        if (!onUnitCommands && ucmAnimState.IsName("SlideIn"))
        {
            float animTime = Mathf.Max(1f - ucmAnimState.normalizedTime, 0f);
            ucmAnim.Play("SlideOut", -1, animTime);
        }

        if (onUnitCommands && targetUnit == battle.currentUnit && ucmAnimState.IsName("SlideOut") && ucmAnimState.normalizedTime > 1f)
        {
            unitCommandsMenu.transform.Find("BackImage/MoveButton").gameObject.GetComponent <Button>().interactable = targetUnit.unit.apCur > 0;
            unitCommandsMenu.transform.Find("BackImage/ActButton").gameObject.GetComponent <Button>().interactable  = targetUnit.unit.apCur > 0;
            unitCommandsMenu.transform.Find("BackImage/APImage/Text").gameObject.GetComponent <Text>().text         = targetUnit.unit.apCur.ToString();
            Color apColor = new Color(1f, 1f, 1f);

            if (targetUnit.unit.apCur == 1)
            {
                apColor = new Color(1f, 196f / 256f, 0f);
            }

            if (targetUnit.unit.apCur == 0)
            {
                apColor = new Color(0.5f, 0.15f, 0.15f);
            }

            unitCommandsMenu.transform.Find("BackImage/APImage/Text").gameObject.GetComponent <Text>().color = apColor;

            ucmAnim.Play("SlideIn");
        }

        // UI: Unit Wait
        Animator          uwAnim      = unitWait.GetComponent <Animator>();
        AnimatorStateInfo uwAnimState = uwAnim.GetCurrentAnimatorStateInfo(0);

        if (!onUnitWait && uwAnimState.IsName("SlideIn"))
        {
            float animTime = Mathf.Max(1f - uwAnimState.normalizedTime, 0f);
            uwAnim.Play("SlideOut", -1, animTime);
        }

        if (onUnitWait && targetUnit == battle.currentUnit && uwAnimState.IsName("SlideOut") && uwAnimState.normalizedTime > 1f)
        {
            uwAnim.Play("SlideIn");
        }

        // UI: Unit Look Status Key
        Animator          uskAnim      = unitStatusKey.GetComponent <Animator>();
        AnimatorStateInfo uskAnimState = uskAnim.GetCurrentAnimatorStateInfo(0);

        if (!(onUnitLook && targetUnit != null) && uskAnimState.IsName("SlideIn"))
        {
            float animTime = Mathf.Max(1f - uskAnimState.normalizedTime, 0f);
            uskAnim.Play("SlideOut", -1, animTime);
        }

        if ((onUnitLook && targetUnit != null) && uskAnimState.IsName("SlideOut") && uskAnimState.normalizedTime > 1f)
        {
            uskAnim.Play("SlideIn");
        }

        // UI: Cancel key
        Animator          uckAnim      = unitCancelKey.GetComponent <Animator>();
        AnimatorStateInfo uckAnimState = uckAnim.GetCurrentAnimatorStateInfo(0);

        if (!(onUnitLook || onStatusScreen || onUnitMove || onUnitAction) && uckAnimState.IsName("SlideIn"))
        {
            float animTime = Mathf.Max(1f - uckAnimState.normalizedTime, 0f);
            uckAnim.Play("SlideOut", -1, animTime);
        }

        if ((onUnitLook || onStatusScreen || onUnitMove || onUnitAction) && uckAnimState.IsName("SlideOut") && uckAnimState.normalizedTime > 1f)
        {
            uckAnim.Play("SlideIn");
        }

        // UI: Unit Move Key
        Animator          umkAnim      = unitMoveKey.GetComponent <Animator>();
        AnimatorStateInfo umkAnimState = umkAnim.GetCurrentAnimatorStateInfo(0);

        if (!(onUnitMove && targetTiles.Contains(targetTile)) && umkAnimState.IsName("SlideIn"))
        {
            float animTime = Mathf.Max(1f - umkAnimState.normalizedTime, 0f);
            umkAnim.Play("SlideOut", -1, animTime);
        }

        if ((onUnitMove && targetTiles.Contains(targetTile)) && umkAnimState.IsName("SlideOut") && umkAnimState.normalizedTime > 1f)
        {
            umkAnim.Play("SlideIn");
        }

        // UI: Unit Action Key
        Animator          uakAnim      = unitActionKey.GetComponent <Animator>();
        AnimatorStateInfo uakAnimState = uakAnim.GetCurrentAnimatorStateInfo(0);
        bool canConfirmAction          = (onUnitAction && (currentAction.GetActionType() == ActionType.Fixed ||
                                                           (currentAction.GetActionType() == ActionType.Targeted && targetTiles.Contains(targetTile))));

        if (!canConfirmAction && uakAnimState.IsName("SlideIn"))
        {
            float animTime = Mathf.Max(1f - uakAnimState.normalizedTime, 0f);
            uakAnim.Play("SlideOut", -1, animTime);
        }

        if (canConfirmAction && uakAnimState.IsName("SlideOut") && uakAnimState.normalizedTime > 1f)
        {
            uakAnim.Play("SlideIn");
        }

        // UI: Unit Status Screen
        Animator          usAnim      = unitStatus.GetComponent <Animator>();
        AnimatorStateInfo usAnimState = usAnim.GetCurrentAnimatorStateInfo(0);

        if (!onStatusScreen && usAnimState.IsName("SlideIn"))
        {
            float animTime = Mathf.Max(1f - usAnimState.normalizedTime, 0f);
            usAnim.Play("SlideOut", -1, animTime);
        }

        if (onStatusScreen && usAnimState.IsName("SlideOut") && usAnimState.normalizedTime > 1f)
        {
            hoverUnit.unit.SetStatusUI(unitStatus);
            usAnim.Play("SlideIn");
        }

        // UI: Unit Action Menu
        Animator          uaAnim      = unitActions.GetComponent <Animator>();
        AnimatorStateInfo uaAnimState = uaAnim.GetCurrentAnimatorStateInfo(0);

        if (!onUnitActions && uaAnimState.IsName("SlideIn"))
        {
            float animTime = Mathf.Max(1f - uaAnimState.normalizedTime, 0f);
            uaAnim.Play("SlideOut", -1, animTime);
        }

        if (onUnitActions && uaAnimState.IsName("SlideOut") && uaAnimState.normalizedTime > 1f)
        {
            foreach (Transform action in unitActionsContent)
            {
                Destroy(action.gameObject);
            }

            foreach (Action action in targetUnit.unit.actions)
            {
                GameObject go = Instantiate(unitActionPrefab, unitActionsContent);
                go.GetComponent <Text>().text = action.GetName();
                go.GetComponent <Button>().onClick.AddListener(() => OnAction(action));
            }

            uaAnim.Play("SlideIn");
        }

        // UI: End Screen
        endScreenWin.SetActive(onEndWin);
        endScreenLose.SetActive(onEndLose);
    }