6월, 2018의 게시물 표시

C# 문자열 비교

if (strCompared.Equals(“문자열”)) { Console.WriteLine(“True”); }

유니티 씬 불러오기

using UnityEngine.SceneManagement; // 씬 불러오기 SceneManager.LoadScene ("Home"); // 씬 확인하기 if (SceneManager.GetActiveScene().name === "Home") // PlayerPrefs 정보모두삭제 PlayerPrefs.DeleteAll(); //안드로이드 백키 종료 if(Input.GetKeyDown(KeyCode.Escape)) { Application.Quit(); }

C# 정규식

// 베이스 C# // 1.문자열에서 숫자만 남기기 & 문자만 남기기 --------------------------- // 참조추가 string tm = "a1b2c3d4"; string num = Regex.Replace(tm, @"\D", ""); // 숫자만 가져옴 // num 에는 1234 만 남는다.. string str = Regex.Replace(tm, @"[\d-]", string.Empty); // str 에는 abcd 만 남는다.

유니티 디바이스 디버깅

cmd창에서 android sdk 폴더에 sdk/platform-tools 경로로 이동한다. 휴대폰에서 발생하는 모든 이벤트 -> adb logcat 유니티에서 발생하는 모든 이벤트 -> adb logcat -s Unity 유니티에서 발생하는 log 이벤트 -> adb logcat Unity:I Native:I *:S

유니티 의존 컴포넌트를 자동추가

using UnityEngine; // PlayerScript requires the GameObject to have a Rigidbody component [RequireComponent (typeof (Rigidbody))] public class PlayerScript : MonoBehaviour { Rigidbody rb; void Start() { rb = GetComponent (); } void FixedUpdate() { rb.AddForce(Vector3.up); } } 출처: https://docs.unity3d.com/ScriptReference/RequireComponent.html

유니티 파티클 이펙트 사이즈 변경 코드

// This script will only work in editor mode. You cannot adjust the scale dynamically in-game! using UnityEngine; using System.Collections; #if UNITY_EDITOR using UnityEditor; #endif [ExecuteInEditMode] public class ParticleScaler : MonoBehaviour { public float particleScale = 1.0f; public bool alsoScaleGameobject = true; float prevScale; void Start() { prevScale = particleScale; } void Update() { #if UNITY_EDITOR // check if we need to update if (prevScale != particleScale && particleScale > 0) { if (alsoScaleGameobject) transform.localScale = new Vector3(particleScale, particleScale, particleScale); float scaleFactor = particleScale / prevScale; // scale legacy particle systems ScaleLegacySystems(scaleFactor); // scale shuriken particle systems ScaleShurikenSystems(scaleFactor); // scale trail renders ScaleTrailRenderers(scaleFactor); prevScale = particleScale; } #endif } void ScaleShurikenSystems(float scaleFactor...

Unity3D PlayerPrefs 삭제

public class EditorTools { [MenuItem("Tools/Reset PlayerPrefs", false)] public static void ResetPlayerPref() { PlayerPrefs.DeleteAll(); Debug.Log("*** PlayerPrefs was reset! ***"); } }

Unity3D Singleton

case : 1 using UnityEngine; using System.Collections; public class Singleton: MonoBehaviour { public static Singleton Instance; //Awake is always called before any Start functions void Awake() { if (Instance) { DestroyImmediate(gameObject); } else { Instance = this; DontDestroyOnLoad(gameObject); } } } case 2 : public class MyClass { private static MyClass _instance; public static MyClass Instance { get { if (!_instance) { _instance = GameObject.FindObjectOfType(typeof(MyClass)); if (!_instance) { GameObject container = new GameObject(); container.name = "My...

유니티 카메라 초기값

이미지
3D Camera Light 2D Camera

유니티 오브젝트 서서히 사라지게

private SpriteRenderer _spriteRenderer; // Use this for initialization void Start() { StartCoroutine(FadeAway()); } IEnumerator FadeAway() { yield return new WaitForSeconds(1); while (_spriteRenderer.color.a > 0) { var color = _spriteRenderer.color; //color.a is 0 to 1. So .5*time.deltaTime will take 2 seconds to fade out color.a -= (.5f * Time.deltaTime); _spriteRenderer.color = color; //wait for a frame yield return null; } Destroy(gameObject); }

유니티 파티클

ParticleSystem testParticle = null; // 버튼이 눌러졌을때 if (Input.GetMouseButtonUp(0) == true) { // 파티클이 있고 if (testParticle) { // 파티클이 재생중이면 재생을 멈추고 지워줍니다 if (testParticle.isPlaying == true) { testParticle.Stop(); testParticle.Clear(); //Debug.Log("STOP"); } // 재생중이 아니라면 재생해주고요 else { testParticle.Play(); //Debug.Log("PLAY"); } } // 파티클이 없다면 새로 만들어주구요 else { Vector3 pos = Vector3.zero; pos.y = 3; pos.x = 3 - 30.0f; Transform particleObject = (Transform)Instantiate(Resources.Load("Prefabs/Effects/pfBlockBomb", typeof(Transform)), pos, Quaternion.identity); testParticle = (ParticleSystem)particleObject.GetComponent(typeof(ParticleSystem)); //Debug.Log("CREATE"); } return; } 출...

유니티 오브젝트풀

https://www.youtube.com/watch?v=nzHzd7B22Zc&t=99s http://hyunity3d.tistory.com/195

유니티 RectTransform

 RectTransform myRectTransform = GetComponent<RectTransform>();  myRectTransform.localPosition += Vector3.right; DOTween demageTexts[poolCheck].GetComponent<RectTransform>().DOAnchorPosY(110f, 0.1f); 참고 https://answers.unity.com/questions/1190533/how-to-move-a-recttransform-on-pos-x-through-code.html

유니티 오브젝트 활성화 체크

if(gameObject.activeSelf == true) 부모 오브젝트 영향받아서 내가 비활성상태인지 체크하려면 activeInHierarchy 를 사용 activeSelf가 true여도 부모가 false면 activeInHierarchy 는 false 참조 : http://docs.unity3d.com/ScriptReference/GameObject-activeInHierarchy.html

DotTween 예제

using DG.Tweening; public class MentalityStart : MonoBehaviour { public GameObject[] bgImages; void Start () { TitlePanel.GetComponent<DOTweenAnimation>().DORestartById("UP"); bgImages[j-1].GetComponent<DOTweenAnimation>().DOPlay(); } }

유니티 Tip

editor Color Tint 색상 변경으로 play mode /Editor Mode 확인하기 Edit ->Preferences -> Colors 에서 Playmode tint 수정 Play에서 설정값 저장 Copy Componet -> Paste Component 활용 http://wiki.unity3d.com/index.php/Singleton - 유니티 함수 리스트 ctrl + shift + m - 함수 팝업 ctrl + 마우스 클릭 ctrl + alt + L : 솔루션 탐색기로 이동 alt + 0 : 다시 에디트파일로 이동 ctrl + G :  해당 줄로 이동 ctrl + shift + s : 전체 파일 저장 ctrl + U : 모두 소문자로 바꾸기 ctrl + shift + U : 모두 대문자로 바꾸기 https://www.youtube.com/watch?v=-ACzLA4mh4Q&index=47&list=PL412Ym60h6uvOCGVKFl1Y12ByyXjPlOUK

MM-Gcamera-daemon

삼성 갤럭시 노트3 사용 중인데 배터리가 너무 빨리 닳아서 확인해 보니 "MM-Gcamera-daemonandroid" 이게 문제인거 같은데 아직 정확한 원인은 모르겠다. {TEXT} 극장 상영중