public override void Attack() { base.Attack(); RaycastHit2D[] hits = Physics2D.RaycastAll(VectorExt.xy(origin.position), playerMove.GetDirection(), 10, (1 << 8) + (1 << 9)); if (hits.Length > 0) { int penetrationCount = 0; foreach (RaycastHit2D hit in hits) { if (hit.collider.tag == "Enemy") { // Hit Unit UnitScript unit = hit.transform.GetComponent <UnitScript>(); HitUnit(unit, hit.point, penetrationCount); penetrationCount++; if (penetrationCount >= penetration) { break; } } } } }
public static Chunk GetChunk(this NetPack pack) { Chunk chunk = new Chunk(); chunk.position = VectorExt.Int3FromBytes(new Span <byte>(pack.data, 0, 12)); chunk.chunkFlags = (ChunkFlag)BitConverter.ToInt32(pack.data, 12); chunk.stamp = BitConverter.ToInt64(pack.data, 16); new Span <byte>(pack.data, 64, 16384).CopyTo(MemoryMarshal.Cast <int, byte>(new Span <int>(chunk.data))); return(chunk); }
void OnTriggerEnter(Collider other) { if (other.CompareTag("Activator")) { currentActivator = other.GetComponent <Activator>(); } else if (other.CompareTag("LevelGoal")) { transform.SetParent(other.transform); transform.localPosition = VectorExt.OneByOneProduct(transform.localPosition, Vector3.up); inputEnabled = false; int goalIndex = other.GetComponent <LevelSelectorData>().levelIndex; GameControl.instance.StartLevelChangeProcess(goalIndex); } }
public void Update(Entity entity, float deltaTime) { C_MoveToTarget c = entity.GetComp <C_MoveToTarget>(); if (MapUtils.CloseEnough(entity.GetPosition(), c.targetPos)) { return; } Vector2 pos = entity.GetPosition(); Vector2 dir = c.targetPos - pos; dir.Normalize(); pos += deltaTime * c.speed * dir; entity.SetRotation(VectorExt.ToRotation(dir)); entity.SetPosition(pos); }
protected override void HitUnit(UnitScript unit, Vector2 hitPos, int penetration = 0) { // Create effects GameObject newblood = ObjectPoolScript.instance.GetObjectForType("blood", false); newblood.transform.position = VectorExt.V2toV3(hitPos); newblood.transform.localRotation = Quaternion.AngleAxis(-playerMove.GetDirection().x * 90, Vector3.up); // Damage unit int damage = damageMin + Random.Range(0, damageVariation); damage /= (penetration + 1); unit.DamageUnit(damage); unit.KnockbackUnit(playerMove.GetDirection() * knockbackForce); // Log Debug.Log("damaged " + damage.ToString() + " on unit " + unit.name); }
void OnCollisionExit(Collision collision) { if (groundCollection.Contains(collision.collider)) { groundCollection.Remove(collision.collider); if (collision.collider.CompareTag("MovingPlatform")) { transform.SetParent(null); Vector3 exitMomentum = collision.collider.GetComponent <PlatformBehaviour>().currentMomentum; exitMomentum = VectorExt.OneByOneProduct(exitMomentum, VectorExt.zeroY); rigBod.AddForce(exitMomentum, ForceMode.VelocityChange); } } if (groundCollection.Count == 0) { grounded = false; playerAnimator.SetBool("Grounded", grounded); } }
private void Update(Entity entity, float deltaTime) { C_MoveToPos c = entity.GetComp <C_MoveToPos>(); Vector2 targetPos = entity.GetComp <C_TargetPos>().targetPos; float move = deltaTime * c.speed; if (MapUtils.CloseEnough(entity.GetPosition(), targetPos, move)) { entity.SetPosition(targetPos); entity.AddComp <C_MoveEnd>(); return; } Vector2 pos = entity.GetPosition(); Vector2 dir = targetPos - pos; dir.Normalize(); pos += move * dir; entity.SetRotation(VectorExt.ToRotation(dir)); entity.SetPosition(pos); }
void updateSelection() { var rekt = new Rect(VectorExt.Min(selectionPtA, selectionPtB), (selectionPtB - selectionPtA).Abs()); foreach (var cell in AllCells) { cell.selected = cachedSelection.Contains(cell) || rekt.Contains(cell.transform.position); } selectedCells.Clear(); unselectedCells.Clear(); foreach (var cell in AllCells) { if (cell.selected) { selectedCells.Add(cell); } else { unselectedCells.Add(cell); } } }
public void UserConnectService(object _serverUserContext) { User user = (User)_serverUserContext; Socket socket = user.socket; NetContext netContext = user.netContext; serverContext.Log(string.Format("connected. {0} {1}", socket.RemoteEndPoint, socket.LocalEndPoint)); PlayerInfo playerInfo = null; DateTime lastNetActionTime = DateTime.Now; try { netContext.Init(socket); Task.Factory.StartNew(netContext.ReceiveService, TaskCreationOptions.LongRunning); netContext.SendStringCompressed((int)NetMessageType.License, serverContext.License); playerInfo = new PlayerInfo(); playerInfo.currentUser = user; playerInfo.PlayerGuid = Guid.NewGuid(); world.playerEnterQueue.Enqueue(playerInfo); while (true) { netContext.receiveEvent.WaitOne(); if (!socket.Connected) { return; } var readList = netContext.receivedBlocks.GetReadList(); foreach (var block in readList) { switch (block.header) { case (int)NetMessageType.Move: playerInfo.PositionI = VectorExt.Int3FromBytes(new Span <byte>(block.data, 0, 12)); playerInfo.PositionF = VectorExt.Vector3FromBytes(new Span <byte>(block.data, 12, 12)); playerInfo.Rotation = VectorExt.QuaternionFromBytes(new Span <byte>(block.data, 24, 16)); break; } } DateTime now = DateTime.Now; playerInfo.lastActivateTime = now; user.SendPacks(); //if (now - lastNetActionTime > TimeSpan.FromMilliseconds(10)) //{ // lastNetActionTime = now; // foreach (var chunkPosition in world.VisibleChunks(playerInfo)) // { // var chunk1 = world.GetChunk(chunkPosition); // if (playerInfo.visibleChunks.TryGetValue(chunkPosition, out var timeStamp1)) // { // if (chunk1 != null && chunk1.stamp > timeStamp1) // { // playerInfo.visibleChunks[chunkPosition] = chunk1.stamp; // chunk1.Send(netContext); // } // } // else if (chunk1 != null) // { // playerInfo.visibleChunks[chunkPosition] = chunk1.stamp; // chunk1.Send(netContext); // } // } // playerInfo.RemoveUnusedChunks(); //} } } catch (Exception e) { user.Log(e); } finally { serverContext.Log(string.Format("connection close. {0} {1}", socket.RemoteEndPoint, socket.LocalEndPoint)); if (playerInfo != null) { world.playerLeaveQueue.Enqueue(playerInfo); } socket.Close(); } }
private void Update() { Vector2 screenSize = new Vector2(mainCamera.pixelWidth, mainCamera.pixelHeight); Ray ray = mainCamera.ScreenPointToRay(GetMousePosition(screenSize)); RaycastHit hitItem; RaycastHit hitWall; bool itemCollided = Physics.Raycast(ray, out hitItem, Mathf.Infinity, 1 << LayerMask.NameToLayer("Item")); bool wallCollided = Physics.Raycast(ray, out hitWall, Mathf.Infinity, 1 << LayerMask.NameToLayer("Default")); Item item = null; if (itemCollided) { item = hitItem.transform.GetComponent <Item>(); } if (itemCollided && (!wallCollided || hitItem.distance < hitWall.distance) && item != null) { // Highlight if (highlightedItem != null) { highlightedItem.Hide(); } if (item != highlightedItem && !showInfoSound.isPlaying) { showInfoSound.Play(); } highlightedItem = item; highlightedItem.Show(); // Select if (!onSuspect && Input.GetMouseButtonDown(0)) { if (selectedItem != null) { selectedItem.Unselect(); selectedItem.Hide(); if (!selectedSound.isPlaying) { selectedSound.Play(); } } if (selectedItem != highlightedItem) { selectedItem = highlightedItem; selectedItem.Select(); suspectButton.SetActive(true); if (!selectedSound.isPlaying) { selectedSound.Play(); } } else { selectedItem = null; suspectButton.SetActive(false); onSuspect = false; } } // Update panel labelText.text = "<b>" + highlightedItem.label + "</b>"; priceText.text = "<b>" + db.GetTranslation("Price") + ":</b> " + highlightedItem.price + " ₽"; descriptionText.text = "<b>" + db.GetTranslation("Descritption") + ":</b>\n" + highlightedItem.description; panel.gameObject.SetActive(true); // Place a panel not on the edge and with offset. Vector3 itemPosition = mainCamera.WorldToScreenPoint(hitItem.transform.position); float dirOffset = (itemPosition.x > screenSize.x / 2) ? +offset : -offset; Vector3 panelPosition = VectorExt.WithZ(itemPosition, 0.0f) + Vector3.left * dirOffset; if (panelPosition.x > screenSize.x - offsetWidth) { panelPosition = VectorExt.WithX(panelPosition, screenSize.x - offsetWidth); } if (panelPosition.x < offsetWidth) { panelPosition = VectorExt.WithX(panelPosition, offsetWidth); } if (panelPosition.y > screenSize.y - offsetHeight) { panelPosition = VectorExt.WithY(panelPosition, screenSize.y - offsetHeight); } if (panelPosition.y < offsetHeight) { panelPosition = VectorExt.WithY(panelPosition, offsetHeight); } panel.position = panelPosition; } else { panel.gameObject.SetActive(false); if (highlightedItem != null) { highlightedItem.Hide(); highlightedItem = null; } } }