Skip to content

Commit

Permalink
Add sprite flip on X
Browse files Browse the repository at this point in the history
  • Loading branch information
h8man committed May 19, 2021
1 parent b205830 commit 325afcd
Show file tree
Hide file tree
Showing 11 changed files with 493 additions and 475 deletions.
16 changes: 11 additions & 5 deletions Assets/Codebehind/Editor/TrackEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ void DrawListItems(Rect rect, int index, bool isActive, bool isFocused)
new GUIContent("label")
);

EditorGUI.PropertyField(
new Rect(rect.x, rect.y + i++ * EditorGUIUtility.singleLineHeight, rect.width, EditorGUIUtility.singleLineHeight),
element.FindPropertyRelative("h"),
new GUIContent("h")
);

EditorGUI.PropertyField(
new Rect(rect.x, rect.y + i++ * EditorGUIUtility.singleLineHeight, rect.width, EditorGUIUtility.singleLineHeight),
element.FindPropertyRelative("curve"),
Expand All @@ -56,15 +62,15 @@ void DrawListItems(Rect rect, int index, bool isActive, bool isFocused)
EditorGUI.PropertyField(
new Rect(rect.x, rect.y + i++ * EditorGUIUtility.singleLineHeight, rect.width, EditorGUIUtility.singleLineHeight),
element.FindPropertyRelative("spriteX"),
new GUIContent("spriteX")
new GUIContent("sprite X")
);

EditorGUI.PropertyField(
new Rect(rect.x, rect.y + i++ * EditorGUIUtility.singleLineHeight, rect.width, EditorGUIUtility.singleLineHeight),
element.FindPropertyRelative("h"),
new GUIContent("h")
element.FindPropertyRelative("flipX"),
new GUIContent("flip X")
);

EditorGUI.PropertyField(
new Rect(rect.x, rect.y + i++ * EditorGUIUtility.singleLineHeight, rect.width, EditorGUIUtility.singleLineHeight),
element.FindPropertyRelative("sprite"),
Expand Down
2 changes: 1 addition & 1 deletion Assets/Codebehind/HQ/HqRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void drawSprite(ref Line line)

Rect target = new Rect(destX, destY, destW, destH);
Rect source = new Rect(Vector2Int.zero, new Vector2(1, 1 - clipH / destH));
Renderer.draw(source, s, target);
Renderer.draw(source, s, target, line.flipX);
}
private void addQuad(Material c, float x1, float y1, float w1, float x2, float y2, float w2, float z)
{
Expand Down
1 change: 1 addition & 0 deletions Assets/Codebehind/HQ/Line.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public struct Line
public float X, Y, W; //screen coord
public float curve, spriteX, clip, scale;
public Sprite sprite;
public bool flipX;

public void project(int camX, int camY, int camZ, int screenWidth2, int screenHeight2, float cameraDepth)
{
Expand Down
6 changes: 3 additions & 3 deletions Assets/Codebehind/HQ/RenderWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal void clear(Color color)
throw new NotImplementedException();
}

internal void draw(Rect offsetSource, Sprite sprite, Rect taret)
internal void draw(Rect offsetSource, Sprite sprite, Rect taret, bool flip)
{
//Graphics.DrawTexture(
// new Rect(
Expand All @@ -35,13 +35,13 @@ internal void draw(Rect offsetSource, Sprite sprite, Rect taret)
// s.rect.width / s.texture.width * Source.width,
// s.rect.height / s.texture.height * Source.height)
// , 0, 0, 0, 0);
var cut = sprite.rect.height / sprite.texture.height * offsetSource.height;
var sign = flip ? -1: 1;

Graphics.DrawTexture(
new Rect(
taret.x,
taret.y,
taret.width,
taret.width * sign,
taret.height * offsetSource.height
),
sprite.texture,
Expand Down
5 changes: 4 additions & 1 deletion Assets/Codebehind/HQ/TrackModifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ public class TrackModifier
{
public string label;
public bool disabled;
public float curve, spriteX, h;
public float curve;
public float h;
public float spriteX;
public bool flipX;
public Sprite sprite;
public Vector2Int Segments;
public int frequency;
Expand Down
1 change: 1 addition & 0 deletions Assets/Codebehind/HQ/TrackObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ protected virtual void Construct()
line.spriteX = m.spriteX;
line.y += Mathf.Sin(i * m.h) * trackHeight;
line.sprite = m.sprite ?? line.sprite;
line.flipX = m.flipX;
}
}

Expand Down
766 changes: 383 additions & 383 deletions Assets/Scenes/HQ.unity

Large diffs are not rendered by default.

Binary file added Assets/Sprites/streetlights.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
74 changes: 52 additions & 22 deletions Assets/Tracks/New Track.asset
Original file line number Diff line number Diff line change
Expand Up @@ -17,70 +17,100 @@ MonoBehaviour:
- label: right turn
disabled: 0
curve: 0.5
spriteX: 0
h: 0
spriteX: 0
flipX: 0
sprite: {fileID: 0}
Segments: {x: 300, y: 700}
frequency: 1
- label: hill
disabled: 0
curve: 0
spriteX: 2
h: 0.033333335
spriteX: 2
flipX: 0
sprite: {fileID: 0}
Segments: {x: 750, y: 1800}
frequency: 1
- label: left turn
disabled: 0
curve: -0.7
spriteX: 0
h: 0
spriteX: 0
flipX: 0
sprite: {fileID: 0}
Segments: {x: 1100, y: 1600}
frequency: 1
- label: lamps1
disabled: 0
curve: 0
spriteX: -2.5
h: 0
sprite: {fileID: -7185895424969228801, guid: 6cfc24268e569b84cb7c900478cc6ace,
spriteX: -2.5
flipX: 0
sprite: {fileID: -2816102195700063125, guid: af7b02d7376e40b429f40c8227118c04,
type: 3}
Segments: {x: 0, y: 300}
frequency: 20
frequency: 23
- label: lamps3
disabled: 0
curve: 0
spriteX: -1.7
h: 0
sprite: {fileID: 281491231418348154, guid: 6cfc24268e569b84cb7c900478cc6ace, type: 3}
Segments: {x: 300, y: 1800}
frequency: 20
spriteX: -1.7
flipX: 0
sprite: {fileID: -2816102195700063125, guid: af7b02d7376e40b429f40c8227118c04,
type: 3}
Segments: {x: 300, y: 750}
frequency: 29
- label: lamps4
disabled: 0
curve: 0
spriteX: -1.3
h: 0
sprite: {fileID: 1590509343616781973, guid: 6cfc24268e569b84cb7c900478cc6ace,
spriteX: -1.53
flipX: 0
sprite: {fileID: -2816102195700063125, guid: af7b02d7376e40b429f40c8227118c04,
type: 3}
Segments: {x: 800, y: 1800}
frequency: 20
- label: lampsSingle
frequency: 26
- label: lamps2
disabled: 0
curve: 0
h: 0
spriteX: 2
flipX: 1
sprite: {fileID: -2816102195700063125, guid: af7b02d7376e40b429f40c8227118c04,
type: 3}
Segments: {x: 0, y: 1800}
frequency: 25
- label: right turn
disabled: 0
curve: 0
h: 0
spriteX: -2
flipX: 0
sprite: {fileID: -9064669081510660656, guid: af7b02d7376e40b429f40c8227118c04,
type: 3}
Segments: {x: 300, y: 700}
frequency: 11
- label: start
disabled: 0
curve: 0
spriteX: -1.3
h: 0
sprite: {fileID: 281491231418348154, guid: 6cfc24268e569b84cb7c900478cc6ace, type: 3}
Segments: {x: 400, y: 401}
spriteX: -0.05
flipX: 0
sprite: {fileID: -188883476259138534, guid: af7b02d7376e40b429f40c8227118c04,
type: 3}
Segments: {x: 0, y: 2}
frequency: 1
- label: lamps2
- label: left trun
disabled: 0
curve: 0
spriteX: 2
h: 0
sprite: {fileID: 1821034816683627037, guid: 6cfc24268e569b84cb7c900478cc6ace,
spriteX: 1.5
flipX: 1
sprite: {fileID: -9064669081510660656, guid: af7b02d7376e40b429f40c8227118c04,
type: 3}
Segments: {x: 0, y: 1800}
frequency: 17
Segments: {x: 1100, y: 1500}
frequency: 11
roadWidth: 1500
segmentLength: 200
trackHeight: 1800

0 comments on commit 325afcd

Please sign in to comment.