private RangedSkill CreateRangedSkill(string type) { if (type == "fire") { return(new RangedSkill("flames", stats, pfOrbFire, UtilsClass.GetMousePosition2D())); } if (type == "water") { return(new RangedSkill("splash", stats, pfOrbWater, UtilsClass.GetMousePosition2D())); } if (type == "earth") { return(new RangedSkill("rock", stats, pfOrbEarth, UtilsClass.GetMousePosition2D())); } if (type == "ice") { return(new RangedSkill("icicle", stats, pfOrbIce, UtilsClass.GetMousePosition2D())); } throw new Exception("skill not found"); }
private void UpdateMolData(int req_num) { string jsonstring = UtilsClass.GetElementData(req_num); // test.text = jsonstring; try{ Structure st = Newtonsoft.Json.JsonConvert.DeserializeObject <Structure>(jsonstring); // print("TEST : " + st.name); mol_heading.text = st.name; mol_desp.text = st.summary; mol_bg.text = st.symbol; phase.text = st.phase; density.text = st.density.ToString(); atomic_mass.text = st.atomic_mass.ToString(); melt_point.text = st.melt.ToString() + " K"; boil_point.text = st.boil.ToString() + " K"; }catch (Exception e) { Debug.Log("JSON DATA HAVE SOME VALUE ERROR!"); } }
//enables movement and shows player possible tiles they can move to. public void EnableMovement() { if (isSelected) { if (canMove == false) { originalPos = transform.position; UtilsClass.CreateWorldSprite( "MovementArea", movementAreaTile, //sprite new Vector3(transform.position.x, transform.position.y - 0.5f, transform.position.z), // pos new Vector3((moveSpeed + 0.5f) * 2, ((moveSpeed) * 2) + 1, 0), // scale 1, //order new Color(0, 0, 139, 0.3f) // color ); canMove = true; } //UtilsClass.CreateWorldSprite(string name, Sprite sprite, Vector3 position, Vector3 localPosition, Vector3 localScale, int sortingOrder, Color color) } }
protected virtual void CheckMouseInput() { if (Input.GetMouseButtonDown(0) && placedWorldTileTypeSO != null) { Vector3 mousePosition = UtilsClass.GetMouseWorldPosition(); SetTileAspect(LoopPathAspect, mousePosition); //PlaceWorldTile(mousePosition); } if (Input.GetMouseButtonDown(1) && placedWorldTileTypeSO != null) { Vector3 mousePosition = UtilsClass.GetMouseWorldPosition(); DeleteTileAspects(mousePosition); //PlaceWorldTile(mousePosition); } }
// Update is called once per frame void Update() { // set moving target if (Input.GetMouseButtonDown(0)) { Vector3 mouseWorldPosition = UtilsClass.GetMouseWorldPosition(); CurrentAction = new ActionGoToTile(this.gameObject); CurrentAction.Execute(); } if (Input.GetKeyDown(KeyCode.F)) { CurrentPlan = new PlanToHaveSex(this.gameObject, this.animator); CurrentPlan.Execute(); } if (CurrentPlan != null) { CurrentPlan.Proceed(); } }
// OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { if (!inMovement) { inMovement = true; randomPosition = new Vector3(Random.Range(0, width * 10), Random.Range(0, height * 10)); Vector3 mouseWorldPosition = UtilsClass.GetMouseWorldPosition(); Testing.pathfinding.GetGrid().GetXY(randomPosition, out int x, out int y); owner.gameObject.GetComponent <CharacterPathfindingMovementHandler>().SetTargetPosition(randomPosition); owner.gameObject.GetComponent <CharacterPathfindingMovementHandler>().colRotation(new Vector3(x * 10, y * 10) + Vector3.one * 5f); } if (time > timeToChangeState) { time = 0; animator.SetTrigger(hashToIdle); } time += Time.deltaTime; }
private void Update() { if (Input.GetMouseButton(0)) { Vector3 mouseWorldPosition = UtilsClass.GetMouseWorldPosition(); tilemap.SetTilemapSprite(mouseWorldPosition, tilemapSprite); } if (Input.GetKeyDown(KeyCode.T)) { tilemapSprite = Tilemap.TilemapObject.TilemapSprite.None; CMDebug.TextPopupMouse(tilemapSprite.ToString()); } if (Input.GetKeyDown(KeyCode.Y)) { tilemapSprite = Tilemap.TilemapObject.TilemapSprite.Ground; CMDebug.TextPopupMouse(tilemapSprite.ToString()); } if (Input.GetKeyDown(KeyCode.U)) { tilemapSprite = Tilemap.TilemapObject.TilemapSprite.Path; CMDebug.TextPopupMouse(tilemapSprite.ToString()); } if (Input.GetKeyDown(KeyCode.I)) { tilemapSprite = Tilemap.TilemapObject.TilemapSprite.Dirt; CMDebug.TextPopupMouse(tilemapSprite.ToString()); } if (Input.GetKeyDown(KeyCode.P)) { tilemap.Save(); CMDebug.TextPopupMouse("Saved!"); } if (Input.GetKeyDown(KeyCode.L)) { tilemap.Load(); CMDebug.TextPopupMouse("Loaded!"); } }
public Grid(int width, int height, float cellSize, Vector3 originPosition, Func <Grid <TGridObject>, int, int, TGridObject> createGridObject) { this.width = width; this.height = height; this.cellSize = cellSize; this.originPosition = originPosition; gridArray = new TGridObject[width, height]; for (int x = 0; x < gridArray.GetLength(0); x++) { for (int y = 0; y < gridArray.GetLength(1); y++) { gridArray[x, y] = createGridObject(this, x, y); } } bool showDebug = false; if (showDebug) { TextMesh[,] debugTextArray = new TextMesh[width, height]; for (int x = 0; x < gridArray.GetLength(0); x++) { for (int y = 0; y < gridArray.GetLength(1); y++) { debugTextArray[x, y] = UtilsClass.CreateWorldText(gridArray[x, y]?.ToString(), null, GetWorldPosition(x, y) + new Vector3(cellSize, cellSize) * .5f, 7, Color.white, TextAnchor.MiddleCenter); Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x, y + 1), Color.white, 100f); Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x + 1, y), Color.white, 100f); } } Debug.DrawLine(GetWorldPosition(0, height), GetWorldPosition(width, height), Color.white, 100f); Debug.DrawLine(GetWorldPosition(width, 0), GetWorldPosition(width, height), Color.white, 100f); OnGridObjectChanged += (object sender, OnGridObjectChangedEventArgs eventArgs) => { debugTextArray[eventArgs.x, eventArgs.y].text = gridArray[eventArgs.x, eventArgs.y]?.ToString(); }; } }
public virtual void PlaceWorldTile(Vector3 _placePosition) { _grid.GetXY(_placePosition, out int x, out int z); Vector2Int _placedObjectOrigin = new Vector2Int(x, z); List <Vector2Int> gridPositionList = placedWorldTileTypeSO.GetGridPositionList(_placedObjectOrigin, dir); bool canBuild = true; foreach (Vector2Int gridPosition in gridPositionList) { if (!_grid.GetGridObject(gridPosition.x, gridPosition.y).CanBuild()) { canBuild = false; break; } } if (canBuild) { Vector2Int rotationOffset = placedWorldTileTypeSO.GetRotationOffset(dir); Vector3 placedObjectWorldPosition = _grid.GetWorldPosition(x, z) + new Vector3(rotationOffset.x, rotationOffset.y) * _grid.GetCellSize(); PlacedObject_WorldTile placedObject = PlacedObject_WorldTile.Create(WorldTileParent, StartingAspects, placedObjectWorldPosition, _placedObjectOrigin, dir, placedWorldTileTypeSO); placedObject.transform.rotation = Quaternion.Euler(0, 0, -placedWorldTileTypeSO.GetRotationAngle(dir)); foreach (Vector2Int gridPosition in gridPositionList) { _grid.GetGridObject(gridPosition.x, gridPosition.y).SetPlacedObject(placedObject); } //OnObjectPlaced?.Invoke(this, EventArgs.Empty); //DeselectObjectType(); } else { // Cannot build here UtilsClass.CreateWorldTextPopup("Cannot Build Here!", _placePosition); } }
/* * private void ShowGraph(List<int> valueList) { * float graphHeight = graphContainer.sizeDelta.y; * float yMaximum = 100f; * float xSize = 50f; * * GameObject lastCircleGameObject = null; * for (int i = 0; i < valueList.Count; i++) { * float xPosition = xSize + i * xSize; * float yPosition = (valueList[i] / yMaximum) * graphHeight; * GameObject circleGameObject = CreateCircle(new Vector2(xPosition, yPosition)); * if (lastCircleGameObject != null) { * CreateDotConnection(lastCircleGameObject.GetComponent<RectTransform>().anchoredPosition, circleGameObject.GetComponent<RectTransform>().anchoredPosition); * } * lastCircleGameObject = circleGameObject; * } * } */ #endregion public GameObject CreateDotConnection(Vector2 dotPositionA, Vector2 dotPositionB, Color color_of_Line) { GameObject gameObject = new GameObject("dotConnection", typeof(Image)); gameObject.transform.SetParent(graphContainer, false); //gameObject.GetComponent<Image>().color = new Color(1,1,1, .5f); gameObject.GetComponent <Image>().color = color_of_Line; RectTransform rectTransform = gameObject.GetComponent <RectTransform>(); Vector2 dir = (dotPositionB - dotPositionA).normalized; float distance = Vector2.Distance(dotPositionA, dotPositionB); rectTransform.anchorMin = new Vector2(0, 0); rectTransform.anchorMax = new Vector2(0, 0); rectTransform.sizeDelta = new Vector2(distance, 3f); rectTransform.anchoredPosition = dotPositionA + dir * distance * .5f; rectTransform.localEulerAngles = new Vector3(0, 0, UtilsClass.GetAngleFromVectorFloat(dir)); return(gameObject); }
private void Update() { if (Input.GetMouseButtonDown(0)) { Vector3 mouseWorldPosition = UtilsClass.GetMouseWorldPosition(); tilemap.SetTilemapSprite(mouseWorldPosition, tilemapSprite); } if (Input.GetKeyDown(KeyCode.A)) { tilemapSprite = TilemapObject.TilemapSprite.None; } if (Input.GetKeyDown(KeyCode.Z)) { tilemapSprite = TilemapObject.TilemapSprite.Ground; } if (Input.GetKeyDown(KeyCode.E)) { tilemapSprite = TilemapObject.TilemapSprite.Path; } }
///<summary> ///Extract data from json file and extract data of pass value of number ///of electrons and calls GenerateStructureModel with Structure variable ///</summary> ///<param name="num_elec">num_elec</param> public void CreateStructure(int num_elec) { string jsonstring = UtilsClass.GetElementData(num_elec); // Debug.Log(jsonstring); try{ Structure st = Newtonsoft.Json.JsonConvert.DeserializeObject <Structure>(jsonstring); GenerateStructureModel(st); // disable all electrons gizmos UtilsClass.ToggleGizmos( structureParent, false ); // GenerateStructureModel(ElectrionDectectionUIManager.SHARED_STRUCTURE); } catch (Exception e) { Debug.Log("JSON DATA HAVE SOME VALUE ERROR!"); } }
public static FunctionUpdater CreateMouseDraggingAction(int mouseButton, Action <Vector3> onMouseDragging) { bool dragging = false; return(FunctionUpdater.Create(() => { if (Input.GetMouseButtonDown(mouseButton)) { dragging = true; } if (Input.GetMouseButtonUp(mouseButton)) { dragging = false; } if (dragging) { onMouseDragging(UtilsClass.GetMouseWorldPosition()); } return false; })); }
public void GizmosBtnPressed() { gizmosPressed = !gizmosPressed; if (gizmosPressed) { Color c = UtilsClass.ToColor("#2699FB"); gizmosBtn.GetComponent <Image>().color = c; gizmosBtn.transform.GetChild(0).GetComponentInChildren <Image>().color = new Color(255, 255, 255, 255); UtilsClass.ToggleGizmos(stParent, true); } else { gizmosBtn.GetComponent <Image>().color = new Color(255, 255, 255, 255); Color c = UtilsClass.ToColor("#464A53"); gizmosBtn.transform.GetChild(0).GetComponentInChildren <Image>().color = c; UtilsClass.ToggleGizmos(stParent, false); } }
//handles the shooting private void HandleShooting() { if (Input.GetButtonDown("Fire1")) { Vector3 mousePosition = UtilsClass.GetMouseWorldPosition(); OnShootLeft?.Invoke(this, new OnShootEventArgs { endPointPosition = firePoint.position, shootPosition = mousePosition, }); } if (Input.GetButtonDown("Fire2")) { Vector3 mousePosition = UtilsClass.GetMouseWorldPosition(); OnShootRight?.Invoke(this, new OnShootEventArgs { endPointPosition = firePoint.position, shootPosition = mousePosition, }); } }
/* * private void HandleMovement() { * float moveX = 0f; * float moveY = 0f; * * if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow)) { * moveY = +1f; * } * if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow)) { * moveY = -1f; * } * if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)) { * moveX = -1f; * } * if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)) { * moveX = +1f; * } * * Vector3 moveDir = new Vector3(moveX, moveY).normalized; * bool isIdle = moveX == 0 && moveY == 0; * if (isIdle) { * characterBase.PlayIdleAnim(); * } else { * characterBase.PlayMoveAnim(moveDir); * transform.position += moveDir * SPEED * Time.deltaTime; * } * } */ private void HandleAttack() { if (Input.GetMouseButtonDown(0)) { // Attack SetStateAttacking(); Vector3 attackDir = (UtilsClass.GetMouseWorldPosition() - GetPosition()).normalized; EnemyHandler enemyHandler = EnemyHandler.GetClosestEnemy(GetPosition() + attackDir * 4f, 20f); if (enemyHandler != null) { //enemyHandler.Damage(this); if (enemyHandler.IsDead()) { OnEnemyKilled?.Invoke(this, EventArgs.Empty); } attackDir = (enemyHandler.GetPosition() - GetPosition()).normalized; transform.position = enemyHandler.GetPosition() + attackDir * -12f; } else { transform.position = transform.position + attackDir * 4f; } Transform swordSlashTransform = Instantiate(GameAssets.i.pfSwordSlash, GetPosition() + attackDir * 13f, Quaternion.Euler(0, 0, UtilsClass.GetAngleFromVector(attackDir))); swordSlashTransform.GetComponent <SpriteAnimator>().onLoop = () => Destroy(swordSlashTransform.gameObject); UnitAnimType activeAnimType = characterBase.GetUnitAnimation().GetActiveAnimType(); if (activeAnimType == GameAssets.UnitAnimTypeEnum.dSwordTwoHandedBack_Sword) { swordSlashTransform.localScale = new Vector3(swordSlashTransform.localScale.x, swordSlashTransform.localScale.y * -1, swordSlashTransform.localScale.z); characterBase.GetUnitAnimation().PlayAnimForced(GameAssets.UnitAnimTypeEnum.dSwordTwoHandedBack_Sword2, attackDir, 1f, (UnitAnim unitAnim) => SetStateNormal(), null, null); } else { characterBase.GetUnitAnimation().PlayAnimForced(GameAssets.UnitAnimTypeEnum.dSwordTwoHandedBack_Sword, attackDir, 1f, (UnitAnim unitAnim) => SetStateNormal(), null, null); } } }
private void Update() { targetPosition = selectionUI.target.transform.position; if (targetPosition.Equals(null)) { return; } Vector3 toPosition = targetPosition; Vector3 fromPosition = Camera.main.transform.position; fromPosition.z = 0f; Vector3 dir = (toPosition - fromPosition).normalized; float angle = UtilsClass.GetAngleFromVectorFloat(dir); pointerRectTransform.localEulerAngles = new Vector3(0, 0, angle); float borderSize = 40f; Vector3 targetPositionScreenPoint = Camera.main.WorldToScreenPoint(targetPosition); bool isOffscreen = targetPositionScreenPoint.x <= borderSize || targetPositionScreenPoint.x >= Screen.width - borderSize || targetPositionScreenPoint.y <= borderSize || targetPositionScreenPoint.y >= Screen.height - borderSize; Debug.Log(isOffscreen + " " + targetPositionScreenPoint); if (isOffscreen) { Vector3 cappedTargetScreenPosition = targetPositionScreenPoint; cappedTargetScreenPosition.x = Mathf.Clamp(cappedTargetScreenPosition.x, borderSize, Screen.width - borderSize); cappedTargetScreenPosition.y = Mathf.Clamp(cappedTargetScreenPosition.y, borderSize, Screen.height - borderSize); Vector3 pointerWorldPosition = uiCamera.ScreenToWorldPoint(cappedTargetScreenPosition); pointerRectTransform.position = pointerWorldPosition; pointerRectTransform.localPosition = new Vector3(pointerRectTransform.localPosition.x, pointerRectTransform.localPosition.y, 0f); } else { Vector3 pointerWorldPosition = uiCamera.ScreenToWorldPoint(targetPositionScreenPoint); pointerRectTransform.position = pointerWorldPosition; pointerRectTransform.localPosition = new Vector3(pointerRectTransform.localPosition.x, pointerRectTransform.localPosition.y, 0f); } }
public Grid(int width, int height, float cellSize, Vector3 originPosition, Func <Grid <TGridObject>, int, int, TGridObject> createGridObject) { _width = width; _height = height; _cellSize = cellSize; _originPosition = originPosition; _gridArray = new TGridObject[_width, _height]; for (int x = 0; x < _width; x++) { for (int y = 0; y < _height; y++) { _gridArray[x, y] = createGridObject(this, x, y); } } bool showDebug = false; if (showDebug) { TextMesh[,] debugTextArray = new TextMesh[_width, _height]; for (int x = 0; x < _gridArray.GetLength(0); x++) { for (int y = 0; y < _gridArray.GetLength(1); y++) { debugTextArray[x, y] = UtilsClass.CreateWorldText(_gridArray[x, y]?.ToString(), null, GetWorldPosition(x, y) + new Vector3(cellSize, cellSize) * 0.5f, 20, Color.white, TextAnchor.MiddleCenter); Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x, y + 1), Color.white, 100f); Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x + 1, y), Color.white, 100f); } } Debug.DrawLine(GetWorldPosition(0, height), GetWorldPosition(width, height), Color.white, 100f); Debug.DrawLine(GetWorldPosition(width, 0), GetWorldPosition(width, height), Color.white, 100f); OnGridValueChanged += (sender, eventArgs) => { debugTextArray[eventArgs.X, eventArgs.Y].text = _gridArray[eventArgs.X, eventArgs.Y]?.ToString(); }; } }
private void CreateWeaponTracer(Vector3 fromPosition, Vector3 targetPosition) { Vector3 dir = (targetPosition - fromPosition).normalized; float eulerZ = UtilsClass.GetAngleFromVectorFloat(dir) - 90; float distance = Vector3.Distance(fromPosition, targetPosition); Vector3 tracerSpawnPosition = fromPosition + dir * distance * .5f; Material tmpWeaponTracerMaterial = new Material(WeaponTracerMaterial); tmpWeaponTracerMaterial.SetTextureScale("_MainTex", new Vector2(1f, distance / 256f)); World_Mesh worldMesh = World_Mesh.Create(tracerSpawnPosition, eulerZ, 6f, distance, tmpWeaponTracerMaterial, null, 10000); int frame = 0; float frameRate = 0.016f; float timer = .1f; worldMesh.SetUVCoords(new World_Mesh.UVCoords(0, 0, 16, 256)); FunctionUpdater.Create(() => { timer -= Time.deltaTime; if (timer <= 0) { frame++; timer += frameRate; if (frame >= 4) { worldMesh.DestroySelf(); return(true); } else { worldMesh.SetUVCoords(new World_Mesh.UVCoords(16 * frame, 0, 16, 256)); } } return(false); }); }
public void TakeSnapshotFinalPath(Grilla <CasillaNodo> grid, List <CasillaNodo> path) { GridSnapshotAction gridSnapshotAction = new GridSnapshotAction(); gridSnapshotAction.AddAction(HideNodeVisuals); for (int x = 0; x < grid.GetWidth(); x++) { for (int y = 0; y < grid.GetHeight(); y++) { CasillaNodo CasillaNodo = grid.GetGridObject(x, y); Vector3 gridPosition = new Vector3(CasillaNodo.x, CasillaNodo.y) * grid.GetCellSize() + Vector3.one * grid.GetCellSize() * .5f; bool isInPath = path.Contains(CasillaNodo); int tmpX = x; int tmpY = y; gridSnapshotAction.AddAction(() => { Transform visualNode = visualNodeArray[tmpX, tmpY]; Color backgroundColor; if (isInPath) { backgroundColor = new Color(0, 1, 0); } else { backgroundColor = UtilsClass.GetColorFromString("636363"); } visualNode.Find("sprite").GetComponent <SpriteRenderer>().color = backgroundColor; }); } } gridSnapshotActionList.Add(gridSnapshotAction); }
public bool debug = true; //aktiviert debug ausgabe public MyGrid(int width, int height, float cellSize, Vector3 origin, Func <MyGrid <MyGridObject>, int, int, MyGridObject> createGridObject) { this.width = width; this.height = height; this.cellSize = cellSize; this.origin = origin; gridArray = new MyGridObject[width, height]; debugTextArray = new TextMesh[width, height]; for (int x = 0; x < gridArray.GetLength(0); x++) //initialisierung aller gridobjekte { for (int y = 0; y < gridArray.GetLength(1); y++) { gridArray[x, y] = createGridObject(this, x, y); } } //grid wird gezeichnet und beschriftet --debug if (debug) { for (int i = 0; i < gridArray.GetLength(0); i++) { for (int j = 0; j < gridArray.GetLength(1); j++) { debugTextArray[i, j] = UtilsClass.CreateWorldText(gridArray[i, j]?.ToString(), null, IsoMatrix.Iso(GetWorldPosition(i, j) + new Vector3(cellSize, cellSize) * 0.5f), 20, Color.white, TextAnchor.MiddleCenter); Debug.DrawLine(IsoMatrix.Iso(GetWorldPosition(i, j)), IsoMatrix.Iso(GetWorldPosition(i, j + 1)), Color.white, 100f); Debug.DrawLine(IsoMatrix.Iso(GetWorldPosition(i, j)), IsoMatrix.Iso(GetWorldPosition(i + 1, j)), Color.white, 100f); } } Debug.DrawLine(IsoMatrix.Iso(GetWorldPosition(0, height)), IsoMatrix.Iso(GetWorldPosition(width, height)), Color.white, 100f); Debug.DrawLine(IsoMatrix.Iso(GetWorldPosition(width, 0)), IsoMatrix.Iso(GetWorldPosition(width, height)), Color.white, 100f); //triggert mit dem event eine Änderung des texts im debugarray falls sich ein gridobject geändert hat OnGridValueChanged += (object sender, OnGridValueChangedEventArgs eventArgs) => { debugTextArray[eventArgs.x, eventArgs.y].text = gridArray[eventArgs.x, eventArgs.y].ToString(); }; } }
public void Setup(int damageAmount, bool isCriticalHit) { textMesh.SetText(damageAmount.ToString()); if (!isCriticalHit) { textMesh.fontSize = 36; textColor = UtilsClass.GetColorFromString("FFC31C"); } else { textMesh.fontSize = 45; textColor = UtilsClass.GetColorFromString("FF2B00"); } textMesh.color = textColor; disappearTimer = DISAPPEAR_TIMER_MAX; sortingOrder++; textMesh.sortingOrder = sortingOrder; moveVector = new Vector3(.7f, 1) * 60f; }
public void PlayAttackAnimation(Vector3 dir, Action onAnimComplete) { lastAttackWasPunch = !lastAttackWasPunch; if (lastAttackWasPunch) { PlayKickAnimation(dir, (Vector3 hitPosition) => { float attackAngle = UtilsClass.GetAngleFromVectorFloat(dir); hitPosition += UtilsClass.GetVectorFromAngle((int)attackAngle) * 4f; Transform impactEffect = Instantiate(GameAssets.i.pfImpactEffect, hitPosition, Quaternion.identity); impactEffect.eulerAngles = new Vector3(0, 0, attackAngle - 90); }, onAnimComplete); } else { PlayPunchAnimation(dir, (Vector3 hitPosition) => { float attackAngle = UtilsClass.GetAngleFromVectorFloat(dir); hitPosition += UtilsClass.GetVectorFromAngle((int)attackAngle) * 4f; Transform impactEffect = Instantiate(GameAssets.i.pfImpactEffect, hitPosition, Quaternion.identity); impactEffect.eulerAngles = new Vector3(0, 0, attackAngle - 90); }, onAnimComplete); } }
public Grid(int width, int height, float cellSize, Vector3 originPosition) { this.width = width; this.height = height; this.cellSize = cellSize; this.originPosition = originPosition; gridArray = new int[width, height]; debugTextArray = new TextMesh[width, height]; for (int x = 0; x < gridArray.GetLength(0); x++) { for (int y = 0; y < gridArray.GetLength(1); y++) { debugTextArray[x, y] = UtilsClass.CreateWorldText(gridArray[x, y].ToString(), null, GetWorldPosition(x, y) + new Vector3(cellSize, cellSize) * .5f, 30, Color.white, TextAnchor.MiddleCenter); Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x, y + 1), Color.white, 100f); Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x + 1, y), Color.white, 100f); } } Debug.DrawLine(GetWorldPosition(0, height), GetWorldPosition(width, height), Color.white, 100f); Debug.DrawLine(GetWorldPosition(width, 0), GetWorldPosition(width, height), Color.white, 100f); }
private void Update() { if (Input.GetMouseButtonDown(0)) { Vector3 mouseWorldPosition = UtilsClass.GetMouseWorldPosition(); pathfinding.GetGrid().GetXY(mouseWorldPosition, out int x, out int y); if (pathfinding.GetGrid().ClickInRange(x, y)) { List <PathNode> path = pathfinding.FindPath(0, 0, x, y); if (path != null) { for (int i = 0; i < (path.Count - 1); i++) { Debug.DrawLine(new Vector3(path[i].x, path[i].y) * 10f + Vector3.one * 5f, new Vector3(path[i + 1].x, path[i + 1].y) * 10f + Vector3.one * 5f, Color.green, 100); } } } } }
void Update() { Vector3 position = UtilsClass.GetMouseWorldPosition(); //if (Input.GetMouseButtonDown(0)) //{ // Vector3 position = UtilsClass.GetMouseWorldPosition(); // HeatMapGridObject heatMapGridObject = grid.GetGridObject(position); // if (heatMapGridObject != null) // { // heatMapGridObject.AddValue(5); // } //} if (Input.GetKeyDown(KeyCode.A)) { stringGrid.GetGridObject(position).AddLetter("A");; } if (Input.GetKeyDown(KeyCode.B)) { stringGrid.GetGridObject(position).AddLetter("B");; } if (Input.GetKeyDown(KeyCode.C)) { stringGrid.GetGridObject(position).AddLetter("C");; } if (Input.GetKeyDown(KeyCode.Alpha1)) { stringGrid.GetGridObject(position).AddNumber("1");; } if (Input.GetKeyDown(KeyCode.Alpha2)) { stringGrid.GetGridObject(position).AddNumber("2");; } if (Input.GetKeyDown(KeyCode.Alpha3)) { stringGrid.GetGridObject(position).AddNumber("3");; } }
public bool TurnTowardsPoint(Vector3 point, float turnSpeed) { desiredRotation = UtilsClass.GetAngleFromVector(point - transform.position) - 90; bool isLookingAtDesiredRotation = true; float difInAngles = Mathf.DeltaAngle(rb.rotation, desiredRotation); if (Mathf.Abs(difInAngles) > .1f) { float rotAmount = Mathf.Sign(difInAngles) * (turnSpeed * Time.deltaTime); if (Mathf.Abs(difInAngles) < Mathf.Abs(rotAmount)) { rotAmount = difInAngles; isLookingAtDesiredRotation = true; } else { isLookingAtDesiredRotation = false; } rb.rotation += rotAmount; } return(isLookingAtDesiredRotation); }
public void Setup(int damageAmount, bool isCriticalHit) { textMesh.SetText(damageAmount.ToString()); if (!isCriticalHit) { //normal hit textMesh.fontSize = 1; textColor = UtilsClass.GetColorFromString("FAC912"); } else { //critical hit textMesh.fontSize = 2; textColor = UtilsClass.GetColorFromString("C10000"); } textMesh.color = textColor; disappearTimer = DISAPPEAR_TIMER_MAX; sortingOrder++; textMesh.sortingOrder = sortingOrder; moveVector = new Vector3(.1f, .1f) * 4f; }
private void HandleAim() { mousePosition = UtilsClass.GetMouseWorldPosition(); Vector3 offsetPosition = new Vector3(0.0f, 0.6f, 0.0f); Vector3 aimDirection = (mousePosition - transform.position - offsetPosition).normalized; angle = Mathf.Atan2(aimDirection.y, aimDirection.x) * Mathf.Rad2Deg; aimTransform.eulerAngles = new Vector3(0, 0, angle); //Debug.Log(aimDirection); Vector3 localScale = Vector3.one; if (angle > 90 || angle < -90) { localScale.y = -1f; } else { localScale.y = +1f; } aimTransform.localScale = localScale; // Debug.Log(angle); }
private void Update() { Vector3 worldPosition = UtilsClass.GetMouseWorldPosition(); if (Input.GetMouseButtonDown(0)) { if (isGameActive) { MapGridObject.Type gridType = map.RevealGridPosition(worldPosition); if (gridType == MapGridObject.Type.Mine) { // Revealed a Mine, Game Over! isGameActive = false; map.RevealEntireMap(); UI_Blocker.Show_Static(); UI_GameOver.Instance.Show(); } } } if (Input.GetMouseButtonDown(1)) { if (isGameActive) { map.FlagGridPosition(worldPosition); } } if (Input.GetKeyDown(KeyCode.T)) { gridPrefabVisual.SetRevealEntireMap(true); } if (Input.GetKeyUp(KeyCode.T)) { gridPrefabVisual.SetRevealEntireMap(false); } HandleTimer(); }