示例#1
0
    public void OnGUI()
    {
        if (cams == null || cams.Length == 0)
        {
            cams = FindObjectsOfType <Camera>();
            return;
        }

        Camera camera = null;

        foreach (var cam in cams)
        {
            if (cam.gameObject.name == "ExtCamera")
            {
                camera = cam;
            }
        }

        if (camera == null || exItemPrefab == null)
        {
            return;
        }

        var centerY = Screen.height / 2;

        worldPos = camera.WorldToScreenPoint(transform.position);

        if (worldPos.y <= centerY)
        {
            var distToCenter = centerY - worldPos.y;
            worldPos.Set(worldPos.x, distToCenter + centerY, worldPos.z);
        }
        else
        {
            var distToCenter = worldPos.y - centerY;
            worldPos.Set(worldPos.x, centerY - distToCenter, worldPos.z);
        }

        AbstractItemBase component = exItemPrefab.GetComponent <AbstractItemBase>();

        if (component == null)
        {
            return;
        }

        if (currentFont == null)
        {
            currentFont = Font.CreateDynamicFontFromOSFont("Consolas", 14);
        }

        var guistyle = new GUIStyle(GUI.skin.label);

        guistyle.fontStyle        = FontStyle.Bold;
        guistyle.normal.textColor = Color.white;

        guistyle.font = currentFont;
        GUI.Label(new Rect(worldPos, new Vector3(100f, 100f)),
                  $"{component.itemLabel ?? "unknown"} ({component.itemValue})",
                  guistyle);
    }
 public void openBox()
 {
     if (this.itemObj != null)
     {
         AbstractItemBase component = this.itemObj.GetComponent <AbstractItemBase>();
         if (component.name.Contains(itemToReplaceName) && Enum.IsDefined(typeof(ItemDatabaseSystem.ItemNames), itemToInsertName))
         {
             component.setItemParameter(itemToInsertName, 1);
             Sprite mapIconSprite = L2SystemCore.getMapIconSprite(L2SystemCore.getItemData((ItemDatabaseSystem.ItemNames)Enum.Parse(typeof(ItemDatabaseSystem.ItemNames), itemToInsertName)));
             this.itemObj.GetComponent <SpriteRenderer>().sprite = mapIconSprite;
         }
     }
     base.openBox();
 }
示例#3
0
        private void ChangeBox(TreasureBoxScript box)
        {
            ItemData oldItemData = GetItemDataFromName(box.itemObj.name);

            if (oldItemData != null && locationToItemMap.TryGetValue((int)oldItemData.getItemName(), out int id))
            {
                ItemID newItemID = (ItemID)id;

                ItemInfo newItemInfo = ItemFlags.GetItemInfo(newItemID);
                ItemData newItemData = GetNewItemData(newItemInfo);

                AbstractItemBase item = box.itemObj.GetComponent <AbstractItemBase>();

                //the flags the box uses to check whether you have that item already if true the box will be open
                //im pretty sure that it wont spawn the item if it this check is true on intialisation therefore if
                //you collect the item that was originally in the box you now cant get the item in the box since it
                //only spawns the item on box open
                foreach (var flagBoxParent in box.openFlags)
                {
                    foreach (var flagBox in flagBoxParent.BOX)
                    {
                        if (flagBox.seet_no1 == 2)
                        {
                            flagBox.flag_no1 = (int)newItemData.getItemName();
                            flagBox.flag_no2 = 1;

                            //the whips and shields use the same flag just increment higher with each upgrade cant just use the same as other items
                            if (newItemID == ItemID.ChainWhip || newItemID == ItemID.SilverShield || newItemID == ItemID.MobileSuperx3P)
                            {
                                flagBox.flag_no2 = 2;
                            }
                            else if (newItemID == ItemID.FlailWhip || newItemID == ItemID.AngelShield)
                            {
                                flagBox.flag_no2 = 3;
                            }
                        }
                    }
                }

                //flags the item uses to check to see if it should be active and visible to the user, important that these are
                //changed because if you only change the label the it will use the original items flags to check. This means that
                //if you change another item to what was this items original is and collect it when it comes to collecting the item
                //this has been changed too if won't be active as it thinks you already have it
                foreach (var flagBoxParent in item.itemActiveFlag)
                {
                    foreach (var flagBox in flagBoxParent.BOX)
                    {
                        if (flagBox.seet_no1 == 2)
                        {
                            flagBox.flag_no1 = (int)newItemData.getItemName();
                            flagBox.comp     = COMPARISON.Equal;
                            flagBox.flag_no2 = 0;

                            //the whips and shields use the same flag just increment higher with each upgrade cant just use the same as other items
                            if (newItemID == ItemID.ChainWhip || newItemID == ItemID.SilverShield || newItemID == ItemID.MobileSuperx3P)
                            {
                                flagBox.flag_no2 = 1;
                                flagBox.comp     = COMPARISON.LessEq;
                            }
                            else if (newItemID == ItemID.FlailWhip || newItemID == ItemID.AngelShield)
                            {
                                flagBox.flag_no2 = 2;
                                flagBox.comp     = COMPARISON.LessEq;
                            }
                            else if (newItemID == ItemID.Buckler)
                            {
                                flagBox.comp = COMPARISON.LessEq;
                            }
                        }
                    }
                }
                //flags that the item sets when you collect it, important to change otherwise the original item will also be collected
                //when you pick up the item because by default it sets the original items flags again, also other flags can be set here
                //usually items that add to flags that are used as a type of counter eg.Sacred Orbs orb count
                item.itemGetFlags = ItemFlags.GetItemGetFlags(newItemID);

                //name used when calling setitem
                item.itemLabel = newItemInfo.boxName;

                //change the sprite to match the new item
                Sprite sprite = L2SystemCore.getMapIconSprite(L2SystemCore.getItemData(newItemInfo.boxName));
                item.gameObject.GetComponent <SpriteRenderer>().sprite = sprite;
            }
        }