歩行処理追加

This commit is contained in:
kimura 2021-08-25 13:51:36 +09:00
parent a1fd392e06
commit d245325863
5 changed files with 273 additions and 5 deletions

View File

@ -0,0 +1,156 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &5409985849651702440
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 5409985849651702441}
- component: {fileID: 5715829407227760309}
- component: {fileID: 1385243083193661112}
m_Layer: 0
m_Name: Customer
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &5409985849651702441
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5409985849651702440}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: -1.55, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 5409985851491668856}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &5715829407227760309
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5409985849651702440}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3aa8dec9a88540bf93de4c93663335ec, type: 3}
m_Name:
m_EditorClassIdentifier:
walkSideTopPos: -1.55
walkSideBottomPos: -6.5
walkSideSpeed: 1.3
walkFrontSpeed: 1
animator: {fileID: 5409985851491668857}
--- !u!114 &1385243083193661112
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5409985849651702440}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 786931d1da2c4b1c8ce9519c9b3c32fd, type: 3}
m_Name:
m_EditorClassIdentifier:
animator: {fileID: 0}
--- !u!1001 &631677504613307640
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 5409985849651702441}
m_Modifications:
- target: {fileID: 4886416728471897984, guid: db654393793a67d45a7d0b70a68b73a6,
type: 3}
propertyPath: m_RootOrder
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4886416728471897984, guid: db654393793a67d45a7d0b70a68b73a6,
type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4886416728471897984, guid: db654393793a67d45a7d0b70a68b73a6,
type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4886416728471897984, guid: db654393793a67d45a7d0b70a68b73a6,
type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4886416728471897984, guid: db654393793a67d45a7d0b70a68b73a6,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4886416728471897984, guid: db654393793a67d45a7d0b70a68b73a6,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4886416728471897984, guid: db654393793a67d45a7d0b70a68b73a6,
type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4886416728471897984, guid: db654393793a67d45a7d0b70a68b73a6,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4886416728471897984, guid: db654393793a67d45a7d0b70a68b73a6,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4886416728471897984, guid: db654393793a67d45a7d0b70a68b73a6,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4886416728471897984, guid: db654393793a67d45a7d0b70a68b73a6,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4886416728471897999, guid: db654393793a67d45a7d0b70a68b73a6,
type: 3}
propertyPath: m_Name
value: NormalBody
objectReference: {fileID: 0}
- target: {fileID: 4886416729748261544, guid: db654393793a67d45a7d0b70a68b73a6,
type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4886416730379292500, guid: db654393793a67d45a7d0b70a68b73a6,
type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: db654393793a67d45a7d0b70a68b73a6, type: 3}
--- !u!4 &5409985851491668856 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 4886416728471897984, guid: db654393793a67d45a7d0b70a68b73a6,
type: 3}
m_PrefabInstance: {fileID: 631677504613307640}
m_PrefabAsset: {fileID: 0}
--- !u!95 &5409985851491668857 stripped
Animator:
m_CorrespondingSourceObject: {fileID: 4886416728471897985, guid: db654393793a67d45a7d0b70a68b73a6,
type: 3}
m_PrefabInstance: {fileID: 631677504613307640}
m_PrefabAsset: {fileID: 0}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 6fbb038c9aae840f2bea57bce30740f7
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,89 @@
using System;
using UniRx;
using UniRx.Triggers;
using UnityEditor.UIElements;
using UnityEngine;
using Random = UnityEngine.Random;
public enum CustomerMovingType
{
WalkFront,
WalkSide,
WalkBack,
StayBack,
WalkFrontEat,
WalkSideEat,
}
public class CustomerController : MonoBehaviour
{
private static readonly int WalkFront = Animator.StringToHash("WalkFront");
private static readonly int WalkSide = Animator.StringToHash("WalkSide");
private static readonly int WalkBack = Animator.StringToHash("WalkBack");
private static readonly int StayBack = Animator.StringToHash("StayBack");
private static readonly int WalkFrontEat = Animator.StringToHash("WalkFrontEat");
private static readonly int WalkSideEat = Animator.StringToHash("WalkSideEat");
// 画面端
private float leftEndPosision = -10f;
// 歩道の幅(min,max)
[SerializeField] private float walkSideTopPos = -1.55f;
[SerializeField] private float walkSideBottomPos = -6.50f;
// 歩行速度
[SerializeField] private float walkSideSpeed = 1.3f; // 1.3f
[SerializeField] private float walkFrontSpeed = 1.0f; // 1.0f
private Vector3 speed = Vector3.zero;
// 停止時間
// 左右どちらから出るか
[SerializeField] private Animator animator;
private void Start()
{
this.UpdateAsObservable().Subscribe(_ =>
{
transform.localPosition += speed * Time.deltaTime;
}).AddTo(this);
}
public void Setup()
{
var tmpPos = Vector3.zero;
tmpPos.x = leftEndPosision;
tmpPos.y = Random.Range(walkSideTopPos, walkSideBottomPos);
transform.localPosition = tmpPos;
}
public void SetMove(CustomerMovingType type)
{
switch (type)
{
case CustomerMovingType.WalkFront:
animator.SetTrigger(WalkFront);
break;
case CustomerMovingType.WalkSide:
speed = Vector3.right * walkSideSpeed;
animator.SetTrigger(WalkSide);
break;
case CustomerMovingType.WalkBack:
animator.SetTrigger(WalkBack);
break;
case CustomerMovingType.StayBack:
speed = Vector3.zero;
animator.SetTrigger(StayBack);
break;
case CustomerMovingType.WalkFrontEat:
animator.SetTrigger(WalkFrontEat);
break;
case CustomerMovingType.WalkSideEat:
animator.SetTrigger(WalkSideEat);
break;
default:
throw new ArgumentOutOfRangeException(nameof(type), type, null);
}
}
public void SetCustomerType()
{
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3aa8dec9a88540bf93de4c93663335ec
timeCreated: 1629854874

View File

@ -12,26 +12,39 @@ public class Market : MonoBehaviour
[SerializeField] private ShopStockView stockView;
[SerializeField] private MarketCartView cartView;
[SerializeField] private GameObject customerPrefab;
// Start is called before the first frame update
void Start()
{
var gameData = GameDataManager.GameData;
CoinManager.Instance.ChangeCoin(gameData.coin);
// 在庫数表示
stockView.SetStock(gameData.StorageTanks);
// 全レシピ
var allRecipe = RecipeData.GetAllRecipe();
// 在庫数表示
stockView.SetStock(gameData.StorageTanks);
StockFlavorLog();
// 陳列
var displayFlavors = gameData.ShopStock.Select(x => x).ToList();
cartView.SetStock(displayFlavors);
// 売り順決定
var shuffledOrder = ShuffleOrder(displayFlavors.Count);
// お客さん出現パターン確率計算と行動パターン計算
Observable.Interval(TimeSpan.FromSeconds(.5f)).Take(5).Subscribe(_ =>
{
var customer = Instantiate(customerPrefab);
var customerController = customer.GetComponent<CustomerController>();
customerController.SetMove(CustomerMovingType.WalkSide);
customerController.Setup();
var heartAnimation = customer.GetComponent<HeartAnimation>();
Observable.Timer(TimeSpan.FromSeconds(2f)).Subscribe(__ =>
{
heartAnimation.GetHeart();
});
}).AddTo(this);
// お客さんの出現タイミング(10秒間に回)
Observable.Timer(TimeSpan.FromSeconds(2f), TimeSpan.FromSeconds(10f))