From 9bcf9a9597f211785b2e074103fcd5bf464793e3 Mon Sep 17 00:00:00 2001 From: kimura Date: Wed, 21 Jul 2021 11:50:36 +0900 Subject: [PATCH] =?UTF-8?q?=E8=8B=97=E3=81=AE=E3=83=AD=E3=82=B8=E3=83=83?= =?UTF-8?q?=E3=82=AF=E3=81=A8=E3=83=93=E3=83=A5=E3=83=BC=E3=82=92=E5=88=86?= =?UTF-8?q?=E5=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Scenes/CornField/Prefabs/Seedling.prefab | 42 +++++++++ .../Scenes/CornField/Scripts/CornSeedling.cs | 81 ++++------------- .../CornField/Scripts/CornSeedlingView.cs | 87 +++++++++++++++++++ .../Scripts/CornSeedlingView.cs.meta | 3 + 4 files changed, 150 insertions(+), 63 deletions(-) create mode 100644 popcorn/Assets/MyGame/Scenes/CornField/Scripts/CornSeedlingView.cs create mode 100644 popcorn/Assets/MyGame/Scenes/CornField/Scripts/CornSeedlingView.cs.meta diff --git a/popcorn/Assets/MyGame/Scenes/CornField/Prefabs/Seedling.prefab b/popcorn/Assets/MyGame/Scenes/CornField/Prefabs/Seedling.prefab index 8b768dbb..35c5f253 100644 --- a/popcorn/Assets/MyGame/Scenes/CornField/Prefabs/Seedling.prefab +++ b/popcorn/Assets/MyGame/Scenes/CornField/Prefabs/Seedling.prefab @@ -314,6 +314,7 @@ GameObject: - component: {fileID: 875275074368017840} - component: {fileID: 875275074368017842} - component: {fileID: 875275074368017841} + - component: {fileID: 3560956324713403295} m_Layer: 0 m_Name: one_d m_TagString: Untagged @@ -404,6 +405,32 @@ Animator: m_HasTransformHierarchy: 1 m_AllowConstantClipSamplingOptimization: 1 m_KeepAnimatorControllerStateOnDisable: 0 +--- !u!61 &3560956324713403295 +BoxCollider2D: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 875275074368017847} + m_Enabled: 1 + m_Density: 1 + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_UsedByEffector: 0 + m_UsedByComposite: 0 + m_Offset: {x: 0, y: -0.74168634} + m_SpriteTilingProperty: + border: {x: 0, y: 0, z: 0, w: 0} + pivot: {x: 0.5, y: 0.5} + oldSize: {x: 1.7, y: 4.04} + newSize: {x: 1.7, y: 4.04} + adaptiveTilingThreshold: 0.5 + drawMode: 0 + adaptiveTiling: 0 + m_AutoTiling: 0 + serializedVersion: 2 + m_Size: {x: 1.0807116, y: 2.404545} + m_EdgeRadius: 0 --- !u!1 &875275074515791082 GameObject: m_ObjectHideFlags: 0 @@ -414,6 +441,7 @@ GameObject: m_Component: - component: {fileID: 875275074515791083} - component: {fileID: 3152473785108484531} + - component: {fileID: 1162919361388578994} m_Layer: 0 m_Name: Seedling m_TagString: Untagged @@ -451,9 +479,23 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 1b5e732e57e34b97a8adc725ce004566, type: 3} m_Name: m_EditorClassIdentifier: + seedlingView: {fileID: 1162919361388578994} +--- !u!114 &1162919361388578994 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 875275074515791082} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: dc986cc5c74043e08218a00c53d6f418, type: 3} + m_Name: + m_EditorClassIdentifier: seedlingStage1: {fileID: 875275074110174225} seedlingStage2: {fileID: 875275074190396077} seedlingStage3: {fileID: 875275073577674106} seedlingStage4: {fileID: 875275074368017847} + stage4Collider: {fileID: 3560956324713403295} growingArrowPrefab: {fileID: 4493492865567033234, guid: b3d641214f420f74290147d368b221fa, type: 3} diff --git a/popcorn/Assets/MyGame/Scenes/CornField/Scripts/CornSeedling.cs b/popcorn/Assets/MyGame/Scenes/CornField/Scripts/CornSeedling.cs index 328e0ace..edff399d 100644 --- a/popcorn/Assets/MyGame/Scenes/CornField/Scripts/CornSeedling.cs +++ b/popcorn/Assets/MyGame/Scenes/CornField/Scripts/CornSeedling.cs @@ -1,10 +1,10 @@ using System; using UniRx; using UnityEngine; -using Random = UnityEngine.Random; public enum SeedlingStage { + Stage0, Stage1, Stage2, Stage3, @@ -20,14 +20,10 @@ public enum SeedlingRank public class CornSeedling : MonoBehaviour { - [SerializeField] private GameObject seedlingStage1; - [SerializeField] private GameObject seedlingStage2; - [SerializeField] private GameObject seedlingStage3; - [SerializeField] private GameObject seedlingStage4; - [SerializeField] private GameObject growingArrowPrefab; - private readonly int nextStageTriggerHash = Animator.StringToHash("NextStageTrigger"); - private static readonly float stage1End = 0.32f; - private static readonly float stage2End = 0.67f; + [SerializeField] private CornSeedlingView seedlingView; + private static readonly float stage0End = 0.25f; + private static readonly float stage1End = 0.50f; + private static readonly float stage2End = 0.75f; private static readonly float stage3End = 1f; private int period; @@ -46,10 +42,7 @@ public class CornSeedling : MonoBehaviour private void ResetGrowth() { - seedlingStage1.SetActive(false); - seedlingStage2.SetActive(false); - seedlingStage3.SetActive(false); - seedlingStage4.SetActive(false); + seedlingView.ResetView(); } public void PromoteGrowth(DateTime newTime) @@ -60,8 +53,7 @@ public class CornSeedling : MonoBehaviour } beginTime = newTime; UpdateStage(); - var arrow = Instantiate(growingArrowPrefab, transform); - this.CallWaitForSeconds(0.5f, () => Destroy(arrow)); + seedlingView.EffectGrowth(); } public void SetSeedlingGene(DateTime dateTime, int periodTime, SeedlingRank rank) @@ -69,65 +61,24 @@ public class CornSeedling : MonoBehaviour completed = false; compositeDisposable.Clear(); ResetGrowth(); + seedlingStage.SetValueAndForceNotify(SeedlingStage.Stage0); beginTime = dateTime; period = periodTime; seedlingRank = rank; // resume対応 // 途中からの場合アニメーションを勧めておく処理 - var stage = GetCurrentStage(); - seedlingStage.SetValueAndForceNotify(stage); - switch (stage) - { - case SeedlingStage.Stage1: - seedlingStage1.SetActive(true); - break; - case SeedlingStage.Stage2: - seedlingStage2.SetActive(true); - break; - case SeedlingStage.Stage3: - seedlingStage3.SetActive(true); - break; - case SeedlingStage.Stage4: - seedlingStage4.SetActive(true); - break; - default: - throw new ArgumentOutOfRangeException(); - } - + seedlingView.SetView(GetCurrentStage()); + // 成長ロジック seedlingStage .TakeWhile(_ => !completed) .Subscribe(x => { - switch (x) + seedlingView.ChangeState(x); + if (x == SeedlingStage.Stage4) { - case SeedlingStage.Stage1: - break; - case SeedlingStage.Stage2: - seedlingStage1.GetComponent().SetTrigger(nextStageTriggerHash); - this.CallWaitForSeconds(.25f, () => - { - seedlingStage2.SetActive(true); - }); - break; - case SeedlingStage.Stage3: - seedlingStage2.GetComponent().SetTrigger(nextStageTriggerHash); - this.CallWaitForSeconds(.25f, () => - { - seedlingStage3.SetActive(true); - }); - break; - case SeedlingStage.Stage4: - seedlingStage3.GetComponent().SetTrigger(nextStageTriggerHash); - this.CallWaitForSeconds(.25f, () => - { - completed = true; - seedlingStage4.SetActive(true); - }); - break; - default: - throw new ArgumentOutOfRangeException(nameof(x), x, null); + completed = true; } }).AddTo(compositeDisposable); @@ -161,6 +112,10 @@ public class CornSeedling : MonoBehaviour { return SeedlingStage.Stage2; } - return SeedlingStage.Stage1; + if (elapsed >= stage0End) + { + return SeedlingStage.Stage1; + } + return SeedlingStage.Stage0; } } \ No newline at end of file diff --git a/popcorn/Assets/MyGame/Scenes/CornField/Scripts/CornSeedlingView.cs b/popcorn/Assets/MyGame/Scenes/CornField/Scripts/CornSeedlingView.cs new file mode 100644 index 00000000..5ef84840 --- /dev/null +++ b/popcorn/Assets/MyGame/Scenes/CornField/Scripts/CornSeedlingView.cs @@ -0,0 +1,87 @@ +using System; +using UnityEngine; + +public class CornSeedlingView : MonoBehaviour +{ + [SerializeField] private GameObject seedlingStage1; + [SerializeField] private GameObject seedlingStage2; + [SerializeField] private GameObject seedlingStage3; + [SerializeField] private GameObject seedlingStage4; + [SerializeField] private Collider2D stage4Collider; + [SerializeField] private GameObject growingArrowPrefab; + private readonly int nextStageTriggerHash = Animator.StringToHash("NextStageTrigger"); + + public void ResetView() + { + seedlingStage1.SetActive(false); + seedlingStage2.SetActive(false); + seedlingStage3.SetActive(false); + seedlingStage4.SetActive(false); + } + + public void SetView(SeedlingStage stage) + { + switch (stage) + { + case SeedlingStage.Stage0: + break; + case SeedlingStage.Stage1: + seedlingStage1.SetActive(true); + break; + case SeedlingStage.Stage2: + seedlingStage2.SetActive(true); + break; + case SeedlingStage.Stage3: + seedlingStage3.SetActive(true); + break; + case SeedlingStage.Stage4: + seedlingStage4.SetActive(true); + break; + default: + throw new ArgumentOutOfRangeException(); + } + } + + // 一段階成長するときアニメーションを再生して次の段階の素材に切り替え + // アニメーション再生中0:15で次の段階の素材に切り替え、アニメーションは最後まで再生 + public void ChangeState(SeedlingStage stage) + { + switch (stage) + { + case SeedlingStage.Stage0: + break; + case SeedlingStage.Stage1: + seedlingStage1.SetActive(true); + break; + case SeedlingStage.Stage2: + seedlingStage1.GetComponent().SetTrigger(nextStageTriggerHash); + this.CallWaitForSeconds(.25f, () => + { + seedlingStage2.SetActive(true); + }); + break; + case SeedlingStage.Stage3: + seedlingStage2.GetComponent().SetTrigger(nextStageTriggerHash); + this.CallWaitForSeconds(.25f, () => + { + seedlingStage3.SetActive(true); + }); + break; + case SeedlingStage.Stage4: + seedlingStage3.GetComponent().SetTrigger(nextStageTriggerHash); + this.CallWaitForSeconds(.25f, () => + { + seedlingStage4.SetActive(true); + }); + break; + default: + throw new ArgumentOutOfRangeException(nameof(stage), stage, null); + } + } + + public void EffectGrowth() + { + var arrow = Instantiate(growingArrowPrefab, transform); + this.CallWaitForSeconds(0.5f, () => Destroy(arrow)); + } +} \ No newline at end of file diff --git a/popcorn/Assets/MyGame/Scenes/CornField/Scripts/CornSeedlingView.cs.meta b/popcorn/Assets/MyGame/Scenes/CornField/Scripts/CornSeedlingView.cs.meta new file mode 100644 index 00000000..4b22bd8f --- /dev/null +++ b/popcorn/Assets/MyGame/Scenes/CornField/Scripts/CornSeedlingView.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: dc986cc5c74043e08218a00c53d6f418 +timeCreated: 1626832646 \ No newline at end of file