コード例 #1
0
    void Update()
    {
        if (IsInActionRadius() == true)
        {
            Vector3        mousePos   = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            Vector2        mousePos2D = new Vector2(mousePos.x, mousePos.y);
            RaycastHit2D[] hits       = Physics2D.RaycastAll(mousePos2D, Vector2.zero);

            if (hits.Length == 0)
            {
                isdetected = false;
            }

            foreach (var hit in hits)
            {
                if (hit.collider.tag == "substitudeItem")
                {
                    BaseConection baseConection = hit.collider.GetComponent <BaseConection>();
                    NPC_Info      npcInfo       = hit.collider.GetComponent <NPC_Info>();
                    PCController  pcController  = baseConection.FindPcInRadius();

                    string interactionStr = Global.Tooltip.LM_INTERACT + " / " + Global.Tooltip.RM_TURN_OFF;

                    if (pcController != null)
                    {
                        bool isConnected = pcController.peripherals.Contains(hit.collider.gameObject);
                        interactionStr = ((isConnected == true) ? Global.Tooltip.LM_DISCONNECT : Global.Tooltip.LM_CONNECT) + " / " + Global.Tooltip.RM_TURN_OFF;
                    }

                    isdetected = true;
                    //tooltipPosition = Camera.main.WorldToScreenPoint(hit.transform.position);
                    ShowToolTip(npcInfo == null ? "obj" : npcInfo.npcName, interactionStr);
                    TooltipLocate(hit.collider.transform.position);
                    return;
                }
                else if (hit.collider.tag == "table")
                {
                    TableController tableController = hit.collider.GetComponent <TableController>();

                    isdetected = true;
                    //tooltipPosition = Camera.main.WorldToScreenPoint(hit.collider.transform.position);

                    if (IsCurrentHandEmpty() && IsObjectExist(hits, Global.DROPED_ITEM_PREFIX, false) == false)
                    {
                        ShowToolTip((tableController.tableName == string.Empty) ? "table" : tableController.tableName,
                                    PrintRed(Global.Tooltip.NO_ACTIONS));
                    }
                    else if (IsCurrentHandEmpty() && IsObjectExist(hits, Global.DROPED_ITEM_PREFIX, false) == true)
                    {
                        Item itemOnTable = FindRaycast(hits, Global.DROPED_ITEM_PREFIX, false)?.collider
                                           .GetComponent <ItemCell>().item;

                        ShowToolTip((tableController.tableName == string.Empty) ? "table" + " (" + itemOnTable.itemName + ")"
                                                              : tableController.tableName + " (" + itemOnTable.itemName + ")",
                                    Global.Tooltip.LM_PICK_UP);
                    }
                    else if (IsCurrentHandEmpty() == false && IsObjectExist(hits, Global.DROPED_ITEM_PREFIX, false) == true)
                    {
                        Item         tool           = controller.GetItemInHand(controller.currentHand);
                        RaycastHit2D?itemOnTableHit = FindRaycast(hits, Global.DROPED_ITEM_PREFIX, false);
                        Item         temOnTable     = itemOnTableHit.GetValueOrDefault().collider.GetComponent <ItemCell>().item;

                        ItemCraftData craftData = CraftController.FindRecept_Static(tool, temOnTable,
                                                                                    CraftType.Cooking, /* TODO */
                                                                                    CraftTable.Table);

                        ShowToolTip((tableController.tableName == string.Empty) ? "table" + " (" + temOnTable.itemName + ")"
                                                              : tableController.tableName + " (" + temOnTable.itemName + ")",
                                    Global.Tooltip.LM_PUT + ((tableController.isCraftTable) ? ((craftData != null) ?
                                                                                               " / " + Global.Tooltip.RM_CRAFT + " " + craftData.recept.craftResult.itemName : string.Empty)
                                : string.Empty));
                    }
                    else
                    {
                        ShowToolTip((tableController.tableName == string.Empty) ? "table" : tableController.tableName,
                                    Global.Tooltip.LM_PUT);
                    }

                    TooltipLocate(hit.collider.transform.position);

                    return;
                }
                else if (hit.collider.name.Contains(Global.DROPED_ITEM_PREFIX))
                {
                    bool onTable = false;

                    foreach (var hitTable in hits)
                    {
                        if (hitTable.collider.tag == "table")
                        {
                            onTable = true;
                        }
                    }

                    if (onTable == false)
                    {
                        Item item       = hit.collider.GetComponent <ItemCell>().item;
                        Item itemInHand = controller.currentHand.GetComponent <ItemCell>().item;

                        isdetected = true;

                        string useInteraction = (item.itemSubstitution.IsSubstituted() == true && item.itemSubstitution.IsItemToUseExist(itemInHand)) ? " / " + Global.Tooltip.RM_TURN_ON : string.Empty;

                        ShowToolTip(item.itemName, (controller.IsEmpty(controller.currentHand) == true) ?
                                    Global.Tooltip.LM_PICK_UP + useInteraction
                            : ((useInteraction == string.Empty) ? PrintRed(Global.Tooltip.NO_ACTIONS) : useInteraction.Substring(" / ".Length)));

                        TooltipLocate(hit.collider.transform.position);

                        return;
                    }
                }
                else if (hit.collider.tag == "case")
                {
                    CaseController caseController = hit.collider.GetComponent <CaseController>();

                    isdetected = true;

                    ShowToolTip((caseController.caseName == string.Empty) ? "case" : caseController.caseName, (caseController.isOpen == false)
                                ? Global.Tooltip.LM_OPEN : Global.Tooltip.LM_CLOSE);

                    TooltipLocate(hit.collider.transform.position);

                    return;
                }
                else if (hit.collider.tag == "tv")
                {
                    TVController tvController = hit.collider.GetComponent <TVController>();

                    isdetected = true;
                    //tooltipPosition = Camera.main.WorldToScreenPoint(hit.collider.transform.position);

                    ShowToolTip("tv", (tvController.IsTvOpen() == false)
                                ? Global.Tooltip.LM_TURN_ON : Global.Tooltip.LM_TURN_OFF + " / " + Global.Tooltip.RM_NEXT_CHANNEL);
                    TooltipLocate(hit.collider.transform.position);

                    return;
                }
                else if (hit.collider.tag == "envObj")
                {
                    VendingController vending = hit.collider.GetComponent <VendingController>();

                    isdetected = true;
                    //tooltipPosition = Camera.main.WorldToScreenPoint(hit.collider.transform.position +
                    //                                                Global.Tooltip.EnvObjOffset());

                    ShowToolTip((vending.headerTitle == string.Empty) ? "vending" : vending.headerTitle.ToLower(),
                                Global.Tooltip.LM_USE);
                    TooltipLocate(hit.collider.transform.position);

                    return;
                }
                else if (hit.collider.tag == "pc")
                {
                    Item         itemInHand   = controller.currentHand.GetComponent <ItemCell>().item;
                    PCController pcController = hit.collider.GetComponent <PCController>();
                    Item         disk         = pcController.disk;

                    isdetected = true;
                    //tooltipPosition = Camera.main.WorldToScreenPoint(hit.collider.transform.position);

                    if (disk != null && controller.IsEmpty(controller.currentHand))
                    {
                        ShowToolTip("pc", Global.Tooltip.LM_INTERACT + " / " + Global.Tooltip.RM_PULL_THE_DISK);
                    }
                    else
                    {
                        ShowToolTip("pc", (controller.IsEmpty(controller.currentHand) == false &&
                                           itemInHand.itemName.Contains("disk"))
                                ? Global.Tooltip.LM_INTERACT + " / " + Global.Tooltip.RM_INSERT : Global.Tooltip.LM_INTERACT);
                    }

                    TooltipLocate(hit.collider.transform.position);
                }
                else if (hit.collider.tag == "playerAction")
                {
                    if (controller.IsEmpty(controller.currentHand) == false &&
                        controller.GetItemInHand(controller.currentHand).itemBuff.buff != null)
                    {
                        playerTooltip.gameObject.SetActive(true);
                    }
                    else
                    {
                        playerTooltip.gameObject.SetActive(false);
                    }

                    return;
                }
                else if (hit.collider.gameObject.name.Contains(Global.ITEM_SWITCH_PREFIX))
                {
                    isdetected = true;
                    ISwitchItem switchItem = hit.collider.GetComponent <ISwitchItem>();
                    Item        itemInHand = controller.GetItemInHand(controller.currentHand);

                    ShowToolTip(switchItem.GetISwitchName(), (itemInHand.IsSameItems(switchItem.GetNeedItem()) ?
                                                              Global.Tooltip.RM_INSERT : PrintRed(Global.Tooltip.NO_ACTIONS)));
                    TooltipLocate(hit.collider.transform.position);
                }
                else
                {
                    isdetected = false;
                }

                //playerTooltip.gameObject.SetActive(hit.collider.tag == "player");
            }

            playerTooltip.gameObject.SetActive(false);

            if (isTooltipOpen == true && isdetected == false)
            {
                HideToolTip();
            }
        }
        else
        {
            if (isTooltipOpen == true)
            {
                HideToolTip();
            }
        }
    }
コード例 #2
0
    void Update()
    {
        if (IsInActionRadius() == true)
        {
            Vector3        mousePos   = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            Vector2        mousePos2D = new Vector2(mousePos.x, mousePos.y);
            RaycastHit2D[] hits       = Physics2D.RaycastAll(mousePos2D, Vector2.zero);

            if (hits.Length == 0)
            {
                isdetected = false;
            }

            foreach (var hit in hits)
            {
                //Debug.Log(hit.collider.name);

                if (hit.collider.tag == "table")
                {
                    TableController tableController = hit.collider.GetComponent <TableController>();

                    isdetected = true;
                    Vector2 tooltipPosition = Camera.main.WorldToScreenPoint(hit.collider.transform.position);

                    if (IsCurrentHandEmpty() && IsObjectExist(hits, Global.DROPED_ITEM_PREFIX, false) == false)
                    {
                        ShowToolTip((tableController.tableName == string.Empty) ? "table" : tableController.tableName,
                                    PrintRed(Global.Tooltip.NO_ACTIONS));
                    }
                    else if (IsCurrentHandEmpty() && IsObjectExist(hits, Global.DROPED_ITEM_PREFIX, false) == true)
                    {
                        ShowToolTip((tableController.tableName == string.Empty) ? "table" : tableController.tableName,
                                    Global.Tooltip.LM_PICK_UP);
                    }
                    else if (IsCurrentHandEmpty() == false && IsObjectExist(hits, Global.DROPED_ITEM_PREFIX, false) == true)
                    {
                        ShowToolTip((tableController.tableName == string.Empty) ? "table" : tableController.tableName,
                                    Global.Tooltip.LM_PUT + ((tableController.isCraftTable) ? " / " + Global.Tooltip.RM_CRAFT : string.Empty));
                    }
                    else
                    {
                        ShowToolTip((tableController.tableName == string.Empty) ? "table" : tableController.tableName,
                                    Global.Tooltip.LM_PUT);
                    }

                    TooltipLocate(tooltipPosition);

                    return;
                }
                else if (hit.collider.name.Contains(Global.DROPED_ITEM_PREFIX))
                {
                    bool onTable = false;
                    foreach (var hitTable in hits)
                    {
                        if (hitTable.collider.tag == "table")
                        {
                            onTable = true;
                        }
                    }

                    if (onTable == false)
                    {
                        Item item = hit.collider.GetComponent <ItemCell>().item;

                        isdetected = true;
                        Vector2 tooltipPosition = Camera.main.WorldToScreenPoint(hit.collider.transform.position);

                        ShowToolTip(item.itemName, (controller.IsEmpty(controller.currentHand) == true) ?
                                    Global.Tooltip.LM_PICK_UP : PrintRed(Global.Tooltip.NO_ACTIONS));
                        TooltipLocate(tooltipPosition);

                        return;
                    }
                }
                else if (hit.collider.tag == "case")
                {
                    CaseController caseController = hit.collider.GetComponent <CaseController>();

                    isdetected = true;
                    Vector2 tooltipPosition = Camera.main.WorldToScreenPoint(hit.collider.transform.position);

                    ShowToolTip((caseController.caseName == string.Empty) ? "case" : caseController.caseName, (caseController.isOpen == false)
                                ? Global.Tooltip.LM_OPEN : Global.Tooltip.LM_CLOSE);
                    TooltipLocate(tooltipPosition);

                    return;
                }
                else if (hit.collider.tag == "tv")
                {
                    TVController tvController = hit.collider.GetComponent <TVController>();

                    isdetected = true;
                    Vector2 tooltipPosition = Camera.main.WorldToScreenPoint(hit.collider.transform.position);

                    ShowToolTip("tv", (tvController.IsTvOpen() == false)
                                ? Global.Tooltip.LM_TURN_ON : Global.Tooltip.LM_TURN_OFF + " / " + Global.Tooltip.RM_NEXT_CHANNEL);
                    TooltipLocate(tooltipPosition);

                    return;
                }
                else
                {
                    isdetected = false;
                }
            }

            if (isTooltipOpen == true && isdetected == false)
            {
                HideToolTip();
            }
        }
        else
        {
            if (isTooltipOpen == true)
            {
                HideToolTip();
            }
        }
    }