//直接穿戴功能(不需拖拽) public void PutOn(_Item item) { _Item exitItem = null; //临时保存需要交换的物品 foreach (_Slot slot in slotArray) //遍历角色面板中的物品槽,查找合适的的物品槽 { _EquipmentSlot equipmentSlot = (_EquipmentSlot)slot; if (equipmentSlot.IsRightItem(item)) //判断物品是否合适放置在该物品槽里 { if (equipmentSlot.transform.childCount > 0) //判断角色面板中的物品槽合适的位置是否已经有了装备 { _ItemUI currentItemUI = equipmentSlot.transform.GetChild(0).GetComponent <_ItemUI>(); exitItem = currentItemUI.Item; currentItemUI.SetItem(item, 1); } else { equipmentSlot.StoreItem(item); } break; } } if (exitItem != null) { _Knapscak.Instance.StoreItem(exitItem); //把角色面板上是物品替换到背包里面 } UpdatePropertyText(); //更新显示角色属性值 }
private void GiveStatsToEvolvedForm(bool thisIsSetup, bool thisIsCaptured, GameObject thisTrainer, string thisTrainersName, string thisNickName, bool thisIsFromTrade, int thisLevel, Genders thisGender, Natures thisNature, int thisHPIV, int thisATKIV, int thisDEFIV, int thisSPATKIV, int thisSPDEFIV, int thisSPDIV, int thisHPEV, int thisATKEV, int thisDEFEV, int thisSPATKEV, int thisSPDEFEV, int thisSPDEV, List <string> ThisKnownMoves, Move thisLastMoveUsed, _Item thisEquippedItem, bool thisIsInBattle, int thisOrigin, bool thisIsShiny) { isSetup = thisIsSetup; isCaptured = thisIsCaptured; trainer = thisTrainer; trainersName = thisTrainersName; nickName = thisNickName; isFromTrade = thisIsFromTrade; level = thisLevel; gender = thisGender; nature = thisNature; hpIV = thisHPIV; atkIV = thisATKIV; defIV = thisDEFIV; spatkIV = thisSPATKIV; spdefIV = thisSPDEFIV; spdIV = thisSPDIV; hpEV = thisHPEV; atkEV = thisATKEV; defEV = thisDEFEV; spatkEV = thisSPATKEV; spdefEV = thisSPDEFEV; spdEV = thisSPDEV; KnownMovesNames = ThisKnownMoves; lastMoveUsed = thisLastMoveUsed; equippedItem = thisEquippedItem; isInBattle = thisIsInBattle; origin = thisOrigin; isShiny = thisIsShiny; }
//更新角色属性显示 private void UpdatePropertyText() { int strength = 0, intellect = 0, agility = 0, stamina = 0, damage = 0; foreach (_EquipmentSlot slot in slotArray) //遍历角色面板中的装备物品槽 { if (slot.transform.childCount > 0) //找到有物品的物品槽,获取里面装备的属性值 { _Item item = slot.transform.GetChild(0).GetComponent <_ItemUI>().Item; if (item is _Equipment)//如果物品是装备,那就加角色对应的属性 { _Equipment e = (_Equipment)item; strength += e.Strength; intellect += e.Intellect; agility += e.Agility; stamina += e.Stamina; } else if (item is _Weapon)///如果物品是武器,那就加角色的伤害(damage)属性 { _Weapon w = (_Weapon)item; damage += w.Damage; } } } strength += player.BasicStrength; intellect += player.BasicIntellect; agility += player.BasicAgility; stamina += player.BasicStamina; damage += player.BasicDamage; string text = string.Format("力量:{0}\n智力:{1}\n敏捷:{2}\n体力:{3}\n攻击力:{4}\n", strength, intellect, agility, stamina, damage); characterPropertyText.text = text; }
protected void BaseRemove(string name) { int cnt = 0; String key; if (this.IsReadOnly) { throw new NotSupportedException("Collection is read-only"); } if (name != null) { m_ItemsContainer.Remove(name); } else { m_NullKeyItem = null; } cnt = m_ItemsArray.Count; for (int i = 0; i < cnt;) { key = BaseGetKey(i); if (Equals(key, name)) { m_ItemsArray.RemoveAt(i); cnt--; } else { i++; } } }
/// <summary> /// Equip an item from the ground. /// </summary> public void Equip(_Item item) { if (item == null) { return; } // If theres already an item equipped Unequip(); if (item is _CoreItem) { var core = item as _CoreItem; coreItems[core.targetSlot] = core; hud.UnlockItem(GetItemSlot(core)); MoveToInventory(item); } else { // Move it MoveToEquipped(item); } item.OnPickup(); }
//当前物品(UI)和 出入物品(UI)交换显示 public void Exchange(_ItemUI itemUI) { _Item itemTemp = itemUI.Item; int amountTemp = itemUI.Amount; itemUI.SetItem(this.Item, this.Amount); this.SetItem(itemTemp, amountTemp); }
public void Remove(_Item item) { items.Remove(item); if (onItemChangedCallBack != null) { onItemChangedCallBack(); } }
//主角购买物品 public void BuyItem(_Item item) { bool isSusscess = player.ConsumeCoin(item.BuyPrice);//主角消耗金币购买物品 if (isSusscess) { _Knapscak.Instance.StoreItem(item); } }
public Utilities(float value, int id, int amount, string img, string name, string desc, _Item typeItem) { this.value = value; this.id = id; this.amount = amount; this.image = img; this.name = name; this.desc = desc; this.typeItem = typeItem; }
public void remove(object obj) { _Item target = (_Item)hash[obj]; if (target != null) { weight_total -= target.weight; hash.Remove(obj); } }
/// <summary> /// SDK: Sets the value of the entry at the specified index of the NameObjectCollectionBase instance. /// </summary> /// <param name="index"></param> /// <param name="value"></param> protected void BaseSet(int index, object value) { if (this.IsReadOnly) { throw new NotSupportedException("Collection is read-only"); } _Item item = (_Item)m_ItemsArray[index]; item.value = value; }
public void AddItem(_Item i) // add an item { if (ItemType[(int)i]) { Debug.LogWarning("There already exists that item!"); } else { ItemType[(int)i] = true; } }
public void RemoveItem(_Item i) //remove an item { if (!ItemType[(int)i]) { Debug.LogWarning("Specified item does not exist in Object Item!"); } else { ItemType[(int)i] = false; } }
/// <summary> /// 解析Json文件 /// </summary> public void ParseItemJson() { itemList = new List <_Item>(); //文本在unity里面是TextAsset类型 TextAsset itemText = Resources.Load <TextAsset>("_ItemJS"); //加载json文本 string itemJson = itemText.text; //得到json文本里面的内容 //Debug.Log(itemJson); JsonData data = JsonMapper.ToObject(itemJson); for (int i = 0; i < data.Count; i++) { int id = (int)data[i]["id"]; string name = (string)data[i]["name"]; _Item.ItemType type = (_Item.ItemType)System.Enum.Parse(typeof(_Item.ItemType), (string)data[i]["type"]); _Item.ItemQuality quality = (_Item.ItemQuality)System.Enum.Parse(typeof(_Item.ItemQuality), (string)data[i]["quality"]); string description = (string)data[i]["description"]; int capacity = (int)data[i]["capacity"]; int buyPrice = (int)data[i]["buyPrice"]; int sellPrice = (int)data[i]["sellPrice"]; string sprite = (string)data[i]["sprite"]; _Item item = null; switch (type) { case _Item.ItemType.Consumable: int hp = (int)data[i]["hp"]; int mp = (int)data[i]["mp"]; item = new _Consumable(id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite, hp, mp); break; case _Item.ItemType.Equipment: int strength = (int)data[i]["strength"]; int intellect = (int)data[i]["intellect"]; int agility = (int)data[i]["agility"]; int stamina = (int)data[i]["stamina"]; _Equipment.EquipmentType equipType = (_Equipment.EquipmentType)System.Enum.Parse(typeof(_Equipment.EquipmentType), (string)data[i]["equipType"]); item = new _Equipment(id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite, strength, intellect, agility, stamina, equipType); break; case _Item.ItemType.Weapon: int damage = (int)data[i]["damage"]; _Weapon.WeaponType weaponType = (_Weapon.WeaponType)System.Enum.Parse(typeof(_Weapon.WeaponType), (string)data[i]["weaponType"]); item = new _Weapon(id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite, damage, weaponType); break; case _Item.ItemType.Material: item = new _Material(id, name, type, quality, description, capacity, buyPrice, sellPrice, sprite); break; } itemList.Add(item); } //Debug.Log(item); }
//判断鼠标上的物品是否适合放在该位置 public bool IsRightItem(_Item item) { if ((item is _Equipment && ((_Equipment)(item)).EquipType == this.equipmentSoltType) || (item is _Weapon && ((_Weapon)(item)).WpType == this.wpType))//如果此物品是装备并且此物品的装备类型和当前物品槽中的装备类型相同 或者 此物品是武器并且此武器的类型和当前物品槽中的武器类型相同,那就可以合适放在该位置,否则不合适。 { return(true); } else { return(false); } }
public void AddHead() { _Item head = null; _Item tail = null; // build the list for (var i = 0; i <= 10_000; i++) { var item = new _Item { Value = i }; tail = tail ?? item; head.AddHead(ref head, item); } // read forward { var cur = head; for (var i = 10_000; i >= 0; i--) { Assert.Equal(i, cur.Value); if (cur.Next.HasValue) { cur = cur.Next.Value; } else { cur = null; } } Assert.Null(cur); } // read backwards { var cur = tail; for (var i = 0; i <= 10_000; i++) { Assert.Equal(i, cur.Value); if (cur.Previous.HasValue) { cur = cur.Previous.Value; } else { cur = null; } } Assert.Null(cur); } }
public void Clear() { if (_activeDoc == null) { return; } _activeDoc = null; _oldTree = null; _modified = false; _tv.SetItems(null); }
//查找存放的物品是相同的物品槽 private _Slot FindSameIDSlot(_Item item) { foreach (_Slot slot in slotArray) { //如果当前的物品槽已经有物品了,并且里面的物品的类型和需要找的类型一样,并且物品槽还没有被填满 if (slot.transform.childCount >= 1 && item.ID == slot.GetItemID() && slot.isFiled() == false) { return(slot); } } return(null); }
//获取(拾取)物品槽里的指定数量的(amount)物品UI public void PickUpItem(_Item item, int amount) { PickedItem.SetItem(item, amount); this.isPickedItem = true; PickedItem.Show(); //获取到物品之后把跟随鼠标的容器(用来盛放捡起的物品的容器)显示出来 this.toolTip.Hide(); //同时隐藏物品信息提示框 //控制盛放物品的容器UI跟随鼠标移动 Vector2 postionPickeItem; RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas.transform as RectTransform, Input.mousePosition, null, out postionPickeItem); pickedItem.SetLocalPosition(postionPickeItem);//设置容器的位置,二维坐标会自动转化为三维坐标但Z坐标为0 }
public static _Item[] CreateAdditiveItemSet(_Item[] itemset, string additiveGroupName) { List <_Item> newItems = new List <_Item>(); for (int i = 0; i < itemset.Length; i++) { _Item item = itemset[i]; item.additiveGroup = additiveGroupName; item.additiveIndex = i; newItems.Add(item); } return(newItems.ToArray()); }
private void Init() { if (equality_comparer != null) { m_ItemsContainer = new Hashtable(m_defCapacity, equality_comparer); } else { m_ItemsContainer = new Hashtable(m_defCapacity, m_hashprovider, m_comparer); } m_ItemsArray = new ArrayList(); m_NullKeyItem = null; }
private void Init() { if (equality_comparer != null) { m_ItemsContainer = new Dictionary <string, string> (m_defCapacity, equality_comparer); } else { m_ItemsContainer = new Dictionary <string, string>(m_defCapacity, m_hashprovider, m_comparer); } m_ItemsArray = new List <int>(); m_NullKeyItem = null; }
public void MoveToEquipped(_Item item) { equipped = item; item.transform.parent = equippedParent; item.transform.localPosition = Vector3.zero; item.transform.localEulerAngles = Vector3.zero; if (item is _CoreItem) (item as _CoreItem).OnEquip(this); if (sound) sound.OnItemEquipped(); }
public void MoveToWorld(_Item item) { item.transform.parent = null; if (item is _CoreItem) { (item as _CoreItem).OnUnequip(this); } if (sound) { sound.OnItemUnequipped(); } }
/// <summary> /// SDK: Gets the value of the first entry with the specified key from the NameObjectCollectionBase instance. /// </summary> /// <remark>CAUTION: The BaseGet method does not distinguish between a null reference which is returned because the specified key is not found and a null reference which is returned because the value associated with the key is a null reference.</remark> /// <param name="name"></param> /// <returns></returns> protected object BaseGet(string name) { _Item item = FindFirstMatchedItem(name); /// CAUTION: The BaseGet method does not distinguish between a null reference which is returned because the specified key is not found and a null reference which is returned because the value associated with the key is a null reference. if (item == null) { return(null); } else { return(item.value); } }
public GameObject itemPrefab;//需要存储的物品预设 /// <summary> ///(重点) 向物品槽中添加(存储)物品,如果自身下面已经有Item了,那就Item.amount++; /// 如果没有,那就根据ItemPrefab去实例化一个Item,放在其下面 /// </summary> public void StoreItem(_Item item) { if (this.transform.childCount == 0)//如果这个物品槽下没有物品,那就实例化一个物品 { GameObject itemGO = Instantiate <GameObject>(itemPrefab) as GameObject; itemGO.transform.SetParent(this.transform); //设置物品为物品槽的子物体 itemGO.transform.localScale = Vector3.one; //正确保存物品的缩放比例 itemGO.transform.localPosition = Vector3.zero; //设置物品的局部坐标,为了与其父亲物品槽相对应 itemGO.GetComponent <_ItemUI>().SetItem(item); //更新ItemUI } else { transform.GetChild(0).GetComponent <_ItemUI>().AddItemAmount();//默认添加一个 } }
static BLXmlConfigItem() { //下面注释掉的两条语句和未注释掉的等价。 //new _Item<string>("name", delegate(BLXmlConfigItem x){return x.name;}, // delegate(BLXmlConfigItem x, string val){ x.name = val;}) , // new _Item<string>("name", x=> x.name,(x,s)=>x.name = s), s_itemName = new _Item <string>("name", S_Get_Name, S_Set_Name); s_items = new _ItemBase[] { s_itemName, s_itemID, s_itemShow, s_itemShowTitle, s_itemExpand, s_itemUserHide, s_itemReadOnly, s_itemValueReadOnly, s_itemFold, s_itemControlType, s_itemUnit, s_itemColumn, s_itemMultiColumn/*,s_itemRatio*/ }; }
/// <summary> ///更新item的UI显示,默认数量为1个 /// </summary> /// <param name="item"></param> public void SetItem(_Item item, int amount = 1) { this.transform.localScale = this.animationScale;//物品更新时放大UI,用于动画 this.Item = item; this.Amount = amount; this.itemImage.sprite = Resources.Load <Sprite>(item.Sprite); //更新UI if (this.Amount > 1) { this.amountText.text = Amount.ToString(); } else { this.amountText.text = ""; } }
public Popup(PopupStyle Style, IEnumerable<MenuItem> Items) { this._Style = Style; double y = 0.0; double width = 0.0; this._Items = new List<_Item>(); foreach (MenuItem mi in Items) { _Item i = new _Item(Style, mi, y); Point size = i.Size; y += size.Y; width = Math.Max(width, size.X); this._Items.Add(i); } this.Size = new Point(width, y) + new Point(this._Style.Margin, this._Style.Margin) * 2.0; }
public void MoveToInventory(_Item item) { item.transform.parent = transform; item.transform.localPosition = Vector3.zero; item.transform.localEulerAngles = Vector3.zero; if (item is _CoreItem) { (item as _CoreItem).OnUnequip(this); } if (sound) { sound.OnItemUnequipped(); } }
public SlotNode(_Item item) { CanUse = item.canUse; Consumable = item.consumable; Count = item.count; Name = item.displayName; if (Enum.IsDefined(typeof(ItemID), item.itemID)) { Item = (ItemID)item.itemID; } else { Item = ItemID.None; } }
/// <summary> /// Sets the value of the first entry with the specified key in the NameObjectCollectionBase instance, if found; otherwise, adds an entry with the specified key and value into the NameObjectCollectionBase instance. /// </summary> /// <param name="name">The String key of the entry to set. The key can be a null reference </param> /// <param name="value">The Object that represents the new value of the entry to set. The value can be a null reference</param> protected void BaseSet(string name, object value) { if (this.IsReadOnly) { throw new NotSupportedException("Collection is read-only"); } _Item item = FindFirstMatchedItem(name); if (item != null) { item.value = value; } else { BaseAdd(name, value); } }
public bool Add(_Item item) { if (!item.isDefaultItem) { if (items.Count >= space) { return(false); } items.Add(item); if (onItemChangedCallBack != null) { onItemChangedCallBack(); } } return(true); }
/// <summary> /// Equip an item from the ground. /// </summary> public void Equip(_Item item) { if (item == null) return; // If theres already an item equipped Unequip(); if (item is _CoreItem) { var core = item as _CoreItem; coreItems[core.targetSlot] = core; hud.UnlockItem(GetItemSlot(core)); MoveToInventory(item); } else { // Move it MoveToEquipped(item); } item.OnPickup(); }
private void Init() { #if NET_2_0 if (equality_comparer != null) m_ItemsContainer = new Hashtable (m_defCapacity, equality_comparer); else m_ItemsContainer = new Hashtable (m_defCapacity, m_hashprovider, m_comparer); #else m_ItemsContainer = new Hashtable(m_defCapacity, m_hashprovider, m_comparer); #endif m_ItemsArray = new ArrayList(); m_NullKeyItem = null; }
// Unequip the equipped item public void Unequip() { if (equipped == null) return; if (equipped is _CoreItem) { MoveToInventory(equipped); } else { _Item item = equipped; interaction.onArmsDown = i => { MoveToWorld(item); item.OnDropped(); i.onArmsDown = null; }; } equipped = null; }
private void Init() { if (equality_comparer != null) m_ItemsContainer = new Dictionary<string, string> (m_defCapacity, equality_comparer); else m_ItemsContainer = new Dictionary<string, string>(m_defCapacity, m_hashprovider, m_comparer); m_ItemsArray = new List<int>(); m_NullKeyItem = null; }
private _Item _ItemAtOffsetIndex(_Item Current, int Offset) { int curindex = 0; _Item cur = Current; for (int t = 0; t < this._Items.Count; t++) { if (this._Items[t] == Current) { curindex = t; break; } } while (Offset > 0) { curindex += 1; if (curindex >= this._Items.Count) { curindex -= this._Items.Count; } cur = this._Items[curindex]; if (cur.Selectable) { Offset--; } } while (Offset < 0) { curindex -= 1; if (curindex < 0) { curindex += this._Items.Count; } cur = this._Items[curindex]; if (cur.Selectable) { Offset++; } } return cur; }
/// <summary> /// /// </summary> /// <param name="index"></param> /// <LAME>This function implemented the way Microsoft implemented it - /// item is removed from hashtable and array without considering the case when there are two items with the same key but different values in array. /// E.g. if /// hashtable is [("Key1","value1")] and array contains [("Key1","value1")("Key1","value2")] then /// after RemoveAt(1) the collection will be in following state: /// hashtable:[] /// array: [("Key1","value1")] /// It's ok only then the key is uniquely assosiated with the value /// To fix it a comparsion of objects stored under the same key in the hashtable and in the arraylist should be added /// </LAME>> protected void BaseRemoveAt(int index) { if (this.IsReadOnly) throw new NotSupportedException("Collection is read-only"); string key = BaseGetKey(index); if (key != null) { // TODO: see LAME description above m_ItemsContainer.Remove(key); } else m_NullKeyItem = null; m_ItemsArray.RemoveAt(index); }
public void MoveToInventory(_Item item) { item.transform.parent = transform; item.transform.localPosition = Vector3.zero; item.transform.localEulerAngles = Vector3.zero; if (item is _CoreItem) (item as _CoreItem).OnUnequip(this); if (sound) sound.OnItemUnequipped(); }
public void MoveToWorld(_Item item) { item.transform.parent = null; if (item is _CoreItem) (item as _CoreItem).OnUnequip(this); if (sound) sound.OnItemUnequipped(); }
private void Init () { if (m_ItemsContainer != null) { m_ItemsContainer.Clear (); m_ItemsContainer = null; } if (m_ItemsArray != null) { m_ItemsArray.Clear (); m_ItemsArray = null; } if (equality_comparer != null) m_ItemsContainer = new Hashtable (m_defCapacity, equality_comparer); else m_ItemsContainer = new Hashtable (m_defCapacity, m_hashprovider, m_comparer); m_ItemsArray = new ArrayList(); m_NullKeyItem = null; }
private void Init() { if (m_ItemsContainer != null) { m_ItemsContainer.Clear(); m_ItemsContainer = null; } if (m_ItemsArray != null) { m_ItemsArray.Clear(); m_ItemsArray = null; } m_ItemsContainer = new Hashtable(m_defCapacity); m_ItemsArray = new ArrayList(); m_NullKeyItem = null; }
//--------------- Protected Instance Methods ------------------- /// <summary> /// Adds an Item with the specified key and value into the <see cref="NameObjectCollectionBase"/>NameObjectCollectionBase instance. /// </summary> /// <param name="name"></param> /// <param name="value"></param> protected void BaseAdd(string name, object value) { if (this.IsReadOnly) throw new NotSupportedException("Collection is read-only"); _Item newitem = new _Item(name, value); if (name == null) { //todo: consider nullkey entry if (m_NullKeyItem == null) m_NullKeyItem = newitem; } else if (m_ItemsContainer[name] == null) { m_ItemsContainer.Add(name, newitem); } m_ItemsArray.Add(newitem); }
/// <summary> /// Gets the item rectangle for an item, given the inner rectangle. /// </summary> private Rectangle _ItemRect(Rectangle Inner, _Item Item) { return new Rectangle(0.0, Item.Y + Inner.Location.Y, this.Size.X, Item.Size.Y); }
protected void BaseRemove(string name) { int cnt = 0; String key; if (this.IsReadOnly) throw new NotSupportedException("Collection is read-only"); if (name != null) { m_ItemsContainer.Remove(name); } else { m_NullKeyItem = null; } cnt = m_ItemsArray.Count; for (int i = 0; i < cnt; ) { key = BaseGetKey(i); if (Equals(key, name)) { m_ItemsArray.RemoveAt(i); cnt--; } else i++; } }
void Update() { // Visualization hover = GetItemInRange(); if (hover != lastHover) { // Hover changed if (hover && hover.nearbyVisual) hover.nearbyVisual.enabled = true; if (lastHover && lastHover.nearbyVisual) lastHover.nearbyVisual.enabled = false; } lastHover = hover; // Check armsUp if (armsUp != _armsUp) { if (armsUp && onArmsUp != null) onArmsUp.Invoke(this); if (!armsUp && onArmsDown != null) onArmsDown.Invoke(this); } _armsUp = armsUp; // Read input if (!inteDown && Input.GetButtonDown("Interact")) inteDown = true; }
public bool IsItemInRange(_Item item) { return item.GetDistance(pickupPoint.position) <= pickupRadius; }
/// <summary> /// Sets the specified item as active. Returns if the selection is new. /// </summary> private bool _Select(_Item Item) { if (Item.Selectable && this._Active != Item) { this._Active = Item; return true; } return false; }