├── Assets
├── Example.unity.meta
├── BitmapTestMaterial.mat.meta
├── Example.cs.meta
├── BitmapDrawing.cs.meta
├── BitmapTestMaterial.mat
├── Example.cs
├── Example.unity
└── BitmapDrawing.cs
├── ProjectSettings
├── EditorBuildSettings.asset
├── NetworkManager.asset
├── TimeManager.asset
├── GraphicsSettings.asset
├── AudioManager.asset
├── EditorSettings.asset
├── Physics2DSettings.asset
├── DynamicsManager.asset
├── TagManager.asset
├── NavMeshLayers.asset
├── QualitySettings.asset
├── InputManager.asset
└── ProjectSettings.asset
├── README.md
└── LICENSE
/Assets/Example.unity.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: c86d9a610dadb6149bb76e1e4381741f
3 | DefaultImporter:
4 | userData:
5 |
--------------------------------------------------------------------------------
/Assets/BitmapTestMaterial.mat.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 7b89c5cfbb6562d4e97216131849bad1
3 | NativeFormatImporter:
4 | userData:
5 |
--------------------------------------------------------------------------------
/ProjectSettings/EditorBuildSettings.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!1045 &1
4 | EditorBuildSettings:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 2
7 | m_Scenes: []
8 |
--------------------------------------------------------------------------------
/ProjectSettings/NetworkManager.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!149 &1
4 | NetworkManager:
5 | m_ObjectHideFlags: 0
6 | m_DebugLevel: 0
7 | m_Sendrate: 15
8 | m_AssetToPrefab: {}
9 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | BitmapDrawingExampleProject
2 | ===========================
3 |
4 | Unity Bitmap Drawing API example project
5 |
6 | Go here for the Bitmap Drawing API:
7 | https://github.com/ProtoTurtle/UnityBitmapDrawing
8 |
--------------------------------------------------------------------------------
/Assets/Example.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 214ca269bd9fc354aab11060950e6476
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/Assets/BitmapDrawing.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 6080576e074cdb24892be3422b7c266c
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/ProjectSettings/TimeManager.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!5 &1
4 | TimeManager:
5 | m_ObjectHideFlags: 0
6 | Fixed Timestep: .0199999996
7 | Maximum Allowed Timestep: .333333343
8 | m_TimeScale: 1
9 |
--------------------------------------------------------------------------------
/ProjectSettings/GraphicsSettings.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!30 &1
4 | GraphicsSettings:
5 | m_ObjectHideFlags: 0
6 | m_AlwaysIncludedShaders:
7 | - {fileID: 7, guid: 0000000000000000f000000000000000, type: 0}
8 |
--------------------------------------------------------------------------------
/ProjectSettings/AudioManager.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!11 &1
4 | AudioManager:
5 | m_ObjectHideFlags: 0
6 | m_Volume: 1
7 | Rolloff Scale: 1
8 | m_SpeedOfSound: 347
9 | Doppler Factor: 1
10 | Default Speaker Mode: 2
11 | m_DSPBufferSize: 0
12 | m_DisableAudio: 0
13 |
--------------------------------------------------------------------------------
/ProjectSettings/EditorSettings.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!159 &1
4 | EditorSettings:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 3
7 | m_ExternalVersionControlSupport: Visible Meta Files
8 | m_SerializationMode: 2
9 | m_WebSecurityEmulationEnabled: 0
10 | m_WebSecurityEmulationHostUrl: http://www.mydomain.com/mygame.unity3d
11 | m_DefaultBehaviorMode: 0
12 | m_SpritePackerMode: 0
13 |
--------------------------------------------------------------------------------
/ProjectSettings/Physics2DSettings.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!19 &1
4 | Physics2DSettings:
5 | m_ObjectHideFlags: 0
6 | m_Gravity: {x: 0, y: -9.81000042}
7 | m_DefaultMaterial: {fileID: 0}
8 | m_VelocityIterations: 8
9 | m_PositionIterations: 3
10 | m_RaycastsHitTriggers: 1
11 | m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
12 |
--------------------------------------------------------------------------------
/ProjectSettings/DynamicsManager.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!55 &1
4 | PhysicsManager:
5 | m_ObjectHideFlags: 0
6 | m_Gravity: {x: 0, y: -9.81000042, z: 0}
7 | m_DefaultMaterial: {fileID: 0}
8 | m_BounceThreshold: 2
9 | m_SleepVelocity: .150000006
10 | m_SleepAngularVelocity: .140000001
11 | m_MaxAngularVelocity: 7
12 | m_MinPenetrationForPenalty: .00999999978
13 | m_SolverIterationCount: 6
14 | m_RaycastsHitTriggers: 1
15 | m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
16 |
--------------------------------------------------------------------------------
/Assets/BitmapTestMaterial.mat:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!21 &2100000
4 | Material:
5 | serializedVersion: 3
6 | m_ObjectHideFlags: 0
7 | m_PrefabParentObject: {fileID: 0}
8 | m_PrefabInternal: {fileID: 0}
9 | m_Name: BitmapTestMaterial
10 | m_Shader: {fileID: 10752, guid: 0000000000000000f000000000000000, type: 0}
11 | m_ShaderKeywords: []
12 | m_CustomRenderQueue: -1
13 | m_SavedProperties:
14 | serializedVersion: 2
15 | m_TexEnvs:
16 | data:
17 | first:
18 | name: _MainTex
19 | second:
20 | m_Texture: {fileID: 0}
21 | m_Scale: {x: 1, y: 1}
22 | m_Offset: {x: 0, y: 0}
23 | m_Floats: {}
24 | m_Colors:
25 | data:
26 | first:
27 | name: _Color
28 | second: {r: 1, g: 1, b: 1, a: 1}
29 |
--------------------------------------------------------------------------------
/Assets/Example.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using System.Collections;
3 |
4 | using ProtoTurtle.BitmapDrawing;
5 |
6 |
7 | public class Example : MonoBehaviour {
8 |
9 |
10 | void Start () {
11 |
12 | Material material = renderer.material;
13 | Texture2D texture = new Texture2D(512,512, TextureFormat.RGB24, false);
14 | texture.wrapMode = TextureWrapMode.Clamp;
15 | material.SetTexture(0, texture);
16 |
17 | texture.DrawFilledRectangle(new Rect(0, 0, 120, 120), Color.green);
18 |
19 | texture.DrawRectangle(new Rect(0, 0, 120, 60), Color.red);
20 |
21 | texture.DrawCircle(256, 256, 100, Color.cyan);
22 | texture.DrawFilledCircle(256, 256, 50, Color.grey);
23 |
24 | texture.DrawCircle(0, 0, 512, Color.red);
25 |
26 | texture.DrawLine(new Vector2(120, 60), new Vector2(256, 256), Color.black);
27 |
28 |
29 |
30 | texture.Apply();
31 |
32 |
33 |
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/ProjectSettings/TagManager.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!78 &1
4 | TagManager:
5 | tags:
6 | -
7 | Builtin Layer 0: Default
8 | Builtin Layer 1: TransparentFX
9 | Builtin Layer 2: Ignore Raycast
10 | Builtin Layer 3:
11 | Builtin Layer 4: Water
12 | Builtin Layer 5:
13 | Builtin Layer 6:
14 | Builtin Layer 7:
15 | User Layer 8:
16 | User Layer 9:
17 | User Layer 10:
18 | User Layer 11:
19 | User Layer 12:
20 | User Layer 13:
21 | User Layer 14:
22 | User Layer 15:
23 | User Layer 16:
24 | User Layer 17:
25 | User Layer 18:
26 | User Layer 19:
27 | User Layer 20:
28 | User Layer 21:
29 | User Layer 22:
30 | User Layer 23:
31 | User Layer 24:
32 | User Layer 25:
33 | User Layer 26:
34 | User Layer 27:
35 | User Layer 28:
36 | User Layer 29:
37 | User Layer 30:
38 | User Layer 31:
39 | m_SortingLayers:
40 | - name: Default
41 | userID: 0
42 | uniqueID: 0
43 | locked: 0
44 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 ProtoTurtle
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/ProjectSettings/NavMeshLayers.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!126 &1
4 | NavMeshLayers:
5 | m_ObjectHideFlags: 0
6 | Built-in Layer 0:
7 | name: Default
8 | cost: 1
9 | editType: 2
10 | Built-in Layer 1:
11 | name: Not Walkable
12 | cost: 1
13 | editType: 0
14 | Built-in Layer 2:
15 | name: Jump
16 | cost: 2
17 | editType: 2
18 | User Layer 0:
19 | name:
20 | cost: 1
21 | editType: 3
22 | User Layer 1:
23 | name:
24 | cost: 1
25 | editType: 3
26 | User Layer 2:
27 | name:
28 | cost: 1
29 | editType: 3
30 | User Layer 3:
31 | name:
32 | cost: 1
33 | editType: 3
34 | User Layer 4:
35 | name:
36 | cost: 1
37 | editType: 3
38 | User Layer 5:
39 | name:
40 | cost: 1
41 | editType: 3
42 | User Layer 6:
43 | name:
44 | cost: 1
45 | editType: 3
46 | User Layer 7:
47 | name:
48 | cost: 1
49 | editType: 3
50 | User Layer 8:
51 | name:
52 | cost: 1
53 | editType: 3
54 | User Layer 9:
55 | name:
56 | cost: 1
57 | editType: 3
58 | User Layer 10:
59 | name:
60 | cost: 1
61 | editType: 3
62 | User Layer 11:
63 | name:
64 | cost: 1
65 | editType: 3
66 | User Layer 12:
67 | name:
68 | cost: 1
69 | editType: 3
70 | User Layer 13:
71 | name:
72 | cost: 1
73 | editType: 3
74 | User Layer 14:
75 | name:
76 | cost: 1
77 | editType: 3
78 | User Layer 15:
79 | name:
80 | cost: 1
81 | editType: 3
82 | User Layer 16:
83 | name:
84 | cost: 1
85 | editType: 3
86 | User Layer 17:
87 | name:
88 | cost: 1
89 | editType: 3
90 | User Layer 18:
91 | name:
92 | cost: 1
93 | editType: 3
94 | User Layer 19:
95 | name:
96 | cost: 1
97 | editType: 3
98 | User Layer 20:
99 | name:
100 | cost: 1
101 | editType: 3
102 | User Layer 21:
103 | name:
104 | cost: 1
105 | editType: 3
106 | User Layer 22:
107 | name:
108 | cost: 1
109 | editType: 3
110 | User Layer 23:
111 | name:
112 | cost: 1
113 | editType: 3
114 | User Layer 24:
115 | name:
116 | cost: 1
117 | editType: 3
118 | User Layer 25:
119 | name:
120 | cost: 1
121 | editType: 3
122 | User Layer 26:
123 | name:
124 | cost: 1
125 | editType: 3
126 | User Layer 27:
127 | name:
128 | cost: 1
129 | editType: 3
130 | User Layer 28:
131 | name:
132 | cost: 1
133 | editType: 3
134 |
--------------------------------------------------------------------------------
/ProjectSettings/QualitySettings.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!47 &1
4 | QualitySettings:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 5
7 | m_CurrentQuality: 3
8 | m_QualitySettings:
9 | - serializedVersion: 2
10 | name: Fastest
11 | pixelLightCount: 0
12 | shadows: 0
13 | shadowResolution: 0
14 | shadowProjection: 1
15 | shadowCascades: 1
16 | shadowDistance: 15
17 | blendWeights: 1
18 | textureQuality: 1
19 | anisotropicTextures: 0
20 | antiAliasing: 0
21 | softParticles: 0
22 | softVegetation: 0
23 | vSyncCount: 0
24 | lodBias: .300000012
25 | maximumLODLevel: 0
26 | particleRaycastBudget: 4
27 | excludedTargetPlatforms: []
28 | - serializedVersion: 2
29 | name: Fast
30 | pixelLightCount: 0
31 | shadows: 0
32 | shadowResolution: 0
33 | shadowProjection: 1
34 | shadowCascades: 1
35 | shadowDistance: 20
36 | blendWeights: 2
37 | textureQuality: 0
38 | anisotropicTextures: 0
39 | antiAliasing: 0
40 | softParticles: 0
41 | softVegetation: 0
42 | vSyncCount: 0
43 | lodBias: .400000006
44 | maximumLODLevel: 0
45 | particleRaycastBudget: 16
46 | excludedTargetPlatforms: []
47 | - serializedVersion: 2
48 | name: Simple
49 | pixelLightCount: 1
50 | shadows: 1
51 | shadowResolution: 0
52 | shadowProjection: 1
53 | shadowCascades: 1
54 | shadowDistance: 20
55 | blendWeights: 2
56 | textureQuality: 0
57 | anisotropicTextures: 1
58 | antiAliasing: 0
59 | softParticles: 0
60 | softVegetation: 0
61 | vSyncCount: 0
62 | lodBias: .699999988
63 | maximumLODLevel: 0
64 | particleRaycastBudget: 64
65 | excludedTargetPlatforms: []
66 | - serializedVersion: 2
67 | name: Good
68 | pixelLightCount: 2
69 | shadows: 2
70 | shadowResolution: 1
71 | shadowProjection: 1
72 | shadowCascades: 2
73 | shadowDistance: 40
74 | blendWeights: 2
75 | textureQuality: 0
76 | anisotropicTextures: 1
77 | antiAliasing: 0
78 | softParticles: 0
79 | softVegetation: 1
80 | vSyncCount: 1
81 | lodBias: 1
82 | maximumLODLevel: 0
83 | particleRaycastBudget: 256
84 | excludedTargetPlatforms: []
85 | - serializedVersion: 2
86 | name: Beautiful
87 | pixelLightCount: 3
88 | shadows: 2
89 | shadowResolution: 2
90 | shadowProjection: 1
91 | shadowCascades: 2
92 | shadowDistance: 70
93 | blendWeights: 4
94 | textureQuality: 0
95 | anisotropicTextures: 2
96 | antiAliasing: 2
97 | softParticles: 1
98 | softVegetation: 1
99 | vSyncCount: 1
100 | lodBias: 1.5
101 | maximumLODLevel: 0
102 | particleRaycastBudget: 1024
103 | excludedTargetPlatforms: []
104 | - serializedVersion: 2
105 | name: Fantastic
106 | pixelLightCount: 4
107 | shadows: 2
108 | shadowResolution: 2
109 | shadowProjection: 1
110 | shadowCascades: 4
111 | shadowDistance: 150
112 | blendWeights: 4
113 | textureQuality: 0
114 | anisotropicTextures: 2
115 | antiAliasing: 2
116 | softParticles: 1
117 | softVegetation: 1
118 | vSyncCount: 1
119 | lodBias: 2
120 | maximumLODLevel: 0
121 | particleRaycastBudget: 4096
122 | excludedTargetPlatforms: []
123 | m_PerPlatformDefaultQuality:
124 | Android: 2
125 | BlackBerry: 2
126 | FlashPlayer: 3
127 | GLES Emulation: 3
128 | PS3: 3
129 | Standalone: 3
130 | Tizen: 2
131 | WP8: 3
132 | Web: 3
133 | Wii: 3
134 | Windows Store Apps: 3
135 | XBOX360: 3
136 | iPhone: 2
137 |
--------------------------------------------------------------------------------
/ProjectSettings/InputManager.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!13 &1
4 | InputManager:
5 | m_ObjectHideFlags: 0
6 | m_Axes:
7 | - serializedVersion: 3
8 | m_Name: Horizontal
9 | descriptiveName:
10 | descriptiveNegativeName:
11 | negativeButton: left
12 | positiveButton: right
13 | altNegativeButton: a
14 | altPositiveButton: d
15 | gravity: 3
16 | dead: .00100000005
17 | sensitivity: 3
18 | snap: 1
19 | invert: 0
20 | type: 0
21 | axis: 0
22 | joyNum: 0
23 | - serializedVersion: 3
24 | m_Name: Vertical
25 | descriptiveName:
26 | descriptiveNegativeName:
27 | negativeButton: down
28 | positiveButton: up
29 | altNegativeButton: s
30 | altPositiveButton: w
31 | gravity: 3
32 | dead: .00100000005
33 | sensitivity: 3
34 | snap: 1
35 | invert: 0
36 | type: 0
37 | axis: 0
38 | joyNum: 0
39 | - serializedVersion: 3
40 | m_Name: Fire1
41 | descriptiveName:
42 | descriptiveNegativeName:
43 | negativeButton:
44 | positiveButton: left ctrl
45 | altNegativeButton:
46 | altPositiveButton: mouse 0
47 | gravity: 1000
48 | dead: .00100000005
49 | sensitivity: 1000
50 | snap: 0
51 | invert: 0
52 | type: 0
53 | axis: 0
54 | joyNum: 0
55 | - serializedVersion: 3
56 | m_Name: Fire2
57 | descriptiveName:
58 | descriptiveNegativeName:
59 | negativeButton:
60 | positiveButton: left alt
61 | altNegativeButton:
62 | altPositiveButton: mouse 1
63 | gravity: 1000
64 | dead: .00100000005
65 | sensitivity: 1000
66 | snap: 0
67 | invert: 0
68 | type: 0
69 | axis: 0
70 | joyNum: 0
71 | - serializedVersion: 3
72 | m_Name: Fire3
73 | descriptiveName:
74 | descriptiveNegativeName:
75 | negativeButton:
76 | positiveButton: left cmd
77 | altNegativeButton:
78 | altPositiveButton: mouse 2
79 | gravity: 1000
80 | dead: .00100000005
81 | sensitivity: 1000
82 | snap: 0
83 | invert: 0
84 | type: 0
85 | axis: 0
86 | joyNum: 0
87 | - serializedVersion: 3
88 | m_Name: Jump
89 | descriptiveName:
90 | descriptiveNegativeName:
91 | negativeButton:
92 | positiveButton: space
93 | altNegativeButton:
94 | altPositiveButton:
95 | gravity: 1000
96 | dead: .00100000005
97 | sensitivity: 1000
98 | snap: 0
99 | invert: 0
100 | type: 0
101 | axis: 0
102 | joyNum: 0
103 | - serializedVersion: 3
104 | m_Name: Mouse X
105 | descriptiveName:
106 | descriptiveNegativeName:
107 | negativeButton:
108 | positiveButton:
109 | altNegativeButton:
110 | altPositiveButton:
111 | gravity: 0
112 | dead: 0
113 | sensitivity: .100000001
114 | snap: 0
115 | invert: 0
116 | type: 1
117 | axis: 0
118 | joyNum: 0
119 | - serializedVersion: 3
120 | m_Name: Mouse Y
121 | descriptiveName:
122 | descriptiveNegativeName:
123 | negativeButton:
124 | positiveButton:
125 | altNegativeButton:
126 | altPositiveButton:
127 | gravity: 0
128 | dead: 0
129 | sensitivity: .100000001
130 | snap: 0
131 | invert: 0
132 | type: 1
133 | axis: 1
134 | joyNum: 0
135 | - serializedVersion: 3
136 | m_Name: Mouse ScrollWheel
137 | descriptiveName:
138 | descriptiveNegativeName:
139 | negativeButton:
140 | positiveButton:
141 | altNegativeButton:
142 | altPositiveButton:
143 | gravity: 0
144 | dead: 0
145 | sensitivity: .100000001
146 | snap: 0
147 | invert: 0
148 | type: 1
149 | axis: 2
150 | joyNum: 0
151 | - serializedVersion: 3
152 | m_Name: Horizontal
153 | descriptiveName:
154 | descriptiveNegativeName:
155 | negativeButton:
156 | positiveButton:
157 | altNegativeButton:
158 | altPositiveButton:
159 | gravity: 0
160 | dead: .189999998
161 | sensitivity: 1
162 | snap: 0
163 | invert: 0
164 | type: 2
165 | axis: 0
166 | joyNum: 0
167 | - serializedVersion: 3
168 | m_Name: Vertical
169 | descriptiveName:
170 | descriptiveNegativeName:
171 | negativeButton:
172 | positiveButton:
173 | altNegativeButton:
174 | altPositiveButton:
175 | gravity: 0
176 | dead: .189999998
177 | sensitivity: 1
178 | snap: 0
179 | invert: 1
180 | type: 2
181 | axis: 1
182 | joyNum: 0
183 | - serializedVersion: 3
184 | m_Name: Fire1
185 | descriptiveName:
186 | descriptiveNegativeName:
187 | negativeButton:
188 | positiveButton: joystick button 0
189 | altNegativeButton:
190 | altPositiveButton:
191 | gravity: 1000
192 | dead: .00100000005
193 | sensitivity: 1000
194 | snap: 0
195 | invert: 0
196 | type: 0
197 | axis: 0
198 | joyNum: 0
199 | - serializedVersion: 3
200 | m_Name: Fire2
201 | descriptiveName:
202 | descriptiveNegativeName:
203 | negativeButton:
204 | positiveButton: joystick button 1
205 | altNegativeButton:
206 | altPositiveButton:
207 | gravity: 1000
208 | dead: .00100000005
209 | sensitivity: 1000
210 | snap: 0
211 | invert: 0
212 | type: 0
213 | axis: 0
214 | joyNum: 0
215 | - serializedVersion: 3
216 | m_Name: Fire3
217 | descriptiveName:
218 | descriptiveNegativeName:
219 | negativeButton:
220 | positiveButton: joystick button 2
221 | altNegativeButton:
222 | altPositiveButton:
223 | gravity: 1000
224 | dead: .00100000005
225 | sensitivity: 1000
226 | snap: 0
227 | invert: 0
228 | type: 0
229 | axis: 0
230 | joyNum: 0
231 | - serializedVersion: 3
232 | m_Name: Jump
233 | descriptiveName:
234 | descriptiveNegativeName:
235 | negativeButton:
236 | positiveButton: joystick button 3
237 | altNegativeButton:
238 | altPositiveButton:
239 | gravity: 1000
240 | dead: .00100000005
241 | sensitivity: 1000
242 | snap: 0
243 | invert: 0
244 | type: 0
245 | axis: 0
246 | joyNum: 0
247 |
--------------------------------------------------------------------------------
/ProjectSettings/ProjectSettings.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!129 &1
4 | PlayerSettings:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 2
7 | AndroidProfiler: 0
8 | defaultScreenOrientation: 0
9 | targetDevice: 2
10 | targetGlesGraphics: 1
11 | targetResolution: 0
12 | accelerometerFrequency: 60
13 | companyName: DefaultCompany
14 | productName: bitmapDrawing
15 | defaultCursor: {fileID: 0}
16 | cursorHotspot: {x: 0, y: 0}
17 | defaultScreenWidth: 1024
18 | defaultScreenHeight: 768
19 | defaultScreenWidthWeb: 960
20 | defaultScreenHeightWeb: 600
21 | m_RenderingPath: 1
22 | m_MobileRenderingPath: 1
23 | m_ActiveColorSpace: 0
24 | m_MTRendering: 1
25 | m_MobileMTRendering: 0
26 | m_UseDX11: 0
27 | iosShowActivityIndicatorOnLoading: -1
28 | androidShowActivityIndicatorOnLoading: -1
29 | displayResolutionDialog: 1
30 | allowedAutorotateToPortrait: 1
31 | allowedAutorotateToPortraitUpsideDown: 1
32 | allowedAutorotateToLandscapeRight: 1
33 | allowedAutorotateToLandscapeLeft: 1
34 | useOSAutorotation: 1
35 | use32BitDisplayBuffer: 1
36 | use24BitDepthBuffer: 1
37 | defaultIsFullScreen: 1
38 | defaultIsNativeResolution: 1
39 | runInBackground: 0
40 | captureSingleScreen: 0
41 | Override IPod Music: 0
42 | Prepare IOS For Recording: 0
43 | enableHWStatistics: 1
44 | usePlayerLog: 1
45 | stripPhysics: 0
46 | forceSingleInstance: 0
47 | resizableWindow: 0
48 | useMacAppStoreValidation: 0
49 | gpuSkinning: 0
50 | xboxPIXTextureCapture: 0
51 | xboxEnableAvatar: 0
52 | xboxEnableKinect: 0
53 | xboxEnableKinectAutoTracking: 0
54 | xboxEnableFitness: 0
55 | macFullscreenMode: 2
56 | xboxSpeechDB: 0
57 | xboxEnableHeadOrientation: 0
58 | xboxEnableGuest: 0
59 | wiiHio2Usage: -1
60 | wiiLoadingScreenRectPlacement: 0
61 | wiiLoadingScreenBackground: {r: 1, g: 1, b: 1, a: 1}
62 | wiiLoadingScreenPeriod: 1000
63 | wiiLoadingScreenFileName:
64 | wiiLoadingScreenRect:
65 | serializedVersion: 2
66 | x: 0
67 | y: 0
68 | width: 0
69 | height: 0
70 | m_SupportedAspectRatios:
71 | 4:3: 1
72 | 5:4: 1
73 | 16:10: 1
74 | 16:9: 1
75 | Others: 1
76 | iPhoneBundleIdentifier: com.Company.ProductName
77 | metroEnableIndependentInputSource: 0
78 | metroEnableLowLatencyPresentationAPI: 0
79 | productGUID: 2284bdb51d9295047baeab0f1ba2e175
80 | iPhoneBundleVersion: 1.0
81 | AndroidBundleVersionCode: 1
82 | AndroidMinSdkVersion: 9
83 | AndroidPreferredInstallLocation: 1
84 | aotOptions:
85 | apiCompatibilityLevel: 2
86 | iPhoneStrippingLevel: 0
87 | iPhoneScriptCallOptimization: 0
88 | ForceInternetPermission: 0
89 | ForceSDCardPermission: 0
90 | CreateWallpaper: 0
91 | APKExpansionFiles: 0
92 | StripUnusedMeshComponents: 0
93 | iPhoneSdkVersion: 988
94 | iPhoneTargetOSVersion: 16
95 | uIPrerenderedIcon: 0
96 | uIRequiresPersistentWiFi: 0
97 | uIStatusBarHidden: 1
98 | uIExitOnSuspend: 0
99 | uIStatusBarStyle: 0
100 | iPhoneSplashScreen: {fileID: 0}
101 | iPhoneHighResSplashScreen: {fileID: 0}
102 | iPhoneTallHighResSplashScreen: {fileID: 0}
103 | iPadPortraitSplashScreen: {fileID: 0}
104 | iPadHighResPortraitSplashScreen: {fileID: 0}
105 | iPadLandscapeSplashScreen: {fileID: 0}
106 | iPadHighResLandscapeSplashScreen: {fileID: 0}
107 | AndroidTargetDevice: 0
108 | AndroidSplashScreenScale: 0
109 | AndroidKeystoreName:
110 | AndroidKeyaliasName:
111 | resolutionDialogBanner: {fileID: 0}
112 | m_BuildTargetIcons: []
113 | m_BuildTargetBatching: []
114 | webPlayerTemplate: APPLICATION:Default
115 | m_TemplateCustomTags: {}
116 | wiiRegion: 1
117 | wiiGameCode: RABA
118 | wiiGameVersion:
119 | wiiCompanyCode: ZZ
120 | wiiSupportsNunchuk: 0
121 | wiiSupportsClassicController: 0
122 | wiiSupportsBalanceBoard: 0
123 | wiiSupportsMotionPlus: 0
124 | wiiControllerCount: 1
125 | wiiFloatingPointExceptions: 0
126 | wiiScreenCrashDumps: 1
127 | XboxTitleId:
128 | XboxImageXexPath:
129 | XboxSpaPath:
130 | XboxGenerateSpa: 0
131 | XboxDeployKinectResources: 0
132 | XboxSplashScreen: {fileID: 0}
133 | xboxEnableSpeech: 0
134 | xboxAdditionalTitleMemorySize: 0
135 | xboxDeployKinectHeadOrientation: 0
136 | xboxDeployKinectHeadPosition: 0
137 | ps3TitleConfigPath:
138 | ps3DLCConfigPath:
139 | ps3ThumbnailPath:
140 | ps3BackgroundPath:
141 | ps3SoundPath:
142 | ps3TrophyCommId:
143 | ps3NpCommunicationPassphrase:
144 | ps3TrophyPackagePath:
145 | ps3BootCheckMaxSaveGameSizeKB: 128
146 | ps3TrophyCommSig:
147 | ps3SaveGameSlots: 1
148 | ps3TrialMode: 0
149 | flashStrippingLevel: 2
150 | spritePackerPolicy:
151 | scriptingDefineSymbols: {}
152 | metroPackageName: bitmapDrawing
153 | metroPackageLogo:
154 | metroPackageVersion:
155 | metroCertificatePath:
156 | metroCertificatePassword:
157 | metroCertificateSubject:
158 | metroCertificateIssuer:
159 | metroCertificateNotAfter: 0000000000000000
160 | metroApplicationDescription: bitmapDrawing
161 | metroTileLogo:
162 | metroTileWideLogo:
163 | metroTileSmallLogo:
164 | metroTileShortName:
165 | metroCommandLineArgsFile:
166 | metroTileShowName: 1
167 | metroTileForegroundText: 1
168 | metroTileBackgroundColor: {r: 0, g: 0, b: 0, a: 1}
169 | metroSplashScreenImage:
170 | metroSplashScreenBackgroundColor: {r: 0, g: 0, b: 0, a: 1}
171 | metroSplashScreenUseBackgroundColor: 0
172 | metroCapabilities: {}
173 | metroUnprocessedPlugins: []
174 | metroCompilationOverrides: 1
175 | blackberryDeviceAddress:
176 | blackberryDevicePassword:
177 | blackberryTokenPath:
178 | blackberryTokenExires:
179 | blackberryTokenAuthor:
180 | blackberryTokenAuthorId:
181 | blackberryAuthorId:
182 | blackberryCskPassword:
183 | blackberrySaveLogPath:
184 | blackberryAuthorIdOveride: 0
185 | blackberrySharedPermissions: 0
186 | blackberryCameraPermissions: 0
187 | blackberryGPSPermissions: 0
188 | blackberryDeviceIDPermissions: 0
189 | blackberryMicrophonePermissions: 0
190 | blackberryGamepadSupport: 0
191 | blackberryBuildId: 0
192 | blackberryLandscapeSplashScreen: {fileID: 0}
193 | blackberryPortraitSplashScreen: {fileID: 0}
194 | blackberrySquareSplashScreen: {fileID: 0}
195 | tizenProductDescription:
196 | tizenProductURL:
197 | tizenCertificatePath:
198 | tizenCertificatePassword:
199 | tizenSaveLogPath:
200 | firstStreamedLevelWithResources: 0
201 | unityRebuildLibraryVersion: 9
202 | unityForwardCompatibleVersion: 39
203 | unityStandardAssetsVersion: 0
204 |
--------------------------------------------------------------------------------
/Assets/Example.unity:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!29 &1
4 | SceneSettings:
5 | m_ObjectHideFlags: 0
6 | m_PVSData:
7 | m_PVSObjectsArray: []
8 | m_PVSPortalsArray: []
9 | m_OcclusionBakeSettings:
10 | smallestOccluder: 5
11 | smallestHole: .25
12 | backfaceThreshold: 100
13 | --- !u!104 &2
14 | RenderSettings:
15 | m_Fog: 0
16 | m_FogColor: {r: .5, g: .5, b: .5, a: 1}
17 | m_FogMode: 3
18 | m_FogDensity: .00999999978
19 | m_LinearFogStart: 0
20 | m_LinearFogEnd: 300
21 | m_AmbientLight: {r: .200000003, g: .200000003, b: .200000003, a: 1}
22 | m_SkyboxMaterial: {fileID: 0}
23 | m_HaloStrength: .5
24 | m_FlareStrength: 1
25 | m_FlareFadeSpeed: 3
26 | m_HaloTexture: {fileID: 0}
27 | m_SpotCookie: {fileID: 0}
28 | m_ObjectHideFlags: 0
29 | --- !u!127 &3
30 | LevelGameManager:
31 | m_ObjectHideFlags: 0
32 | --- !u!157 &4
33 | LightmapSettings:
34 | m_ObjectHideFlags: 0
35 | m_LightProbes: {fileID: 0}
36 | m_Lightmaps: []
37 | m_LightmapsMode: 1
38 | m_BakedColorSpace: 0
39 | m_UseDualLightmapsInForward: 0
40 | m_LightmapEditorSettings:
41 | m_Resolution: 50
42 | m_LastUsedResolution: 0
43 | m_TextureWidth: 1024
44 | m_TextureHeight: 1024
45 | m_BounceBoost: 1
46 | m_BounceIntensity: 1
47 | m_SkyLightColor: {r: .860000014, g: .930000007, b: 1, a: 1}
48 | m_SkyLightIntensity: 0
49 | m_Quality: 0
50 | m_Bounces: 1
51 | m_FinalGatherRays: 1000
52 | m_FinalGatherContrastThreshold: .0500000007
53 | m_FinalGatherGradientThreshold: 0
54 | m_FinalGatherInterpolationPoints: 15
55 | m_AOAmount: 0
56 | m_AOMaxDistance: .100000001
57 | m_AOContrast: 1
58 | m_LODSurfaceMappingDistance: 1
59 | m_Padding: 0
60 | m_TextureCompression: 0
61 | m_LockAtlas: 0
62 | --- !u!196 &5
63 | NavMeshSettings:
64 | m_ObjectHideFlags: 0
65 | m_BuildSettings:
66 | agentRadius: .5
67 | agentHeight: 2
68 | agentSlope: 45
69 | agentClimb: .400000006
70 | ledgeDropHeight: 0
71 | maxJumpAcrossDistance: 0
72 | accuratePlacement: 0
73 | minRegionArea: 2
74 | widthInaccuracy: 16.666666
75 | heightInaccuracy: 10
76 | m_NavMesh: {fileID: 0}
77 | --- !u!1 &1199403797
78 | GameObject:
79 | m_ObjectHideFlags: 0
80 | m_PrefabParentObject: {fileID: 0}
81 | m_PrefabInternal: {fileID: 0}
82 | serializedVersion: 4
83 | m_Component:
84 | - 4: {fileID: 1199403801}
85 | - 33: {fileID: 1199403800}
86 | - 64: {fileID: 1199403799}
87 | - 23: {fileID: 1199403798}
88 | - 114: {fileID: 1199403802}
89 | m_Layer: 0
90 | m_Name: BitmapTestQuad
91 | m_TagString: Untagged
92 | m_Icon: {fileID: 0}
93 | m_NavMeshLayer: 0
94 | m_StaticEditorFlags: 0
95 | m_IsActive: 1
96 | --- !u!23 &1199403798
97 | Renderer:
98 | m_ObjectHideFlags: 0
99 | m_PrefabParentObject: {fileID: 0}
100 | m_PrefabInternal: {fileID: 0}
101 | m_GameObject: {fileID: 1199403797}
102 | m_Enabled: 1
103 | m_CastShadows: 1
104 | m_ReceiveShadows: 1
105 | m_LightmapIndex: 255
106 | m_LightmapTilingOffset: {x: 1, y: 1, z: 0, w: 0}
107 | m_Materials:
108 | - {fileID: 2100000, guid: 7b89c5cfbb6562d4e97216131849bad1, type: 2}
109 | m_SubsetIndices:
110 | m_StaticBatchRoot: {fileID: 0}
111 | m_UseLightProbes: 0
112 | m_LightProbeAnchor: {fileID: 0}
113 | m_ScaleInLightmap: 1
114 | m_SortingLayer: 0
115 | m_SortingOrder: 0
116 | m_SortingLayerID: 0
117 | --- !u!64 &1199403799
118 | MeshCollider:
119 | m_ObjectHideFlags: 0
120 | m_PrefabParentObject: {fileID: 0}
121 | m_PrefabInternal: {fileID: 0}
122 | m_GameObject: {fileID: 1199403797}
123 | m_Material: {fileID: 0}
124 | m_IsTrigger: 0
125 | m_Enabled: 1
126 | serializedVersion: 2
127 | m_SmoothSphereCollisions: 0
128 | m_Convex: 0
129 | m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0}
130 | --- !u!33 &1199403800
131 | MeshFilter:
132 | m_ObjectHideFlags: 0
133 | m_PrefabParentObject: {fileID: 0}
134 | m_PrefabInternal: {fileID: 0}
135 | m_GameObject: {fileID: 1199403797}
136 | m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0}
137 | --- !u!4 &1199403801
138 | Transform:
139 | m_ObjectHideFlags: 0
140 | m_PrefabParentObject: {fileID: 0}
141 | m_PrefabInternal: {fileID: 0}
142 | m_GameObject: {fileID: 1199403797}
143 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
144 | m_LocalPosition: {x: 0, y: 0, z: 0}
145 | m_LocalScale: {x: 1, y: 1, z: 1}
146 | m_Children: []
147 | m_Father: {fileID: 0}
148 | --- !u!114 &1199403802
149 | MonoBehaviour:
150 | m_ObjectHideFlags: 0
151 | m_PrefabParentObject: {fileID: 0}
152 | m_PrefabInternal: {fileID: 0}
153 | m_GameObject: {fileID: 1199403797}
154 | m_Enabled: 1
155 | m_EditorHideFlags: 0
156 | m_Script: {fileID: 11500000, guid: 214ca269bd9fc354aab11060950e6476, type: 3}
157 | m_Name:
158 | m_EditorClassIdentifier:
159 | --- !u!1 &1913734782
160 | GameObject:
161 | m_ObjectHideFlags: 0
162 | m_PrefabParentObject: {fileID: 0}
163 | m_PrefabInternal: {fileID: 0}
164 | serializedVersion: 4
165 | m_Component:
166 | - 4: {fileID: 1913734787}
167 | - 20: {fileID: 1913734786}
168 | - 92: {fileID: 1913734785}
169 | - 124: {fileID: 1913734784}
170 | - 81: {fileID: 1913734783}
171 | m_Layer: 0
172 | m_Name: Main Camera
173 | m_TagString: MainCamera
174 | m_Icon: {fileID: 0}
175 | m_NavMeshLayer: 0
176 | m_StaticEditorFlags: 0
177 | m_IsActive: 1
178 | --- !u!81 &1913734783
179 | AudioListener:
180 | m_ObjectHideFlags: 0
181 | m_PrefabParentObject: {fileID: 0}
182 | m_PrefabInternal: {fileID: 0}
183 | m_GameObject: {fileID: 1913734782}
184 | m_Enabled: 1
185 | --- !u!124 &1913734784
186 | Behaviour:
187 | m_ObjectHideFlags: 0
188 | m_PrefabParentObject: {fileID: 0}
189 | m_PrefabInternal: {fileID: 0}
190 | m_GameObject: {fileID: 1913734782}
191 | m_Enabled: 1
192 | --- !u!92 &1913734785
193 | Behaviour:
194 | m_ObjectHideFlags: 0
195 | m_PrefabParentObject: {fileID: 0}
196 | m_PrefabInternal: {fileID: 0}
197 | m_GameObject: {fileID: 1913734782}
198 | m_Enabled: 1
199 | --- !u!20 &1913734786
200 | Camera:
201 | m_ObjectHideFlags: 0
202 | m_PrefabParentObject: {fileID: 0}
203 | m_PrefabInternal: {fileID: 0}
204 | m_GameObject: {fileID: 1913734782}
205 | m_Enabled: 1
206 | serializedVersion: 2
207 | m_ClearFlags: 1
208 | m_BackGroundColor: {r: .192156866, g: .301960796, b: .474509805, a: .0196078438}
209 | m_NormalizedViewPortRect:
210 | serializedVersion: 2
211 | x: 0
212 | y: 0
213 | width: 1
214 | height: 1
215 | near clip plane: .300000012
216 | far clip plane: 1000
217 | field of view: 60
218 | orthographic: 1
219 | orthographic size: 1
220 | m_Depth: -1
221 | m_CullingMask:
222 | serializedVersion: 2
223 | m_Bits: 4294967295
224 | m_RenderingPath: -1
225 | m_TargetTexture: {fileID: 0}
226 | m_HDR: 0
227 | m_OcclusionCulling: 1
228 | --- !u!4 &1913734787
229 | Transform:
230 | m_ObjectHideFlags: 0
231 | m_PrefabParentObject: {fileID: 0}
232 | m_PrefabInternal: {fileID: 0}
233 | m_GameObject: {fileID: 1913734782}
234 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
235 | m_LocalPosition: {x: 0, y: 0, z: -10}
236 | m_LocalScale: {x: 1, y: 1, z: 1}
237 | m_Children: []
238 | m_Father: {fileID: 0}
239 |
--------------------------------------------------------------------------------
/Assets/BitmapDrawing.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using UnityEngine;
3 | using System.Collections.Generic;
4 |
5 | /**
6 | The MIT License (MIT)
7 | Copyright (c) 2014 Lauri Hosio
8 |
9 | Permission is hereby granted, free of charge, to any person obtaining a copy
10 | of this software and associated documentation files (the "Software"), to deal
11 | in the Software without restriction, including without limitation the rights
12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | copies of the Software, and to permit persons to whom the Software is
14 | furnished to do so, subject to the following conditions:
15 |
16 | The above copyright notice and this permission notice shall be included in all
17 | copies or substantial portions of the Software.
18 |
19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | SOFTWARE.
26 | */
27 |
28 | namespace ProtoTurtle.BitmapDrawing
29 | {
30 | ///
31 | /// A extension class for UnityEngine.Texture2D that provides a bitmap drawing API.
32 | /// Provides drawing methods line Line, Circle, Rectangle etc.
33 | /// This class uses a convention of having the 0,0 point at the left-top corner!
34 | ///
35 | /// Check this out for more cool middleware stuff:
36 | /// http://prototurtle.com
37 | ///
38 | ///
39 | public static class BitmapDrawingExtensions
40 | {
41 |
42 |
43 | ///
44 | /// Draws a pixel just like SetPixel except 0,0 is the left top corner.
45 | public static void DrawPixel(this Texture2D texture, int x, int y, Color color)
46 | {
47 | if (x < 0 || x > texture.width || y < 0 || y > texture.height)
48 | {
49 | return;
50 | }
51 | texture.SetPixel(x, TransformToLeftTop_y(y, texture.height), color);
52 | }
53 |
54 | ///
55 | /// Draws a pixel just like SetPixel except 0,0 is the left top corner.
56 | /// Takes the width and height as parameters - faster for calling this in a loop.
57 | ///
58 | /// Width of the target bitmap
59 | /// Height of the target bitmap
60 | public static void DrawPixel(this Texture2D texture, int x, int y, int width, int height, Color color)
61 | {
62 | if (x < 0 || x > width || y < 0 || y > height)
63 | {
64 | return;
65 | }
66 | texture.SetPixel(x, TransformToLeftTop_y(y, height), color);
67 | }
68 |
69 | ///
70 | /// Draws a circle with the midpoint being x0, x1.
71 | /// Implementation of Bresenham's circle algorithm
72 | ///
73 | public static void DrawCircle(this Texture2D texture, int x, int y, int radius, Color color)
74 | {
75 | Circle(texture, x, y, radius, color, false);
76 | }
77 |
78 | ///
79 | /// Draws a filled circle with the midpoint being x0, x1.
80 | /// Implementation of Bresenham's circle algorithm
81 | ///
82 | public static void DrawFilledCircle(this Texture2D texture, int x, int y, int radius, Color color)
83 | {
84 | Circle(texture, x, y, radius, color, true);
85 | }
86 |
87 |
88 | private static void Circle(Texture2D texture, int x, int y, int radius, Color color, bool filled = false)
89 | {
90 | int cx = radius;
91 | int cy = 0;
92 | int radiusError = 1 - cx;
93 |
94 | while (cx >= cy)
95 | {
96 | if (!filled)
97 | {
98 | PlotCircle(texture, cx, x, cy, y, color);
99 | }
100 | else
101 | {
102 | ScanLineCircle(texture, cx, x, cy, y, color);
103 | }
104 |
105 | cy++;
106 |
107 | if (radiusError < 0)
108 | {
109 | radiusError += 2 * cy + 1;
110 | }
111 | else
112 | {
113 | cx--;
114 | radiusError += 2 * (cy - cx + 1);
115 | }
116 | }
117 | }
118 |
119 | private static void PlotCircle(Texture2D texture, int cx, int x, int cy, int y, Color color)
120 | {
121 | texture.DrawPixel(cx + x, cy + y, color); // Point in octant 1...
122 | texture.DrawPixel(cy + x, cx + y, color);
123 | texture.DrawPixel(-cx + x, cy + y, color);
124 | texture.DrawPixel(-cy + x, cx + y, color);
125 | texture.DrawPixel(-cx + x, -cy + y, color);
126 | texture.DrawPixel(-cy + x, -cx + y, color);
127 | texture.DrawPixel(cx + x, -cy + y, color);
128 | texture.DrawPixel(cy + x, -cx + y, color); // ... point in octant 8
129 | }
130 |
131 | // Draw scanlines from opposite sides of the circle on y-scanlines instead of just plotting pixels
132 | // at the right coordinates
133 | private static void ScanLineCircle(Texture2D texture, int cx, int x, int cy, int y, Color color)
134 | {
135 | //texture.DrawPixel(cx + x, cy + y, color);
136 | //texture.DrawPixel(-cx + x, cy + y, color);
137 | texture.DrawLine(cx + x, cy + y, -cx + x, cy + y, color);
138 |
139 | //texture.DrawPixel(cy + x, cx + y, color);
140 | //texture.DrawPixel(-cy + x, cx + y, color);
141 | texture.DrawLine(cy + x, cx + y, -cy + x, cx + y, color);
142 |
143 | //texture.DrawPixel(-cx + x, -cy + y, color);
144 | //texture.DrawPixel(cx + x, -cy + y, color);
145 | texture.DrawLine(-cx + x, -cy + y, cx + x, -cy + y, color);
146 |
147 | //texture.DrawPixel(-cy + x, -cx + y, color);
148 | //texture.DrawPixel(cy + x, -cx + y, color);
149 | texture.DrawLine(-cy + x, -cx + y, cy + x, -cx + y, color);
150 | }
151 |
152 |
153 | ///
154 | /// Starts a flood fill at point startX, startY.
155 | /// This is a pretty slow flood fill, biggest bottle neck is comparing two colors which happens
156 | /// a lot. Should be a way to make it much faster.
157 | /// O(n) space. n = width*height - makes a copy of the bitmap temporarily in the memory
158 | ///
159 | ///
160 | ///
161 | ///
162 | ///
163 | public static void FloodFill(this Texture2D texture, int startX, int startY, Color newColor)
164 | {
165 | Point start = new Point(startX, TransformToLeftTop_y(startY, texture.height));
166 |
167 | Flat2DArray copyBmp = new Flat2DArray(texture.height, texture.width, texture.GetPixels());
168 |
169 | Color originalColor = texture.GetPixel(start.X, start.Y);
170 | int width = texture.width;
171 | int height = texture.height;
172 |
173 |
174 | if (originalColor == newColor)
175 | {
176 | return;
177 | }
178 |
179 | copyBmp[start.X, start.Y] = newColor;
180 |
181 | Queue openNodes = new Queue();
182 | openNodes.Enqueue(start);
183 |
184 | int i = 0;
185 |
186 | // TODO: remove this
187 | // emergency switch so it doesn't hang if something goes wrong
188 | int emergency = width*height;
189 |
190 | while (openNodes.Count > 0)
191 | {
192 | i++;
193 |
194 | if (i > emergency)
195 | {
196 | return;
197 | }
198 |
199 | Point current = openNodes.Dequeue();
200 | int x = current.X;
201 | int y = current.Y;
202 |
203 | if (x > 0)
204 | {
205 | if (copyBmp[x - 1, y] == originalColor)
206 | {
207 | copyBmp[x - 1, y] = newColor;
208 | openNodes.Enqueue(new Point(x - 1, y));
209 | }
210 | }
211 | if (x < width - 1)
212 | {
213 | if (copyBmp[x + 1, y] == originalColor)
214 | {
215 | copyBmp[x + 1, y] = newColor;
216 | openNodes.Enqueue(new Point(x + 1, y));
217 | }
218 | }
219 | if (y > 0)
220 | {
221 | if (copyBmp[x, y - 1] == originalColor)
222 | {
223 | copyBmp[x, y - 1] = newColor;
224 | openNodes.Enqueue(new Point(x, y - 1));
225 | }
226 | }
227 | if (y < height - 1)
228 | {
229 | if (copyBmp[x, y + 1] == originalColor)
230 | {
231 | copyBmp[x, y + 1] = newColor;
232 | openNodes.Enqueue(new Point(x, y + 1));
233 | }
234 | }
235 | }
236 |
237 | texture.SetPixels(copyBmp.data);
238 | }
239 |
240 | // Could be its own file
241 | private class Flat2DArray
242 | {
243 | public Color[] data;
244 | private readonly int height;
245 | private readonly int width;
246 |
247 | public Flat2DArray(int height, int width, Color[] data)
248 | {
249 | this.height = height;
250 | this.width = width;
251 |
252 | this.data = data;
253 | }
254 |
255 | public Color this[int x, int y]
256 | {
257 | get
258 | {
259 | return data[x + y * width];
260 | }
261 | set
262 | {
263 | data[x + y * width] = value;
264 | }
265 | }
266 | }
267 |
268 | private struct Point
269 | {
270 | public int X;
271 | public int Y;
272 |
273 | public Point(int x, int y)
274 | {
275 | this.X = x;
276 | this.Y = y;
277 | }
278 | }
279 |
280 | ///
281 | /// Draws a rectangle
282 | ///
283 | public static void DrawRectangle(this Texture2D texture, Rect rectangle, Color color)
284 | {
285 | int x = (int)rectangle.x;
286 | int y = (int)rectangle.y;
287 | int height = (int)rectangle.height;
288 | int width = (int)rectangle.width;
289 |
290 |
291 | // top left to bottom left
292 | texture.DrawLine(x, y, x, y + height, color);
293 |
294 | // bottom left to bottom right
295 | texture.DrawLine(x, y + height, x + width, y + height, color);
296 |
297 | // bottom right to top right
298 | texture.DrawLine(x + width, y + height, x + width, y, color);
299 |
300 | // top right to top left
301 | texture.DrawLine(x + width, y, x, y, color);
302 |
303 | }
304 |
305 | ///
306 | /// Fills the given rectangle area with a solid color.
307 | public static void DrawFilledRectangle(this Texture2D texture, Rect rectangle, Color color)
308 | {
309 | Color[] colorsArray = new Color[(int)rectangle.width * (int)rectangle.height];
310 | for (int i = 0; i < colorsArray.Length; i++)
311 | {
312 | colorsArray[i] = color;
313 | }
314 |
315 | int transformedY = TransformToLeftTop_y(rectangle.y, texture.height) - (int)rectangle.height;
316 | texture.SetPixels((int)rectangle.x, transformedY,
317 | (int)rectangle.width, (int)rectangle.height, colorsArray);
318 | }
319 |
320 |
321 |
322 | public static void DrawLine(this Texture2D texture, Vector3 start, Vector3 end, Color color)
323 | {
324 | Line(texture, (int)start.x, (int)start.y, (int)end.x, (int)end.y, color);
325 | }
326 |
327 | public static void DrawLine(this Texture2D texture, Vector2 start, Vector2 end, Color color)
328 | {
329 | Line(texture, (int)start.x, (int)start.y, (int)end.x, (int)end.y, color);
330 | }
331 |
332 | ///
333 | /// Draws a line between two points. Implementation of Bresenham's line algorithm.
334 | ///
335 | /// x of the start point
336 | /// y of the start point
337 | /// x of the end point
338 | /// y of the end point
339 | public static void DrawLine(this Texture2D texture, int x0, int y0, int x1, int y1, Color color)
340 | {
341 | Line(texture, x0, y0, x1, y1, color);
342 | }
343 |
344 | private static void Line(Texture2D texture, int x0, int y0, int x1, int y1, Color color)
345 | {
346 | int width = texture.width;
347 | int height = texture.height;
348 |
349 | bool isSteep = Math.Abs(y1 - y0) > Math.Abs(x1 - x0);
350 | if (isSteep)
351 | {
352 | Swap(ref x0, ref y0);
353 | Swap(ref x1, ref y1);
354 | }
355 | if (x0 > x1)
356 | {
357 | Swap(ref x0, ref x1);
358 | Swap(ref y0, ref y1);
359 | }
360 |
361 | int deltax = x1 - x0;
362 | int deltay = Math.Abs(y1 - y0);
363 |
364 | int error = deltax / 2;
365 | int ystep;
366 | int y = y0;
367 |
368 | if (y0 < y1)
369 | ystep = 1;
370 | else
371 | ystep = -1;
372 |
373 | for (int x = x0; x < x1; x++)
374 | {
375 | if (isSteep)
376 | texture.DrawPixel(y, x, width, height, color);
377 | else
378 | texture.DrawPixel(x, y, width, height, color);
379 |
380 | error = error - deltay;
381 | if (error < 0)
382 | {
383 | y = y + ystep;
384 | error = error + deltax;
385 | }
386 | }
387 | }
388 |
389 |
390 | ///
391 | /// Swap two ints by reference.
392 | ///
393 | private static void Swap(ref int x, ref int y)
394 | {
395 | int temp = x;
396 | x = y;
397 | y = temp;
398 | }
399 |
400 | ///
401 | /// Transforms a point in the texture plane so that 0,0 points at left-top corner.
402 | private static int TransformToLeftTop_y(int y, int height)
403 | {
404 | return height - y;
405 | }
406 |
407 | ///
408 | /// Transforms a point in the texture plane so that 0,0 points at left-top corner.
409 | private static int TransformToLeftTop_y(float y, int height)
410 | {
411 | return height - (int)y;
412 | }
413 |
414 | }
415 |
416 |
417 | }
418 |
--------------------------------------------------------------------------------