Пример #1
0
    public void askItem(Vector3 position, NetworkPlayer player)
    {
        Point2 region = NetworkRegions.getRegion(position);
        int    indexFromPositionServer = SpawnItems.getIndexFromPositionServer(region, position);

        if (indexFromPositionServer != -1)
        {
            GameObject modelFromPlayer = NetworkUserList.getModelFromPlayer(player);
            if (modelFromPlayer != null)
            {
                Inventory component = modelFromPlayer.GetComponent <Inventory>();
                if (component.hasSpace(SpawnItems.regions[region.x, region.y].items[indexFromPositionServer]) == 0)
                {
                    component.addItem(SpawnItems.regions[region.x, region.y].items[indexFromPositionServer]);
                    base.networkView.RPC("destroyItem", RPCMode.All, new object[] { position });
                    NetworkSounds.askSound("Sounds/General/take", component.transform.position, 0.1f, UnityEngine.Random.Range(0.9f, 1.1f), 1f);
                    NetworkManager.error(Texts.ALERT_ITEM_ADDED, string.Empty, player);
                    if (!modelFromPlayer.networkView.isMine)
                    {
                        modelFromPlayer.networkView.RPC("tookItem", player, new object[0]);
                    }
                    else
                    {
                        modelFromPlayer.GetComponent <Player>().tookItem();
                    }
                }
            }
        }
    }
Пример #2
0
    public void destroyItem(Vector3 position)
    {
        int    indexFromPositionServer;
        Point2 region = NetworkRegions.getRegion(position);

        if (Network.isServer)
        {
            indexFromPositionServer = SpawnItems.getIndexFromPositionServer(region, position);
            if (indexFromPositionServer != -1 && indexFromPositionServer < SpawnItems.regions[region.x, region.y].items.Count)
            {
                SpawnItems.regions[region.x, region.y].items.RemoveAt(indexFromPositionServer);
            }
        }
        indexFromPositionServer = SpawnItems.getIndexFromPositionClient(region, position);
        if (indexFromPositionServer != -1 && indexFromPositionServer < SpawnItems.regions[region.x, region.y].models.Count)
        {
            UnityEngine.Object.Destroy(SpawnItems.regions[region.x, region.y].models[indexFromPositionServer]);
            SpawnItems.regions[region.x, region.y].models.RemoveAt(indexFromPositionServer);
        }
    }