=FORMULATEXT()
반대의 경우는 준비된 함수가 없기 때문에
모듈을 새로 추가하여 아래와 같이 커스텀 함수를 만들어 준다.
Function Eval(Ref As String)
Application.Volatile
Eval = Evaluate(Ref)
End Function
추가 한 후 아래커스텀 함수를 사용하면 된다.
=Eval()
Function Eval(Ref As String)
Application.Volatile
Eval = Evaluate(Ref)
End Function
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Kpaper;
namespace Kpaper
{
public class InventorySystem : MonoBehaviour
{
#region Inventory
// 인벤토리 시스템 기초 구조만 담긴 코드
// _itemID 를 itemTable 에서 찾아서 정보를 표시하거나 하는 부분은 별도로 구현해야 한다.
// 아이템의 아이디 갯수 itemID, count
public Dictionary items = new Dictionary();
// items 에 입력한 아이템 ID와 카운트를 더해준다. (add 다. assign 아님)
public void setAddItem(int _itemID, int _count)
{
// 아이템이 목록에 없다면 넣어준다.(초기 갯수는 0개)
if (items.ContainsKey(_itemID) == false)
{
items.Add(_itemID, 0);
}
// 아이템 수량 증가 적용
items[_itemID] += _count;
if (Debug.isDebugBuild)
Debug.Log(string.Format("{0} {1}을 {2} 개", "아이템 삽입", _itemID, _count));
}
// items 에서 해당 아이템 키가 있는지 확인하고 있으면 카운트 만큼 빼준다. 카운트가 0인 경우에는 아이템 키를 제거해준다.
public void setRemoveItem(int _itemID, int _count)
{
// 아이템이 목록에 없다면 아무것도 하지 않는다.
if (items.ContainsKey(_itemID) == false)
{
if (Debug.isDebugBuild)
Debug.Log("아이템이 목록에 없습니다.");
return;
}
// 아이템 수량 감소 적용
items[_itemID] -= _count;
// 아이템 수를 감소 시켰더니 0개 이하이면 아이템을 사전 목록에서 제거한다.
if (items[_itemID] <= 0)
items.Remove(_itemID);
if (Debug.isDebugBuild)
Debug.Log(string.Format("{0} {1}을 {2} 개", "아이템 제거", _itemID, _count));
}
// 보유한 아이템 목록
public List keys = new List();
// 아이템 목록 새로 고침
public void setRefreshInventory()
{
if (Debug.isDebugBuild)
Debug.Log(items.Count + " 개의 아이템이 있습니다.");
// 딕셔너리의 키 묶음을 들고와서 Keys 리스트를 만든다.
keys = new List(items.Keys);
// Keys 리스트를 기준으로 아이템 ID와 수량을 출력한다.
for (int i = 0; i < keys.Count; i++)
{
int _itemID = keys[i];
int _itemCount = items[_itemID];
if (Debug.isDebugBuild)
Debug.Log("아이템 키 : " + _itemID + " 아이템 수량 : " + _itemCount); // 이 부분을 리스트로 만들어 쓰던가 하면 관리하기 편하다.
}
}
// 아이템 아이디를 입력하면 해당 아이템의 보유 수량을 리턴한다. 아이템을 찾을 수 없으면 0을 보낸다.
public int getItemCountByItemIndex(int _itemID)
{
if (items.ContainsKey(_itemID))
{
return items[_itemID];
}
else
{
Debug.Log(string.Format("인벤토리 안에서 찾을 수 없는 아이템ID {0} 를 요청했습니다.",_itemID));
return 0;
}
}
#endregion
#region MonoBehavior
private void Start()
{
// 시연
// 임의로 1이라는 itemID를 가진 아이템을 10개 넣고 5개씩 2번 빼서 0으로 만들어 본다.
// 인벤토리 리프레시
setRefreshInventory();
// 아이템 1을 10개 넣고
setAddItem(1, 10);
// 인벤토리 리프레시
setRefreshInventory();
// 아이템 갯수 찾기 테스트
Debug.Log(getItemCountByItemIndex(2));
// 1을 5개 제거
setRemoveItem(1, 5);
// 인벤토리 리프레시
setRefreshInventory();
// 1을 5개 제거
setRemoveItem(1, 5);
// 인벤토리 리프레시
setRefreshInventory();
}
#endregion
}
}
Function requestHTTP()
Dim PostData As String
Dim T As String
'Web에서 가져오기, 에러 발생하면 참조모듈 확인 (Microsoft WinHttpRequest 가 참조되어야 함)
Dim httpRequest As New WinHttpRequest
'아래에 넘길 포스트 데이터를 적는다.
PostData = "postData=_postData"
With httpRequest
.Open "POST", "http://오픈할 Open API 주소"
.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"
.Send PostData
.WaitForResponse: DoEvents
T = .ResponseText
End With
requestHTTP = T
End Function
public static Texture2D RotateImage(Texture2D originTexture, int angle)
{
Texture2D result;
result = new Texture2D(originTexture.width, originTexture.height);
Color32[] pix1 = result.GetPixels32();
Color32[] pix2 = originTexture.GetPixels32();
int W = originTexture.width;
int H = originTexture.height;
int x = 0;
int y = 0;
Color32[] pix3 = rotateSquare(pix2, (Math.PI / 180 * (double)angle), originTexture);
for (int j = 0; j < H; j++)
{
for (var i = 0; i < W; i++)
{
//pix1[result.width/2 - originTexture.width/2 + x + i + result.width*(result.height/2-originTexture.height/2+j+y)] = pix2[i + j*originTexture.width];
pix1[result.width / 2 - W / 2 + x + i + result.width * (result.height / 2 - H / 2 + j + y)] = pix3[i + j * W];
}
}
result.SetPixels32(pix1);
result.Apply();
return result;
}
static Color32[] rotateSquare(Color32[] arr, double phi, Texture2D originTexture)
{
int x;
int y;
int i;
int j;
double sn = Math.Sin(phi);
double cs = Math.Cos(phi);
Color32[] arr2 = originTexture.GetPixels32();
int W = originTexture.width;
int H = originTexture.height;
int xc = W / 2;
int yc = H / 2;
for (j = 0; j < H; j++)
{
for (i = 0; i < W; i++)
{
arr2[j * W + i] = new Color32(0, 0, 0, 0);
x = (int)(cs * (i - xc) + sn * (j - yc) + xc);
y = (int)(-sn * (i - xc) + cs * (j - yc) + yc);
if ((x > -1) && (x < W) && (y > -1) && (y < H))
{
arr2[j * W + i] = arr[y * W + x];
}
}
}
return arr2;
}
private Texture2D _texture2D;
private Texture _mainTexture;
private RenderTexture _renderTexture;
public Color32[] getTexture2D_AsPixel32()
{
if (_mainTexture == null)
_mainTexture = _liveCamera.OutputTexture;
if (_texture2D == null)
{
_texture2D = new Texture2D(_mainTexture.width, _mainTexture.height, TextureFormat.RGBA32, false);
}
//RenderTexture currentRT = RenderTexture.active;
if (_renderTexture == null)
_renderTexture = new RenderTexture(_mainTexture.width, _mainTexture.height, 32);
// mainTexture 의 픽셀 정보를 renderTexture 로 카피
Graphics.Blit(_mainTexture, _renderTexture);
// renderTexture 의 픽셀 정보를 근거로 texture2D 의 픽셀 정보를 작성
RenderTexture.active = _renderTexture;
_texture2D.ReadPixels(new Rect(0, 0, _renderTexture.width, _renderTexture.height), 0, 0);
_texture2D.Apply();
return _texture2D.GetPixels32();
}
// _width 는 가로 해상도, _height 는 세로 해상도 픽셀 값
public string getResolutionRatio(int _width, int _height)
{
int a;
int b;
// 화면의 가로/세로 중 긴 쪽을 앞으로 하기
if (_width < _height)
{
a = _width;
b = _height;
}
else
{
a = _height;
b = _width;
}
// 최대 공약수, 유클리드 호제법
int gcd = gcd3(a, b);
return string.Format("{0}:{1}", _width / gcd, _height / gcd);
}
private int gcd3(int a, int b)
{
return a % b == 0 ? b : gcd3(b, a % b);
}
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TimeServer : MonoBehaviour {
[SerializeField]
private string _comment = "만료시킬 날짜를 적으세요 (한국시각 기준)";
public int _yyyy, _mm, _dd;
private DateTime _expireDateTime, _nowServerDateTime, _nowLocalDateTime;
private TimeSpan _duration;
// Use this for initialization
void Start () {
// 한국 시각
_duration = System.TimeSpan.FromHours(9);
_expireDateTime = new DateTime(Mathf.Clamp(_yyyy, 1900, 3000), Mathf.Clamp(_mm, 1,12), Mathf.Clamp(_dd, 1, 31));
_nowLocalDateTime = DateTime.Now;
_nowServerDateTime = GetNISTDate().Add(_duration);
if (Debug.isDebugBuild)
{
Debug.LogWarning("만료지정일 : " + _expireDateTime);
Debug.LogWarning("현재 로컬 시각 :" + _nowLocalDateTime);
Debug.LogWarning("현재 서버 시각 :" + _nowServerDateTime);
}
if (_nowLocalDateTime < _expireDateTime)
{
if (_nowServerDateTime < _expireDateTime)
{
// Debug.Log("실행");
}
else
{
// Debug.Log("서버 체크 결과 만료 됨");
}
}
else
{
// Debug.Log("로컬 체크 결과 만료 됨");
}
}
#region NTPTIME
//NTP time 을 NIST 에서 가져오기
// 4초 이내에 한번 이상 요청 하면, ip가 차단됩니다.
public static DateTime GetDummyDate()
{
return new DateTime(2017, 12, 24); //to check if we have an online date or not.
}
public static DateTime GetNISTDate()
{
System.Random ran = new System.Random(DateTime.Now.Millisecond);
DateTime date = GetDummyDate();
string serverResponse = string.Empty;
// NIST 서버 목록
string[] servers = new string[] {
"time.bora.net",
//"time.nuri.net",
//"ntp.kornet.net",
//"time.kriss.re.kr",
//"time.nist.gov",
//"maths.kaist.ac.kr",
"nist1-ny.ustiming.org",
"time-a.nist.gov",
"nist1-chi.ustiming.org",
"time.nist.gov",
"ntp-nist.ldsbc.edu",
"nist1-la.ustiming.org"
};
// 너무 많은 요청으로 인한 차단을 피하기 위해 한 서버씩 순환한다. 5번만 시도한다.
for (int i = 0; i < 5; i++)
{
try
{
// StreamReader(무작위 서버)
StreamReader reader = new StreamReader(new System.Net.Sockets.TcpClient(servers[ran.Next(0, servers.Length)], 13).GetStream());
serverResponse = reader.ReadToEnd();
reader.Close();
// 서버 리스폰스를 표시한다. (디버그 확인용)
if (Debug.isDebugBuild)
Debug.Log(serverResponse);
// 시그니처가 있는지 확인한다.
if (serverResponse.Length > 47 && serverResponse.Substring(38, 9).Equals("UTC(NIST)"))
{
// 날짜 파싱
int jd = int.Parse(serverResponse.Substring(1, 5));
int yr = int.Parse(serverResponse.Substring(7, 2));
int mo = int.Parse(serverResponse.Substring(10, 2));
int dy = int.Parse(serverResponse.Substring(13, 2));
int hr = int.Parse(serverResponse.Substring(16, 2));
int mm = int.Parse(serverResponse.Substring(19, 2));
int sc = int.Parse(serverResponse.Substring(22, 2));
if (jd > 51544)
yr += 2000;
else
yr += 1999;
date = new DateTime(yr, mo, dy, hr, mm, sc);
// Exit the loop
break;
}
}
catch (Exception e)
{
/* 아무것도 하지 않고 다음 서버를 시도한다. */
}
}
return date;
}
#endregion
}
using UnityEngine;
using UnityEditor;
public class EditorGUILayoutToggle : UnityEditor.EditorWindow
{
bool showBtn = true;
[MenuItem("Examples/Editor GUILayout Toggle Usage")]
static void Init()
{
EditorGUILayoutToggle window = (EditorGUILayoutToggle)EditorWindow.GetWindow(typeof(EditorGUILayoutToggle), true, "My Empty Window");
window.Show();
}
void OnGUI()
{
showBtn = EditorGUILayout.Toggle("Show Button", showBtn);
if (showBtn)
if (GUILayout.Button("Close"))
this.Close();
}
}
input keyevent 4
//혹은
input keyevent 187
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
[InitializeOnLoad]
public class Startup
{
static Startup()
{
string VersionInfo = "1.0." + string.Format("{0:00}", System.DateTime.Now.Year).Substring(2, 2) + "." + string.Format("{0:00}", System.DateTime.Now.Month) + string.Format("{0:00}", System.DateTime.Now.Day);
System.IO.File.WriteAllText(Application.dataPath + "/Resources/AppVersionInfo.txt", VersionInfo.ToString());
Debug.LogWarning("오늘의 버전 정보 갱신 : " + VersionInfo + "\n저장 경로 : " +Application.dataPath+"/Resources/AppVersionInfo.txt");
}
}
public class BasicEntity
{
public int Index = 0;
public string Name = string.Empty;
public float Value = 0f;
}
// true 면 낮은 순부터 0 false 면 반대
public List<BasicEntity> sortFilterEntity(List<BasicEntity> list, bool order)
{
List<BasicEntity> result = list;
if (order)
{
result.Sort(delegate (BasicEntity A, BasicEntity B)
{
if (A.Index > B.Index) return 1;
else if (A.Index < B.Index) return -1;
return 0;
});
}
else
{
result.Sort(delegate (BasicEntity A, BasicEntity B)
{
if (A.Index > B.Index) return -1;
else if (A.Index < B.Index) return 1;
return 0;
});
}
for (int i = 0; i < result.Count; i++)
{
Debug.LogError(result[i].Name);
}
return result;
}