private BaseEntity CreateWorldObject(int itemId, string name, Vector3 pos, bool canPickup)
        {
            Item item = ItemManager.CreateByItemID(itemId);

            if (!string.IsNullOrEmpty(name))
            {
                item.name = name;
            }

            BaseEntity worldEntity = GameManager.server.CreateEntity(BURLAPSACK_PREFAB, pos);

            WorldItem worldItem = worldEntity as WorldItem;

            if (worldItem != null)
            {
                worldItem.InitializeItem(item);
            }

            worldEntity.Invoke(() =>
            {
                (worldEntity as DroppedItem).CancelInvoke((worldEntity as DroppedItem).IdleDestroy);
            }, 1f);

            worldItem.enableSaving = false;
            worldItem.allowPickup  = canPickup;
            worldEntity.Spawn();

            item.SetWorldEntity(worldEntity);

            return(worldEntity);
        }
示例#2
0
    public BaseEntity CreateWorldObject(Vector3 pos, Quaternion rotation = null, BaseEntity parentEnt = null, uint parentBone = 0)
    {
        BaseEntity worldEntity = this.GetWorldEntity();

        if (worldEntity != null)
        {
            return(worldEntity);
        }
        worldEntity = GameManager.server.CreateEntity("assets/prefabs/misc/burlap sack/generic_world.prefab", pos, rotation, true);
        if (worldEntity == null)
        {
            Debug.LogWarning("Couldn't create world object for prefab: items/generic_world");
            return(null);
        }
        WorldItem worldItem = worldEntity as WorldItem;

        if (worldItem != null)
        {
            worldItem.InitializeItem(this);
        }
        if (parentEnt != null)
        {
            worldEntity.SetParent(parentEnt, parentBone, false, false);
        }
        worldEntity.Spawn();
        this.SetWorldEntity(worldEntity);
        return(this.GetWorldEntity());
    }