요약 정리 

클래스란 무엇인가?

클래스는 컴퓨터 메모리에 있는 객체를 사용할 수 있는 설계도라 생각할 수 있다.
클래스는 객체에 사용할 수 있는 데이터와 기능을 저장한다. 

클래스는 또한, 객체에 속하지 않는 클래스 자체에 속하는 데이터와 기능을 저장할 수 있다.
이는 주로 전역적으로 이용되는 기능을 제공할 때 사용된다. 


접근 한정자(public, private, protected, internal) ?

사진 출처 : https://edmundtips.tistory.com/12

monobehaviour 이란?

게임 오브젝트에 custom behaviour를 프로그래밍하기 위해서 사용된다.
.Net프레임워크의 다중 프레임워크 구현인 Mono프로젝트를 사용함. 
(그래서 이름이 Mono + Behaviour임.)


namespace 란?

코드를 위한 도메인이라고 생각하면 된다. 
namespace는 코드를 조직화하고 이름간의 중복 오류로 인한 충돌을 방지한다.

namespace를 사용하기 위해서 계속 앞에 붙이는 것이 번거롭기에
컴파일러에게 미리 namespace를 찾아두라고 말할 수 있다. 
코드의 맨 앞에 using namespace;의 형태로 사용한다. 


structure란?

structure는 class와 유사하게 설계도의 역할을 합니다. 
다만, class와는 다르게 객체를 생성하는 것이 아닌, 값(정수 혹은 색상)을 생성합니다. 
class와 정의하는 방법이 같습니다. 


const란?

수정하지 않을 값. 필드(객체에서 속성, 변수)일 필요가 없음.
컴파일할 때 계산된다. 숫자와 같은 기본 유형에서만 가능함. 


시계 코드 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System
using UnityEngine;
 
public class Clock : MonoBehaviour 
{
    public Transform hoursTransform, minutesTransform, secondsTransform;
    const float degreesPerHour = 30f;
    const float degreesPerMinute = 6f;
    const float degreesPerSecond = 6f;
 
    public bool Continous; 
 
    private void Update()
    {
        if (Continous)
        {
            ContinousTime();
        }
        else
            DiscreteTime();
    }
 
    //digital적으로 시계추 움직임 
    private void DiscreteTime()
    {
        //시간 데이터 받아오기 
        DateTime time = DateTime.Now;
        //회전 
        hoursTransform.localRotation = Quaternion.Euler(0f, time.Hour * degreesPerHour, 0f);
        minutesTransform.localRotation = Quaternion.Euler(0f, time.Minute * degreesPerMinute, 0f);
        secondsTransform.localRotation = Quaternion.Euler(0f, time.Second * degreesPerSecond, 0f);
    }
 
    //analog적으로 시계추 움직임 
    private void ContinousTime()
    {
        //시간 데이터 받아오기 
        TimeSpan time = DateTime.Now.TimeOfDay;
        //회전 
        hoursTransform.localRotation = Quaternion.Euler(0f, (float)time.TotalHours * degreesPerHour, 0f);
        minutesTransform.localRotation = Quaternion.Euler(0f, (float)time.TotalMinutes * degreesPerMinute, 0f);
        secondsTransform.localRotation = Quaternion.Euler(0f, (float)time.TotalSeconds * degreesPerSecond, 0f);
    }
}
cs

완성된 영상 


관련링크 
https://catlikecoding.com/unity/tutorials/basics/game-objects-and-scripts/


Posted by 도이(doi)
,

'Project > TouchMe' 카테고리의 다른 글

10/6 procedural grid, physics and soft body(nvidia flux)  (0) 2019.10.08
10/5 procedural Mesh  (0) 2019.10.05
04. 10/3 softBody effect  (0) 2019.10.04
03. 10/2 physics & leapmotion SDK  (0) 2019.10.02
02. 기술 기획  (0) 2019.10.02
Posted by 도이(doi)
,
1. Grid

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
[RequireComponent (typeof(MeshFilter), typeof(MeshRenderer))]
public class ProceduralGrid : MonoBehaviour
{
    Mesh mesh;
    Vector3[] vertices;
    int[] triangles;
 
    public float cellSize = 1.0f;
    public Vector3 gridOffset;
    public int gridSize;
 
    private void Awake()
    {
        //get mesh
        mesh = GetComponent<MeshFilter>().mesh;
    }
 
    void Start()
    {
        ContinousGridMesh();
        UpdateMesh();
    }
 
    void DiscreteGridMesh()
    {
        vertices = new Vector3[4*gridSize*gridSize];
        triangles = new int[6*gridSize*gridSize];
 
        float vertexOffset = cellSize * 0.5f;
 
        int v = 0;
        int t = 0;
 
        //create vertex grid and triangle 
        //cell을 하나하나 씩 그려준다고 생각하면 된다. 
        for(int x=0; x<gridSize; x++)
        {
            for(int y=0; y<gridSize; y++)
            {
                Vector3 cellOffset = new Vector3(cellSize * x, 0, cellSize * y);
 
                vertices[v] = new Vector3(-vertexOffset, x+y, -vertexOffset) + cellOffset + gridOffset;
                vertices[v+1= new Vector3(-vertexOffset, x+y, vertexOffset) + cellOffset + gridOffset;
                vertices[v+2= new Vector3(vertexOffset, x+y, -vertexOffset) + cellOffset + gridOffset;
                vertices[v+3= new Vector3(vertexOffset, x+y, vertexOffset) + cellOffset + gridOffset;
 
                triangles[t] = v;
                triangles[t + 1= triangles[t+4= v + 1;
                triangles[t + 2= triangles[t+3= v + 2;
                triangles[t + 5= v + 3;
 
                v += 4;
                t += 6;
            }
        }
    }
 
    void ContinousGridMesh()
    {
        vertices = new Vector3[(gridSize + 1* (gridSize + 1)];
        triangles = new int[6 * gridSize * gridSize];
 
        float vertexOffset = cellSize * 0.5f;
 
        int v = 0;
        int t = 0;
 
        //create vertex grid
        //연결된 vertices를 구하기 때문에 한 번에 구함 
        for (int x = 0; x <= gridSize; x++)
        {
            for (int y = 0; y <= gridSize; y++)
            {
                vertices[v] = new Vector3(((x * cellSize) - vertexOffset), (x+y)*0.2f, ((y*cellSize)-vertexOffset));
                v++;
            }
        }
 
        //reset v
        v = 0;
 
        //setting each cell's triangle
        //vertices의 순서가 전체적으로 순차적으로 진행되기 때문에 
        //cell의 윗 부분은 gridSize+1을 더해준 순서로 구해진.  
        for(int x=0; x<gridSize; x++)
        {
            for(int y=0; y< gridSize; y++)
            {
                triangles[t] = v;
                triangles[t + 1= triangles[t + 4= v + 1;
                triangles[t + 2= triangles[t + 3= v + (gridSize+1);
                triangles[t + 5= v + (gridSize+1)+1;
 
                v++;
                t += 6;
            }
            v++;
        }
    }
 
    void UpdateMesh()
    {
        mesh.Clear();
        mesh.vertices = vertices;
        mesh.triangles = triangles;
        mesh.RecalculateNormals();
    }
 
 
}
 
cs

2. soft Body

https://www.youtube.com/watch?v=TNAKv1dkYyQ


'Project > TouchMe' 카테고리의 다른 글

10/8 joint 안정화 작업  (0) 2019.10.09
10/5 procedural Mesh  (0) 2019.10.05
04. 10/3 softBody effect  (0) 2019.10.04
03. 10/2 physics & leapmotion SDK  (0) 2019.10.02
02. 기술 기획  (0) 2019.10.02
Posted by 도이(doi)
,

1. Quad 그리기

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
[RequireComponent(typeof(MeshFilter))]
public class proceduralMesh : MonoBehaviour
{
    Mesh mesh;
    Material material;
 
    Vector3[] vertices;
    int[] triangles;
 
 
    private void Awake()
    {
        mesh = GetComponent<MeshFilter>().mesh;
        material = GetComponent<Renderer>().material;
    }
    // Start is called before the first frame update
    void Start()
    {
        meshData();
        createObj();
    }
 
    void meshData()
    {
        //vertices, triangles베열에 값 넣기
        //vertices에서는 점의 위치를 설정
        vertices = new Vector3[] { new Vector3(000), new Vector3(001), new Vector3(100), new Vector3(1,0,1) };
        //triangles에서는 vertices를 어떻게 연결할지 정하기 
        triangles = new int[] { 012213 };
    }
 
    //obj 그리기 
    void createObj()
    {
        mesh.vertices = vertices;
        mesh.triangles = triangles;
        material.color = Color.green;
 
        //법선벡터 계산(라이팅)
        mesh.RecalculateNormals();
    }
 
    }
 
cs


'Project > TouchMe' 카테고리의 다른 글

10/8 joint 안정화 작업  (0) 2019.10.09
10/6 procedural grid, physics and soft body(nvidia flux)  (0) 2019.10.08
04. 10/3 softBody effect  (0) 2019.10.04
03. 10/2 physics & leapmotion SDK  (0) 2019.10.02
02. 기술 기획  (0) 2019.10.02
Posted by 도이(doi)
,