void HandleOn_SelfDisappear(DropItem dropItem) { dropItem.On_SelfDisappear -= HandleOn_SelfDisappear; dropItem.On_PickUp -= HandleOn_PickUp; _dropItemMap.Remove(dropItem.GetInstanceID()); GameObject.Destroy(dropItem.gameObject); }
public void Init() { _resMap = new Dictionary <int, Texture2D>(); _dropItemMap = new Dictionary <int, DropItem>(); _dropItemPrefab = Resources.Load <DropItem>(DropItemPrefab); needCheckDrop = !WorldConfig.Instance.isCreateMode; }
void HandleOn_PickUp(DropItem dropItem, GameObject player) { if (BackpackItemManager.Instance.GetLeaveNum(dropItem.userItem) < 0) { return; } BackpackItemManager.Instance.AddUserItem(dropItem.userItem); dropItem.On_PickUp -= HandleOn_PickUp; dropItem.FlyToPlayer(player); }
void OnDestroy() { foreach (var item in _dropItemMap) { item.Value.On_PickUp -= HandleOn_PickUp; item.Value.On_SelfDisappear -= HandleOn_SelfDisappear; } _dropItemMap.Clear(); _resMap.Clear(); _dropItemPrefab = null; }
private void DropItemObj(WorldPos pos, int itemId, int num) { UserItem userItem = UserItemFactory.GenerateUserItem(itemId, num, (int)ItemPlaceType.Scene); Texture2D tex = GetItemTexture(itemId); float x = UnityEngine.Random.Range(0.2f, 0.8f); float z = UnityEngine.Random.Range(0.2f, 0.8f); DropItem dropItem = GameObject.Instantiate(_dropItemPrefab, new Vector3(pos.x + x, pos.y + 0.5f, pos.z + z), Quaternion.identity) as DropItem; dropItem.transform.parent = this.transform; dropItem.Init(userItem, tex); dropItem.On_PickUp += HandleOn_PickUp; dropItem.On_SelfDisappear += HandleOn_SelfDisappear; _dropItemMap.Add(dropItem.GetInstanceID(), dropItem); }