private void ThrowMove(float deltaTime) { if (mMoveType == Hi5ObjectMoveType.EThrowMove && mMoveData != null) { //if (Hi5_Interaction_Const.TestPhycis) { ObjectMoveData temp = mMoveData; { mMoveData.cd += deltaTime; float gravity = Physics.gravity.y * 8.1f / 9.8f; //float gravity = Physics.gravity.y; float y = 0; //y = (mMoveData.ySpeed /*- gravity*(9.8f-8.1f) * deltaTime*/)* (1.0f - mAirFrictionRate); y = (temp.ySpeed + gravity * deltaTime) * (1.0f - mAirFrictionRate); mMoveData.ySpeed = y; mMoveData.mDirection *= (1.0f - mAirFrictionRate); Vector3 move = new Vector3(mMoveData.mDirection.x, y, mMoveData.mDirection.z); if (!float.IsNaN(move.x) && !float.IsNaN(move.y) && !float.IsNaN(move.z)) { if (deltaTime > Hi5_Interaction_Const.PRECISION) { //mItem.transform.Translate(move * deltaTime, Space.World); mItem.GetComponent <Rigidbody>().velocity = move; } } } } } }
// OnUpdate runs on the main thread. protected override void OnUpdate() { float dt = Time.deltaTime; Debug.Assert(this.m_entityManager != null); Debug.Assert(this.m_bulletsList != null); Entities.ForEach(( ref BulletFactoryData factoryData ) => { factoryData.SpawnTimer -= dt; if (factoryData.SpawnTimer < 0) { factoryData.SpawnTimer = factoryData.SpawnCycle; Translation currentWorldPos = m_entityManager.GetComponentData <Translation>(factoryData.ParentEntity); ObjectMoveData moveData = new ObjectMoveData() { Speed = factoryData.Speed, Direction = new Translation() { Value = factoryData.MoveDirection } }; m_bulletsList.TryGetValue(factoryData.BulletListHandler, out var list); Spawn(m_entityManager, list, currentWorldPos.Value, factoryData.Damage, factoryData.BulletType, moveData); } }); }
internal void SetPlaneMove(Collision collision) { if (mMoveType == Hi5ObjectMoveType.EThrowMove || mMoveType == Hi5ObjectMoveType.EFree) { return; } //if (Hi5_Interaction_Const.TestPlaneMoveUsePhysic) { mMoveType = Hi5ObjectMoveType.EPlaneMove; return; } Queue <Hi5_Position_Record> records = null; if (collision.gameObject.GetComponent <Hi5_Hand_Collider_Visible_Finger>() != null) { records = collision.gameObject.GetComponent <Hi5_Hand_Collider_Visible_Finger>().mQueuePositionRecord; } if (collision.gameObject.GetComponent <Hi5_Hand_Palm_Move>() != null) { records = collision.gameObject.GetComponent <Hi5_Hand_Palm_Move>().GetRecord(); } if (records != null && records.Count > 0) { Vector3 distanceVector = Vector3.zero; int index = 0; int weightPointCount = 0; float timeCount = 0.0f; foreach (Hi5_Position_Record item in records) { if (Hi5_Interaction_Const.RecordPositionWeight.Length > index) { int weight = Hi5_Interaction_Const.RecordPositionWeight[index]; weightPointCount += weight; timeCount += item.mIntervalTime * weight; distanceVector += item.mMoveVector * weight; } index++; } mMoveData = new ObjectMoveData(); mMoveData.mDirection = distanceVector / timeCount; mMoveData.y = mMoveData.mDirection.y; mMoveData.ySpeed = mMoveData.mDirection.y; mMoveType = Hi5ObjectMoveType.EPlaneMove; contactPointNormal = collision.contacts[0].normal; contactPointNormal.y = 0.0f; mItem.SetIsLockYPosition(true); //mFlyMoveStartProtectionCd = Hi5_Interaction_Const.FingerPinchPauseProtectionTime; } }
public void Convert(Entity _entity, EntityManager dstManager, GameObjectConversionSystem _conversionSystem) { Translation t = new Translation(); t.Value = new float3(0f, 0f, 0f); var bulletData = new BulletData() { Damage = 1, }; var moveData = new ObjectMoveData() { Speed = 1.0f, Direction = t, }; dstManager.AddComponentData(_entity, bulletData); dstManager.AddComponentData(_entity, moveData); }
internal void StopMove() { //isMove = false; mMoveData = null; mMoveType = Hi5ObjectMoveType.ENone; //if (Hi5_Interaction_Const.TestPlaneMoveUsePhysic) { // mItem.SetIsKinematic(false); // mItem.SetIsLockYPosition(true); } //else //{ // mItem.SetIsKinematic(true); // mItem.SetIsLockYPosition(false); //} // mItem.SetUseGravity(true); //mItem.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationZ | RigidbodyConstraints.FreezePositionY; }
public void Convert(Entity _entity, EntityManager dstManager, GameObjectConversionSystem _conversionSystem) { Translation t = new Translation(); t.Value = new float3(0f, 0f, 0.0f); var moveData = new ObjectMoveData() { Speed = 1.0f, Direction = t, }; var playerData = new PlayerData() { Life = m_life, PrevScreenPos = new float2(Screen.width * 0.5f, Screen.height * 0.5f), }; var bulletFactoryData = new BulletFactoryData() { ParentEntity = _entity, PositionOffset = float3.zero, RotationOffset = float3.zero, SpawnCycle = m_spawnCycle, SpawnTimer = m_spawnCycle, /* バレットパラメーター */ Speed = 0.1f, MoveDirection = new float3(0f, 0f, 1f), Damage = 1, BulletType = 0, }; var bulletFactorySys = World.Active.GetOrCreateSystem <BulletFactorySystem>(); if (bulletFactorySys != null) { Camera cam = Camera.main; float frustumHeight = cam.transform.position.y * Mathf.Tan(cam.fieldOfView * 0.5f * Mathf.Deg2Rad); float frustumWidth = frustumHeight / Screen.height * Screen.width; float maxSize = math.max(frustumHeight * 2.0f, frustumWidth * 2.0f); int count = BulletFactorySystem.CalcPreloadObjectCount(maxSize, bulletFactoryData.Speed, 1.0f, bulletFactoryData.SpawnCycle); bulletFactoryData.BulletListHandler = bulletFactorySys.CreateBulletObject(count, m_bulletObjectPrefab, "MyBullet"); } dstManager.AddComponentData(_entity, moveData); dstManager.AddComponentData(_entity, playerData); dstManager.AddComponentData(_entity, bulletFactoryData); BulletCollisionSystem bulletSys = World.Active.GetOrCreateSystem <BulletCollisionSystem>(); bulletSys.Initialize(_entity); GAME.UI.UISystemManager.I.SetPlayerEntity(_entity); World.Active.GetOrCreateSystem <BulletComponentSystem>().Initialize(Camera.main); }
void CreatePlayer(PlayerScriptableObject _data, World _currentWorld) { EntityManager manager = _currentWorld.EntityManager; m_playerEntity = manager.Instantiate(GameObjectConversionUtility.ConvertGameObjectHierarchy(_data.ObjectModel, _currentWorld)); Translation t = new Translation(); t.Value = new float3(_data.DefaultPosition); var moveData = new ObjectMoveData() { Speed = 1.0f, Direction = t, }; var playerData = new PlayerData() { Life = _data.HP, PrevScreenPos = new float2(Screen.width * 0.5f, Screen.height * 0.5f), }; var bulletFactoryData = new BulletFactoryData() { ParentEntity = m_playerEntity, PositionOffset = float3.zero, RotationOffset = float3.zero, SpawnCycle = _data.SpawnCycle, SpawnTimer = _data.SpawnCycle, /* バレットパラメーター */ Speed = _data.BuleltSpeed, MoveDirection = new float3(0f, 0f, 1f), Damage = _data.BulletDamage, BulletType = 0, }; var bulletFactorySys = _currentWorld.GetOrCreateSystem <BulletFactorySystem>(); if (bulletFactorySys != null) { Camera cam = Camera.main; float frustumHeight = cam.transform.position.y * Mathf.Tan(cam.fieldOfView * 0.5f * Mathf.Deg2Rad); float frustumWidth = frustumHeight / Screen.height * Screen.width; float maxSize = math.max(frustumHeight * 2.0f, frustumWidth * 2.0f); int count = BulletFactorySystem.CalcPreloadObjectCount(maxSize, bulletFactoryData.Speed, 1.0f, bulletFactoryData.SpawnCycle); bulletFactoryData.BulletListHandler = bulletFactorySys.CreateBulletObject(count, _data.BulletModel, "MyBullet"); } manager.SetComponentData <Translation>(m_playerEntity, t); manager.AddComponentData(m_playerEntity, moveData); manager.AddComponentData(m_playerEntity, playerData); manager.AddComponentData(m_playerEntity, bulletFactoryData); BulletCollisionSystem bulletSys = _currentWorld.GetOrCreateSystem <BulletCollisionSystem>(); bulletSys.Initialize(m_playerEntity); _currentWorld.GetOrCreateSystem <BulletComponentSystem>().Initialize(Camera.main); }
void CreateEnemy(EnemyScriptableObject _data, World _currentWorld, int index) { EntityManager manager = _currentWorld.EntityManager; Entity model = manager.Instantiate(GameObjectConversionUtility.ConvertGameObjectHierarchy(_data.ObjectModel, _currentWorld)); #if UNITY_EDITOR manager.SetName(model, $"Enemy_{index:D4}"); #endif // Entity 管理に登録 EnemyComponentSystem enemySys = _currentWorld.GetOrCreateSystem <EnemyComponentSystem>(); int enemyId = enemySys.GetInstanceId(); enemySys.AddEnemyEntity(enemyId, model); // Enemy の基本データ EnemyData enemyData = new EnemyData() { Id = enemyId, HP = _data.HP, Score = _data.Score }; manager.AddComponentData(model, enemyData); Translation initPos = new Translation(); initPos.Value = new float3(_data.DefaultPosition); manager.SetComponentData <Translation>(model, initPos); Translation t = new Translation(); t.Value = new float3(0f, 0f, 0.0f); var moveData = new ObjectMoveData() { Speed = 0.0f, Direction = t, }; manager.AddComponentData(model, moveData); var bulletFactorySys = _currentWorld.GetOrCreateSystem <BulletFactorySystem>(); Camera cam = Camera.main; float frustumHeight = cam.transform.position.y * Mathf.Tan(cam.fieldOfView * 0.5f * Mathf.Deg2Rad); float frustumWidth = frustumHeight / Screen.height * Screen.width; float maxSize = math.max(frustumHeight * 2.0f, frustumWidth * 2.0f); for (int i = 0; i < _data.Nway; i++) { var factoryEntity = manager.CreateEntity(); var bulletFactoryData = new BulletFactoryData() { ParentEntity = model, PositionOffset = float3.zero, RotationOffset = float3.zero, SpawnCycle = _data.SpawnCycle, SpawnTimer = _data.SpawnCycle, /* バレットパラメーター */ Speed = _data.BuleltSpeed, MoveDirection = Utils.CalcDirection(i, _data.Nway - 1, new float3(0f, 0f, -1f), _data.Angle), Damage = 1, BulletType = 1, }; if (bulletFactorySys != null) { int count = BulletFactorySystem.CalcPreloadObjectCount(maxSize, bulletFactoryData.Speed, 1.0f, bulletFactoryData.SpawnCycle); bulletFactoryData.BulletListHandler = bulletFactorySys.CreateBulletObject(count, _data.BulletModel); manager.AddComponentData(factoryEntity, bulletFactoryData); // Enemy 管理システムにも登録 enemySys?.AddBulletFactoryRelation(enemyData.Id, factoryEntity); } } }
public void Convert(Entity _entity, EntityManager dstManager, GameObjectConversionSystem _conversionSystem) { Entity model = dstManager.Instantiate(GameObjectConversionUtility.ConvertGameObjectHierarchy(m_objectModel, World.Active)); // Entity 管理に登録 EnemyComponentSystem enemySys = World.Active.GetOrCreateSystem <EnemyComponentSystem>(); int enemyId = enemySys.GetInstanceId(); enemySys.AddEnemyEntity(enemyId, model); // Enemy の基本データ EnemyData enemyData = new EnemyData() { Id = enemyId, HP = m_hitPoint, Score = m_score }; dstManager.AddComponentData(model, enemyData); Translation initPos = new Translation(); initPos.Value = new float3(this.transform.position.x, this.transform.position.y, this.transform.position.z); dstManager.SetComponentData <Translation>(model, initPos); Translation t = new Translation(); t.Value = new float3(0f, 0f, 0.0f); var moveData = new ObjectMoveData() { Speed = 0.0f, Direction = t, }; dstManager.AddComponentData(model, moveData); var bulletFactorySys = World.Active.GetOrCreateSystem <BulletFactorySystem>(); Camera cam = Camera.main; float frustumHeight = cam.transform.position.y * Mathf.Tan(cam.fieldOfView * 0.5f * Mathf.Deg2Rad); float frustumWidth = frustumHeight / Screen.height * Screen.width; float maxSize = math.max(frustumHeight * 2.0f, frustumWidth * 2.0f); for (int i = 0; i < m_nway; i++) { var factoryEntity = dstManager.CreateEntity(); var bulletFactoryData = new BulletFactoryData() { ParentEntity = model, PositionOffset = float3.zero, RotationOffset = float3.zero, SpawnCycle = m_spawnCycle, SpawnTimer = m_spawnCycle, /* バレットパラメーター */ Speed = m_buleltSpeed, MoveDirection = CalcDirection(i, m_nway - 1, new float3(0f, 0f, -1f), m_angle), Damage = 1, BulletType = 1, }; if (bulletFactorySys != null) { int count = BulletFactorySystem.CalcPreloadObjectCount(maxSize, bulletFactoryData.Speed, 1.0f, bulletFactoryData.SpawnCycle); bulletFactoryData.BulletListHandler = bulletFactorySys.CreateBulletObject(count, m_bulletModel); dstManager.AddComponentData(factoryEntity, bulletFactoryData); // Enemy 管理システムにも登録 enemySys?.AddBulletFactoryRelation(enemyData.Id, factoryEntity); } } }
public void Spawn(EntityManager _entityManager, List <Entity> list, float3 _parentPos, int _damage, int _bulletType, ObjectMoveData moveData) { Debug.Assert(list != null); if (list == null) { return; } for (int i = 0; i < list.Count; i++) { BulletData bulletInfo = _entityManager.GetComponentData <BulletData>(list[i]); if (!bulletInfo.IsInitialized) { bulletInfo.IsInitialized = true; bulletInfo.IsCollide = false; bulletInfo.Damage = _damage; bulletInfo.BulletType = _bulletType; _entityManager.SetComponentData <Translation>(list[i], new Translation { Value = _parentPos }); _entityManager.SetComponentData <ObjectMoveData>(list[i], moveData); _entityManager.SetComponentData <BulletData>(list[i], bulletInfo); break; } } }
internal void SetMoveData(ObjectMoveData data) { mMoveData = data; }
//GameObject Clone = null; internal void CalculateThrowMove(Queue <Hi5_Position_Record> records, Transform handPalm, Hi5_Glove_Interaction_Hand hand) { mIsFlyMovePause = false; int index = 0; int weightPointCount = 0; float timeCount = 0.0f; Vector3 distanceVector = Vector3.zero; foreach (Hi5_Position_Record item in records) { if (Hi5_Interaction_Const.RecordPositionWeight.Length > index) { int weight = Hi5_Interaction_Const.RecordPositionWeight[index]; weightPointCount += weight; timeCount += item.mIntervalTime * weight; distanceVector += item.mMoveVector * weight; } index++; } if (index <= 1) { // mMoveData = new ObjectMoveData(); // mMoveData.mDirection = new Vector3 (0.0f, 0.08598139f, 0.0f); // mMoveData.y = mMoveData.mDirection.y; // mMoveData.ySpeed = mMoveData.mDirection.y; //Debug.Log("index <= 1"); Vector3 temp = hand.MoveAnchor.position - hand.mPalm.transform.position; temp.Normalize(); mMoveData = new ObjectMoveData(); mMoveData.mDirection = temp * 0.3998139f; mMoveData.y = mMoveData.mDirection.y; mMoveData.ySpeed = mMoveData.mDirection.y; // mMoveData = new ObjectMoveData(); // mMoveData.mDirection = distanceVector / timeCount* Hi5_Interaction_Const.ThrowSpeed; // mMoveData.y = mMoveData.mDirection.y; // mMoveData.ySpeed = mMoveData.mDirection.y; Hi5_Interaction_Const.WriteItemMoveXml(records, mMoveData); } else { //Debug.Log("index > 1"); mMoveData = new ObjectMoveData(); mMoveData.mDirection = distanceVector / timeCount * Hi5_Interaction_Const.ThrowSpeed; mMoveData.y = mMoveData.mDirection.y; mMoveData.ySpeed = mMoveData.mDirection.y; Hi5_Interaction_Const.WriteItemMoveXml(records, mMoveData); } //if (Hi5_Interaction_Const.TestPhycis) //if (Hi5_Interaction_Const.TestModifyConstraints) { //mItem.SetIsKinematic (false); //mItem.SetUseGravity (true); //mItem.CleanLock (); if (mItem.GetComponent <Hi5_Object_Property>() != null && mItem.GetComponent <Hi5_Object_Property>().ObjectProperty.AirMoveProperty != null) { mItem.SetIsKinematic(false); mItem.SetUseGravity(true); mItem.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.None; mItem.GetComponent <Hi5_Object_Property>().SetRotation(mItem.GetComponent <Hi5_Object_Property>().ObjectProperty.AirMoveProperty.ConstraintsFreezeRotation, mItem.GetComponent <Hi5_Object_Property>().ObjectProperty.AirMoveProperty.ConstraintsFreezeRotation, mItem.GetComponent <Hi5_Object_Property>().ObjectProperty.AirMoveProperty.ConstraintsFreezeRotation); } else { mItem.SetIsKinematic(false); mItem.SetUseGravity(true); mItem.CleanLock(); } } mMoveType = Hi5ObjectMoveType.EThrowMove; protectedTransform = handPalm; IsProtectFly = true; }
//internal void SetPlaneMove() //{ // if (mMoveType == Hi5ObjectMoveType.EThrowMove || mMoveType == Hi5ObjectMoveType.EFree) // return; // mMoveType = Hi5ObjectMoveType.EPlaneMove; //} internal void SetPlaneMove(Collision collision) { if (mMoveType == Hi5ObjectMoveType.EThrowMove || mMoveType == Hi5ObjectMoveType.EFree) { return; } //if (Hi5_Interaction_Const.TestPlaneMoveUsePhysic) { mMoveType = Hi5ObjectMoveType.EPlaneMove; if (mItem.GetComponent <Hi5_Object_Property>() != null && mItem.GetComponent <Hi5_Object_Property>().ObjectProperty.PlaneMoveProperty != null) { mItem.SetIsKinematic(false); mItem.SetUseGravity(true); mItem.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.None; mItem.GetComponent <Hi5_Object_Property>().SetRotation(mItem.GetComponent <Hi5_Object_Property>().ObjectProperty.PlaneMoveProperty.ConstraintsFreezeRotation, mItem.GetComponent <Hi5_Object_Property>().ObjectProperty.PlaneMoveProperty.ConstraintsFreezeRotation, mItem.GetComponent <Hi5_Object_Property>().ObjectProperty.PlaneMoveProperty.ConstraintsFreezeRotation); } else { mItem.SetIsKinematic(false); mItem.SetUseGravity(true); mItem.CleanLock(); } return; } Queue <Hi5_Position_Record> records = null; if (collision.gameObject.GetComponent <Hi5_Hand_Collider_Visible_Finger>() != null) { records = collision.gameObject.GetComponent <Hi5_Hand_Collider_Visible_Finger>().mQueuePositionRecord; } if (collision.gameObject.GetComponent <Hi5_Hand_Palm_Move>() != null) { records = collision.gameObject.GetComponent <Hi5_Hand_Palm_Move>().GetRecord(); } if (records != null && records.Count > 0) { Vector3 distanceVector = Vector3.zero; int index = 0; int weightPointCount = 0; float timeCount = 0.0f; foreach (Hi5_Position_Record item in records) { if (Hi5_Interaction_Const.RecordPositionWeight.Length > index) { int weight = Hi5_Interaction_Const.RecordPositionWeight[index]; weightPointCount += weight; timeCount += item.mIntervalTime * weight; distanceVector += item.mMoveVector * weight; } index++; } mMoveData = new ObjectMoveData(); mMoveData.mDirection = distanceVector / timeCount; mMoveData.y = mMoveData.mDirection.y; mMoveData.ySpeed = mMoveData.mDirection.y; mMoveType = Hi5ObjectMoveType.EPlaneMove; contactPointNormal = collision.contacts[0].normal; contactPointNormal.y = 0.0f; { //mItem.SetUseGravity(true); //mItem.SetIsKinematic(false); //mItem.CleanLock(); if (mItem.GetComponent <Hi5_Object_Property>() != null && mItem.GetComponent <Hi5_Object_Property>().ObjectProperty.PlaneMoveProperty != null) { mItem.SetIsKinematic(false); mItem.SetUseGravity(true); mItem.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.None; mItem.GetComponent <Hi5_Object_Property>().SetRotation(mItem.GetComponent <Hi5_Object_Property>().ObjectProperty.PlaneMoveProperty.ConstraintsFreezeRotation, mItem.GetComponent <Hi5_Object_Property>().ObjectProperty.PlaneMoveProperty.ConstraintsFreezeRotation, mItem.GetComponent <Hi5_Object_Property>().ObjectProperty.PlaneMoveProperty.ConstraintsFreezeRotation); } else { mItem.SetIsKinematic(false); mItem.SetUseGravity(true); mItem.CleanLock(); } } } }
internal void CacullateThrowMove(Queue <Hi5_Position_Record> records, Transform handPalm, Hi5_Glove_Interaction_Hand hand) { mIsFlyMovePause = false; int index = 0; int weightPointCount = 0; float timeCount = 0.0f; Vector3 distanceVector = Vector3.zero; foreach (Hi5_Position_Record item in records) { if (Hi5_Interaction_Const.RecordPositionWeight.Length > index) { int weight = Hi5_Interaction_Const.RecordPositionWeight[index]; weightPointCount += weight; timeCount += item.mIntervalTime * weight; distanceVector += item.mMoveVector * weight; } index++; } if (index <= 1) { // mMoveData = new ObjectMoveData(); // mMoveData.mDirection = new Vector3 (0.0f, 0.08598139f, 0.0f); // mMoveData.y = mMoveData.mDirection.y; // mMoveData.ySpeed = mMoveData.mDirection.y; Vector3 temp = hand.MoveAnchor.position - hand.mPalm.transform.position; temp.Normalize(); mMoveData = new ObjectMoveData(); mMoveData.mDirection = temp * 0.3998139f; mMoveData.y = mMoveData.mDirection.y; mMoveData.ySpeed = mMoveData.mDirection.y; // mMoveData = new ObjectMoveData(); // mMoveData.mDirection = distanceVector / timeCount* Hi5_Interaction_Const.ThrowSpeed; // mMoveData.y = mMoveData.mDirection.y; // mMoveData.ySpeed = mMoveData.mDirection.y; Hi5_Interaction_Const.WriteItemMoveXml(records, mMoveData); } else { mMoveData = new ObjectMoveData(); mMoveData.mDirection = distanceVector / timeCount * Hi5_Interaction_Const.ThrowSpeed; mMoveData.y = mMoveData.mDirection.y; mMoveData.ySpeed = mMoveData.mDirection.y; Hi5_Interaction_Const.WriteItemMoveXml(records, mMoveData); } //if (Hi5_Interaction_Const.TestFlyMoveNoUsedGravity) { mItem.SetIsKinematic(true); mItem.SetUseGravity(false); } //else //{ // mItem.SetIsKinematic(false); // mItem.SetUseGravity(true); //} mMoveType = Hi5ObjectMoveType.EThrowMove; protecedTransform = handPalm; IsProtectFly = true; }