public MyEvent(UnityAction <float> action, ShotData data) { Action = action; Timer = data.Delay; Count = data.Count; Data = data; }
private void OnUserThrowerReadyToShot(ShotData data) { StopCoroutine(m_OnBallThrownLateUpdate); ResetCameraMovementData(); //set camera initial offset behind the ball. Vector3 dirEndV3ToStartV3 = data.spotV3 - data.targetV3; dirEndV3ToStartV3.y = m_OffSetOnStartV3.y; dirEndV3ToStartV3.Normalize(); m_CameraToMove.localPosition = data.spotV3 - (dirEndV3ToStartV3 * (m_OffSetOnStartV3.z)); //set camera initial rot. Vector3 dirCameraToEndV3 = (data.targetV3 - m_CameraToMove.localPosition).normalized; dirCameraToEndV3.y = 0; m_CameraToMove.forward = dirCameraToEndV3; //set camera final offset. Vector3 dirEndV3ToCamera = m_CameraToMove.localPosition - data.targetV3; dirEndV3ToCamera.y = m_OffsetOnEndV3.y; dirEndV3ToCamera.Normalize(); m_EndV3 = data.targetV3 + (dirEndV3ToCamera * (m_OffsetOnEndV3.z)); m_EndDistanceToCover = m_EndV3.magnitude; //set camera final rot. Vector3 localEulerAngles = m_CameraToMove.localRotation.eulerAngles; m_QuatToReach = Quaternion.RotateTowards(m_CameraToMove.localRotation, Quaternion.Euler(30f, localEulerAngles.y, localEulerAngles.z), 50f); }
public MyEvent(UnityAction action, ShotData data) { Action = (t) => action(); Timer = data.Delay; Count = data.Count; Data = data; }
public void BallFollowArc(ulong netID) { Player player = GameManager.GetPlayerByNetworkID(netID); print($"{player} | BALLFOLLOWARC | {PlayerLastTouched} {netID}"); State = BallState.SHOT; m_body.isKinematic = false; ShotData shot = ShotManager.Singleton.ShotData.Value; print($"{shot} | shotdata"); float h = ShotController.GetShotRange(shot.type) == ShotRange.LONG ? UnityEngine.Random.Range(1.5f, 3f) : UnityEngine.Random.Range(.3f, .8f); float d = shot.distance / (SHOT_SPEED + UnityEngine.Random.Range(0, 1)); if (shot.bankshot == BankType.NONE) { StartCoroutine(FollowArc(m_ball.transform.position, GameManager.Singleton.baskets[player.TeamID].netPos.position, h, d)); } else { StartCoroutine(FollowBackboard(shot, m_ball.transform.position, GameManager.Singleton.baskets[player.TeamID].netPos.position, h, d)); } }
private void shoot(Vector3 targetPos, Vector3 pos) { ShotData shot = getShotData(); Vector3 aimDir = (targetPos - pos).normalized; float aimAngle = Mathf.Atan2(aimDir.y, aimDir.x) * Mathf.Rad2Deg; float toShootFloat = shotNumPartial + shot.numBullets; int toShoot = (int)toShootFloat; shotNumPartial = toShootFloat - toShoot; float totalAngle = shot.baseSpread + shot.perBulletSpread * (toShoot - 1); for (int i = 0; i < toShoot; ++i) { float randomAngle = Random.Range(-shot.randomSpread, shot.randomSpread) / 2.0f; float cyclicAngle = shot.cyclicSpread * Mathf.Sin(Time.time * shot.cyclicFrequency * 2.0f * Mathf.PI); float multiBulletAngle = 0.0f; if (toShoot > 1) { multiBulletAngle = totalAngle * (i - (toShoot - 1) / 2.0f) / (toShoot - 1); } float angle = aimAngle + cyclicAngle + randomAngle + multiBulletAngle; Vector3 dir = VectorUtil.Unit(angle * Mathf.Deg2Rad); GameObject bulletObject = GameObject.Instantiate(data.bulletPrefab); Bullet bullet = bulletObject.GetComponent <Bullet>(); bullet.Init(shot, pos, dir); } shotTimer += 1.0f / shot.attackSpeed; }
protected new void Awake() { base.Awake(); this.data = new ShotData(); this.name = ShotData.name; this.gameObject.SetActive(false); }
public void Initialize(ShotData shotData) { _rigidbody = GetComponent <Rigidbody>(); _rigidbody.velocity = shotData.Velocity; transform.forward = shotData.Velocity.normalized; Destroy(gameObject, 0.5f); }
public void Init(ShotData shot, Vector3 pos, Vector3 dir) { transform.position = pos; _dir = dir.normalized; MathUtil.LookAt2D(transform, pos + dir); _speed *= shot.projectileSpeed; }
public void Initialize(IBall cueBall) { ShotCount = 0; m_ShotData = new ShotData(cueBall); m_ShotData.Force = 2000; m_ShotData.Direction = 0; m_Evolve = false; }
private void ResetSlider(ShotData data) { m_ShotSlider.minValue = data.forceMinMagnitude; m_ShotSlider.maxValue = data.forceMaxMagnitude; m_ShotSlider.value = m_ShotSlider.minValue; m_PerfectPowerBarRectTransform.anchoredPosition = Vector2.up * (m_SliderHeight * Constant.NormalizedData(data.forceToScoreV3.magnitude, data.forceMinMagnitude, data.forceMaxMagnitude)); }
public void Modify(ShotData shot) { increase(ref shot.attackSpeed, increasedAttackSpeed); increase(ref shot.projectileSpeed, increasedProjectileSpeed); shot.manaCost *= manaMultiplier; shot.numBullets += additionalProjectiles; }
public void ResetPosition(ShotData data) { m_EntityRb.useGravity = false; m_EntityRb.velocity = Vector3.zero; m_EntityRb.angularVelocity = Vector3.zero; this.transform.position = data.spotV3; this.transform.rotation = data.spotQuat; }
private ShotData getShotData() { ShotData shot = data.shotData.Copy(); foreach (GunSupportData support in supports) { support.Modify(shot); } return(shot); }
public void Initialize(IBall cueBall) { ShotCount = 0; m_ShotData = new ShotData(cueBall); //Add mouse hook to application m_MouseHook = new MouseHook(); m_MouseHook.MouseDown += OnMouseDown; m_MouseHook.MouseUp += OnMouseUp; Application.AddMessageFilter(m_MouseHook); }
public ShotData Copy() { ShotData ret = new ShotData(); System.Type t = typeof(ShotData); foreach (FieldInfo field in t.GetFields()) { field.SetValue(ret, field.GetValue(this)); } return(ret); }
public override void OnInspectorGUI() { ShotData data = target as ShotData; //共通 data.ShotType = (ShotType)EditorGUILayout.EnumPopup("ShotType", data.ShotType); if (data.ShotType == ShotType.AllRange || data.ShotType == ShotType.Gather) { data.AllRangeShotShape = (AllRangeShotShape)EditorGUILayout.EnumPopup("AllRangeShotShape", data.AllRangeShotShape); if (data.AllRangeShotShape == AllRangeShotShape.Random || data.AllRangeShotShape == AllRangeShotShape.Plane) { data.BulletNum = Mathf.Max(1, EditorGUILayout.IntField("BulletNum", data.BulletNum)); } } else { data.BulletNum = Mathf.Max(1, EditorGUILayout.IntField("BulletNum", data.BulletNum)); } EditorGUILayout.Separator(); if (data.ShotType == ShotType.Normal) { data.RandomDiffusion = EditorGUILayout.Toggle("RandomDiffusion", data.RandomDiffusion); data.BulletShake = EditorGUILayout.Slider("BulletShake", data.BulletShake, 0.0f, 1.0f); EditorGUILayout.Separator(); } if (data.ShotType == ShotType.Gather) { data.GatherAtTarget = EditorGUILayout.Toggle("GatherAtTarget", data.GatherAtTarget); data.PassGatherPoint = EditorGUILayout.Toggle("PassGatherPoint", data.PassGatherPoint); if (data.PassGatherPoint) { data.DistanceFromGatherPoint = Mathf.Max(0, EditorGUILayout.FloatField("DistanceFromGatherPoint", data.DistanceFromGatherPoint)); } EditorGUILayout.Separator(); } data.Count = Mathf.Max(1, EditorGUILayout.IntField("Count", data.Count)); if (data.Count > 1) { data.Cycle = Mathf.Max(0, EditorGUILayout.FloatField("Cycle", data.Cycle)); if (data.AllRangeShotShape != AllRangeShotShape.Random) { data.AngularSpeed = Mathf.Max(0, EditorGUILayout.FloatField("AngularSpeed", data.AngularSpeed)); data.Axis = EditorGUILayout.Vector3Field("Axis", data.Axis); } } EditorUtility.SetDirty(target); }
public override void SetNextShot(ShotData data) { base.SetNextShot(data); m_IsReadyToBeStopped = true; m_CurrentAimingTime = 0; m_CurrentForceV3 = Vector3.zero; m_InputObserver.RequireInputNotification(new InputObserverData(HandledInputs.LEFT_MOUSE_BUTTON_PRESSED, OnLeftMouseButtonPressed), new InputObserverData(HandledInputs.LEFT_MOUSE_BUTTON_RELEASED, OnLeftMouseButtonReleased), new InputObserverData(HandledInputs.LEFT_MOUSE_BUTTON_HELD_DOWN, OnLeftMouseButtonHeldDown)); CallEvent(OnShotDataSet, data); }
private void SetThrowParameters(ShotStatus stauts) { if (stauts == ShotStatus.FAILED) { m_BallThrower.RepeatShot(); return; } ShotData currentThrowData = m_ShootingSpots[m_SpotsCounter].GetShotData(m_TrDestinationPoint.position); m_BallThrower.SetNextShot(currentThrowData); m_SpotsCounter = m_SpotsCounter + 1 <= m_ShootingSpots.Length - 1 ? m_SpotsCounter + 1 : 0; }
private void Shoot(Vector2 direction) { AudioManager.Instance.Play("Shot", 0.7f); var particle = Instantiate(_shotParticlePrefab, transform.position, Quaternion.identity); var shot = particle.GetComponent <Shot>(); var shotData = new ShotData(direction, _shotSpeed, _maxShotRange); shot.ShotData = shotData; _shotCoolDownTimer = _shotCoolDown; }
private void Shoot() { var direction = Quaternion.EulerRotation(0, UnityEngine.Random.Range(-_spread, _spread), 0) * transform.forward; ShotData shotData = new ShotData(direction * _bulletSpeed * (AvatarController.Inverted ? -1 : 1)); var bullet = Instantiate(_bulletPrefab).GetComponent <Bullet>(); bullet.transform.position = transform.position; bullet.Initialize(shotData); if (OnShoot != null) { OnShoot.Invoke(shotData); } }
/// <summary> /// Reads value from the reader and applies it /// </summary> /// <param name="stream">The stream to read the value from</param> /// <param name="keepDirtyDelta">Whether or not the container should keep the dirty delta, or mark the delta as consumed</param> public void ReadDelta(Stream stream, bool keepDirtyDelta) { using (PooledBitReader reader = PooledBitReader.Get(stream)) { ShotData previousValue = InternalValue; InternalValue = (ShotData)reader.ReadObjectPacked((typeof(ShotData))); if (keepDirtyDelta) { isDirty = true; } OnValueChanged?.Invoke(previousValue, InternalValue); } }
//TODO private IEnumerator FollowBackboard(ShotData shot, Vector3 start, Vector3 end, float height, float duration) { Vector3 bankPos = GameManager.Singleton.baskets[GameManager.Singleton.Possession].banks[(int)shot.bankshot].transform.position; float startTime = Time.time; float fracComplete; // This is the loop for slerping the ball position from the player to the bank position // This statement will break itself at 99% completion of journey for (;;) { // Sets the center Vector3 center = (start + bankPos) * 0.5f; // Adjusts the height of the center point based on shot type center -= (shot.type == ShotType.SHOT) ? Vector3.up * height : Vector3.up; // Gets the points to Slerp with based on center Vector3 riseRelCenter = start - center; Vector3 setRelCenter = bankPos - center; fracComplete = (Time.time - startTime) / duration; // Breaks loop if gotten to destination if (fracComplete > .99) { break; } transform.position = Vector3.Slerp(riseRelCenter, setRelCenter, fracComplete); transform.position += center; yield return(null); } //Resets values startTime = Time.time; fracComplete = 0; // This is the loop for lerping ball position from bank spot on backboard to basket. while (fracComplete < .99) { // Using duration here does not makes sense since its a constant distance between the bank and the // basket. Think about moveing this to a static const or some better way? fracComplete = (Time.time - startTime) / (duration * .75f); transform.position = Vector3.Lerp(bankPos, end, fracComplete); yield return(null); } State = BallState.LOOSE; }
public static byte[] ShowShotData(ShotData ShotData) { var result = new PangyaBinaryWriter(); result.Write(new byte[] { 0x64, 0x00 }); result.WriteUInt32(ShotData.ConnectionId); result.WriteDouble(ShotData.Pos.X); result.WriteDouble(ShotData.Pos.Y); result.WriteDouble(ShotData.Pos.Z); result.WriteByte((byte)ShotData.ShotType); //result.Write(ShotData.Un); result.WriteUInt32(ShotData.Pang); result.WriteUInt32(ShotData.BonusPang); //result.Write(ShotData.Un2); //result.Write(ShotData.MatchData); //result.Write(ShotData.ShotDecrypt); return(result.GetBytes()); }
public override void SetNextShot(ShotData data) { base.SetNextShot(data); m_IsReadyToBeStopped = true; Vector3 perfectForceV3 = data.forceToScoreV3; m_CurrentForceV3 = perfectForceV3; //set an offset to the final force if the successful % to //make a perfect shot isn't met. if (Random.Range(0f, 1f) > m_SelectedAIData.successfulRate) { //the min magnitude to apply on the ball is calculated from //the min force possible from the shooting point (we don't want the min force to be 0). //then do an addition to that magnitude (this parameter is set from editor based on the ai difficulty), //to make the ai seems more precise. float minMagnitude = data.forceMinMagnitude + m_SelectedAIData.minMagnitudeMultiplier; //we do the same things with the min magnitude to the max magnitude, but we insted lower the //value of the max magnitude. float maxMagnitude = data.forceMaxMagnitude - m_SelectedAIData.maxMagnitudeMultipleir; //to make the ai seems more "human" we set an offset on the x axis of the final force. //this make the ai shoot more "randomly" on the x axis too. float minXOffset = perfectForceV3.x + m_SelectedAIData.maxXOffset; float maxXOffset = perfectForceV3.x - m_SelectedAIData.minXOffset; //the final force formula is almost the same as the player. we get the direction of the perfect shot vector, //and then we add a random range on the magnitude with the previous calculated values, and a random //offset on the x value. m_CurrentForceV3 = perfectForceV3.normalized * Random.Range(minMagnitude, maxMagnitude) + Vector3.right * Random.Range(minXOffset, maxXOffset); } //we delay the throw ball method invoke, otherwise, //the ai will be too fast compared with the user. //this will "mimic" the aiming stage of the user. StartCoroutine(m_OnThrowDelay = DelayThrowEntity()); }
public void Initialize(IBall cueBall) { ShotCount = 0; for (int i = 0; i < s_MaxShots; i++) { if (i < m_Shots.Count) { m_Shots[i] = new ShotData(cueBall) { Force = m_Shots[i].Force, Direction = m_Shots[i].Direction }; } else { m_Shots.Add(new ShotData(cueBall) { Force = GetRandom(i == 0 ? c_MaxForce / 2 : 0, c_MaxForce), Direction = GetRandom(i == 0 ? -45 : -180, i == 0 ? 45 : 180) }); } } s_Brains.Add(this); }
/// <summary> /// ShotDataをもとにActionを生成するメソッド /// </summary> /// <param name="shotData">発射するShotData</param> /// <returns></returns> private UnityAction <float> GetUnityAction(AttackerType attackerType, ShotData shotData, BulletData bulletData, GameObject aim, GameObject target) { // var position = shooter.transform.position; //発射位置を固定したい場合はキャッシュしておく ※固定するとFunnelから出る弾の発射位置も移動しなくなるので注意 var velocity = (aim == default) ? default : (aim.transform.position - transform.position).normalized; Vector3[] directions = ShotManager.Instance.GetShotShape(shotData.AllRangeShotShape, shotData.GetBulletNum, RandomNum); switch (shotData.ShotType) { case ShotType.Normal: return((t) => ShotManager.Instance.NormalShot.Shot(shotData.GetBulletNum, attackerType, gameObject, bulletData.BulletType, bulletData, aim, target, shotData.RandomDiffusion, shotData.BulletShake)); case ShotType.AllRange: if (velocity != default && shotData.AllRangeShotShape == AllRangeShotShape.Plane) { for (int i = 0; i < shotData.BulletNum; i++) { directions[i].TransformDirection(velocity); } } return((t) => ShotManager.Instance.AllRangeShot.Shot(shotData.GetBulletNum, attackerType, gameObject, directions, bulletData, target, t, shotData.AngularSpeed, shotData.Axis)); case ShotType.Gather: var gatherAtTarget = target != default && shotData.GatherAtTarget; if (velocity != default && shotData.AllRangeShotShape == AllRangeShotShape.Plane) { for (int i = 0; i < shotData.BulletNum; i++) { directions[i] = directions[i].TransformDirection(velocity); } } return((t) => ShotManager.Instance.GatherShot.Shot(shotData.GetBulletNum, attackerType, gatherAtTarget ? target : gameObject, directions, bulletData, target, t, shotData.AngularSpeed, shotData.Axis, shotData.PassGatherPoint, shotData.DistanceFromGatherPoint)); default: return(default); } }
public IEnumerator Shot_IsDestroyedWhen_OverMaxRange() // TODO make work { var shotGameObject = TestHelpers.InstantiatePrefab("shot"); var shot = shotGameObject.GetComponent <Shot>(); var shotData = new ShotData(Vector2.right, 10, 10); shot.ShotData = shotData; yield return(null); // Use the Assert class to test conditions. // Use yield to skip a frame. // var timer = 0f; // // while ((timer += Time.deltaTime) < 5.0f) // { // Debug.Log(Time.deltaTime); // Debug.Log("true"); // yield return null; // } // // yield return null; // Debug.Log(shot._distanceCovered); // Assert.IsTrue(shot.IsBeingDestroyed); }
private void OnShoot(ShotData shotData) { _movement.AddVelocity(-shotData.Velocity * recoilRatio); }
public virtual void SetNextShot(ShotData data) { m_PreviouseShotData = data; m_CurrentForceV3 = Vector3.zero; m_ThrowEntity.ResetPosition(data); }
/// <summary> /// Creates a NetworkedVar with a custom value and custom settings /// </summary> /// <param name="settings">The settings to use for the NetworkedVar</param> /// <param name="value">The initial value to use for the NetworkedVar</param> public NetworkedShotData(NetworkedVarSettings settings, ShotData value) { this.Settings = settings; this.InternalValue = value; }