style fixes

This commit is contained in:
2016-11-27 02:55:43 +07:00
parent 219799c404
commit dddd778c34
5 changed files with 131 additions and 254 deletions

View File

@@ -37,8 +37,8 @@ namespace IsoTools.Internal {
}
}
public bool Contains(T value) {
return _dict.ContainsKey(value);
public bool Contains(T item) {
return _dict.ContainsKey(item);
}
public void Add(T item) {

View File

@@ -92,8 +92,7 @@ namespace IsoTools.Internal {
set {
if ( value < _size ) {
throw new ArgumentOutOfRangeException("value");
}
if ( value != _data.Length ) {
} else if ( value != _data.Length ) {
if ( value > 0 ) {
var new_data = new T[value];
if ( _size > 0 ) {

View File

@@ -15,9 +15,11 @@ namespace IsoTools.Internal {
public static readonly Vector2 vec2OneX = new Vector2(1.0f, 0.0f);
public static readonly Vector2 vec2OneY = new Vector2(0.0f, 1.0f);
public static readonly Vector3 vec3OneX = new Vector3(1.0f, 0.0f, 0.0f);
public static readonly Vector3 vec3OneY = new Vector3(0.0f, 1.0f, 0.0f);
public static readonly Vector3 vec3OneZ = new Vector3(0.0f, 0.0f, 1.0f);
public static readonly Vector3 vec3OneXY = new Vector3(1.0f, 1.0f, 0.0f);
public static readonly Vector3 vec3OneYZ = new Vector3(0.0f, 1.0f, 1.0f);
public static readonly Vector3 vec3OneXZ = new Vector3(1.0f, 0.0f, 1.0f);
@@ -31,28 +33,37 @@ namespace IsoTools.Internal {
// ---------------------------------------------------------------------
public struct Rect {
public float xMin;
public float yMin;
public float xMax;
public float yMax;
public MinMax x;
public MinMax y;
public Rect(float xmin, float ymin, float width, float height) {
this.xMin = xmin;
this.yMin = ymin;
this.xMax = xmin + width;
this.yMax = ymin + height;
public Rect(float x_min, float y_min, float x_max, float y_max) : this() {
x = new MinMax(x_min, x_max);
y = new MinMax(y_min, y_max);
}
public Vector2 size {
get {
return new Vector2(xMax - xMin, yMax - yMin);
}
get { return new Vector2(x.size, y.size); }
}
public Vector2 center {
get { return new Vector2(x.center, y.center); }
}
public void Set(float x_min, float y_min, float x_max, float y_max) {
x.Set(x_min, x_max);
y.Set(y_min, y_max);
}
public bool Overlaps(Rect other) {
return
xMax > other.xMin && xMin < other.xMax &&
yMax > other.yMin && yMin < other.yMax;
x.Overlaps(other.x) &&
y.Overlaps(other.y);
}
public bool Approximately(Rect other) {
return
x.Approximately(other.x) &&
y.Approximately(other.y);
}
public static Rect zero {
@@ -70,7 +81,7 @@ namespace IsoTools.Internal {
public float min;
public float max;
public MinMax(float min, float max) {
public MinMax(float min, float max) : this() {
this.min = min;
this.max = max;
}
@@ -83,10 +94,21 @@ namespace IsoTools.Internal {
get { return min / 2.0f + max / 2.0f; }
}
public bool Approximately(MinMax minmax) {
public void Set(float min, float max) {
this.min = min;
this.max = max;
}
public bool Overlaps(MinMax other) {
return
Mathf.Approximately(min, minmax.min) &&
Mathf.Approximately(max, minmax.max);
max > other.min &&
min < other.max;
}
public bool Approximately(MinMax other) {
return
Mathf.Approximately(min, other.min) &&
Mathf.Approximately(max, other.max);
}
public static MinMax zero {
@@ -141,46 +163,46 @@ namespace IsoTools.Internal {
}
public static Vector2 Vec2Min(Vector2 a, float b) {
if ( b < a.x ) {
if ( a.x > b ) {
a.x = b;
}
if ( b < a.y ) {
if ( a.y > b ) {
a.y = b;
}
return a;
}
public static Vector2 Vec2Min(Vector2 a, Vector2 b) {
if ( b.x < a.x ) {
if ( a.x > b.x ) {
a.x = b.x;
}
if ( b.y < a.y ) {
if ( a.y > b.y ) {
a.y = b.y;
}
return a;
}
public static Vector3 Vec3Min(Vector3 a, float b) {
if ( b < a.x ) {
if ( a.x > b ) {
a.x = b;
}
if ( b < a.y ) {
if ( a.y > b ) {
a.y = b;
}
if ( b < a.z ) {
if ( a.z > b ) {
a.z = b;
}
return a;
}
public static Vector3 Vec3Min(Vector3 a, Vector3 b) {
if ( b.x < a.x ) {
if ( a.x > b.x ) {
a.x = b.x;
}
if ( b.y < a.y ) {
if ( a.y > b.y ) {
a.y = b.y;
}
if ( b.z < a.z ) {
if ( a.z > b.z ) {
a.z = b.z;
}
return a;
@@ -200,46 +222,46 @@ namespace IsoTools.Internal {
}
public static Vector2 Vec2Max(Vector2 a, float b) {
if ( b > a.x ) {
if ( a.x < b ) {
a.x = b;
}
if ( b > a.y ) {
if ( a.y < b ) {
a.y = b;
}
return a;
}
public static Vector2 Vec2Max(Vector2 a, Vector2 b) {
if ( b.x > a.x ) {
if ( a.x < b.x ) {
a.x = b.x;
}
if ( b.y > a.y ) {
if ( a.y < b.y ) {
a.y = b.y;
}
return a;
}
public static Vector3 Vec3Max(Vector3 a, float b) {
if ( b > a.x ) {
if ( a.x < b ) {
a.x = b;
}
if ( b > a.y ) {
if ( a.y < b ) {
a.y = b;
}
if ( b > a.z ) {
if ( a.z < b ) {
a.z = b;
}
return a;
}
public static Vector3 Vec3Max(Vector3 a, Vector3 b) {
if ( b.x > a.x ) {
if ( a.x < b.x ) {
a.x = b.x;
}
if ( b.y > a.y ) {
if ( a.y < b.y ) {
a.y = b.y;
}
if ( b.z > a.z ) {
if ( a.z < b.z ) {
a.z = b.z;
}
return a;
@@ -256,16 +278,16 @@ namespace IsoTools.Internal {
// -----------------------------
public static Vector2 Vec2Ceil(Vector2 v) {
return new Vector2(
Mathf.Ceil(v.x),
Mathf.Ceil(v.y));
v.x = Mathf.Ceil(v.x);
v.y = Mathf.Ceil(v.y);
return v;
}
public static Vector3 Vec3Ceil(Vector3 v) {
return new Vector3(
Mathf.Ceil(v.x),
Mathf.Ceil(v.y),
Mathf.Ceil(v.z));
v.x = Mathf.Ceil(v.x);
v.y = Mathf.Ceil(v.y);
v.z = Mathf.Ceil(v.z);
return v;
}
// -----------------------------
@@ -273,16 +295,16 @@ namespace IsoTools.Internal {
// -----------------------------
public static Vector2 Vec2Floor(Vector2 v) {
return new Vector2(
Mathf.Floor(v.x),
Mathf.Floor(v.y));
v.x = Mathf.Floor(v.x);
v.y = Mathf.Floor(v.y);
return v;
}
public static Vector3 Vec3Floor(Vector3 v) {
return new Vector3(
Mathf.Floor(v.x),
Mathf.Floor(v.y),
Mathf.Floor(v.z));
v.x = Mathf.Floor(v.x);
v.y = Mathf.Floor(v.y);
v.z = Mathf.Floor(v.z);
return v;
}
// -----------------------------
@@ -290,16 +312,16 @@ namespace IsoTools.Internal {
// -----------------------------
public static Vector2 Vec2Round(Vector2 v) {
return new Vector2(
Mathf.Round(v.x),
Mathf.Round(v.y));
v.x = Mathf.Round(v.x);
v.y = Mathf.Round(v.y);
return v;
}
public static Vector3 Vec3Round(Vector3 v) {
return new Vector3(
Mathf.Round(v.x),
Mathf.Round(v.y),
Mathf.Round(v.z));
v.x = Mathf.Round(v.x);
v.y = Mathf.Round(v.y);
v.z = Mathf.Round(v.z);
return v;
}
// ---------------------------------------------------------------------
@@ -383,17 +405,18 @@ namespace IsoTools.Internal {
// -----------------------------
public static Vector2 Vec2ChangeX(Vector2 v, float x) {
return new Vector2(x, v.y);
v.x = x;
return v;
}
public static Vector2 Vec2ChangeY(Vector2 v, float y) {
return new Vector2(v.x, y);
v.y = y;
return v;
}
public static Vector2 Vec2ChangeI(Vector2 v, int index, float n) {
var c = v;
c[index] = n;
return c;
v[index] = n;
return v;
}
// -----------------------------
@@ -401,59 +424,63 @@ namespace IsoTools.Internal {
// -----------------------------
public static Vector3 Vec3ChangeX(Vector3 v, float x) {
return new Vector3(x, v.y, v.z);
v.x = x;
return v;
}
public static Vector3 Vec3ChangeY(Vector3 v, float y) {
return new Vector3(v.x, y, v.z);
v.y = y;
return v;
}
public static Vector3 Vec3ChangeZ(Vector3 v, float z) {
return new Vector3(v.x, v.y, z);
v.z = z;
return v;
}
public static Vector3 Vec3ChangeXY(Vector3 v, float x, float y) {
return new Vector3(x, y, v.z);
v.x = x;
v.y = y;
return v;
}
public static Vector3 Vec3ChangeYZ(Vector3 v, float y, float z) {
return new Vector3(v.x, y, z);
v.y = y;
v.z = z;
return v;
}
public static Vector3 Vec3ChangeXZ(Vector3 v, float x, float z) {
return new Vector3(x, v.y, z);
v.x = x;
v.z = z;
return v;
}
public static Vector3 Vec3ChangeI(Vector3 v, int index, float n) {
var c = v;
c[index] = n;
return c;
v[index] = n;
return v;
}
// -----------------------------
// ColorChange
// -----------------------------
public static Color ColorChangeA(Color color, float a) {
var c = color;
public static Color ColorChangeA(Color c, float a) {
c.a = a;
return c;
}
public static Color ColorChangeR(Color color, float r) {
var c = color;
public static Color ColorChangeR(Color c, float r) {
c.r = r;
return c;
}
public static Color ColorChangeG(Color color, float g) {
var c = color;
public static Color ColorChangeG(Color c, float g) {
c.g = g;
return c;
}
public static Color ColorChangeB(Color color, float b) {
var c = color;
public static Color ColorChangeB(Color c, float b) {
c.b = b;
return c;
}
@@ -483,16 +510,16 @@ namespace IsoTools.Internal {
}
public static Vector2 VectorBeautifier(Vector2 v) {
return new Vector2{
x = FloatBeautifier(v.x),
y = FloatBeautifier(v.y)};
v.x = FloatBeautifier(v.x);
v.y = FloatBeautifier(v.y);
return v;
}
public static Vector3 VectorBeautifier(Vector3 v) {
return new Vector3{
x = FloatBeautifier(v.x),
y = FloatBeautifier(v.y),
z = FloatBeautifier(v.z)};
v.x = FloatBeautifier(v.x);
v.y = FloatBeautifier(v.y);
v.z = FloatBeautifier(v.z);
return v;
}
// ---------------------------------------------------------------------
@@ -508,52 +535,20 @@ namespace IsoTools.Internal {
: obj.AddComponent<T>();
}
public static IsoCollider IsoConvertCollider(Collider collider) {
var fake_collider = collider ? collider.GetComponent<IsoFakeCollider>() : null;
return fake_collider ? fake_collider.isoCollider : null;
}
public static IsoRigidbody IsoConvertRigidbody(Rigidbody rigidbody) {
var fake_rigidbody = rigidbody ? rigidbody.GetComponent<IsoFakeRigidbody>() : null;
return fake_rigidbody ? fake_rigidbody.isoRigidbody : null;
}
public static GameObject IsoConvertGameObject(GameObject game_object) {
var fake_object = game_object ? game_object.GetComponent<IsoFakeObject>() : null;
var iso_object = fake_object ? fake_object.isoObject : null;
return iso_object ? iso_object.gameObject : null;
}
public static IsoContactPoint[] IsoConvertContactPoints(ContactPoint[] points) {
var iso_points = new IsoContactPoint[points.Length];
for ( int i = 0, e = points.Length; i < e; ++i ) {
iso_points[i] = new IsoContactPoint(points[i]);
}
return iso_points;
}
public static IsoRaycastHit[] IsoConvertRaycastHits(RaycastHit[] hits) {
var iso_hits = new IsoRaycastHit[hits.Length];
for ( int i = 0, e = hits.Length; i < e; ++i ) {
iso_hits[i] = new IsoRaycastHit(hits[i]);
}
return iso_hits;
}
// ---------------------------------------------------------------------
//
// Debug draw
//
// ---------------------------------------------------------------------
#if UNITY_EDITOR
#if UNITY_EDITOR
static void DrawTop(IsoWorld iso_world, Vector3 pos, Vector3 size) {
if ( iso_world ) {
var points = new Vector3[]{
iso_world.IsoToScreen(pos),
iso_world.IsoToScreen(pos + IsoUtils.Vec3FromX(size.x)),
iso_world.IsoToScreen(pos + IsoUtils.Vec3FromX (size.x)),
iso_world.IsoToScreen(pos + IsoUtils.Vec3FromXY(size.x, size.y)),
iso_world.IsoToScreen(pos + IsoUtils.Vec3FromY(size.y)),
iso_world.IsoToScreen(pos + IsoUtils.Vec3FromY (size.y)),
iso_world.IsoToScreen(pos)
};
Handles.DrawLine(points[0], points[1]);
@@ -576,10 +571,10 @@ namespace IsoTools.Internal {
Handles.color = color;
var pos = center - size * 0.5f;
DrawTop (iso_world, pos, size);
DrawTop (iso_world, pos + IsoUtils.Vec3FromZ(size.z), size);
DrawTop (iso_world, pos + IsoUtils.Vec3FromZ (size.z), size);
DrawVert(iso_world, pos, size);
DrawVert(iso_world, pos + IsoUtils.Vec3FromX(size.x), size);
DrawVert(iso_world, pos + IsoUtils.Vec3FromY(size.y), size);
DrawVert(iso_world, pos + IsoUtils.Vec3FromX (size.x), size);
DrawVert(iso_world, pos + IsoUtils.Vec3FromY (size.y), size);
DrawVert(iso_world, pos + IsoUtils.Vec3FromXY(size.x, size.y), size);
}
}
@@ -611,6 +606,6 @@ namespace IsoTools.Internal {
}
}
}
#endif
#endif
}
}

View File

@@ -278,7 +278,7 @@ namespace IsoTools {
var r = iso_world.IsoToScreen(position + IsoUtils.Vec3FromX(size.x)).x;
var b = iso_world.IsoToScreen(position).y;
var t = iso_world.IsoToScreen(position + size).y;
Internal.ScreenRect = new IsoUtils.Rect(l, b, r - l, t - b);
Internal.ScreenRect = new IsoUtils.Rect(l, b, r, t);
}
}

View File

@@ -179,14 +179,10 @@ namespace IsoTools {
}
// ---------------------------------------------------------------------
//
// Raycast
//
// ---------------------------------------------------------------------
//
// RayFromIsoCameraToIsoPoint
//
// ---------------------------------------------------------------------
public Ray RayFromIsoCameraToIsoPoint(Vector3 iso_pnt) {
var screen_pnt = IsoToScreen(iso_pnt);
@@ -200,119 +196,6 @@ namespace IsoTools {
return new Ray(iso_down_pnt, iso_pnt - iso_down_pnt);
}
//
// Raycast
//
public bool Raycast(Ray ray, out IsoRaycastHit iso_hit_info) {
return Raycast(ray, out iso_hit_info,
Mathf.Infinity, Physics.DefaultRaycastLayers,
QueryTriggerInteraction.UseGlobal);
}
public bool Raycast(Ray ray, out IsoRaycastHit iso_hit_info,
float max_distance)
{
return Raycast(ray, out iso_hit_info,
max_distance, Physics.DefaultRaycastLayers,
QueryTriggerInteraction.UseGlobal);
}
public bool Raycast(Ray ray, out IsoRaycastHit iso_hit_info,
float max_distance, int layer_mask)
{
return Raycast(ray, out iso_hit_info,
max_distance, layer_mask,
QueryTriggerInteraction.UseGlobal);
}
public bool Raycast(Ray ray, out IsoRaycastHit iso_hit_info,
float max_distance, int layer_mask,
QueryTriggerInteraction query_trigger_interaction)
{
var hit_info = new RaycastHit();
var result = Physics.Raycast(ray, out hit_info,
max_distance, layer_mask, query_trigger_interaction);
iso_hit_info = result ? new IsoRaycastHit(hit_info) : new IsoRaycastHit();
return result;
}
//
// RaycastAll
//
public IsoRaycastHit[] RaycastAll(Ray ray) {
return RaycastAll(ray,
Mathf.Infinity, Physics.DefaultRaycastLayers,
QueryTriggerInteraction.UseGlobal);
}
public IsoRaycastHit[] RaycastAll(Ray ray,
float max_distance)
{
return RaycastAll(ray,
max_distance, Physics.DefaultRaycastLayers,
QueryTriggerInteraction.UseGlobal);
}
public IsoRaycastHit[] RaycastAll(Ray ray,
float max_distance, int layer_mask)
{
return RaycastAll(ray,
max_distance, layer_mask,
QueryTriggerInteraction.UseGlobal);
}
public IsoRaycastHit[] RaycastAll(Ray ray,
float max_distance, int layer_mask,
QueryTriggerInteraction query_trigger_interaction)
{
var hits_info = Physics.RaycastAll(ray,
max_distance, layer_mask, query_trigger_interaction);
return IsoUtils.IsoConvertRaycastHits(hits_info);
}
//
// RaycastNonAlloc
//
public int RaycastNonAlloc(Ray ray, IsoRaycastHit[] results) {
return RaycastNonAlloc(ray, results,
Mathf.Infinity, Physics.DefaultRaycastLayers,
QueryTriggerInteraction.UseGlobal);
}
public int RaycastNonAlloc(Ray ray, IsoRaycastHit[] results,
float max_distance)
{
return RaycastNonAlloc(ray, results,
max_distance, Physics.DefaultRaycastLayers,
QueryTriggerInteraction.UseGlobal);
}
public int RaycastNonAlloc(Ray ray, IsoRaycastHit[] results,
float max_distance, int layer_mask)
{
return RaycastNonAlloc(ray, results,
max_distance, layer_mask,
QueryTriggerInteraction.UseGlobal);
}
static RaycastHit[] _raycastNonAllocBuffer = new RaycastHit[128];
public int RaycastNonAlloc(Ray ray, IsoRaycastHit[] results,
float max_distance, int layer_mask,
QueryTriggerInteraction query_trigger_interaction)
{
var hit_count = Physics.RaycastNonAlloc(ray, _raycastNonAllocBuffer,
max_distance, layer_mask, query_trigger_interaction);
var min_hit_count = Mathf.Min(hit_count, results.Length);
for ( var i = 0; i < min_hit_count; ++i ) {
results[i] = new IsoRaycastHit(_raycastNonAllocBuffer[i]);
}
System.Array.Clear(_raycastNonAllocBuffer, 0, _raycastNonAllocBuffer.Length);
return min_hit_count;
}
// ---------------------------------------------------------------------
//
// TouchIsoPosition
@@ -641,10 +524,10 @@ namespace IsoTools {
var iso_internal = _visibles[i].Internal;
// high performance tricks
var min_x = iso_internal.ScreenRect.xMin / _sectorsSize;
var min_y = iso_internal.ScreenRect.yMin / _sectorsSize;
var max_x = iso_internal.ScreenRect.xMax / _sectorsSize;
var max_y = iso_internal.ScreenRect.yMax / _sectorsSize;
var min_x = iso_internal.ScreenRect.x.min / _sectorsSize;
var min_y = iso_internal.ScreenRect.y.min / _sectorsSize;
var max_x = iso_internal.ScreenRect.x.max / _sectorsSize;
var max_y = iso_internal.ScreenRect.y.max / _sectorsSize;
iso_internal.MinSector.x = (int)(min_x >= 0.0f ? min_x : min_x - 1.0f);
iso_internal.MinSector.y = (int)(min_y >= 0.0f ? min_y : min_y - 1.0f);
iso_internal.MaxSector.x = (int)(max_x >= 0.0f ? max_x + 1.0f : max_x);