'전체보기'에 해당되는 글 1152건
- 2021.06.16 홈트레이닝 모음
- 2021.06.15 유니티 기즈모 (Gizmo) 관련코드
- 2021.06.12 Depth 쉐이더
- 2021.06.10 유니티 안드로이드 빌드관련 스크립트
- 2021.06.01 유니티 오디오 관련 코드
- 2021.05.19 블렌더 2.78 -> 2.8 변경점 모음
- 2021.05.16 오큘러스 함수들
- 2021.05.15 유니티 VR 세팅관련
구를그림
void OnDrawGizmos()
{
Gizmos.DrawWireSphere(transform.position, radius);
}
가려지지 않는 구를 그림
void OnDrawGizmos()
{
#if UNITY_EDITOR
UnityEditor.Handles.DrawWireDisc(transform.position, transform.up, radius);
UnityEditor.Handles.DrawWireDisc(transform.position, transform.right, radius);
UnityEditor.Handles.DrawWireDisc(transform.position, transform.forward, radius);
#endif
}
원을 그림
void OnDrawGizmos()
{
UnityEditor.Handles.DrawWireDisc(transforms[i].position, fowordAngle * Vector3.up, radius);
}
텍스트 표시
#if UNITY_EDITOR
void OnDrawGizmos()
{
UnityEditor.Handles.Label(transform.position, "text");
}
#endif
폰트설정한 텍스트 표시
var guiStyle = new GUIStyle();
guiStyle.alignment = TextAnchor.MiddleCenter; //왜인지 UpperLeft로만 된다
guiStyle.fontSize = 48;
guiStyle.normal.textColor = color;
UnityEditor.Handles.Label(transform.position, "text", guiStyle);
선그리기 커스텀
void DrawLine(params Transform[] transforms)
{
transforms = System.Array.FindAll(transforms, x => x != null);
if ((transforms == null) || (transforms.Length < 2))
{
return;
}
for (int i = 0; i < transforms.Length-1; i++)
{
Gizmos.DrawLine(transforms[i].position, transforms[i+1].position);
}
}
회전가능한 Cube
static void DrawWireCubeOverlay(Vector3 center, Vector3 size, Quaternion rotation)
{
#if UNITY_EDITOR
{
var size1 = size;
var size2 = size1;
for (int x = -1; x <= 1; x += 2)
{
for (int y = -1; y <= 1; y += 2)
{
size1.x = size.x * x;
size1.y = size.y * y;
size2 = size1;
size1.z = size.z;
size2.z = -size1.z;
DrawLine(size1, size2);
}
}
for (int y = -1; y <= 1; y += 2)
{
for (int z = -1; z <= 1; z += 2)
{
size1.y = size.y * y;
size1.z = size.z * z;
size2 = size1;
size1.x = size.x;
size2.x = -size1.x;
DrawLine(size1, size2);
}
}
for (int x = -1; x <= 1; x += 2)
{
for (int z = -1; z <= 1; z += 2)
{
size1.x = size.x * x;
size1.z = size.z * z;
size2 = size1;
size1.y = size.y;
size2.y = -size1.y;
DrawLine(size1, size2);
}
}
}
void DrawLine(Vector3 size1, Vector3 size2)
{
UnityEditor.Handles.DrawLine(center + rotation * (size1 / 2), center + rotation*(size2 / 2));
}
#endif
}
캡슐을 그림
static void DrawCapsule(float radius, params Transform[] transforms)
{
transforms = System.Array.FindAll(transforms, x => x != null);
if ((transforms == null) || (transforms.Length < 2))
{
return;
}
for (int i = 1; i < transforms.Length; i++)
{
DrawCapsule(transforms[i - 1].position, transforms[i].position, radius);
}
}
static void DrawCapsule(Vector3 start, Vector3 end, float radius)
{
var fowordAngle = Quaternion.LookRotation(start - end, Vector3.up);
start += (end - start).normalized * radius;
end -= (end - start).normalized * radius;
#if UNITY_EDITOR
UnityEditor.Handles.DrawWireDisc(start, fowordAngle * Vector3.forward, radius);
UnityEditor.Handles.DrawWireArc(start, fowordAngle * Vector3.up, fowordAngle * -Vector3.right, 180, radius);
UnityEditor.Handles.DrawWireArc(start, fowordAngle * Vector3.right, fowordAngle * Vector3.up, 180, radius);
UnityEditor.Handles.DrawWireDisc(end, fowordAngle * Vector3.forward, radius);
UnityEditor.Handles.DrawWireArc(end, fowordAngle * Vector3.up, fowordAngle * Vector3.right, 180, radius);
UnityEditor.Handles.DrawWireArc(end, fowordAngle * Vector3.right, fowordAngle * -Vector3.up, 180, radius);
#endif
Vector3 upVector = fowordAngle * Vector3.up * radius;
Vector3 rightVector = fowordAngle * Vector3.right * radius;
#if UNITY_EDITOR
UnityEditor.Handles.DrawLine(start + upVector, end + upVector);
UnityEditor.Handles.DrawLine(start + rightVector, end + rightVector);
UnityEditor.Handles.DrawLine(start - upVector, end - upVector);
UnityEditor.Handles.DrawLine(start - rightVector, end - rightVector);
#endif
}
실린더를 그림
void DrawCylinder(float radius, params Transform[] transforms)
{
transforms = System.Array.FindAll(transforms, x => x != null);
if ((transforms == null) || (transforms.Length < 2))
{
return;
}
for (int i = 1; i < transforms.Length; i++)
{
DrawCylinder(transforms[i - 1].position, transforms[i].position, radius);
}
}
void DrawCylinder(Vector3 start, Vector3 end, float radius)
{
var fowordAngle = Quaternion.LookRotation(start - end, Vector3.up);
#if UNITY_EDITOR
UnityEditor.Handles.DrawWireDisc(start, fowordAngle * Vector3.forward, radius);
UnityEditor.Handles.DrawWireDisc(end, fowordAngle * Vector3.forward, radius);
#endif
Vector3 upVector = fowordAngle * Vector3.up * radius;
Vector3 rightVector = fowordAngle * Vector3.right * radius;
#if UNITY_EDITOR
UnityEditor.Handles.DrawLine(start + upVector, end + upVector);
UnityEditor.Handles.DrawLine(start + rightVector, end + rightVector);
UnityEditor.Handles.DrawLine(start - upVector, end - upVector);
UnityEditor.Handles.DrawLine(start - rightVector, end - rightVector);
#endif
}
콜라이더를 그림
void DrawColliderGizmo(Transform transform)
{
if (transform != null)
{
DrawColliderGizmo(transform.gameObject);
}
}
void DrawColliderGizmo(GameObject gameObject)
{
if (gameObject != null)
{
var sphereCollider = gameObject.GetComponent<SphereCollider>();
if (sphereCollider != null)
{
Gizmos.DrawWireSphere(transform.position, sphereCollider.radius);
}
}
}
컬러적용
Gizmos.color = Color.red;
{
Gizmos.DrawLine(cameraPosition.position, thirdPersonPoint.position);
}
Gizmos.color = Color.white;
선택된 상태에서만 기즈모를 그림
void OnDrawGizmosSelected()
{
//기즈모를 그림
}
혹은
#if UNITY_EDITOR
if (Selection.transforms.Contains(transform))
{
//기즈모를 그림
}
#endif
화살표 표시 (arrow)
#if UNITY_EDITOR
Handles.color = Handles.xAxisColor;
UnityEditor.Handles.ArrowHandleCap(0, transform.position, transform.rotation * Quaternion.Euler(0, 90, 0), size: 0.25f, EventType.Repaint);
Handles.color = Handles.yAxisColor;
UnityEditor.Handles.ArrowHandleCap(0, transform.position, transform.rotation * Quaternion.Euler(-90, 0, 0), size: 0.25f, EventType.Repaint);
Handles.color = Handles.zAxisColor;
UnityEditor.Handles.ArrowHandleCap(0, transform.position, transform.rotation, size: 0.25f, EventType.Repaint);
Handles.color = Color.white;
#endif
EditorWindow에서 그릴때
Debug 계열만 됨
void OnGUI()
{
if (armTransform != null)
{
Debug.DrawLine(armTransform.position, armTransform.position+Vector3.forward,Color.red);
}
}
void Update()
{
Repaint();
}
'Unity > C#' 카테고리의 다른 글
유니티 커스텀 인터페이스 (0) | 2021.06.24 |
---|---|
유니티 안드로이드 빌드관련 스크립트 (0) | 2021.06.10 |
유니티 오디오 관련 코드 (0) | 2021.06.01 |
에셋번들에 포함되는것 : 텍스트파일(단, 리소스 폴더 하위에 있어야함), 스크립트오브젝트
미포함되는것 : 스크립트
'Unity > C#' 카테고리의 다른 글
유니티 기즈모 (Gizmo) 관련코드 (0) | 2021.06.15 |
---|---|
유니티 오디오 관련 코드 (0) | 2021.06.01 |
오큘러스 함수들 (0) | 2021.05.16 |
public static void WaveToMP3(string waveFileName, string mp3FileName, NAudio.Lame.LAMEPreset bitRate = NAudio.Lame.LAMEPreset.ABR_128)
{
using (var reader = new NAudio.Wave.WZT.WaveFileReader(waveFileName))
using (var writer = new NAudio.Lame.LameMP3FileWriter(mp3FileName, new NAudio.Wave.WZT.WaveFormat(), bitRate))
reader.CopyTo(writer);
}
public void SaveMp3(string filePath,AudioClip clip)
{
if (clip == null)
{
Debug.LogError("클립없음");
return;
}
var tempPath = Application.temporaryCachePath + "/tempAudio";
//Debug.Log(tempPath);
SavWav.Save(tempPath, clip);
//Debug.Log(filePath);
WaveToMP3(tempPath, filePath);
System.IO.File.Delete(tempPath);
}
볼륨 프로토 타입
float GetVolume(float[] audioData, int index, int samplingRate)
{
if ((audioData == null) || (audioData.Length == 0))
{
return 0;
}
float checkTime = 0.05f;
var startIndex = index;
var length = Mathf.Min(audioData.Length - index, (int)(samplingRate * checkTime));
var sliceArray = audioData.Skip(startIndex).Take(length).ToArray();
//return System.Array.ConvertAll(sliceArray, x => Mathf.Abs(x)).Average();
if ((sliceArray == null) || (sliceArray.Length == 0))
{
return 0;
}
return sliceArray.Max();
}
현재 오디오소스의 볼륨을 가져옴
public AudioSource audioSource;
float GetVolume(float[] audioData, int index, int samplingRate)
{
if ((audioData == null) || (audioData.Length == 0))
{
return 0;
}
float checkTime = 0.05f;
var startIndex = index;
var length = Mathf.Min(audioData.Length - index, (int)(samplingRate * checkTime));
var sliceArray = audioData.Skip(startIndex).Take(length).ToArray();
//return System.Array.ConvertAll(sliceArray, x => Mathf.Abs(x)).Average();
if ((sliceArray == null) || (sliceArray.Length == 0))
{
return 0;
}
return sliceArray.Max();
}
// Update is called once per frame
void Update()
{
var clip = audioSource.clip;
var ratio = audioSource.time / clip.length;
var samplingRate = clip.frequency;
int index = (int)(clip.samples * ratio / clip.channels);
float[] audioData = new float[clip.samples * clip.channels];
audioSource.clip.GetData(audioData, 0);
float volume = GetVolume(audioData, index, samplingRate);
//float volume2 = audioData[index] - audioData[Mathf.Max(0, index - 1)];
var localScale = transform.localScale;
localScale.x= volume;
transform.localScale = localScale;
}
wav로 저장
https://gist.github.com/darktable/2317063
var savePath = SFB.StandaloneFileBrowser.SaveFilePanel("Save File",directory:"", "defaultName", ".wav");
if (savePath == null)
{
return;
}
SavWav.Save(savePath, clip);
mp3로 저장 (Unity3D-save-audioClip-to-MP3)
https://github.com/BeatUpir/Unity3D-save-audioClip-to-MP3
var savePath = SFB.StandaloneFileBrowser.SaveFilePanel("Save File",directory:"", "defaultName", ".mp3");
if (savePath == null)
{
return;
}
EncodeMP3.convert(clip, savePath, bitRate: 128);
mp3로 저장 (Lame-For-Unity)
위에거보단 느리고 불안정
조심할점은 위의 Unity3D-save-audioClip-to-MP3와 충돌한다는 점이다
https://github.com/3wz/Lame-For-Unity
public static void WaveToMP3(string waveFileName, string mp3FileName, NAudio.Lame.LAMEPreset bitRate = NAudio.Lame.LAMEPreset.ABR_128)
{
using (var reader = new NAudio.Wave.WZT.WaveFileReader(waveFileName))
using (var writer = new NAudio.Lame.LameMP3FileWriter(mp3FileName, new NAudio.Wave.WZT.WaveFormat(), bitRate))
reader.CopyTo(writer);
}
public void SaveMp3(string filePath,AudioClip clip)
{
if (clip == null)
{
Debug.LogError("클립없음");
return;
}
var tempPath = Application.temporaryCachePath + $"/tempAudio.wav";
//Debug.Log(tempPath);
SavWav.Save(tempPath, clip);
//Debug.Log(filePath);
WaveToMP3(tempPath, filePath);
System.IO.File.Delete(tempPath);
}
윈도우에서 mp3로드
https://assetstore.unity.com/packages/tools/audio/audioimporter-146746
'Unity > C#' 카테고리의 다른 글
유니티 안드로이드 빌드관련 스크립트 (0) | 2021.06.10 |
---|---|
오큘러스 함수들 (0) | 2021.05.16 |
유니티 에디터 윈도우 (0) | 2021.04.12 |
Display face normals as Lines의 위치
Parent설정의 위치
쿼드뷰
그리고 뷰 잠금해제는
텍스처 넣기
2.78에선 보이던 Collection이 2.8에서 안 보일때
눈이 활성화 되어있는데도 안 보인다
Collection 우클릭하고 Visibility 누르고 Enable in Viewports
고쳐짐
웨이트 페인팅시
오브젝트 모드에서 아마추어 선택후 의상 선택하여 웨이트 페인팅 진행
Remove Doubles -> By Distance
블러 브러쉬 위치
웨이트 미러
백그라운드 추가
레퍼런스는 앞에 깔리고 백그라운드는 뒤에 깔린다
UV 셀렉트하면 3D 뷰포트상에서도 셀렉트 되는 기능
동일한 버튼이다
뷰포트 쉐이딩 텍스처 모드
2.8 폴리곤 미터
체크하면 우측 하단에 나타난다
'3D > 블렌더' 카테고리의 다른 글
솔방울오징어 만들기 (0) | 2022.11.06 |
---|---|
블렌더 애니메이션 (0) | 2021.03.15 |
블렌더 오류 모음 (0) | 2021.03.15 |
OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, OVRInput.Controller.LTouch);
//얼마나 그랩이 당겨졌는지 반환
'Unity > C#' 카테고리의 다른 글
유니티 오디오 관련 코드 (0) | 2021.06.01 |
---|---|
유니티 에디터 윈도우 (0) | 2021.04.12 |
코드 모음 사이트 (0) | 2021.01.24 |
'Unity' 카테고리의 다른 글
유니티 이벤트 모음 (0) | 2021.06.22 |
---|---|
오큘러스 컴포넌트 및 프리팹 (0) | 2021.05.15 |
유니티 오큘러스퀘스트 세팅 (0) | 2021.05.14 |