基础弹幕系统

This commit is contained in:
sin365 2023-01-17 17:28:47 +08:00
parent 0efb1bba27
commit 366bc4276e
14 changed files with 501 additions and 8 deletions

View File

@ -28,7 +28,8 @@ Transform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Children:
- {fileID: 6273990009438270686}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -91,8 +92,89 @@ BoxCollider:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3926400312630769306}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_IsTrigger: 1
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 0.5, y: 0.5, z: 0.5}
m_Center: {x: 0, y: 0, z: 0}
--- !u!1 &6862467690558022025
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 6273990009438270686}
- component: {fileID: 1223491631508479639}
- component: {fileID: 5437983146542946664}
m_Layer: 0
m_Name: Capsule
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &6273990009438270686
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6862467690558022025}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0.2, y: 0.2, z: 0.2}
m_Children: []
m_Father: {fileID: 1694234330929003566}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!33 &1223491631508479639
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6862467690558022025}
m_Mesh: {fileID: 10208, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &5437983146542946664
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6862467690558022025}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 31321ba15b8f8eb4c954353edc038b1d, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 8a238977bf9e79e449ad714592bd3539
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,42 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 066a4514947a39a4cb32a81dc2c9166d, type: 3}
m_Name: 1
m_EditorClassIdentifier:
TaskList:
- StartTime: 0
StartAngle: 0
IntervalTime: 0.1
IntervalAngle: 20
Speed: 5
sprite: {fileID: 0}
AfterFireAngle: 10
bCicircular: 0.5
LimitNum: 10
- StartTime: 0.6
StartAngle: 0
IntervalTime: 0.1
IntervalAngle: 20
Speed: 5
sprite: {fileID: 0}
AfterFireAngle: 10
bCicircular: 0.5
LimitNum: 10
- StartTime: 1.2
StartAngle: 0
IntervalTime: 0.1
IntervalAngle: 20
Speed: 5
sprite: {fileID: 0}
AfterFireAngle: 10
bCicircular: 0.5
LimitNum: 10

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6ec85d61b8d0edd498cc2ba2ae16556e
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,51 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 066a4514947a39a4cb32a81dc2c9166d, type: 3}
m_Name: 2
m_EditorClassIdentifier:
TaskList:
- StartTime: 0
StartAngle: 180
IntervalTime: 0.1
IntervalAngle: -20
Speed: 5
sprite: {fileID: 0}
AfterFireAngle: 10
bCicircular: 0.5
LimitNum: 10
- StartTime: 0.1
StartAngle: 180
IntervalTime: 0.1
IntervalAngle: -20
Speed: 5
sprite: {fileID: 0}
AfterFireAngle: 10
bCicircular: 0.5
LimitNum: 10
- StartTime: 0.2
StartAngle: 180
IntervalTime: 0.1
IntervalAngle: -20
Speed: 5
sprite: {fileID: 0}
AfterFireAngle: 10
bCicircular: 0.5
LimitNum: 10
- StartTime: 0.3
StartAngle: 180
IntervalTime: 0.1
IntervalAngle: -20
Speed: 5
sprite: {fileID: 0}
AfterFireAngle: 10
bCicircular: 0.5
LimitNum: 10

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 27a7474892ef1004e80827daa83ee917
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -22,13 +22,35 @@ namespace Game
return false;
}
#region µ¯Ä»
static public string GetBulletProfabPath(string Name)
{
return $"Assets/GameAssets/Prefabs/Bullet/{Name}.prefab"; ;
}
static public string GetBulletCfgPath(string Name)
{
return "Assets/GameAssets/ScriptableObjectCfg/BulletCfg/" + Name + ".asset"; ;
}
#endregion
/// <summary>
/// 根据角度算向量
/// </summary>
/// <param name="angle"></param>
static public Vector3 GetVecForAngleXZ(float angle)
{
return new Vector3(100 * Mathf.Cos(angle * Mathf.PI / 180), 0,100 * Mathf.Sin(angle * Mathf.PI / 180)).normalized;
}
/// <summary>
/// 根据角度算向量
/// </summary>
/// <param name="angle"></param>
static public Vector3 GetVecForAngleXY(float angle)
{
return new Vector3(100 * Mathf.Cos(angle * Mathf.PI / 180),100 * Mathf.Sin(angle * Mathf.PI / 180),0).normalized;
}
}
}

View File

@ -55,6 +55,10 @@ namespace Game
void Update()
{
Update_MoveForInput();
//test
if (Input.GetKeyDown(KeyCode.Z)) GamePlayEntry.BulletMgr.AddBulletRun(GamePlayEntry.MainPlayer.Player.transform.position, "1");
if (Input.GetKeyDown(KeyCode.X)) GamePlayEntry.BulletMgr.AddBulletRun(GamePlayEntry.MainPlayer.Player.transform.position, "2");
}
public void LoadPlayer()

View File

@ -5,6 +5,9 @@ using Axibug.Resources;
using System.Collections.Generic;
using System.Diagnostics.SymbolStore;
using System.Runtime.Remoting.Metadata.W3cXsd2001;
using System.Linq;
using Axibug;
using UnityEditor.Graphs;
namespace Game
{
@ -28,7 +31,8 @@ namespace Game
public override void FixedUpdate()
{
FixedUpdate_BullteCheck();
FixedUpdate_BullteFly();
}
public override void OnApplicationPause()
@ -41,11 +45,205 @@ namespace Game
}
#endregion
void NewBullet()
#region
class BulletRunState
{
public Vector3 CenterPos;
public float RunStartTime;
public BulletGroupCfg cfgs;
public bool[] Task_bStart;
public bool[] Task_bFinish;
public float[] Task_LastDoTime;
public int[] Task_Num;
public float[] Task_LastAngle;
}
List<BulletRunState> _BulletRunList = new List<BulletRunState>();
List<BulletRunState> Temp_RemoveRun = new List<BulletRunState>();
public void AddBulletRun(Vector3 CenterPos,string BulletCfgName)
{
string path = Common.GetBulletCfgPath(BulletCfgName);
BulletGroupCfg cfg = GamePlayEntry.Resources.LoadAsset(path) as BulletGroupCfg;
AddBulletRun(CenterPos, cfg);
}
public void AddBulletRun(Vector3 CenterPos, BulletGroupCfg cfg)
{
BulletRunState run = new BulletRunState();
run.CenterPos = CenterPos;
run.RunStartTime = Time.time;
run.cfgs = cfg;
int taskcount = cfg.TaskList.Count;
run.Task_bStart = new bool[taskcount];
run.Task_bFinish = new bool[taskcount];
run.Task_LastDoTime = new float[taskcount];
run.Task_Num = new int[taskcount];
run.Task_LastAngle = new float[taskcount];
for (int i = 0; i < cfg.TaskList.Count; i++)
{
run.Task_bStart[i] = false;
run.Task_bFinish[i] = false;
run.Task_LastDoTime[i] = -1f;
run.Task_LastAngle[i] = 0;
run.Task_Num[i] = 0;
}
_BulletRunList.Add(run);
}
void FixedUpdate_BullteCheck()
{
Temp_RemoveRun.Clear();
for (int i = 0; i < _BulletRunList.Count; i++)
{
BulletRunState run = _BulletRunList[i];
//没有未完成
if (!run.Task_bFinish.Contains(false))
{
Temp_RemoveRun.Add(run);
continue;
}
for (int j = 0; j < run.Task_bFinish.Length; j++)
{
//已完成
if (run.Task_bFinish[j]) continue;
BulletGroupCfg_Task onecfg = run.cfgs.TaskList[j];
bool bFrie = false;
bool bFrist = false;
//未开始 判断开始时间
if (!run.Task_bStart[j])
{
if (Time.time - run.RunStartTime > onecfg.StartTime)
{
run.Task_bStart[j] = true;
bFrist = true;
bFrie = true;
}
}
else//未开始 判断间隔时间
{
if (Time.time - run.Task_LastDoTime[j]> onecfg.IntervalTime)
{
run.Task_bStart[j] = true;
bFrie = true;
}
}
//如果发射才执行
if (!bFrie) continue;
float FrieAngle;
if (bFrist)//如果是第一次
{
FrieAngle = onecfg.StartAngle;
}
else//不是第一次
{
FrieAngle = run.Task_LastAngle[j] + onecfg.IntervalAngle;
}
//修正角度(?可能求余 好一些?
if (FrieAngle > 360) FrieAngle -= 360;
if (FrieAngle < -360) FrieAngle += 360;
run.Task_LastAngle[j] = FrieAngle;
run.Task_LastDoTime[j] = Time.time;
run.Task_Num[j]++;
//TODO 发射
//FrieAngle + onecfg.AfterFireAngle;
AddBulletFly(run.CenterPos, onecfg, FrieAngle + onecfg.AfterFireAngle);
AxibugLog.Debug("发送弹幕");
//判断是否结束
if (onecfg.bCicircular > 0)//按照圈数
{
if (Mathf.Abs(run.Task_Num[j] * onecfg.IntervalAngle) / 360f >= onecfg.bCicircular)
run.Task_bFinish[j] = true;
}
else//不按照圈数,按照数量
{
if (run.Task_Num[j] >= onecfg.LimitNum)
run.Task_bFinish[j] = true;
}
}
}
if (Temp_RemoveRun.Count > 0)
{
for (int i = 0; i < Temp_RemoveRun.Count; i++)
{
_BulletRunList.Remove(Temp_RemoveRun[i]);
}
Temp_RemoveRun.Clear(); ;
}
}
#endregion
#region Bullte
class BulletFlyState
{
public Vector3 StartPos;
public float StartTime;
public float Speed;
public Vector3 Dir;
public GameObject go;
}
const float BulletMaxTime = 5f;
List<BulletFlyState> _BulletFlyStateList = new List<BulletFlyState>();
List<BulletFlyState> Temp_RemoveFly = new List<BulletFlyState>();
public void FixedUpdate_BullteFly()
{
Temp_RemoveFly.Clear();
for (int i = 0; i < _BulletFlyStateList.Count; i++)
{
BulletFlyState fly = _BulletFlyStateList[i];
if (Time.time - fly.StartTime > BulletMaxTime)
{
Temp_RemoveFly.Add(fly);
continue;
}
//飞行移动
fly.go.transform.position += Time.deltaTime * fly.Speed * fly.Dir;
}
if (Temp_RemoveFly.Count > 0)
{
for (int i = 0; i < Temp_RemoveFly.Count; i++)
{
//回池
Temp_RemoveFly[i].go.SetActive(false);
_BulletFlyStateList.Remove(Temp_RemoveFly[i]);
}
Temp_RemoveFly.Clear();
}
}
void AddBulletFly(Vector3 Center, BulletGroupCfg_Task cfg,float FrieAngle)
{
GameObject obj = _BulletPool.GetAnyHide();
obj.GetHashCode();
//TODO sprite
//TODO 音效
//TODO 发射位置偏移(距离中心位置偏移距离
obj.transform.position = Center;
_BulletFlyStateList.Add(new BulletFlyState()
{
Speed = cfg.Speed,
StartPos = Center,
StartTime = Time.time,
Dir = Common.GetVecForAngleXY(FrieAngle),
go = obj
});
}
#endregion
}
}

View File

@ -24,7 +24,6 @@ namespace Game
private float temp_RequestTime = 0;
private int mRoleIdSeed = 0;
#region
public RoleMgrNoMono(string Name, Transform trans = null) : base(Name, trans)
{

View File

@ -0,0 +1,59 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "BulletGroupCfg", menuName = "ScriptableObject/创建BulletGroupCfg", order = 0)]
public class BulletGroupCfg : ScriptableObject
{
public List<BulletGroupCfg_Task> TaskList;
public BulletGroupCfg()
{
TaskList = new List<BulletGroupCfg_Task>();
}
}
[Serializable]
public class BulletGroupCfg_Task
{
/// <summary>
/// 开始时间(距离释放时间)
/// </summary>
public float StartTime;
/// <summary>
/// 开始角度
/// </summary>
public float StartAngle;
/// <summary>
/// 每次间隔时间
/// </summary>
public float IntervalTime;
/// <summary>
/// 每次间隔角度
/// </summary>
public float IntervalAngle;
/// <summary>
/// 速度
/// </summary>
public float Speed = 5;
public Sprite sprite;
/// <summary>
/// 发射后的相对角度
/// </summary>
public float AfterFireAngle;
/// <summary>
/// 是否圆周 [0]不使用圆周限制 [1] [2] [3] 限制周数
/// </summary>
public float bCicircular;
/// <summary>
/// 最大数量(如果不是圆)
/// </summary>
public float LimitNum;
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 066a4514947a39a4cb32a81dc2c9166d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -3,7 +3,7 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "BulletData", menuName = "ScriptableObject/子弹数据", order = 0)]
[CreateAssetMenu(fileName = "MapMonsterCfg", menuName = "ScriptableObject/´´½¨MapMonsterCfg", order = 0)]
public class MapMonsterCfg : ScriptableObject
{
public int MapID;

View File

@ -57,6 +57,7 @@ public class PrefabPoolForPath
mb_vParentTf = tfParent;
switch (mb_vPrefabType)
{
case E_PREFAB_TYPE.NONE:
case E_PREFAB_TYPE.EFFECT:
mb_vPrefabPath = prefabPath;
break;