ºÇ½ª¹¹¿·¡§ orika_ex_miyako 2023ǯ10·î30Æü(·î) 18:52:24ÍúÎò
³Æ¥Þ¥¹¤´¤È¤Ëʬ´ô(ÁªÂò»è)¤¬¤¢¤ê¡¢Ç¤°Õ¤Î¥¤¥Ù¥ó¥È¤ò¼Â¹Ô¤·¤Ê¤¬¤é¿Ê¹Ô¤¹¤ë¥¿¥¤¥×¤Î¥²¡¼¥à¥·¥¹¥Æ¥à¤Î¼ÂÁõÎã¤Ç¤¹¡£
¡¡¤³¤³¤Ç¤Ïʬ´ô½èÍý¤Ï¤Ê¤¯¡¢£±¥Þ¥¹¤º¤Ä¤Î¥¤¥Ù¥ó¥È¤ò¿Ê¹Ô¤µ¤»¤Æ¤¤¤¯ÊýË¡¤ò¼ÂÁõ¤·¤Þ¤¹¡£
Ëè²ó·è¤á¤é¤ì¤¿¥¤¥Ù¥ó¥È¤ò¥¯¥ê¥¢¤¹¤ë¥¿¥¤¥×¤Ë¤Ê¤ê¤Þ¤¹¡£
¡¡¤³¤Î½èÍý¤òÍý²ò¤Ç¤¤Æ¤«¤éʬ´ô½èÍý¤òºîÀ®¤·¤Æ¤¤¤¯¤è¤¦¤Ë¤·¤Þ¤·¤ç¤¦¡£
¡¡³Æ¥Þ¥¹¤Ç¤Ï¿§¡¹¤Ê¥¤¥Ù¥ó¥È¤¬È¯À¸¤¹¤ë¤¿¤á¡¢¥¤¥Ù¥ó¥È¤Ë¤Ä¤¤¤Æ¤Ï¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤ÈÃê¾Ý¥¯¥é¥¹¤òÍøÍѤ·¤ÆÀ߷פ·¤Þ¤¹¡£
¤½¤·¤Æ¥µ¥Ö¥¯¥é¥¹¤Ç¡Ö¥Ð¥È¥ë¡×¡Öõº÷¡×¡ÖµÙ©¡×¡Ö¥·¥ç¥Ã¥×¡×¤È¤¤¤Ã¤¿³Æ¥Þ¥¹¤Ç¤Î¥¤¥Ù¥ó¥È¤òºîÀ®¤¹¤ë¤è¤¦¤Ë¤·¤Þ¤¹¡£
¡¡½èÍý¤òÃê¾Ý²½¤¹¤ë¤³¤È¤Ë¤è¤ê¡¢¥¤¥Ù¥ó¥È¤Î¼Â¹ÔÌ¿Îá¤ò¹Ô¤¦¤³¤È¤ËÆò½¤·¡¢¥¤¥Ù¥ó¥È¤Î¾ÜºÙ¤Þ¤Ç¤Ï´ØÍ¿¤·¤Ê¤¤·Á¤Ç¼ÂÁõ¤·¤Þ¤¹¡£
¡¡¤Ê¤ª¶ñÂÎŪ¤Ê¥¤¥Ù¥ó¥È¤ÎÆâÍƤˤĤ¤¤Æ¤Ï¤³¤Î¶µºà¤Ç¤Ï¼ÂÁõ¤Ï¤·¤Æ¤¤¤Þ¤»¤ó¡£
¡¡ºÇ½é¤Ë¥¤¥Ù¥ó¥È¤Î¼ïÎà¤ò enum ¤ÇÅÐÏ¿¤·¤Þ¤¹¡£
// ¥¤¥Ù¥ó¥È¤Î¼ïÎà¤òɽ¤¹Îóµó·¿ public enum EventType { Battle, Exploration, Shop }
¡¡É¬Íפ˱þ¤¸¤ÆÄɲ䷤Ƥ¯¤À¤µ¤¤¡£
¡¡¼¡¤Ë¥¤¥Ù¥ó¥È¼Â¹Ô¤Î¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤òºîÀ®¤·¤Þ¤¹¡£
using System.Collections; // ¥¤¥Ù¥ó¥È¤Î¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹ public interface IEvent { IEnumerator ExecuteEvent(); EventType GetEventType(); }
¡¡¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤Ï¶ñÂÎŪ¤Ê¼ÂÁõ¤òÄ󶡤·¤Ê¤¤¤¿¤á¡¢¥¯¥é¥¹¤¬¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤ò¼ÂÁõ¤¹¤ëºÝ¤Ë¡¢¤É¤Î¤è¤¦¤Ë¼ÂÁõ¤¹¤ë¤«¤Ï¶ñÂÎŪ¤Ê¥¯¥é¥¹¤Ë°Ñ¤Í¤é¤ì¤Þ¤¹¡£
¤³¤ì¤Ë¤è¤ê¡¢¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤òÄêµÁ¤¹¤ë¤È¤¤Ë¤Ï¡¢¤½¤Î¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤ò¼ÂÁõ¤¹¤ë¥¯¥é¥¹¤Î¾ÜºÙ¤Ê¼ÂÁõ¤Ë°Í¸¤·¤Ê¤¤·Á¤ÇÀ߷פǤ¤Þ¤¹¡£
¡¡¤Þ¤¿¡¢¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤ò»ÈÍѤ¹¤ë¤³¤È¤Ç¡¢¿·¤·¤¤¥¯¥é¥¹¤òÄɲä·¡¢´û¸¤Î¥¯¥é¥¹¤¬¿·¤·¤¤¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤ò¼ÂÁõ¤¹¤ë¤À¤±¤Ç¡¢¥³¡¼¥É¤Î³ÈÄ¥¤¬Íưפ˹Ԥ¨¤Þ¤¹¡£
¤³¤ì¤Ë¤è¤ê¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Î³ÈÄ¥¤äÊѹ¹¤¬´Êñ¤Ë¹Ô¤¨¤ë¤è¤¦¤Ë¤Ê¤ê¤Þ¤¹¡£
¡¡¥¤¥Ù¥ó¥ÈÍѤÎÃê¾Ý¥¯¥é¥¹¤òºîÀ®¤·¡¢¿Æ¥¯¥é¥¹¤È¤·¤Þ¤¹¡£
¡¡Ãê¾Ý¥¯¥é¥¹¤Ï¡¢¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤ò¼ÂÁõ¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤¹¡£
¤½¤Î¤¿¤á¡¢¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤ò¼ÂÁõ¤¹¤ëÊ£¿ô¤Î¥¯¥é¥¹¤¬¡¢¶¦Ä̤ÎÃê¾Ý¥¯¥é¥¹¤Î¥á¥½¥Ã¥É¤ä¥×¥í¥Ñ¥Æ¥£¤ò»ý¤Ä¤³¤È¤¬¤Ç¤¤Þ¤¹¡£
¡¡¤³¤ì¤Ï¡¢¥¯¥é¥¹³¬ÁؤǤΰì´ÓÀ¤òÊݤÁ¡¢¥³¡¼¥É¤ÎÊݼéÀ¤ò¸þ¾å¤µ¤»¤ë¤Î¤ËÌòΩ¤Á¤Þ¤¹¡£
using UnityEngine; using System.Collections; // ¥¤¥Ù¥ó¥È¤ÎÃê¾Ý¥¯¥é¥¹ public abstract class EventBase : MonoBehaviour, IEvent { public abstract IEnumerator ExecuteEvent(); // ExecuteEvent ¥á¥½¥Ã¥É¤òÃê¾Ý¥á¥½¥Ã¥É¤È¤·¤Æ¼ÂÁõ public abstract EventType GetEventType(); }
¡¡Ãê¾Ý¥¯¥é¥¹¤Ë¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤òÃê¾Ý¥á¥½¥Ã¥É¤È¤·¤Æ¼ÂÁõ¤¹¤ë¤³¤È¤Ë¤è¤ê¡¢»Ò¥¯¥é¥¹¤Ç¤Î¿¶¤ëÉñ¤¤¤Î¼ÂÁõ¤ò¶¯À©¤¹¤ë¤³¤È¤¬¤Ç¤¤Þ¤¹¡£
¤³¤ì¤¬½ÅÍפÊÍýͳ¤Ï¡¢°Ê²¼¤ÎÄ̤ê¤Ç¤¹¡§
¡¡¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤òÃê¾Ý¥¯¥é¥¹¤ËÁȤ߹þ¤à¤³¤È¤Ç¡¢¤¹¤Ù¤Æ¤Î»Ò¥¯¥é¥¹¤¬Æ±¤¸¥á¥½¥Ã¥É¡ÊÃê¾Ý¥á¥½¥Ã¥É¡Ë¤ò»ý¤Ä¤³¤È¤¬Êݾڤµ¤ì¤Þ¤¹¡£
¤³¤ì¤Ë¤è¤ê¡¢¥¯¥é¥¹³¬ÁØÆâ¤Ç°ì´ÓÀ¤¬°Ý»ý¤µ¤ì¡¢ÆÃÄê¤Î¥á¥½¥Ã¥É¤Î¸ºß¤¬³Î¼Â¤ËÊݾڤµ¤ì¤Þ¤¹¡£
¡¡»Ò¥¯¥é¥¹¤ÏÃê¾Ý¥¯¥é¥¹¤ò·Ñ¾µ¤·¡¢Ãê¾Ý¥á¥½¥Ã¥É¤ò¼ÂÁõ¤·¤Ê¤±¤ì¤Ð¤Ê¤ê¤Þ¤»¤ó¡£
¤³¤ì¤Ë¤è¤ê¡¢»Ò¥¯¥é¥¹¤¬ÆÃÄê¤Î¥á¥½¥Ã¥É¤ò¼ÂÁõ¤·¤Ê¤¤¸Â¤ê¡¢¥³¥ó¥Ñ¥¤¥ë¥¨¥é¡¼¤¬È¯À¸¤·¤Þ¤¹¡£
¡¡¤Ä¤Þ¤ê¡¢Ë¾¤Þ¤Ê¤¤¿¶¤ëÉñ¤¤¤ÎÈ´¤±Ï³¤ì¤òËɤ®¡¢¥×¥í¥°¥é¥Þ¤¬Àµ¤·¤¤¼ÂÁõ¤ò¶¯À©¤Ç¤¤Þ¤¹¡£
¡¡Ãê¾Ý¥¯¥é¥¹¤ò»ÈÍѤ·¤Æ¡¢¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤Î°ìÉô¤Î¥Ç¥Õ¥©¥ë¥È¼ÂÁõ¤òÄ󶡤¹¤ë¤³¤È¤â¤Ç¤¤Þ¤¹¡£
¤³¤Î¾ì¹ç¡¢»Ò¥¯¥é¥¹¤ÏɬÍפ˱þ¤¸¤Æ¥Ç¥Õ¥©¥ë¥È¤Î¼ÂÁõ¤òºÆÄêµÁ¤¹¤ë¤³¤È¤¬¤Ç¤¡¢¤è¤ê½ÀÆð¤ÊÀ߷פò¼Â¸½¤Ç¤¤Þ¤¹¡£
¡¡¤³¤Î¤è¤¦¤Ë¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹¤ÈÃê¾Ý¥¯¥é¥¹¤ÎÁȤ߹ç¤ï¤»¤Ï¡¢¥¯¥é¥¹³¬ÁؤòÀ߷פ·¡¢¥³¡¼¥É¤Î½ÀÆðÀ¡¢³ÈÄ¥À¡¢ÊݼéÀ¤ò¸þ¾å¤µ¤»¤ë¤Î¤ËÌòΩ¤Ä¶¯ÎϤʼêË¡¤Ç¤¹¡£
¶ñÂÎŪ¤ÊÍ×·ï¤äÀß·×¾å¤ÎÍ×°ø¤Ë±þ¤¸¤Æ¡¢¤É¤Á¤é¤òÁªÂò¤¹¤ë¤«¤Ï¥×¥í¥¸¥§¥¯¥È¤Ë¤è¤Ã¤Æ°Û¤Ê¤ë¤³¤È¤¬¤¢¤ê¤Þ¤¹¡£
¡¡¥×¥ì¥¤¥ä¡¼¤È¥Þ¥¹¤òÀ©¸æ¤¹¤ë¥¹¥¯¥ê¥×¥È¤òºîÀ®¤·¤Þ¤¹¡£
using UnityEngine; using System.Collections; using System.Collections.Generic; using System.Linq; public class GameController : MonoBehaviour { public Transform player; // ¥×¥ì¥¤¥ä¡¼¤Î¥È¥é¥ó¥¹¥Õ¥©¡¼¥à public List<EventBase> events; // ¥Þ¥¹¤Ë´ØÏ¢ÉÕ¤±¤é¤ì¤¿¥¤¥Ù¥ó¥È¤Î¥ê¥¹¥È private int currentPosition = 0; // ¸½ºß¤Î°ÌÃÖ private bool isEventRunning = false; // ¥¤¥Ù¥ó¥È¤¬¼Â¹ÔÃ椫¤É¤¦¤«¤Î¥Õ¥é¥° private bool isEventRunning = false; private Coroutine currentEventCoroutine; private void Start() { MoveToNextPosition(); } private void Update() { if (isEventRunning) return; if (Input.GetKeyDown(KeyCode.Space)) { // ¥×¥ì¥¤¥ä¡¼¤¬¥Ü¥¿¥ó¤ò²¡¤¹¤È¥¤¥Ù¥ó¥È¤ò³«»Ï StartEvent(); } } private void StartEvent() { if (currentPosition >= events.Count) { // ¥²¡¼¥à½ªÎ» Debug.Log("¥²¡¼¥à½ªÎ»"); return; } EventBase currentEvent = events[currentPosition]; currentEventCoroutine = StartCoroutine(RunEvent(currentEvent)); } private IEnumerator RunEvent(EventBase eventObj) { isEventRunning = true; // ¥¤¥Ù¥ó¥È¼Â¹ÔÃæ¤Ï¥²¡¼¥à¤Î¿Ê¹Ô¤ò°ì»þÄä»ß Time.timeScale = 0f; yield return StartCoroutine(eventObj.ExecuteEvent()); // ¥¤¥Ù¥ó¥È½ªÎ»¤Þ¤ÇÂÔµ¡ while (isEventRunning) { yield return null; } // ¥¤¥Ù¥ó¥È¤¬½ªÎ»¤·¤¿¤é¥²¡¼¥à¤Î¿Ê¹Ô¤òºÆ³« Time.timeScale = 1f; currentPosition++; MoveToNextPosition(); } public void EndEvent() { isEventRunning = false; currentPosition++; // ¼¡¤Î¥Þ¥¹¤Ë°ÜÆ°¤·¡¢¥Ü¥¿¥ó¤òɽ¼¨ MoveToNextPosition(); } private void MoveToNextPosition() { if (currentPosition < events.Count) { Vector3 nextPosition = new Vector3(currentPosition, 0, 0); // ¥Þ¥¹¤´¤È¤ËXºÂɸ¤òÊѤ¨¤ë player.position = nextPosition; // ¼¡¤Î¥Þ¥¹¤Ë¥Ü¥¿¥ó¤òɽ¼¨ events[currentPosition].gameObject.SetActive(true); } } }
¡¡¤³¤Î¥µ¥ó¥×¥ë¥³¡¼¥É¤Ç¤Ï¡¢¥×¥ì¥¤¥ä¡¼¤¬¥¹¥Ú¡¼¥¹¥¡¼¤ò²¡¤¹¤È¥¤¥Ù¥ó¥È¤¬¼Â¹Ô¤µ¤ì¡¢
¥¤¥Ù¥ó¥È¤¬½ªÎ»¤¹¤ë¤È¼¡¤Î¥Þ¥¹¤Ë°ÜÆ°¤·¡¢¼¡¤Î¥¤¥Ù¥ó¥È¤Î¥Ü¥¿¥ó¤òɽ¼¨¤·¤Þ¤¹¡£¥²¡¼¥à¤Î¿Ê¹Ô¤Ï¥¤¥Ù¥ó¥È¼Â¹ÔÃæ¤ËÄä»ß¤·¤Þ¤¹¡£
¡¡¥³¥ë¡¼¥Á¥ó¥á¥½¥Ã¥ÉÆâÉô¤Î½èÍý¤Ë¤Ï¡¢¿§¡¹¤Ê¥¢¥×¥í¡¼¥Á¤¬¤¢¤ê¤Þ¤¹¡£
private IEnumerator RunEvent(EventBase eventObj) { isEventRunning = true; // ¥¤¥Ù¥ó¥È¼Â¹ÔÃæ¤Ï¥²¡¼¥à¤Î¿Ê¹Ô¤¬Ää»ß // UniTask¤äyield return StartCoroutine¤ò»È¤Ã¤Æ¤â¤è¤¤ eventObj.ExecuteEvent(); // ¥¤¥Ù¥ó¥È½ªÎ»¤Þ¤ÇÂÔµ¡ while (isEventRunning) { yield return null; } }
private IEnumerator RunEvent(EventBase eventObj) { isEventRunning = true; // ¥¤¥Ù¥ó¥È¼Â¹ÔÃæ¤Ï¥²¡¼¥à¤Î¿Ê¹Ô¤¬Ää»ß yield retrurn StartCoroutine(eventObj.ExecuteEvent()); // ¥¤¥Ù¥ó¥È½ªÎ»¤Þ¤ÇÂÔµ¡ yield return new WaitUntil(() => !isEventRunning); }
private IEnumerator RunEvent(EventBase eventObj) { isEventRunning = true; // ¥¤¥Ù¥ó¥È¼Â¹ÔÃæ¤Ï¥²¡¼¥à¤Î¿Ê¹Ô¤¬Ää»ß eventObj.ExecuteEvent(); // ¥¤¥Ù¥ó¥È½ªÎ»¤Þ¤ÇÂÔµ¡ yield return new WaitUntil(() => !isEventRunning); }
¡¡Â¾¤Ë¤â UniTask ¤ò³èÍѤ¹¤ë¤³¤È¤Ç¤â¥ê¥Õ¥¡¥¯¥¿¥ê¥ó¥°¤Ç¤¤Þ¤¹¡£
¡¡¥¤¥Ù¥ó¥ÈÍѤλҥ¯¥é¥¹¤Ç¤¹¡£
using UnityEngine; using System.Collections; public class BattleEvent : EventBase { public override IEnumerator ExecuteEvent() { Debug.Log("¥Ð¥È¥ë¥¤¥Ù¥ó¥È¤¬È¯À¸¤·¤Þ¤·¤¿¡£Å¨¤ÈÀ襤¤Þ¤¹¡ª"); // ¥Ð¥È¥ë¤Î¼ÂºÝ¤Î½èÍý¤ò¤³¤³¤ËÄɲà // ¥Ð¥È¥ë¤¬½ªÎ»¤¹¤ë¤Þ¤ÇÂÔµ¡ yield return new WaitForSeconds(2.0f); // ²¾¤ÎÂÔµ¡»þ´Ö // ¥Ð¥È¥ë¤¬½ªÎ»¤·¤¿¤é¥¤¥Ù¥ó¥È½ªÎ»¤òÄÌÃÎ EndEvent(); } public override EventType GetEventType() { return EventType.Battle; } }
- ¥«¥Æ¥´¥ê¡§
- ¿Ê³Ø/¥¹¥¯¡¼¥ë
- ¥×¥í¥°¥é¥ß¥ó¥°
¥³¥á¥ó¥È¤ò¤«¤¯