2020년 1월 29일 수요일

Unity 치명적인 버그 (FPS 관련)

게임 tab을 두개 키면

에디터 모드에서 프레임이 비정상 적으로 빨라진다!!!!!!

검색해도 안나와서 식겁햇네...

2020년 1월 27일 월요일

Button Listner 저장하기

UnityEngine.Events.UnityAction Event_Save;


Event_Save= new UnityEngine.Events.UnityAction(() => Function());

이런식으로 저장해서



onClick.RemoveAllListeners();

onClick.AddListener(() => Event_Save()

이런식으로 사용가능

중복제거 랜덤

public int[] GetRandomIntInstant(int length, int min, int max)
    {
        int[] randArray = new int[length];
        bool isSame;

        for (int i = 0; i < length; i++)
        {
            while (true)
            {
                randArray[i] = UnityEngine.Random.Range(min, max);
                isSame = false;

                for(int j=0;j<i;++j)
                {
                    if (randArray[j] == randArray[i])
                    {
                        isSame = true;
                        break;
                    }
                }
                if (!isSame) break;
            }
        }
        return randArray;
    }

2020년 1월 25일 토요일

Distance measured showing negative values.

  1. var ai : Transform ;
  2. function Update(){
  3. var relativePos = transform.InverseTransformPoint(ai.position) ;
  4. if(relativePos.z > 0)
  5. print("ai in front with positive distance stuff") ;
  6. else
  7. print("ai in back with negative distance stuff") ;
  8. }

2020년 1월 11일 토요일

Apache 도움말

관리자 명령 프롬프트창에
httpd -k install이라고 입력해서 아파치 설치

httpd - k start라고 입력해서 아파치 서비스 시작하고

확인은 http://127.0.0.1이라고 입력해서




이렇게 나오면 성공한것!



아파치 서비스 종료 : httpd -k stop
아파치 서비스 재시작은 httpd.exe - k restart
아파치 서비스 제거는 httpd.exe -k uninstall 혹은
httpd.exe -k uninstall -n APM_Apache2 처럼 서비스 이름을 같이 적으면 된다

phpmyadmin 으로 나중에 연결해야함

https://abc0123.tistory.com/167

일단 로컬에서는 테스트 완료햇음

저걸써서 하거나 클라우드로 하거나 정하자


2020년 1월 10일 금요일

Unity 멀티터치 줌인아웃 ,이동 ,구역제한

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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TouchMoveCam : MonoBehaviour
{
    // Start is called before the first frame update
    public float perspectiveZoomSpeed = 0.5f;        // The rate of change of the field of view in perspective mode.
    public float orthoZoomSpeed = 0.5f;
    public Camera camera;
    public float movespeed = 2f;
    Vector2 prevPos = Vector2.zero;
    public float minPosX = -10;
    public float maxPosX = 10;
    public float minPosZ = -10;
    public float maxPosZ = 10;
    //영역제한용
    public float xOffset; 
    public float yOffset;
    public float ZoomInMin;
    public float ZoomInMax;
    public bool showGizmo = true;
    bool isLimited;
    float fv;
    void Start()
    {
        Screen.orientation = ScreenOrientation.Portrait;
        camera.orthographicSize = ZoomInMax;
    }
    public void SpeedChangeZoomPer()
    {
        movespeed = (ZoomInMax - camera.orthographicSize) * 1f+1000f;
    }
    void Update()
    {
        SpeedChangeZoomPer();
        
        if (Input.touchCount == 1)
        {
            Calculate(fv);
            if (prevPos == Vector2.zero)
            {
                prevPos = Input.GetTouch(0).position;
                
                return;
            }
            Vector2 dir = (Input.GetTouch(0).position - prevPos).normalized;
            Vector3 vec = new Vector3(dir.x, dir.y, 0);
            Vector3 tmp = camera.transform.position;
            tmp -= vec * movespeed * Time.deltaTime;
            Debug.Log("dir" + dir);
            switch (Input.GetTouch(0).phase)
            {
                case TouchPhase.Moved:
                    if (dir.x != 0)
                    {
                        if (maxPosX >= tmp.x && tmp.x >= minPosX)
                        {
                            camera.transform.position = tmp;
                        }
                        //좌우 움직임
                    }
                    if (dir.y != 0)
                    {
                        if (maxPosZ >= tmp.y && tmp.y >= minPosZ)
                        {
                            camera.transform.position = tmp;
                        }
                        //상하 움직임
                    }
                    break;
            }
            MoveLimit();
            prevPos = Input.GetTouch(0).position;
        }
        else if (Input.touchCount == 2)
        {
            // Store both touches.
            Touch touchZero = Input.GetTouch(0);
            Touch touchOne = Input.GetTouch(1);
            // Find the position in the previous frame of each touch.
            Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition;
            Vector2 touchOnePrevPos = touchOne.position - touchOne.deltaPosition;
            // Find the magnitude of the vector (the distance) between the touches in each frame.
            float prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude;
            float touchDeltaMag = (touchZero.position - touchOne.position).magnitude;
            // Find the difference in the distances between each frame.
            float deltaMagnitudeDiff = prevTouchDeltaMag - touchDeltaMag;
            
            // If the camera is orthographic...
            if (camera.orthographic)
            {
                float temp = camera.orthographicSize;
                temp += deltaMagnitudeDiff * orthoZoomSpeed;
                //camera.orthographicSize += deltaMagnitudeDiff * orthoZoomSpeed;
                //fv = Mathf.Max(camera.orthographicSize, 0.1f);
                fv = Mathf.Max(temp, 0.1f);
                Calculate(fv);
                MoveLimit();
                if (fv > ZoomInMax)
                {
                    camera.orthographicSize = ZoomInMax;
                }
                else if (ZoomInMin > fv)
                {
                    camera.orthographicSize = ZoomInMin;
                }
                else
                {
                    camera.orthographicSize = fv;
                }
                
            }
            else
            {
                // Otherwise change the field of view based on the change in distance between the touches.
                camera.fieldOfView += deltaMagnitudeDiff * perspectiveZoomSpeed;
                // Clamp the field of view to make sure it's between 0 and 180.
                camera.fieldOfView = Mathf.Clamp(camera.fieldOfView, 0.1f, 179.9f);
                fv = camera.fieldOfView;
            }
        }
    }
    void MoveLimit()
    {
        Vector2 temp;
        temp.x = Mathf.Clamp(camera.transform.position.x, minPosX, maxPosX);
        temp.y = Mathf.Clamp(camera.transform.position.y, minPosZ, maxPosZ);
        camera.transform.position = temp;
    }
    void OnDrawGizmos()
    {
        if (showGizmo)
        {
            
            Calculate(fv);
            Vector3 p1 = new Vector3(minPosX , maxPosZ , transform.position.z);
            Vector3 p2 = new Vector3(maxPosX , maxPosZ , transform.position.z);
            Vector3 p3 = new Vector3(maxPosX , minPosZ , transform.position.z);
            Vector3 p4 = new Vector3(minPosX , minPosZ , transform.position.z);
            
            //영역 테스트용
            Gizmos.color = Color.green;
            Gizmos.DrawLine(p1, p2);
            Gizmos.DrawLine(p2, p3);
            Gizmos.DrawLine(p3, p4);
            Gizmos.DrawLine(p4, p1);
        }
    }
    void Calculate(float size)
    {
        minPosX = -(ZoomInMax - camera.orthographicSize) / xOffset;
        maxPosX = (ZoomInMax - camera.orthographicSize) / xOffset;
        minPosZ = -(ZoomInMax - camera.orthographicSize) / yOffset;
        maxPosZ = (ZoomInMax - camera.orthographicSize) / yOffset;
    }
}
cs

해당코드를 사용하면 된다

기즈모로 영역 제한 offset값을 맞추고(손으로 직접..)
카메라에 붙여서 사용하면 됩니다!








2020년 1월 7일 화요일

유용한 unity관련 블로그

https://ssscool.tistory.com/343

무슨 채굴러 만드신분 같은데 엄청나게 실력자 느낌 뿜뿜임

ftp연결 관련 코드

ftp 연결 관련 코드

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
try
        {
            Uri ftpUrl = new Uri("ftp://" + path);
            FtpWebRequest reqFtp = (FtpWebRequest)WebRequest.Create(ftpUrl);
            reqFtp.Credentials = new NetworkCredential(user, pwd);
            reqFtp.Method = WebRequestMethods.Ftp.DownloadFile;
            reqFtp.KeepAlive = false;
            reqFtp.UseBinary = true;
            FtpWebResponse resFtp = (FtpWebResponse)reqFtp.GetResponse(); // Ftp 연결
            string localPath = Path.Combine(libraryPath, Path.GetFileName(path));
            Stream stream = resFtp.GetResponseStream();
            FileStream writeStream = new FileStream(localPath, FileMode.Create);
            int length = 2048;
            byte[] buffer = new byte[length];
            int bytesRead = stream.Read(buffer, 0, length);
            while (bytesRead > 0)
            {
                writeStream.Write(buffer, 0, bytesRead);
                bytesRead = stream.Read(buffer, 0, length);
            }
            stream.Close();
            writeStream.Close();
            reqFtp = null;
            resFtp = null;
            Debug.Log("Download Success : " + Path.GetFileName(path) + " Download Path : " + localPath);
            return true;
        }
        catch (Exception e)
        {
            Debug.Log(e.ToString());
            return false;
        }
cs

c# ftp 파일&디렉토리 리스트 얻기

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
//c# ftp 파일&디렉토리 리스트 얻기!!
 
    public void FTP_Connect(string path)
 
    {
 
        Uri ftpUri = new Uri(path);
 
        FtpWebRequest reqFtp = (FtpWebRequest)WebRequest.Create(ftpUri);
 
        reqFtp.Credentials = new NetworkCredential("hubiz""hubiz");
 
        reqFtp.Timeout = 10000;
 
        reqFtp.Method = WebRequestMethods.Ftp.ListDirectory;
 
 
 
 
 
        FtpWebResponse resFtp = (FtpWebResponse)reqFtp.GetResponse();
 
 
 
        StreamReader reader;
 
        reader = new StreamReader(resFtp.GetResponseStream(), System.Text.Encoding.Default);
 
 
 
 
 
        string strData;
 
        strData = reader.ReadToEnd();
 
 
 
        fileNames = strData.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
 
 
 
        resFtp.Close();
 
 
 
    }
cs

Dictionary 사용 예제(특정값 나눠서 넣기)

특정파일을 원하는 크기만큼 나누려고 한건가...기억이 안남

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
//int를 넣은만큼 나누기
 
    [SerializeField]
 
    public Dictionary<intList<string>> totaldivine = new Dictionary<intList<string>>();
 
 
 
    public void dic_divine(int value)
 
    {
 
        int divinevalue = value;
 
        int totalLen = 99;
 
        //divinevalue = totalLen / 10;
 
 
 
        int vvv = totalLen / value;
 
        int count = 0;
 
        for (int i = 0; i < totalLen; i+= vvv)
 
        {
 
            List<string> tmp = new List<string>();
 
 
 
            if ((i + vvv) < totalLen)
 
            {
 
                tmp = new List<string>();
 
                for (int j = i; j < i + vvv; j++)
 
                {
 
                    tmp.Add(j.ToString());
 
                }
 
            } else
 
            {
 
                tmp = new List<string>();
 
                for (int j = i; j < totalLen; j++)
 
                {
 
                    tmp.Add(j.ToString());
 
                }
 
            }
 
 
 
            totaldivine.Add(count, tmp);
 
            count++;
 
        }
 
     
 
        for (int i = 0; i < totaldivine.Count; i++)
 
        {
 
            for (int k = 0; k < totaldivine[i].Count; k++)
 
            {
 
                Debug.Log("totaldivine["+i+"]["+k+"]" + totaldivine[i][k]);
 
            }
 
        }
 
 
 
    }
cs

git rejected error(feat. cherry-pick)

 문제 아무 생각 없이 pull을 받지않고 로컬에서 작업! 커밋, 푸시 진행을 해버렷다. push에선 remote와 다르니 당연히 pull을 진행해라고 하지만 로컬에서 작업한 내용을 백업하지 않고 진행하기에는 부담스럽다(로컬작업 유실 가능성) 해결하려...