// public GameObject Target; public void SetRoadPicture(RoadPictureItem roadPicture) { _roadPicture = roadPicture; float angle = (90f + 45f) * Mathf.Deg2Rad; // if (Type == RoadManager.RoadType.RightToDown) angle = 0f; else if (Type == RoadManager.RoadType.DownToLeft) { angle = (180f + 45f) * Mathf.Deg2Rad; } else if (Type == RoadManager.RoadType.LeftToUp) { angle = (270f + 45f) * Mathf.Deg2Rad; } else if (Type == RoadManager.RoadType.UpToRight) { angle = (45f) * Mathf.Deg2Rad; } Vector3 localCenter = _roadPicture.GetCenter(); _localCenter = new Vector2(localCenter.x * Mathf.Cos(angle), localCenter.y * Mathf.Sin(angle)); _localCenter = new Vector2(_localCenter.x + transform.position.x, _localCenter.y + transform.position.y); D.Log(_localCenter); // if (Target) Target.transform.position = _localCenter; }
private void RotateByType(RoadPictureItem rpi, RoadManager.RoadType type) { SpriteRenderer spr = rpi.GetComponent <SpriteRenderer>(); switch (type) { case RoadManager.RoadType.UpToRight: { if (spr.flipX) { spr.flipX = false; } if (spr.flipY) { spr.flipY = false; } } break; case RoadManager.RoadType.RightToDown: { if (!spr.flipX) { spr.flipX = true; } if (spr.flipY) { spr.flipY = false; } } break; case RoadManager.RoadType.DownToLeft: { if (!spr.flipX) { spr.flipX = true; } if (!spr.flipY) { spr.flipY = true; } } break; case RoadManager.RoadType.LeftToUp: { if (spr.flipX) { spr.flipX = false; } if (!spr.flipY) { spr.flipY = true; } } break; } }
public RoadPictureItem GetSuitablePicture(RoadManager.RoadType type, RoadManager.RoadType prevType, RoadManager.BuildState buildState, Vector3 position, bool isRightDirection) { RoadPictureItem rpi = GetCachedObject(buildState, isRightDirection, type, prevType); if (rpi == null) { rpi = GetCachedObject(buildState, isRightDirection, type, prevType, true); } rpi.transform.position = position; RotateByType(rpi, type); return(rpi); }