void Start() { PlayerStats _playerStats = GetComponentInParent <PlayerStats>(); GameObject _bulletsContainer = GameObject.Find("BulletsContainer"); SignalRIdentity _signalRIdentity = GetComponentInParent <SignalRIdentity>(); for (int i = 0; i < _playerStats.Bullets.Length; i++) { int _size = 0; BulletStats _bulletStats = _playerStats.Bullets[i].GetComponent <BulletStats>(); if (_bulletStats.Patrons >= 10) { _size = 10; } else { _size = _bulletStats.Patrons; } Pool _poolObj = new Pool { Size = _size, Tag = _bulletStats.gameObject.name, Prefab = _bulletStats.gameObject }; Pools.Add(_poolObj); } PoolDictionary = new Dictionary <string, Queue <GameObject> >(); foreach (Pool _pool in Pools) { Queue <GameObject> _objectPool = new Queue <GameObject>(); for (int i = 0; i < _pool.Size; i++) { GameObject _obj = Instantiate(_pool.Prefab); _obj.SetActive(false); _objectPool.Enqueue(_obj); _obj.transform.SetParent(_bulletsContainer.transform); SignalRIdentity signalRIdentity = new SignalRIdentity { NetworkID = i, ParentID = _signalRIdentity.NetworkID, TeamID = _signalRIdentity.TeamID }; if (_signalRIdentity.IsAuthority) { signalRIdentity.IsAuthority = true; } } PoolDictionary.Add(_pool.Tag, _objectPool); } }
private IEnumerator SendAndSyncData() { yield return(new WaitForSeconds(0.06f)); //каждые 60 мс шлет Update if (IsPlayerRegister) { //реализация дисконекта DisconnectInUpdate(); if (GameHelper.CurrentPlayerGameObject) { Vector3 pos = _playerController.SyncPosition; Quaternion rot = _playerController.SyncRotation; SyncObjectModel syncObjectModel = new SyncObjectModel() { Id = GameHelper.CurrentPlayerGameObject.GetComponent <SignalRIdentity>().NetworkID, X = pos.x, Y = pos.y, Z = pos.z, aX = rot.x, aY = rot.y, aZ = rot.z, aQ = rot.w }; //отправляет на обновление syncObjectModel HubProxy.Invoke("UpdateModel", syncObjectModel); } //синкаем позицию if (_syncObjectPool.Count > 0) { foreach (var syncObjectModel in _syncObjectPool) { SignalRIdentity signalRIdentity = GameHelper.OtherPlayers.FirstOrDefault(p => p.NetworkID == syncObjectModel.Id); if (signalRIdentity) { PlayerController playerController = signalRIdentity.GetComponent <PlayerController>(); Vector3 pos = new Vector3(syncObjectModel.X, syncObjectModel.Y, syncObjectModel.Z); Quaternion rot = new Quaternion(syncObjectModel.aX, syncObjectModel.aY, syncObjectModel.aZ, syncObjectModel.aQ); playerController.SyncPosition = pos; playerController.SyncRotation = rot; } } } _syncObjectPool.Clear(); } StartCoroutine(SendAndSyncData()); }
void Start() { _signalRIdentity = GetComponent <SignalRIdentity>(); xMax = Camera.main.GetComponent <CameraController>().xMax + 14f - 0.5f; xMin = Camera.main.GetComponent <CameraController>().xMin - 14f + 0.5f; yMin = Camera.main.GetComponent <CameraController>().yMin - 10.2f + 0.5f; yMax = Camera.main.GetComponent <CameraController>().yMax + 10.2f - 0.5f; }
//Почемуто не хочет работать с этим //public KeyCode _keyCode = KeyCode.LeftShift; private void Start() { _forcing = GetComponent <ParticleSystem>(); _rigidbody2D = GetComponentInParent <Rigidbody2D>(); _playerStats = GetComponentInParent <PlayerStats>(); _signalRIdentity = GetComponentInParent <SignalRIdentity>(); speed = _playerStats.MoveSpeed; }
private void Start() { _signalRIdentity = GetComponent <SignalRIdentity>(); _rigidbody2D = GetComponent <Rigidbody2D>(); _playerStats = GetComponent <PlayerStats>(); speed = _playerStats.MoveSpeed; rotationSpeed = speed * 30; inclineX = 0; }
void Start() { signalRClient = SignalRClient.instance; hubProxy = signalRClient.HubProxy; _signalRIdentity = GetComponentInParent <SignalRIdentity>(); playerStats = GetComponentInParent <PlayerStats>(); clip = playerStats.Clips[0]; shootingRate = playerStats.Bullets[0].GetComponent <BulletStats>().AttackSpeed; shotCooldown = 0f; shotPrefab = playerStats.Bullets[0]; }
private void Start() { _rigidbody2D = GetComponent <Rigidbody2D>(); _bulletStats = GetComponent <BulletStats>(); _signalRShooting = SignalRShooting.instance; _signalRIdentity = GetComponent <SignalRIdentity>(); speed = _bulletStats.BulletSpeed * 10; damage = _bulletStats.Damage; Invoke("BulletOff", _bulletStats.LifeTime); //выдается ошибка так, как поля еще не обозначены, а OnEnable запускается быстрее Start. //А сам OnEnable нужен потому, что Start работает лишь при 1ом включении _onPlay = true; }
private void RegisteredInUpdate() { if (_instantiatePlayerPool.Count > 0) { foreach (var syncObjectModel in _instantiatePlayerPool) { GameObject gameObj = GameObject.Instantiate(Resources.Load <GameObject>(syncObjectModel.PrefabName), new Vector3(syncObjectModel.X, syncObjectModel.Y, syncObjectModel.Z), new Quaternion(syncObjectModel.aX, syncObjectModel.aY, syncObjectModel.aZ, syncObjectModel.aQ)) as GameObject; SignalRIdentity signalRIdentety = gameObj.GetComponent <SignalRIdentity>(); signalRIdentety.NetworkID = syncObjectModel.Id; if (HubConnection.ConnectionId == syncObjectModel.Authority) { signalRIdentety.IsAuthority = true; GameHelper.CurrentPlayerGameObject = gameObj; gameObj.GetComponent <PlayerStats>().IsEnemy = false; _playerController = GameHelper.CurrentPlayerGameObject.GetComponent <PlayerController>(); } else { gameObj.GetComponent <PlayerStats>().IsEnemy = true; } GameHelper.OtherPlayers.Add(signalRIdentety); GameHelper.AllPlayers.Add(gameObj); } //объект призван, очищает список _instantiatePlayerPool.Clear(); } }