Skip to content

Commit 03d3228

Browse files
committed
-Global position is dynamic now.
-Added camera controller. Now we need to get index position out of it.
1 parent 306904b commit 03d3228

File tree

9 files changed

+407
-94
lines changed

9 files changed

+407
-94
lines changed

Assets/Materials/Obstacle.mat

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!21 &2100000
4+
Material:
5+
serializedVersion: 6
6+
m_ObjectHideFlags: 0
7+
m_CorrespondingSourceObject: {fileID: 0}
8+
m_PrefabInstance: {fileID: 0}
9+
m_PrefabAsset: {fileID: 0}
10+
m_Name: Obstacle
11+
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
12+
m_ShaderKeywords:
13+
m_LightmapFlags: 4
14+
m_EnableInstancingVariants: 0
15+
m_DoubleSidedGI: 0
16+
m_CustomRenderQueue: -1
17+
stringTagMap: {}
18+
disabledShaderPasses: []
19+
m_SavedProperties:
20+
serializedVersion: 3
21+
m_TexEnvs:
22+
- _BumpMap:
23+
m_Texture: {fileID: 0}
24+
m_Scale: {x: 1, y: 1}
25+
m_Offset: {x: 0, y: 0}
26+
- _DetailAlbedoMap:
27+
m_Texture: {fileID: 0}
28+
m_Scale: {x: 1, y: 1}
29+
m_Offset: {x: 0, y: 0}
30+
- _DetailMask:
31+
m_Texture: {fileID: 0}
32+
m_Scale: {x: 1, y: 1}
33+
m_Offset: {x: 0, y: 0}
34+
- _DetailNormalMap:
35+
m_Texture: {fileID: 0}
36+
m_Scale: {x: 1, y: 1}
37+
m_Offset: {x: 0, y: 0}
38+
- _EmissionMap:
39+
m_Texture: {fileID: 0}
40+
m_Scale: {x: 1, y: 1}
41+
m_Offset: {x: 0, y: 0}
42+
- _MainTex:
43+
m_Texture: {fileID: 0}
44+
m_Scale: {x: 1, y: 1}
45+
m_Offset: {x: 0, y: 0}
46+
- _MetallicGlossMap:
47+
m_Texture: {fileID: 0}
48+
m_Scale: {x: 1, y: 1}
49+
m_Offset: {x: 0, y: 0}
50+
- _OcclusionMap:
51+
m_Texture: {fileID: 0}
52+
m_Scale: {x: 1, y: 1}
53+
m_Offset: {x: 0, y: 0}
54+
- _ParallaxMap:
55+
m_Texture: {fileID: 0}
56+
m_Scale: {x: 1, y: 1}
57+
m_Offset: {x: 0, y: 0}
58+
m_Floats:
59+
- _BumpScale: 1
60+
- _Cutoff: 0.5
61+
- _DetailNormalMapScale: 1
62+
- _DstBlend: 0
63+
- _GlossMapScale: 1
64+
- _Glossiness: 0.5
65+
- _GlossyReflections: 1
66+
- _Metallic: 0
67+
- _Mode: 0
68+
- _OcclusionStrength: 1
69+
- _Parallax: 0.02
70+
- _SmoothnessTextureChannel: 0
71+
- _SpecularHighlights: 1
72+
- _SrcBlend: 1
73+
- _UVSec: 0
74+
- _ZWrite: 1
75+
m_Colors:
76+
- _Color: {r: 1, g: 1, b: 1, a: 1}
77+
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}

Assets/Materials/Obstacle.mat.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Materials/Target.mat

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!21 &2100000
4+
Material:
5+
serializedVersion: 6
6+
m_ObjectHideFlags: 0
7+
m_CorrespondingSourceObject: {fileID: 0}
8+
m_PrefabInstance: {fileID: 0}
9+
m_PrefabAsset: {fileID: 0}
10+
m_Name: Target
11+
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
12+
m_ShaderKeywords:
13+
m_LightmapFlags: 4
14+
m_EnableInstancingVariants: 0
15+
m_DoubleSidedGI: 0
16+
m_CustomRenderQueue: -1
17+
stringTagMap: {}
18+
disabledShaderPasses: []
19+
m_SavedProperties:
20+
serializedVersion: 3
21+
m_TexEnvs:
22+
- _BumpMap:
23+
m_Texture: {fileID: 0}
24+
m_Scale: {x: 1, y: 1}
25+
m_Offset: {x: 0, y: 0}
26+
- _DetailAlbedoMap:
27+
m_Texture: {fileID: 0}
28+
m_Scale: {x: 1, y: 1}
29+
m_Offset: {x: 0, y: 0}
30+
- _DetailMask:
31+
m_Texture: {fileID: 0}
32+
m_Scale: {x: 1, y: 1}
33+
m_Offset: {x: 0, y: 0}
34+
- _DetailNormalMap:
35+
m_Texture: {fileID: 0}
36+
m_Scale: {x: 1, y: 1}
37+
m_Offset: {x: 0, y: 0}
38+
- _EmissionMap:
39+
m_Texture: {fileID: 0}
40+
m_Scale: {x: 1, y: 1}
41+
m_Offset: {x: 0, y: 0}
42+
- _MainTex:
43+
m_Texture: {fileID: 0}
44+
m_Scale: {x: 1, y: 1}
45+
m_Offset: {x: 0, y: 0}
46+
- _MetallicGlossMap:
47+
m_Texture: {fileID: 0}
48+
m_Scale: {x: 1, y: 1}
49+
m_Offset: {x: 0, y: 0}
50+
- _OcclusionMap:
51+
m_Texture: {fileID: 0}
52+
m_Scale: {x: 1, y: 1}
53+
m_Offset: {x: 0, y: 0}
54+
- _ParallaxMap:
55+
m_Texture: {fileID: 0}
56+
m_Scale: {x: 1, y: 1}
57+
m_Offset: {x: 0, y: 0}
58+
m_Floats:
59+
- _BumpScale: 1
60+
- _Cutoff: 0.5
61+
- _DetailNormalMapScale: 1
62+
- _DstBlend: 0
63+
- _GlossMapScale: 1
64+
- _Glossiness: 0.5
65+
- _GlossyReflections: 1
66+
- _Metallic: 0
67+
- _Mode: 0
68+
- _OcclusionStrength: 1
69+
- _Parallax: 0.02
70+
- _SmoothnessTextureChannel: 0
71+
- _SpecularHighlights: 1
72+
- _SrcBlend: 1
73+
- _UVSec: 0
74+
- _ZWrite: 1
75+
m_Colors:
76+
- _Color: {r: 1, g: 1, b: 1, a: 1}
77+
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}

Assets/Materials/Target.mat.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Scripts/CameraController.cs

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using UnityEngine;
5+
6+
public class CameraController : MonoBehaviour
7+
{
8+
new private Camera camera;
9+
public Vector3 localPos = new Vector3(0, 10, 0);
10+
public int thickness = 5;
11+
public float panSpeed = 10f;
12+
13+
public enum CameraFSM
14+
{
15+
clickOrDrag,
16+
clickSelect,
17+
clickDeselect
18+
}
19+
20+
public CameraFSM cameraFSM;
21+
public bool canMove;
22+
23+
// Start is called before the first frame update
24+
void Start()
25+
{
26+
camera = Camera.main;
27+
}
28+
29+
// Update is called once per frame
30+
void Update()
31+
{
32+
if (canMove == false)
33+
return;
34+
CameraPositionUpdate();
35+
CameraStateMachine();
36+
}
37+
38+
private void CameraStateMachine()
39+
{
40+
switch (cameraFSM)
41+
{
42+
case CameraFSM.clickOrDrag:
43+
ClickOrDrag();
44+
break;
45+
case CameraFSM.clickSelect:
46+
ClickSelect();
47+
break;
48+
case CameraFSM.clickDeselect:
49+
ClickDeselect();
50+
break;
51+
default:
52+
break;
53+
}
54+
}
55+
56+
private void ClickDeselect()
57+
{
58+
59+
}
60+
61+
private void ClickSelect()
62+
{
63+
64+
}
65+
66+
private void ClickOrDrag()
67+
{
68+
69+
}
70+
71+
private void CameraPositionUpdate()
72+
{
73+
Vector3 cameraLocalPos = localPos, pos = transform.position;
74+
camera.transform.localPosition = cameraLocalPos;
75+
if (Input.GetKey(KeyCode.D) || Input.mousePosition.x >= Screen.width - thickness)
76+
{
77+
pos.x += panSpeed * Time.deltaTime;
78+
}
79+
if (Input.GetKey(KeyCode.A) || Input.mousePosition.x <= thickness)
80+
{
81+
pos.x -= panSpeed * Time.deltaTime;
82+
}
83+
84+
if (Input.GetKey(KeyCode.W) || Input.mousePosition.y >= Screen.height - thickness)
85+
{
86+
pos.z += panSpeed * Time.deltaTime;
87+
}
88+
if (Input.GetKey(KeyCode.S) || Input.mousePosition.y <= thickness)
89+
{
90+
pos.z -= panSpeed * Time.deltaTime;
91+
}
92+
transform.position = pos;
93+
}
94+
}

Assets/Scripts/CameraController.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Scripts/Pathfinder.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,51 @@ public class Pathfinder : MonoBehaviour
88
public Vector2Int index;
99
public Transform target;
1010
public bool pathFind = true;
11+
public GameObject[] obstacles;
1112

1213
// Start is called before the first frame update
1314
void Start()
1415
{
1516
// Just generating grid at start.
16-
grid.GenerateTiles(grid.GetOrigin());
17+
grid.origin = Vector3.zero;
18+
grid.GenerateTiles();
1719
}
1820

1921
// Update is called once per frame
2022
void Update()
2123
{
24+
foreach (var o in obstacles)
25+
{
26+
Vector2Int index = grid.GetIndexFromGridPosition(o.transform.position);
27+
var neighbors = grid.GetNeightborAStar(index);
28+
29+
foreach (var n in neighbors)
30+
{
31+
if (n.distance == -2)
32+
continue;
33+
n.distance = -1;
34+
}
35+
36+
grid.tiles[index.x, index.y].distance = -2;
37+
}
38+
2239
grid.UpdateFlowField(target.position);
2340
index = grid.GetIndexFromGridPosition(transform.position);
41+
2442
if (pathFind == true)
2543
{
2644
pathFind = false;
2745
}
2846
}
2947

48+
public Vector3 FollowToPath(Vector3 pos)
49+
{
50+
Vector2Int unitIndex = grid.GetIndexFromGridPosition(pos);
51+
//Vector2Int targetIndex = grid.GetIndexFromGridPosition(target.position);
52+
53+
return grid.tiles[unitIndex.x, unitIndex.y].direction;
54+
}
55+
3056
private void OnDrawGizmos()
3157
{
3258
if (Application.isPlaying)

0 commit comments

Comments
 (0)