From a1c12b6e3380b2d9082635e42b8c371ed29373bd Mon Sep 17 00:00:00 2001 From: kimura Date: Thu, 24 Jun 2021 09:54:32 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=95=E3=83=A9=E3=82=A4=E3=83=91=E3=83=B3?= =?UTF-8?q?=E3=81=AE=E5=8B=95=E3=81=8D=E3=82=92=E5=90=8C=E6=9C=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MyGame/Scenes/Main/Controller.prefab | 2 +- popcorn/Assets/MyGame/Scenes/Main/Main.unity | 28 +++++++++++ popcorn/Assets/MyGame/Scenes/Main/Pan.cs | 5 +- .../MyGame/Scenes/Main/PanController.cs | 46 +++++++++++-------- popcorn/Assets/PopcornGameManager.cs | 10 +++- 5 files changed, 68 insertions(+), 23 deletions(-) diff --git a/popcorn/Assets/MyGame/Scenes/Main/Controller.prefab b/popcorn/Assets/MyGame/Scenes/Main/Controller.prefab index da0a9859..1c3c5667 100644 --- a/popcorn/Assets/MyGame/Scenes/Main/Controller.prefab +++ b/popcorn/Assets/MyGame/Scenes/Main/Controller.prefab @@ -168,7 +168,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 9389c53fc5fd43caaa8a8b9ac0a38cba, type: 3} m_Name: m_EditorClassIdentifier: - thrust: 1 + thrust: 0.01 --- !u!58 &1458261573237666836 CircleCollider2D: m_ObjectHideFlags: 0 diff --git a/popcorn/Assets/MyGame/Scenes/Main/Main.unity b/popcorn/Assets/MyGame/Scenes/Main/Main.unity index 2a9a581a..e300cdd1 100644 --- a/popcorn/Assets/MyGame/Scenes/Main/Main.unity +++ b/popcorn/Assets/MyGame/Scenes/Main/Main.unity @@ -238,6 +238,18 @@ RectTransform: m_AnchoredPosition: {x: 0, y: 0} m_SizeDelta: {x: 100, y: 100} m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &402129742 stripped +MonoBehaviour: + m_CorrespondingSourceObject: {fileID: 1453251556377932374, guid: b6b05cbc51c744ac2ad95a8b229d4ddd, + type: 3} + m_PrefabInstance: {fileID: 2137549891} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 722195db1b0214a7ab110e4cf4c2a7ce, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &420543913 GameObject: m_ObjectHideFlags: 0 @@ -753,6 +765,7 @@ MonoBehaviour: powerMeter: {fileID: 8786490829663474092} powerResultText: {fileID: 8786490830332208977} gameResultText: {fileID: 1003859323} + panController: {fileID: 402129742} --- !u!4 &1870432534 Transform: m_ObjectHideFlags: 0 @@ -874,6 +887,11 @@ PrefabInstance: m_Modification: m_TransformParent: {fileID: 0} m_Modifications: + - target: {fileID: 1453251556377932374, guid: b6b05cbc51c744ac2ad95a8b229d4ddd, + type: 3} + propertyPath: lerpTime + value: 17.89 + objectReference: {fileID: 0} - target: {fileID: 1453251556377932392, guid: b6b05cbc51c744ac2ad95a8b229d4ddd, type: 3} propertyPath: m_Name @@ -949,6 +967,16 @@ PrefabInstance: propertyPath: m_LocalEulerAnglesHint.z value: 0 objectReference: {fileID: 0} + - target: {fileID: 1453251556405238011, guid: b6b05cbc51c744ac2ad95a8b229d4ddd, + type: 3} + propertyPath: thrust + value: 3 + objectReference: {fileID: 0} + - target: {fileID: 1453251557352552633, guid: b6b05cbc51c744ac2ad95a8b229d4ddd, + type: 3} + propertyPath: m_EdgeRadius + value: 0.63 + objectReference: {fileID: 0} - target: {fileID: 1760968235348138510, guid: b6b05cbc51c744ac2ad95a8b229d4ddd, type: 3} propertyPath: m_Material diff --git a/popcorn/Assets/MyGame/Scenes/Main/Pan.cs b/popcorn/Assets/MyGame/Scenes/Main/Pan.cs index 4efb0e13..25d0db0b 100644 --- a/popcorn/Assets/MyGame/Scenes/Main/Pan.cs +++ b/popcorn/Assets/MyGame/Scenes/Main/Pan.cs @@ -7,7 +7,6 @@ namespace MyGame.Scenes.Main { [SerializeField] private float thrust; private PanController controller; - private int direct; private void Start() { @@ -18,7 +17,9 @@ namespace MyGame.Scenes.Main { // Debug.Log(controller.Direction); // 移動量が少ないときは動かない - direct = controller.Delta.magnitude < 0.1f ? 0 : 1; + // if (controller.Delta.magnitude >= 1f) Debug.Log(controller.Delta.magnitude); + var direct = 1f; + // direct = controller.Delta.magnitude < 0.1f ? 0 : 1; other.attachedRigidbody.AddForce(controller.Delta * thrust * direct, ForceMode2D.Impulse); } } diff --git a/popcorn/Assets/MyGame/Scenes/Main/PanController.cs b/popcorn/Assets/MyGame/Scenes/Main/PanController.cs index 2a5444f2..e74cdcb6 100644 --- a/popcorn/Assets/MyGame/Scenes/Main/PanController.cs +++ b/popcorn/Assets/MyGame/Scenes/Main/PanController.cs @@ -8,45 +8,55 @@ using UnityEngine.EventSystems; [RequireComponent(typeof(BoxCollider2D))] public class PanController : MonoBehaviour//, IDragHandler, IBeginDragHandler { + [SerializeField] private float lerpTime = 0.1f; private Transform cacheTransform; private Vector3 offset; private readonly (float min, float max) borderX = (-4.1f, 4.1f); private readonly (float min, float max) borderY = (-4.1f, 4.1f); - // private readonly float futonSpeedMagnificcation = 20f; - // public float FutonSpeed { get; private set; } - // public bool IsEnter { get; private set; } + private Vector2 direction; - public Vector2 Direction => direction; + // public Vector2 Direction => direction; private Vector2 delta; public Vector2 Delta => delta; private Vector3 prevPos; + private float deltaTime = 0f; + private bool isMove; // Start is called before the first frame update void Start() { cacheTransform = gameObject.transform; prevPos = cacheTransform.position; + deltaTime = 0.5f; + direction = Vector2.left; + target = transform.position + 1.5f / 2 * new Vector3(direction.x, direction.y, 0f); } + private Vector3 target; // Update is called once per frame void Update() { - // FutonSpeed = 0f; - // localPosを比較 - // IsEnter = cacheTransform.localPosition.y >= clearLocalPosition.y; - // OnDragが更新されていない場合は方向をゼロにしたいがUpdateでゼロにすると使えなくなるため保留 - if (cacheTransform.position == prevPos) - { - direction = Vector2.zero; - } - prevPos = cacheTransform.position; - } + // if (cacheTransform.position == prevPos) + // { + // direction = Vector2.zero; + // } - private void OnEnable() - { - // FutonSpeed = 0f; - // IsEnter = false; + if (deltaTime >= 1f) + { + isMove = !isMove; + deltaTime = 0f; + } + if (!isMove && Mathf.Approximately(transform.position.x, target.x)) + { + direction = direction * -1; + target = transform.position + 1.3f * new Vector3(direction.x, direction.y, 0f); + } + transform.position = Vector3.Lerp(transform.position, target, lerpTime * Time.deltaTime); + delta = cacheTransform.position - prevPos; + + deltaTime += Time.deltaTime; + prevPos = cacheTransform.position; } public void OnDrag(PointerEventData eventData) diff --git a/popcorn/Assets/PopcornGameManager.cs b/popcorn/Assets/PopcornGameManager.cs index 374e4628..c162c21b 100644 --- a/popcorn/Assets/PopcornGameManager.cs +++ b/popcorn/Assets/PopcornGameManager.cs @@ -11,6 +11,7 @@ public class PopcornGameManager : MonoBehaviour [SerializeField] private PowerMeter powerMeter; [SerializeField] private Text powerResultText; [SerializeField] private Text gameResultText; + [SerializeField] private PanController panController; private Action tapAction; private bool isProgress; @@ -27,13 +28,16 @@ public class PopcornGameManager : MonoBehaviour startingGuide.SetActive(true); powerMeter.StopMove(); isProgress = false; + panController.enabled = false; // タップしたら案内非表示&ゲーム開始 tapAction = () => { startingGuide.SetActive(false); + // panController.enabled = true; GameStart(); }; + } private void GameStart() @@ -63,7 +67,8 @@ public class PopcornGameManager : MonoBehaviour gameResultText.text = "失敗!"; powerMeter.gameObject.SetActive(false); tapAction = () => { }; - this.CallWaitForSeconds(1f, () => + panController.enabled = false; + this.CallWaitForSeconds(2f, () => { gameResultText.text = "タップでリスタート"; tapAction = () => { @@ -81,7 +86,8 @@ public class PopcornGameManager : MonoBehaviour gameResultText.text = "成功!"; powerMeter.gameObject.SetActive(false); tapAction = () => { }; - this.CallWaitForSeconds(1f, () => + panController.enabled = false; + this.CallWaitForSeconds(2f, () => { gameResultText.text = "タップでリスタート"; tapAction = () => {