private void AddCollider(ColType c) { RemoveColliders(); foreach(pb_Entity obj in serializedObject.targetObjects) { GameObject go = obj.gameObject; switch(c) { case ColType.MeshCollider: go.AddComponent<MeshCollider>(); break; case ColType.BoxCollider: go.AddComponent<BoxCollider>(); break; case ColType.SphereCollider: go.AddComponent<SphereCollider>(); break; default: break; } } }
public SQLiteColumn(string colName, ColType colDataType) { ColumnName = colName; PrimaryKey = false; ColDataType = colDataType; AutoIncrement = false; }
/// <summary> /// 转化工具 /// </summary> /// <param name="v"></param> /// <returns></returns> private static string ConvertType(ColType v) { switch (v) { case ColType.NTSInt: return "System.Int32"; case ColType.NTSString: return "System.String"; case ColType.NTSDecimal: return "System.Decimal"; case ColType.NTSDateTime: return "System.Int32"; default: return "System.DateTime"; } }
public SQLiteColumn(string colName, bool autoIncrement) { ColumnName = colName; if (autoIncrement) { PrimaryKey = true; ColDataType = ColType.Integer; AutoIncrement = true; } else { PrimaryKey = false; ColDataType = ColType.Text; AutoIncrement = false; } }
public SQLiteColumn(string colName, ColType colDataType, bool primaryKey, bool autoIncrement, bool notNull, string defaultValue) { ColumnName = colName; if (autoIncrement) { PrimaryKey = true; ColDataType = ColType.Integer; AutoIncrement = true; } else { PrimaryKey = primaryKey; ColDataType = colDataType; AutoIncrement = false; NotNull = notNull; DefaultValue = defaultValue; } }
private object ReadCol(IDbStatement stmt, int index, ColType type, Type clrType) { if (type == ColType.Null) { return(null); } if (clrType == typeof(String)) { return(_sqlitePlatform.SQLiteApi.ColumnText16(stmt, index)); } if (clrType == typeof(Int32)) { return(_sqlitePlatform.SQLiteApi.ColumnInt(stmt, index)); } if (clrType == typeof(Boolean)) { return(_sqlitePlatform.SQLiteApi.ColumnInt(stmt, index) == 1); } if (clrType == typeof(double)) { return(_sqlitePlatform.SQLiteApi.ColumnDouble(stmt, index)); } if (clrType == typeof(float)) { return((float)_sqlitePlatform.SQLiteApi.ColumnDouble(stmt, index)); } if (clrType == typeof(TimeSpan)) { return(new TimeSpan(_sqlitePlatform.SQLiteApi.ColumnInt64(stmt, index))); } if (clrType == typeof(DateTime)) { if (_conn.StoreDateTimeAsTicks) { return(new DateTime(_sqlitePlatform.SQLiteApi.ColumnInt64(stmt, index))); } string text = _sqlitePlatform.SQLiteApi.ColumnText16(stmt, index); return(DateTime.Parse(text)); } if (clrType.IsEnum) { return(_sqlitePlatform.SQLiteApi.ColumnInt(stmt, index)); } if (clrType == typeof(Int64)) { return(_sqlitePlatform.SQLiteApi.ColumnInt64(stmt, index)); } if (clrType == typeof(UInt32)) { return((uint)_sqlitePlatform.SQLiteApi.ColumnInt64(stmt, index)); } if (clrType == typeof(decimal)) { return((decimal)_sqlitePlatform.SQLiteApi.ColumnDouble(stmt, index)); } if (clrType == typeof(Byte)) { return((byte)_sqlitePlatform.SQLiteApi.ColumnInt(stmt, index)); } if (clrType == typeof(UInt16)) { return((ushort)_sqlitePlatform.SQLiteApi.ColumnInt(stmt, index)); } if (clrType == typeof(Int16)) { return((short)_sqlitePlatform.SQLiteApi.ColumnInt(stmt, index)); } if (clrType == typeof(sbyte)) { return((sbyte)_sqlitePlatform.SQLiteApi.ColumnInt(stmt, index)); } if (clrType == typeof(byte[])) { return(_sqlitePlatform.SQLiteApi.ColumnByteArray(stmt, index)); } if (clrType == typeof(Guid)) { string text = _sqlitePlatform.SQLiteApi.ColumnText16(stmt, index); return(new Guid(text)); } if (_conn.Serializer != null && _conn.Serializer.CanDeserialize(clrType)) { var bytes = _sqlitePlatform.SQLiteApi.ColumnByteArray(stmt, index); return(_conn.Serializer.Deserialize(bytes, clrType)); } throw new NotSupportedException("Don't know how to read " + clrType); }
private void ParseColType(string[] cols) { m_colType = new ColType[cols.Length]; for (int i = 0; i < cols.Length; ++i) { var ci = cols[i]; m_colType[i] = ColType.Ignore; if (ci == "Index") { m_colType[i] = ColType.Index; } else if (ci.Contains("POSITION0")) { if (ci.EndsWith("Component 0")) { m_colType[i] = ColType.Pos0; } else if (ci.EndsWith("Component 1")) { m_colType[i] = ColType.Pos1; } else if (ci.EndsWith("Component 2")) { m_colType[i] = ColType.Pos2; } } else if (ci.Contains("NORMAL0")) { if (ci.EndsWith("Component 0")) { m_colType[i] = ColType.Normal0; } else if (ci.EndsWith("Component 1")) { m_colType[i] = ColType.Normal1; } else if (ci.EndsWith("Component 2")) { m_colType[i] = ColType.Normal2; } if (ci.Contains("R8G8B8A8")) { m_isDecimalNormal = true; } } else if (ci.Contains("TEXCOORD0")) { if (ci.EndsWith("Component 0")) { m_colType[i] = ColType.Uv00; } else if (ci.EndsWith("Component 1")) { m_colType[i] = ColType.Uv01; } else if (ci.EndsWith("Component 2")) { m_colType[i] = ColType.Uv02; } else if (ci.EndsWith("Component 3")) { m_colType[i] = ColType.Uv03; } } else if (ci.Contains("TEXCOORD1")) { if (ci.EndsWith("Component 0")) { m_colType[i] = ColType.Uv10; } else if (ci.EndsWith("Component 1")) { m_colType[i] = ColType.Uv11; } else if (ci.EndsWith("Component 2")) { m_colType[i] = ColType.Uv12; } else if (ci.EndsWith("Component 3")) { m_colType[i] = ColType.Uv13; } } //ignore tangent } m_typeCol = new int[(int)ColType.Count]; for (int i = 0; i < m_colType.Length; ++i) { if (m_colType[i] >= 0) { m_typeCol[(int)m_colType[i]] = i; } } }
private static object calculateAggregation(IEnumerable <object> vals, Aggregation aggregation, ColType colType) { var value = _calculateAggregation(vals, aggregation, colType); // if (value is double) { value = Math.Round(Convert.ToDouble(value), 6); } // else if (value is float) { value = Math.Round(Convert.ToSingle(value), 6); } return(value); }
public static BindFunc GetBindFunc(ColType coltype) { return colTypeToFunc[coltype]; }
public Collision(ColType _type, int _id) { type = _type; id = _id; }
void CollideWithWall(RecBounds bounds) { if (DebugStopOnCol) { DebugStopOnCol = DebugStopOnCol; } StateMachine.DrawBounds(bounds, Color.cyan); //Get the side of the wall that was collided with. Ignore collision if necessary. ColType c = CollisionType(thisActor.NextActorBounds, thisActor.Velocity, bounds); if (disableVerticalColl && (c == ColType.Bottom || c == ColType.Top)) { return; } //Get the closest single wall inside the bound to the player. Vector2 wallCenter = new Vector2(Mathf.RoundToInt(transform.position.x), Mathf.RoundToInt(transform.position.y)); RecBounds tempB; wallCenter = new Vector2(Mathf.Clamp(wallCenter.x, bounds.left + 0.5f, bounds.right - 0.5f), Mathf.Clamp(wallCenter.y, bounds.bottom + 0.5f, bounds.top - 0.5f)); if (false && !bounds.Inside(wallCenter)) { switch (c) { case ColType.Bottom: wallCenter.y += 1.0f; break; case ColType.Left: wallCenter.x += 1.0f; break; case ColType.Top: wallCenter.y -= 1.0f; break; case ColType.Right: wallCenter.x -= 1.0f; break; default: throw new NotImplementedException(); } } tempB = new RecBounds(wallCenter, new Vector2(1.0f, 1.0f)); Line l = null; //Check to see if the line exists in the collision tracker. if (!colTracker.Lines.WallExists(tempB)) { //Debug.Log("Wall not valid: wall " + bounds + ", small wall " + tempB + ", side " + CollisionManager.ToString(c)); //Create a substitute line. switch (c) { case ColType.Bottom: l = new Line(Line.Orientation.Horizontal, new Interval(tempB.left, tempB.right, true, 2), tempB.bottom); break; case ColType.Left: l = new Line(Line.Orientation.Vertical, new Interval(tempB.bottom, tempB.top, true, 2), tempB.left); break; case ColType.Top: l = new Line(Line.Orientation.Horizontal, new Interval(tempB.left, tempB.right, true, 2), tempB.top); break; case ColType.Right: l = new Line(Line.Orientation.Vertical, new Interval(tempB.bottom, tempB.top, true, 2), tempB.right); break; } } else if (!colTracker.Lines.SideExists(tempB, c)) { //Debug.Log("Coll. side not valid: wall " + bounds + ", small wall " + tempB + ", side " + CollisionManager.ToString(c)); //Create a substitute line. switch (c) { case ColType.Bottom: l = new Line(Line.Orientation.Horizontal, new Interval(tempB.left, tempB.right, true, 2), tempB.bottom); break; case ColType.Left: l = new Line(Line.Orientation.Vertical, new Interval(tempB.bottom, tempB.top, true, 2), tempB.left); break; case ColType.Top: l = new Line(Line.Orientation.Horizontal, new Interval(tempB.left, tempB.right, true, 2), tempB.top); break; case ColType.Right: l = new Line(Line.Orientation.Vertical, new Interval(tempB.bottom, tempB.top, true, 2), tempB.right); break; } } else { l = colTracker.Lines.GetLine(tempB, c); } l = new Line(l.Dir, new Interval(l.LineRange), l.ConstValue); l.LineRange.Range -= ColLineMarginOfError * 2.0f; //If the collision was already being tracked, don't change anything. if (WallSides[c].Contains(l)) { return; } //Otherwise, start tracking the line. WallSides[c].Add(l); SendMessage("WallCollision", new ColIndexPair() { Index = WallSides[c].Count - 1, Type = c }, SendMessageOptions.DontRequireReceiver); }
public override void Update(GameTime gameTime) { if ((float)gameTime.TotalGameTime.TotalMilliseconds - lastTimePressed < 200) { return; } bool moved = false; Vector2 moveVec = new Vector2(0, 0); var kstate = Keyboard.GetState(); if (kstate.IsKeyDown(Keys.Up)) { moveVec.Y -= Tile.TILE_SIZE; moved = true; } else if (kstate.IsKeyDown(Keys.Down)) { moveVec.Y += Tile.TILE_SIZE; moved = true; } else if (kstate.IsKeyDown(Keys.Right)) { moveVec.X += Tile.TILE_SIZE; moved = true; } else if (kstate.IsKeyDown(Keys.Left)) { moveVec.X -= Tile.TILE_SIZE; moved = true; } if (moved) { ColType col = checkCollision((int)(moveVec.X + Position.X), (int)(moveVec.Y + Position.Y)); if (col == ColType.gameobject) { GameObject colObj = _rw.currentRoom.collisionArray[(int)(((moveVec.X + Position.X) - _rw.map.offset.X) / Tile.TILE_SIZE), (int)(((moveVec.Y + Position.Y) - _rw.map.offset.Y) / Tile.TILE_SIZE)]; if (colObj != null) { if (colObj.mType == MoveType.moveable) { if (((Pushable)colObj).move((int)moveVec.X, (int)moveVec.Y)) { Position.X += moveVec.X; Position.Y += moveVec.Y; setDrawRect(); lastTimePressed = (float)gameTime.TotalGameTime.TotalMilliseconds; } } } } else if (col == ColType.none) { Position.X += moveVec.X; Position.Y += moveVec.Y; setDrawRect(); lastTimePressed = (float)gameTime.TotalGameTime.TotalMilliseconds; } } }
void WallCollision(ColIndexPair pair) { ColType c = pair.Type; int index = pair.Index; Line line = ColManager.WallSides[c][index]; //Indicate a collision happened. collided = true; //Floor. if (c == ColType.Top) { MoveAboveOrBelowSurface(line, c); //Don't count it as a floor if the player was moving upward. if (Velocity.y > 0) { ColManager.WallSides[c].Remove(line); return; } CurrentState.HitFloor(line); } //Ceiling. else if (c == ColType.Bottom) { MoveAboveOrBelowSurface(line, c); //Don't count it as a ceiling if the player was moving downward. if (Velocity.y < 0) { ColManager.WallSides[c].Remove(line); return; } CurrentState.HitCeiling(line); } //Right side. else if (c == ColType.Left) { MoveToSideOfSurface(line, c); //Don't count it as a wall collision if the player's velocity is pointing away from it. if (Sign(Velocity.x, WorldConstants.MinMovementSpeed) == -Sign(line.ConstValue - transform.position.x, WorldConstants.MinMovementSpeed)) { ColManager.WallSides[c].Remove(line); return; } CurrentState.HitSide(line, c); } //Left side. else if (c == ColType.Right) { MoveToSideOfSurface(line, c); //Don't count it as a wall collision if the player's velocity is pointing away from it. if (Sign(Velocity.x, WorldConstants.MinMovementSpeed) == -Sign(line.ConstValue - transform.position.x, WorldConstants.MinMovementSpeed)) { ColManager.WallSides[c].Remove(line); return; } CurrentState.HitSide(line, c); } }
public static bool OnLine(Line l, ColType side, RecBounds b) { const float error = 0.01f; switch (side) { case ColType.Bottom: //Make sure this line makes sense. if (l.Dir == Line.Orientation.Vertical) { throw new ArgumentException(); } //Next, if the bound's top edge isn't touching the line, exit. float top = b.center.y + b.extents.y; float lineTop = l.ConstValue; if (!StateMachine.WithinError(top, lineTop, error)) { return(false); } //Finally, check to make sure the bounds are within the range of the line. return(l.LineRange.Touches(new Interval(b.center.x - b.extents.x, b.center.x + b.extents.x, true, 2))); case ColType.Top: //Make sure this line makes sense. if (l.Dir == Line.Orientation.Vertical) { throw new ArgumentException(); } //Next, if the bound's bottom edge isn't touching the line, exit. float bottom = b.center.y - b.extents.y; float lineBottom = l.ConstValue; if (!StateMachine.WithinError(bottom, lineBottom, error)) { return(false); } //Finally, check to make sure the bounds are within the range of the line. return(l.LineRange.Touches(new Interval(b.center.x - b.extents.x, b.center.x + b.extents.x, true, 2))); case ColType.Left: //Make sure this line makes sense. if (l.Dir == Line.Orientation.Horizontal) { throw new ArgumentException(); } //Next, if the bound's right edge isn't touching the line, exit. float right = b.center.x + b.extents.x; float lineRight = l.ConstValue; if (!StateMachine.WithinError(right, lineRight, error)) { return(false); } //Finally, check to make sure the bounds are within the range of the line. return(l.LineRange.Touches(new Interval(b.center.y - b.extents.y, b.center.y + b.extents.y, true, 2))); case ColType.Right: //Make sure this line makes sense. if (l.Dir == Line.Orientation.Horizontal) { throw new ArgumentException(); } //Next, if the bound's left edge isn't touching the line, exit. float left = b.center.x - b.extents.x; float lineLeft = l.ConstValue; if (!StateMachine.WithinError(left, lineLeft, error)) { return(false); } //Finally, check to make sure the bounds are within the range of the line. return(l.LineRange.Touches(new Interval(b.center.y - b.extents.y, b.center.y + b.extents.y, true, 2))); default: throw new NotImplementedException(); } }
private void AddCollider(ColType c) { Collider[] colliders = serializedObject.targetObjects.Where(x => x is pb_Entity).SelectMany(x => ((pb_Entity)x).gameObject.GetComponents<Collider>()).ToArray(); bool isTrigger = false; if( colliders != null ) isTrigger = colliders.Any(x => x.isTrigger); RemoveColliders(); foreach(pb_Entity obj in serializedObject.targetObjects) { GameObject go = obj.gameObject; switch(c) { case ColType.MeshCollider: { MeshCollider col = go.AddComponent<MeshCollider>(); if(ent.entityType == EntityType.Trigger) { col.convex = true; col.isTrigger = true; } else if(ent.entityType == EntityType.Collider) { col.convex = true; } else if(isTrigger) { col.convex = true; col.isTrigger = true; } break; } case ColType.BoxCollider: { BoxCollider col = go.AddComponent<BoxCollider>(); if(ent.entityType == EntityType.Trigger || isTrigger) col.isTrigger = true; break; } case ColType.SphereCollider: { SphereCollider col = go.AddComponent<SphereCollider>(); if(ent.entityType == EntityType.Trigger || isTrigger) col.isTrigger = true; break; } default: break; } } }
private void AddCollider(ColType c) { Collider[] colliders = serializedObject.targetObjects.Where(x => x is pb_Entity).SelectMany(x => ((pb_Entity)x).gameObject.GetComponents <Collider>()).ToArray(); bool isTrigger = false; if (colliders != null) { isTrigger = colliders.Any(x => x.isTrigger); } RemoveColliders(); foreach (pb_Entity obj in serializedObject.targetObjects) { GameObject go = obj.gameObject; switch (c) { case ColType.MeshCollider: { MeshCollider col = go.AddComponent <MeshCollider>(); if (ent.entityType == EntityType.Trigger) { col.convex = true; col.isTrigger = true; } else if (ent.entityType == EntityType.Collider) { col.convex = true; } else if (isTrigger) { col.convex = true; col.isTrigger = true; } break; } case ColType.BoxCollider: { BoxCollider col = go.AddComponent <BoxCollider>(); if (ent.entityType == EntityType.Trigger || isTrigger) { col.isTrigger = true; } break; } case ColType.SphereCollider: { SphereCollider col = go.AddComponent <SphereCollider>(); if (ent.entityType == EntityType.Trigger || isTrigger) { col.isTrigger = true; } break; } default: break; } } }
private object ReadCol(IDbStatement stmt, int index, ColType type, Type clrType) { var interfaces = clrType.GetTypeInfo().ImplementedInterfaces.ToList(); if (type == ColType.Null) { return(null); } if (clrType == typeof(string)) { return(sqlite.ColumnText16(stmt, index)); } if (interfaces.Contains(typeof(ISerializable <string>))) { var value = sqlite.ColumnText16(stmt, index); return(_conn.Resolver.CreateObject(clrType, new object[] { value })); } if (clrType == typeof(int)) { return(sqlite.ColumnInt(stmt, index)); } if (interfaces.Contains(typeof(ISerializable <int>))) { var value = sqlite.ColumnInt(stmt, index); return(_conn.Resolver.CreateObject(clrType, new object[] { value })); } if (clrType == typeof(bool)) { return(sqlite.ColumnInt(stmt, index) == 1); } if (interfaces.Contains(typeof(ISerializable <bool>))) { var value = sqlite.ColumnInt(stmt, index) == 1; return(_conn.Resolver.CreateObject(clrType, new object[] { value })); } if (clrType == typeof(double)) { return(sqlite.ColumnDouble(stmt, index)); } if (interfaces.Contains(typeof(ISerializable <double>))) { var value = sqlite.ColumnDouble(stmt, index); return(_conn.Resolver.CreateObject(clrType, new object[] { value })); } if (clrType == typeof(float)) { return((float)sqlite.ColumnDouble(stmt, index)); } if (interfaces.Contains(typeof(ISerializable <float>))) { var value = (float)sqlite.ColumnDouble(stmt, index); return(_conn.Resolver.CreateObject(clrType, new object[] { value })); } if (clrType == typeof(TimeSpan)) { return(new TimeSpan(sqlite.ColumnInt64(stmt, index))); } if (interfaces.Contains(typeof(ISerializable <TimeSpan>))) { var value = new TimeSpan(sqlite.ColumnInt64(stmt, index)); return(_conn.Resolver.CreateObject(clrType, new object[] { value })); } if (clrType == typeof(DateTime)) { if (_conn.StoreDateTimeAsTicks) { return(new DateTime(sqlite.ColumnInt64(stmt, index), DateTimeKind.Utc)); } return(DateTime.Parse(sqlite.ColumnText16(stmt, index), CultureInfo.InvariantCulture)); } if (clrType == typeof(DateTimeOffset)) { return(new DateTimeOffset(sqlite.ColumnInt64(stmt, index), TimeSpan.Zero)); } if (interfaces.Contains(typeof(ISerializable <DateTime>))) { DateTime value; if (_conn.StoreDateTimeAsTicks) { value = new DateTime(sqlite.ColumnInt64(stmt, index), DateTimeKind.Utc); } else { value = DateTime.Parse(sqlite.ColumnText16(stmt, index), CultureInfo.InvariantCulture); } return(Activator.CreateInstance(clrType, value)); } if (clrType.GetTypeInfo().IsEnum) { return(sqlite.ColumnInt(stmt, index)); } if (clrType == typeof(long)) { return(sqlite.ColumnInt64(stmt, index)); } if (interfaces.Contains(typeof(ISerializable <long>))) { var value = sqlite.ColumnInt64(stmt, index); return(_conn.Resolver.CreateObject(clrType, new object[] { value })); } if (clrType == typeof(uint)) { return((uint)sqlite.ColumnInt64(stmt, index)); } if (interfaces.Contains(typeof(ISerializable <long>))) { var value = (uint)sqlite.ColumnInt64(stmt, index); return(_conn.Resolver.CreateObject(clrType, new object[] { value })); } if (clrType == typeof(decimal)) { return((decimal)sqlite.ColumnDouble(stmt, index)); } if (interfaces.Contains(typeof(ISerializable <decimal>))) { var value = (decimal)sqlite.ColumnDouble(stmt, index); return(_conn.Resolver.CreateObject(clrType, new object[] { value })); } if (clrType == typeof(byte)) { return((byte)sqlite.ColumnInt(stmt, index)); } if (interfaces.Contains(typeof(ISerializable <byte>))) { var value = (byte)sqlite.ColumnInt(stmt, index); return(_conn.Resolver.CreateObject(clrType, new object[] { value })); } if (clrType == typeof(ushort)) { return((ushort)sqlite.ColumnInt(stmt, index)); } if (interfaces.Contains(typeof(ISerializable <ushort>))) { var value = (ushort)sqlite.ColumnInt(stmt, index); return(_conn.Resolver.CreateObject(clrType, new object[] { value })); } if (clrType == typeof(short)) { return((short)sqlite.ColumnInt(stmt, index)); } if (interfaces.Contains(typeof(ISerializable <short>))) { var value = (short)sqlite.ColumnInt(stmt, index); return(_conn.Resolver.CreateObject(clrType, new object[] { value })); } if (clrType == typeof(sbyte)) { return((sbyte)sqlite.ColumnInt(stmt, index)); } if (interfaces.Contains(typeof(ISerializable <sbyte>))) { var value = (sbyte)sqlite.ColumnInt(stmt, index); return(_conn.Resolver.CreateObject(clrType, new object[] { value })); } if (clrType == typeof(byte[])) { return(sqlite.ColumnByteArray(stmt, index)); } if (interfaces.Contains(typeof(ISerializable <byte[]>))) { var value = sqlite.ColumnByteArray(stmt, index); return(_conn.Resolver.CreateObject(clrType, new object[] { value })); } if (clrType == typeof(Guid)) { return(new Guid(sqlite.ColumnText16(stmt, index))); } if (interfaces.Contains(typeof(ISerializable <Guid>))) { var value = new Guid(sqlite.ColumnText16(stmt, index)); return(_conn.Resolver.CreateObject(clrType, new object[] { value })); } if (clrType == typeof(XElement)) { var text = sqlite.ColumnText16(stmt, index); return(text == null ? null : XElement.Parse(text)); } if (_conn.Serializer != null && _conn.Serializer.CanDeserialize(clrType)) { var bytes = sqlite.ColumnByteArray(stmt, index); return(_conn.Serializer.Deserialize(bytes, clrType)); } throw new NotSupportedException("Don't know how to read " + clrType); }
public static BindFunc GetBindFunc(ColType coltype) { return(colTypeToFunc[coltype]); }
public static ColType CollisionType(RecBounds actor, Vector2 velocity, RecBounds wall) { //TODO: [SO FAR, THIS DOESN'T SEEM NECESSARY]. If the player hit a wall but only barely, and the y interval below/above the wall that the player is mainly occupying is clear, let him pass through the wall. //Figure out which edge was collided with first: top/bottom, or side. Return that edge. //1) Get the closest wall corner to the actor's center, and the opposite corner on the actor's bounds. Vector2 lastCenter = actor.center - (velocity * Time.fixedDeltaTime); ColType topOrBottom = (lastCenter.y > wall.center.y) ? ColType.Top : ColType.Bottom; ColType leftOrRight = (lastCenter.x > wall.center.x) ? ColType.Right : ColType.Left; //If the actor is going at least half a unit per second, use Vector2 playerCenter = new Vector2(actor.center.x, actor.center.y); Vector2 wallCorner = new Vector2(wall.center.x - wall.extents.x, wall.center.y - wall.extents.y); Vector2 actorOppositeCorner = new Vector2(actor.center.x + actor.extents.x, actor.center.y + actor.extents.y); float temp, tempDistSqr = System.Single.MaxValue; //Go through every corner searching for the closest. Vector2 tempDir, tempCorner; for (int i = 0; i < 4; ++i) { switch (i) { case 0: tempDir = new Vector2(-1.0f, -1.0f); break; case 1: tempDir = new Vector2(-1.0f, 1.0f); break; case 2: tempDir = new Vector2(1.0f, -1.0f); break; case 3: tempDir = new Vector2(1.0f, 1.0f); break; default: tempDir = Vector2.zero; break; } tempCorner = new Vector2(wall.center.x + (tempDir.x * wall.extents.x), wall.center.y + (tempDir.y * wall.extents.y)); temp = Mathf.Pow(playerCenter.x - tempCorner.x, 2.0f) + Mathf.Pow(playerCenter.y - tempCorner.y, 2.0f); if (temp < tempDistSqr) { tempDistSqr = temp; actorOppositeCorner = new Vector2(actor.center.x - (tempDir.x * actor.extents.x), actor.center.y - (tempDir.y * actor.extents.y)); wallCorner = tempCorner; } } //2) Get the amount of overlap along both dimensions. Vector2 overlap = wallCorner - actorOppositeCorner; //3) Handle edge cases for the overlap. const float marginOfErrorOverlap = 0.01f; if (Mathf.Abs(overlap.x) <= marginOfErrorOverlap) { return(leftOrRight); } if (Mathf.Abs(overlap.y) <= marginOfErrorOverlap) { return(topOrBottom); } //4) Handle edge cases for velocity. //No margin of error is needed because StateMachines already set the velocity to 0 when under a certain magnitude. if (velocity.x == 0) { return(topOrBottom); } if (velocity.y == 0) { return(leftOrRight); } //5) Get the amount of time needed at the actor's current velocity // to move both the side and top/bottom edges back to bare contact with the wall. Vector2 t = new Vector2(Mathf.Abs(overlap.x / velocity.x), Mathf.Abs(overlap.y / velocity.y)); //6) Depending on which edge would take longer to move back to bare contact // (i.e. which edge was collided with first), return the correct value. if (t.x < t.y) { return(leftOrRight); } else { return(topOrBottom); } }
/// <summary> /// Finds if the given side of the given wall exists in this system. /// </summary> public bool SideExists(RecBounds wall, ColType side) { return(references.ContainsKey(wall) && references[wall].ContainsKey(side)); }
public override void OnInspectorGUI() { DrawDefaultInspector(); //Collider ColType colliderType = (ColType)EditorGUILayout.EnumPopup(new GUIContent("Auto collider 2D", "Automatically create a collider. Set to \"None\" if you want to create your collider by hand"), script.colliderType); if (colliderType != script.colliderType) { Undo.RecordObject(script, "Change collider type"); script.colliderType = colliderType; AddCollider(colliderType); script.UpdateCollider(); EditorUtility.SetDirty(script); EditorGUIUtility.ExitGUI(); } //Export mesh EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(new GUIContent("Export mesh", "Save mesh as a separate prefab in project root")); if (GUILayout.Button("Export mesh as asset")) { ExportMesh(); } EditorGUILayout.EndHorizontal(); //Sorting layer options GUILayout.Space(10); //Get sorting layers int[] layerIDs = GetSortingLayerUniqueIDs(); string[] layerNames = GetSortingLayerNames(); //Get selected sorting layer int selected = -1; for (int i = 0; i < layerIDs.Length; i++) { if (layerIDs[i] == script.sortingLayer) { selected = i; } } //Select Default layer if no other is selected if (selected == -1) { for (int i = 0; i < layerIDs.Length; i++) { if (layerIDs[i] == 0) { selected = i; } } } //Sorting layer dropdown /* * EditorGUI.BeginChangeCheck(); * selected=EditorGUILayout.Popup("Sorting Layer",selected,layerNames); * if(EditorGUI.EndChangeCheck()){ * Undo.RecordObject(script,"Change sorting layer"); * script.sortingLayer=layerIDs[selected]; * EditorUtility.SetDirty(script); * } */ //Sorting layer dropdown EditorGUI.BeginChangeCheck(); GUIContent[] dropdown = new GUIContent[layerNames.Length + 2]; for (int i = 0; i < layerNames.Length; i++) { dropdown[i] = new GUIContent(layerNames[i]); } dropdown[layerNames.Length] = new GUIContent(); dropdown[layerNames.Length + 1] = new GUIContent("Add Sorting Layer..."); selected = EditorGUILayout.Popup(new GUIContent("Sorting Layer", "Name of the Renderer's sorting layer"), selected, dropdown); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(script, "Change sorting layer"); if (selected == layerNames.Length + 1) { EditorApplication.ExecuteMenuItem("Edit/Project Settings/Tags and Layers"); } else { script.sortingLayer = layerIDs[selected]; } EditorUtility.SetDirty(script); } //Order in layer field EditorGUI.BeginChangeCheck(); int order = EditorGUILayout.IntField("Order in Layer", script.orderInLayer); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(script, "Change order in layer"); script.orderInLayer = order; EditorUtility.SetDirty(script); } }
public ColToken(ColType type, CollisionEngine _ce, int _engine_id, object _parent) { local_type = type; ce = _ce; parent = _parent; updated_this_frame = false; cols = new List<ColToken>(); engine_id = _engine_id; }
private static object parseValue(ReadOnlySpan <char> value, char[] missingValue, ColType colType, string dFormat = null) { //check the missing value if (IsMissingValue(value, missingChars: missingValue)) { return(DataFrame.NAN); } //#if NETSTANDARD2_1 switch (colType) { case ColType.I2: return(bool.Parse(value)); case ColType.IN: return(new string(value.ToArray())); case ColType.I32: return(int.Parse(value)); case ColType.I64: return(long.Parse(value)); case ColType.F32: return(float.Parse(value)); case ColType.DD: return(double.Parse(value)); case ColType.STR: return(new string(value.ToArray())); case ColType.DT: { if (string.IsNullOrEmpty(dFormat)) { return(DateTime.Parse(value, CultureInfo.InvariantCulture, DateTimeStyles.None)); } else { return(DateTime.ParseExact(value, dFormat, CultureInfo.InvariantCulture, DateTimeStyles.None)); } } default: throw new Exception("column type is not known."); } //#else // var v = new Span<byte>(value.ToArray().Select(x => (byte)x).ToArray()); // switch (colType) // { // case ColType.I2: // { // Utf8Parser.TryParse(v,out bool bValue, out int p); // return bValue; // } // case ColType.IN: // return new string(value.ToArray()); // case ColType.I32: // { // Utf8Parser.TryParse(v, out int bValue, out int p); // return bValue; // } // case ColType.I64: // { // Utf8Parser.TryParse(v, out long bValue, out int p); // return bValue; // } // case ColType.F32: // { // Utf8Parser.TryParse(v, out float bValue, out int p); // return bValue; // } // case ColType.DD: // { // Utf8Parser.TryParse(v, out double bValue, out int p); // return bValue; // } // case ColType.STR: // return new string(value.ToArray()); // case ColType.DT: // { // var vStr= new string(value.ToArray()); // if (string.IsNullOrEmpty(dFormat)) // { // DateTime.TryParse(vStr, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime bValue); // return bValue; // } // else // { // DateTime.TryParseExact(vStr, dFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime bValue); // return bValue; // } // } // default: // throw new Exception("column type is not known."); // } //#endif }
public ColToken register_object(object parent, ColType type) { ColToken new_object = new ColToken(type, this, unique_id++, parent); all_objects.Add(new_object); return new_object; // make a new object for the game }
public Col(int index, Func <object, HelperResult> description, IEnumerable <SelectListItem> all, ColType type) { Index = index; Description = description; All = all; Type = type; }
private object ReadCol(IDbStatement stmt, int index, ColType type, Type clrType) { var interfaces = clrType.GetTypeInfo().ImplementedInterfaces.ToList(); if (type == ColType.Null) { return(null); } if (clrType == typeof(String)) { return(_sqlitePlatform.SQLiteApi.ColumnText16(stmt, index)); } if (interfaces.Contains(typeof(ISerializable <string>))) { var value = _sqlitePlatform.SQLiteApi.ColumnText16(stmt, index); return(Activator.CreateInstance(clrType, new object[] { value })); } if (clrType == typeof(Int32)) { return(_sqlitePlatform.SQLiteApi.ColumnInt(stmt, index)); } if (interfaces.Contains(typeof(ISerializable <Int32>))) { var value = _sqlitePlatform.SQLiteApi.ColumnInt(stmt, index); return(Activator.CreateInstance(clrType, new object[] { value })); } if (clrType == typeof(Boolean)) { return(_sqlitePlatform.SQLiteApi.ColumnInt(stmt, index) == 1); } if (interfaces.Contains(typeof(ISerializable <Boolean>))) { var value = _sqlitePlatform.SQLiteApi.ColumnInt(stmt, index) == 1; return(Activator.CreateInstance(clrType, new object[] { value })); } if (clrType == typeof(double)) { return(_sqlitePlatform.SQLiteApi.ColumnDouble(stmt, index)); } if (interfaces.Contains(typeof(ISerializable <double>))) { var value = _sqlitePlatform.SQLiteApi.ColumnDouble(stmt, index); return(Activator.CreateInstance(clrType, new object[] { value })); } if (clrType == typeof(float)) { return((float)_sqlitePlatform.SQLiteApi.ColumnDouble(stmt, index)); } if (interfaces.Contains(typeof(ISerializable <float>))) { var value = (float)_sqlitePlatform.SQLiteApi.ColumnDouble(stmt, index); return(Activator.CreateInstance(clrType, new object[] { value })); } if (clrType == typeof(TimeSpan)) { return(new TimeSpan(_sqlitePlatform.SQLiteApi.ColumnInt64(stmt, index))); } if (interfaces.Contains(typeof(ISerializable <TimeSpan>))) { var value = new TimeSpan(_sqlitePlatform.SQLiteApi.ColumnInt64(stmt, index)); return(Activator.CreateInstance(clrType, new object[] { value })); } if (clrType == typeof(DateTime)) { if (_conn.StoreDateTimeAsTicks) { return(new DateTime(_sqlitePlatform.SQLiteApi.ColumnInt64(stmt, index))); } return(DateTime.Parse(_sqlitePlatform.SQLiteApi.ColumnText16(stmt, index))); } if (clrType == typeof(DateTimeOffset)) { return(new DateTimeOffset(_sqlitePlatform.SQLiteApi.ColumnInt64(stmt, index), TimeSpan.Zero)); } if (interfaces.Contains(typeof(ISerializable <DateTime>))) { DateTime value; if (_conn.StoreDateTimeAsTicks) { value = new DateTime(_sqlitePlatform.SQLiteApi.ColumnInt64(stmt, index)); } else { value = DateTime.Parse(_sqlitePlatform.SQLiteApi.ColumnText16(stmt, index)); } return(Activator.CreateInstance(clrType, new object[] { value })); } if (clrType.GetTypeInfo().IsEnum) { return(_sqlitePlatform.SQLiteApi.ColumnInt(stmt, index)); } if (clrType == typeof(Int64)) { return(_sqlitePlatform.SQLiteApi.ColumnInt64(stmt, index)); } if (interfaces.Contains(typeof(ISerializable <Int64>))) { var value = _sqlitePlatform.SQLiteApi.ColumnInt64(stmt, index); return(Activator.CreateInstance(clrType, new object[] { value })); } if (clrType == typeof(UInt32)) { return((uint)_sqlitePlatform.SQLiteApi.ColumnInt64(stmt, index)); } if (interfaces.Contains(typeof(ISerializable <Int64>))) { var value = (uint)_sqlitePlatform.SQLiteApi.ColumnInt64(stmt, index); return(Activator.CreateInstance(clrType, new object[] { value })); } if (clrType == typeof(decimal)) { return((decimal)_sqlitePlatform.SQLiteApi.ColumnDouble(stmt, index)); } if (interfaces.Contains(typeof(ISerializable <decimal>))) { var value = (decimal)_sqlitePlatform.SQLiteApi.ColumnDouble(stmt, index); return(Activator.CreateInstance(clrType, new object[] { value })); } if (clrType == typeof(Byte)) { return((byte)_sqlitePlatform.SQLiteApi.ColumnInt(stmt, index)); } if (interfaces.Contains(typeof(ISerializable <Byte>))) { var value = (byte)_sqlitePlatform.SQLiteApi.ColumnInt(stmt, index); return(Activator.CreateInstance(clrType, new object[] { value })); } if (clrType == typeof(UInt16)) { return((ushort)_sqlitePlatform.SQLiteApi.ColumnInt(stmt, index)); } if (interfaces.Contains(typeof(ISerializable <UInt16>))) { var value = (ushort)_sqlitePlatform.SQLiteApi.ColumnInt(stmt, index); return(Activator.CreateInstance(clrType, new object[] { value })); } if (clrType == typeof(Int16)) { return((short)_sqlitePlatform.SQLiteApi.ColumnInt(stmt, index)); } if (interfaces.Contains(typeof(ISerializable <Int16>))) { var value = (short)_sqlitePlatform.SQLiteApi.ColumnInt(stmt, index); return(Activator.CreateInstance(clrType, new object[] { value })); } if (clrType == typeof(sbyte)) { return((sbyte)_sqlitePlatform.SQLiteApi.ColumnInt(stmt, index)); } if (interfaces.Contains(typeof(ISerializable <sbyte>))) { var value = (sbyte)_sqlitePlatform.SQLiteApi.ColumnInt(stmt, index); return(Activator.CreateInstance(clrType, new object[] { value })); } if (clrType == typeof(byte[])) { return(_sqlitePlatform.SQLiteApi.ColumnByteArray(stmt, index)); } if (interfaces.Contains(typeof(ISerializable <byte[]>))) { var value = _sqlitePlatform.SQLiteApi.ColumnByteArray(stmt, index); return(Activator.CreateInstance(clrType, new object[] { value })); } if (clrType == typeof(Guid)) { return(new Guid(_sqlitePlatform.SQLiteApi.ColumnText16(stmt, index))); } if (interfaces.Contains(typeof(ISerializable <Guid>))) { var value = new Guid(_sqlitePlatform.SQLiteApi.ColumnText16(stmt, index)); return(Activator.CreateInstance(clrType, new object[] { value })); } if (_conn.Serializer != null && _conn.Serializer.CanDeserialize(clrType)) { var bytes = _sqlitePlatform.SQLiteApi.ColumnByteArray(stmt, index); return(_conn.Serializer.Deserialize(bytes, clrType)); } throw new NotSupportedException("Don't know how to read " + clrType); }
public override void HitSide(Line line, ColType c) { base.HitSide(line, c); Owner.Velocity.x = 0.0f; Owner.MoveToSideOfSurface(line, c); }
public ColInfo(string field, string alias, ColType type, string lookupTbl, bool visible) { Init(field, alias, type, lookupTbl, visible); }
public TableColumn(string ColName, ColType ColType, string ColRemark = "") { this.ColName = ColName; this.ColType = TypeConvert.ChangeToCSharpType(ColType.ToString()); this.ColRemark = ColRemark; }
public ColInfo(string field, string alias, ColType type, bool visible = true) { Init(field, alias, type, null, visible); }
public Series(List <object> data, List <object> ind = null, string name = "series", ColType type = ColType.STR) { if (data == null) { throw new Exception("the list object cannot be null"); } // _data = new List <object>(data); Name = name; if (ind != null && ind.Count == data.Count) { this._index = new Index(ind); } else if (ind != null && ind.Count != data.Count) { throw new Exception("Series index is not consistent with the series"); } else if (ind == null) { _index = new Index(Enumerable.Range(0, _data.Count).Select(x => (object)x).ToList()); } this._type = type; }