본문 바로가기

프로그래밍/Unity95

Unity 어드레서블 통빌드(풀빌드) 시 주의 어드레서블 에셋 통이나 풀이냐 뭐 그런걸 떠나서 어드레서블 에셋 빌드를 한번도 안하고 apk 빌드를 하면 실행하자 마자 에러를 만나게 됩니다 MissingMethodException: Default constructor not found for type UnityEngine.ResourceManagement.ResourceManager+CompletedOperation`1[[UnityEngine.Sprite, UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]] System.RuntimeType.CreateInstanceMono (System.Boolean nonPublic) (at :0) 2021. 10. 28.
Unity 일정 시간 동안 목표 위치까지 이동 using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class Enable_Move : MonoBehaviour { private Vector3 m_Position_Default; [SerializeField] protected Vector3 m_Position_End; [SerializeField] protected float m_RunTime = 1.0f; private void Awake() { m_Position_Default = transform.position; } private void OnEnable() { StartCoroutine(Run(m_RunTime)); .. 2021. 10. 5.
txt 파일 생성 using System.IO; public void MakeTextFile(string name, List list) { var filePath = $"{Application.dataPath}/{name}.txt"; Debug.Log($"### SAVE @ {filePath}"); StreamWriter fileWriter = File.CreateText(filePath); for (int i = 0; i < list.Count; i++) { Debug.Log((string)list[i]); fileWriter.WriteLine((string)list[i]); } fileWriter.Close(); } assets/패스 경로에 생깁니다 2021. 9. 9.
Unity EditorTool 을 활용한 Component 값 제어 개발을 하다 보면 이런 경우가 있죠 대량의 프리팹 내부의 특정 컴포넌트 의 값을 바꿔줘야 하는 경우- 초기 세팅할게 많은 프리팹의 경우 일일히 손으로 하기 그러니 툴을 만 들어 봅시다 using UnityEngine; using UnityEditor; using UnityEditor.EditorTools; [EditorTool("Monster EditorTool")] public class MonsterTool : EditorTool { public GUIContent m_IconContent { get; set; } private void OnEnable() { m_IconContent = new GUIContent() { image = Resources.Load("Common/icon_tool"), .. 2021. 8. 24.
Unity 어드레서블 에셋 http://docs.unity3d.com/Packages/com.unity.addressables@1.18/manual/index.html Unity Addressable Asset system | Addressables | 1.18.15 Unity Addressable Asset system The Addressable Asset system provides an easy way to load assets by “address”. It handles asset management overhead by simplifying content pack creation and deployment. The Addressable Asset system uses asynchronous loadi docs.unity.. 2021. 8. 9.
CinemachineVirtualCamera Aim 속성 Tracked Object Offset 오프셋 Lookahead Time 대상의 움직임에 따라 대상을 따라가기에서 가상 카메라의 오프셋을 조정합니다. Cinemachine은 몇 초 후에 목표가 될 지점을 예측합니다. 이 기능은 노이즈가 많은 애니메이션에 민감하며 노이즈를 증폭시켜 원하지 않는 카메라 지터를 유발할 수 있습니다. 대상이 움직일 때 카메라가 허용할 수 없을 정도로 떨리는 경우 이 속성을 낮추거나 대상을 보다 부드럽게 애니메이션합니다. Lookahead Smoothing 예측 알고리즘의 부드러움. 값이 클수록 불안정한 예측이 부드러워지고 예측 지연이 늘어납니다. Lookahead Ignore Y 선택하면 예측 계산을 위해 Y축을 따라 이동을 무시합니다. Horizontal Damping 카메라.. 2021. 7. 30.
Simple Controller 간단한 컨트롤러. 박스나 캡슐 GameObject 생성 후 Component 로 붙여주기만 하면 끝 using UnityEngine; [RequireComponent(typeof(Rigidbody))] public class SimpleController : MonoBehaviour { private Rigidbody m_Rigidbody; public float m_MoveSpeed = 6.0f; private void Awake() { m_Rigidbody = GetComponent(); m_Rigidbody.constraints = RigidbodyConstraints.FreezeRotation; } // Update is called once per frame void Update() { m_Ri.. 2021. 5. 29.
UGUI Particle 파티클 / Effect 이펙트 GitHub - mob-sakai/ParticleEffectForUGUI: Render particle effect in UnityUI(uGUI). Maskable, sortable, and no extra Camera/RenderTexture/Canvas. mob-sakai/ParticleEffectForUGUI Render particle effect in UnityUI(uGUI). Maskable, sortable, and no extra Camera/RenderTexture/Canvas. - mob-sakai/ParticleEffectForUGUI github.com 위에서 받아서 깔고 사용은 파티클에 AddComponent UIParticle 추가 2021. 5. 12.
Unity Draw Call 유틸 https://assetstore.unity.com/packages/tools/utilities/pro-draw-call-optimizer-light-16888 Pro Draw call Optimizer Light | 유틸리티 도구 | Unity Asset Store Use the Pro Draw call Optimizer Light from PencilSquareGames on your next project. Find this utility tool & more on the Unity Asset Store. assetstore.unity.com Simplest Mesh Baker | Utilities Tools | Unity Asset Store Simplest Mesh Baker | 유틸리티 도구 .. 2021. 4. 30.
Spine Skin Attachment public class Test_Attachment : MonoBehaviour { internal SkeletonAnimation m_Spine; [SpineSlot(dataField: "m_Spine")] public string m_SlotName; public float m_Rotate = 0.0f; private void Awake() { m_Spine = GetComponent(); } // http://suyeongpark.me/archives/1906 // http://ko.esotericsoftware.com/forum/Combining-Skins-Additive-6507 void Load2() { string PartsName = "Leg_F2"; var Origin = m_Spine... 2021. 4. 28.
Unity - Joystick Pack 최초 터치 문제 protected void Awake() { m_JoyStick = GameObject.Find("Dynamic Joystick").GetComponent(); m_JoyStick.OnPointerDown(new PointerEventData(EventSystem.current)); m_JoyStick.OnPointerUp(new PointerEventData(EventSystem.current)); } 최초 터치 시 이런식으로 가운데가 안맞는다면 위의 코드를 해주면 한번 임의로 눌렀다 뗀거로 해서 이후로는 정상적으로 작동 2021. 4. 16.
Unity - Collider Center & Top 좌표 구하기 using System.Collections; using System.Collections.Generic; using UnityEngine; public class Test_Collider : MonoBehaviour { public Transform m_Obj_Head; public Transform m_Obj_Center; Collider2D m_Collider; private void Awake() { m_Collider = GetComponent(); } // Start is called before the first frame update void Start() { m_Obj_Center.position = m_Collider.bounds.center; m_Obj_Head.position = m.. 2021. 3. 29.
Unity - 오브젝트 가까운 순으로 정렬 feat Linq using System.Linq; void Test() { var list = GameObject.FindGameObjectsWithTag("Enemy").OrderBy( x => Vector2.Distance(transform.position, x.transform.position) ).ToList(); } 2021. 3. 25.
SoundManagerPro 3 : Next Gen 수정해야 되는 점 SoundManager_SFX_Internal.cs private GameObject AddOwnedSFXObject(AudioClip clip) { GameObject SFXObject = new GameObject("SFX-["+clip.name+"]", typeof(AudioSource)); SFXObject.transform.parent = transform; SFXObject.name += "(" + SFXObject.GetInstanceID() + ")"; SFXObject.GetComponent().playOnAwake = false; //GameObject.DontDestroyOnLoad(SFXObject); // 이하 생략... } GameObject.DontDestroyOnLoad(SF.. 2021. 3. 22.
SoundManagerPro 3 : Next Gen SFX 음량 들쭉 날쭉한 문제 갑자기 PlaySFX 로 효과음을 내는데 소리가 점점 작아졌다 다시 돌아왔다 작아졌다를 반복하는 현 상이 일어났다. 원인은 이 부분에 값을 넣었더니 그 SFX 말고 다른 SFX 에 까지 볼륨 조절이 적용 됐던 것;; 그냥 0100 으로 쓰자;; 2021. 3. 22.
Spine Animation - AnimationState 가 null 일 때 SkeletonAnimation m_Spine; private void Awake() { m_Spine = GetComponent(); // 이 때 하면 AnimationState 가 null 일 때도 있다 m_Spine.AnimationState.SetEmptyAnimation(0, 0.0f); } private void Start() { // 이 때 하면 awake 에서는 null 이던게 아니게 된다 m_Spine.AnimationState.SetEmptyAnimation(0, 0.0f); } 늘 그런건 아니지만 Awake 에서 AnimationState 가 null 일 때도 있으니 한템포 쉬고 Start 쪽에서 참조하면 값이 있다.. 코루틴 같은 상황에서는 WaitFor 시리즈로 한틱 정도만 쉬어준.. 2021. 2. 26.
Unity Spine Animation y 축 180 돌렸을 때 덜덜 떨리는 현상 transform.rotation = new Quaternion(0.0f, 0.0f, 0.0f, 0.0f); //gameObject.transform.SetPositionAndRotation(gameObject.transform.position, Quaternion.Euler(0, 0, 0)); transform.rotation = new Quaternion(0.0f, 180.0f, 0.0f, 0.0f); //SetPositionAndRotation(gameObject.transform.position, Quaternion.Euler(0, 180, 0)); 아래 주석으로 했을 때 180 돌린 후 이동하면 덜덜 떨었는데 new 로 한 다음엔 괜찮음 SetPositionAndRotation 말고도 Engle.. 2021. 2. 23.
30프레임에 한번씩 미리 가비지 컬렉션 if (Time.frameCount % 30 == 0) { System.GC.Collect(); } 2021. 2. 8.
Unity 네비메쉬 2D GitHub - h8man/NavMeshPlus: Unity NavMesh 2D Pathfinding h8man/NavMeshPlus Unity NavMesh 2D Pathfinding. Contribute to h8man/NavMeshPlus development by creating an account on GitHub. github.com 네비메쉬플러스를 사용 :) 2021. 1. 26.
KinematicObject 계열의 캐릭터 주의점 유니티에서 샘플로 받을 수 있는 2D 플랫포머의 캐릭터 컨트롤러를 참고 하다보면 KinematicObject 라는 클래스를 참고해서 2D 게임을 만드는 경 우가 많을 것 같은데 본인 역시 이걸 가져다가 없는 기능 2개 정도를 추가해서 사용 중 다수의 총알을 쏘고 맞는 게임을 제작 중 이상 동작을 하는 것을 확인.. 대략 이틀 정도 고민 끝에 원인을 발견.. 원인은 여기서 ContactFilter2D 를 설정해서 RaycastHit2D[] 버퍼에 받는 과정이 문제... 일단 캐릭간 충돌, 총알과 캐릭간 충돌, 바닥 타일간 충돌 이 설정된 Enemy 라는 Layer를 사용했더니 다수의 탄을 맞을 때 RaycastHit2D의 디폴트 버퍼 15를 탄알이 가득 채워버리는 바람에 정작 해야할 그라운드의 체크를 못해.. 2021. 1. 25.