version: "2.15.1"
services:
postgres:
image: postgres:13.3
environment:
POSTGRES_DB: "username"
POSTGRES_USER: "username"
POSTGRES_PASSWORD: "username"
PGDATA: "/var/lib/postgresql/data/pgdata"
volumes:
- ./Initer:/docker-entrypoint-initdb.d
- usr-data:/var/lib/postgresql/data
ports:
- "5437:5432"
volumes:
usr-data:
void Start()
{
Thread t = new Thread(ReceiveData);
t.Start();
}
private void ReceiveData()
{
while (true)
{
if (connected)
{
Debug.Log("Run");
try
{
int bytes = 0; // Счетчик полученных байт с сервера
byte[] buffer = new byte[1024]; // Массив байт, для данных полученных с сервера
StringBuilder builder = new StringBuilder();
do
{
bytes = socket.Receive(buffer); // Прием данных от сервера
builder.Append(Encoding.UTF8.GetString(buffer, 0, bytes)); // Строим сообщение из полученных данных ( массива байт )
}
while (socket.Available > 0);
string[] allInfo = builder.ToString().Split(';');
for (int i = 0; i < allInfo.Length; i++)
{
string[] info = allInfo[i].Split('|');
Action action = () => { data.Add(info[0], info[1] + '|' + info[2] + '|' + info[3]); };
action.Invoke();
}
}
catch (Exception ex)
{
Debug.Log("Error in Helper.FixedUpdate: " + ex.Message);
}
}
}
}
[SyncVar] Vector3 syncBulletStartPosition;
[SyncVar] Quaternion syncBulletStartRotation;
[SyncVar] bool syncTrueFire;
/// <summary>
/// Метод для осуществления стрельбы
/// </summary>
private void Update()
{
if(isLocalPlayer)
{
if (Input.GetButton("Fire1"))
{
//CmdShoot();
int weapon = 0;
// Create the Bullet from the Bullet Prefab
GameObject bullet = (GameObject)Instantiate(
bulletPref[weapon],
bulletPivot[weapon].position,
bulletPivot[weapon].rotation);
CmdSendBullet(bulletPivot[weapon].position, bulletPivot[weapon].rotation);
}
}
}
[Command]
void CmdSendBullet(Vector3 startPosition, Quaternion startRotation)
{
syncBulletStartPosition = startPosition;
syncBulletStartRotation = startRotation;
syncTrueFire = true;
}
/// <summary>
/// Вызов всех еобходимых методов для смены и синхронизации оружия
/// </summary>
void FixedUpdate()
{
SpawnBulletToAllClients();
}
void SpawnBulletToAllClients()
{
if (!isLocalPlayer)
{
if (syncTrueFire == true)
{
int weapon = 0;
GameObject bullet = (GameObject)Instantiate(
bulletPref[weapon],
bulletPivot[weapon].position,
bulletPivot[weapon].rotation);
CmdSyncTrueFire();
syncTrueFire = false;
}
}
}
[Command]
void CmdSyncTrueFire()
{
syncTrueFire = false;
}
using UnityEngine;
using UnityEngine.Networking;
public class PlayerScrolWeapon : NetworkBehaviour
{
public GameObject[] weapon;
[SyncVar] int syncWeaponIndex;
private int weaponIndex = 0;
[Client]
void FixedUpdate()
{
ScrolWeapon();
if(isLocalPlayer)
CmdSendToServerSyncWeapon(weaponIndex);
SendToClientSyncWeapon();
}
void ScrolWeapon()
{
if(isLocalPlayer)
{
if(Input.GetAxisRaw("Mouse ScrollWheel") > 0f)
{
if (weaponIndex > 3)
weaponIndex = 0;
else
weaponIndex++;
}
else if(Input.GetAxisRaw("Mouse ScrollWheel") < 0f)
{
if (weaponIndex < 0)
weaponIndex = 3;
else
weaponIndex--;
}
for (int i = 0; i < 4; i++)
if (i == weaponIndex)
weapon[i].SetActive(true);
else
weapon[i].SetActive(false);
}
}
void SendToClientSyncWeapon()
{
if(!isLocalPlayer)
{
for (int i = 0; i < 4; i++)
if (i == syncWeaponIndex)
weapon[i].SetActive(true);
else
weapon[i].SetActive(false);
}
}
[Command]
void CmdSendToServerSyncWeapon(int _weaponIndex)
{
syncWeaponIndex = _weaponIndex;
}
}