Unity/스크립터블오브젝트15 Scriptable Object - 응용: Interactable, 커스텀 에디터 (10) Interactable Interactable은 구성한 Condition들로 Reaction을 수행한다. Condition과 해당 Reaction의 구성은 ConditionCollection에 저장된다. 저장된 Condition들을 현재 Player의 상태값인 'AllConditions'와 비교해서 Reaction을 수행할지 말지 결정한다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 using UnityEngine; public class Interactable : MonoBehaviour { public Transform interactionLocation; public ConditionCollection[] conditionCollections = ne.. 2020. 6. 8. Scriptable Object - 응용: Scene.unity 파일에 직렬화하기 (9) 샘플 프로젝트 (AdventureTutorial) 소스 : https://assetstore.unity.com/packages/essentials/tutorial-projects/adventure-sample-game-76216#reviews Adventure - Sample Game | 자습서 | Unity Asset Store Get the Adventure - Sample Game package from Unity Technologies and speed up your game development process. Find this & other 자습서 options on the Unity Asset Store. assetstore.unity.com Scene.unity 파일에 직렬화하기 Scrip.. 2020. 6. 4. Scriptable Object - 응용: Dual Serialization, 세이브 & 로드 (8) Dual Serialization JSON Utility를 통해 Scriptable Object의 인스턴스를 .asset 뿐만 아니라 JSON 파일의 문자열(string)로 직렬화 할 수 있다. Desiralization 방법 1 2 // Load built-in level from an AssetBundle level = lvlsBundle.LoadAsset("lvl1.asset"); 첫 번째 방법은 .asset을 역직렬화하는 것이다. 역직렬화된 .asset파일의 인스턴스를 그대로 사용한다. 1 2 3 4 // Load level from JSON level = CreateInstance(); var json = File.ReadAllText("customlevel.json"); JsonUtility... 2020. 6. 3. Scriptable Object - 응용: Destructible, Brain(AI) (7) Destructible 일정 데미지가 누적되면 파괴되는 개체가 있다. 파괴되는 연출을 다형화하기 위해 ScriptableObject로 정의해보자. 파괴 이벤트는 건물 파괴의 시각적 이펙트를 보여준 후 씬에서 해당 오브젝트를 Destroy한다. 이펙트가 보여지는 중 Destroy에 의해 끊기면 안되므로 코루틴을 사용한다. 파괴에 대한 연출을 Scriptable Object로 정의하고 Inspector뷰에서 구성할 수 있도록 구현해보자. 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 using UnityEngine; public class Destructible : MonoBehaviour { public float Healt.. 2020. 6. 2. Scriptable Object - 응용: 오디오 이벤트, 프로퍼티 드로워, 커스텀 에디터 (6) 샘플 프로젝트 (richardfine-scriptableobjectdemo) 소스 : https://bitbucket.org/richardfine/scriptableobjectdemo/src/default/ 오디오 이벤트 추상 클래스는 다형화를 구현하는 대표적인 수단이다. 사용자인 MonoBehaviour는 인스턴스의 타입이 무엇인지에 상관없이 Play()만 호출할 뿐이다. 다형성은 OOP가 지향하는 것으로 변경에 대비해 사용자와 특정 클래스 사이를 추상 클래스나 인터페이스로 분리시키는 것이다. 기능의 변경이 발생하면 사용자의 코드는 건들지 않아도 된다. 기능 정의는 자식 클래스에서 이뤄지기 때문이다. 1 2 3 4 5 6 using UnityEngine; public abstract class Audi.. 2020. 6. 1. 이전 1 2 3 다음