提交 73a4b170 编写于 作者: 魔术师Dix's avatar 魔术师Dix

添加本地测试用例,生成粒子以调试;

上级 46ea5106
......@@ -23,8 +23,153 @@ MonoBehaviour:
SerializationNodes: []
Config:
BatchParticleCount: 512
ParticleGroups: []
ListGroupConfig: []
ParticleGroupConfigs:
- ConfigID: 0
SourceParticlePrefab: {fileID: 2408373863616230867, guid: 9b5c60020a23743418f9bad0a4ed0eda, type: 3}
BatchParticleCount: 512
ReserveCount: 8
ExpansionCount: 4
Particles:
- ParticleSystemIndex: 0
Duration: 3
Loop: 1
m_Position:
x: 0
y: 0
z: 0
m_Velocity:
x: 0
y: 0
z: 0
m_AnimatedVelocity:
x: 0
y: 0
z: 0
m_InitialVelocity:
x: 0
y: 0
z: 0
m_AxisOfRotation:
x: 0
y: 0
z: 1
m_Rotation:
x: 0
y: 0
z: 0
m_AngularVelocity:
x: 0
y: 0
z: 0
m_StartSize:
x: 1.78
y: 1.78
z: 1.78
m_StartColor:
serializedVersion: 2
rgba: 3662723320
m_RandomSeed: 638269364
m_ParentRandomSeed: 0
m_Lifetime: 0.44981024
m_StartLifetime: 1.9498088
m_MeshIndex: -1
m_EmitAccumulator0: 0
m_EmitAccumulator1: 0
m_Flags: 0
- ParticleSystemIndex: 1
Duration: 1
Loop: 1
m_Position:
x: 0
y: 0
z: 0
m_Velocity:
x: 0
y: 0
z: 0
m_AnimatedVelocity:
x: 0
y: 0
z: 0
m_InitialVelocity:
x: 0
y: 0
z: 0
m_AxisOfRotation:
x: 0
y: 0
z: 1
m_Rotation:
x: 0
y: 0
z: 0
m_AngularVelocity:
x: 0
y: 0
z: 0
m_StartSize:
x: 1.78
y: 1.78
z: 1.78
m_StartColor:
serializedVersion: 2
rgba: 4294967295
m_RandomSeed: 2820221114
m_ParentRandomSeed: 0
m_Lifetime: 0.33333337
m_StartLifetime: 1
m_MeshIndex: -1
m_EmitAccumulator0: 0
m_EmitAccumulator1: 0
m_Flags: 0
- ParticleSystemIndex: 2
Duration: 5
Loop: 1
m_Position:
x: 0
y: 0
z: 0
m_Velocity:
x: 0
y: 0
z: 0
m_AnimatedVelocity:
x: 0
y: 0
z: 0
m_InitialVelocity:
x: 0
y: 0
z: 0
m_AxisOfRotation:
x: 0
y: 0
z: 1
m_Rotation:
x: 0
y: 0
z: 0
m_AngularVelocity:
x: 0
y: 0
z: 0
m_StartSize:
x: 1.78
y: 1.78
z: 1.78
m_StartColor:
serializedVersion: 2
rgba: 4294967295
m_RandomSeed: 2820221114
m_ParentRandomSeed: 0
m_Lifetime: 0.33333337
m_StartLifetime: 1
m_MeshIndex: -1
m_EmitAccumulator0: 0
m_EmitAccumulator1: 0
m_Flags: 0
ListGroupConfig:
- {fileID: 11400000, guid: 84469826bb78844429d3ad29d6d0d436, type: 2}
ListFxPrefab:
- {fileID: 2408373863616230867, guid: 9b5c60020a23743418f9bad0a4ed0eda, type: 3}
ConfigPath: Assets/GameRes/Config/ParticleGroup
......@@ -4869,7 +4869,7 @@ ParticleSystemRenderer:
m_FreeformStretching: 0
m_RotateWithStretchDirection: 1
m_VertexStreams: 0001030409
m_Mesh: {fileID: 4300000, guid: f8186d29d6a404f4bab3ca0a333be00e, type: 3}
m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0}
m_Mesh1: {fileID: 0}
m_Mesh2: {fileID: 0}
m_Mesh3: {fileID: 0}
......
......@@ -35,9 +35,9 @@ namespace TouchFish.Omphalia.Local
[PropertyOrder(10)]
public void UpdateData()
{
Config.ParticleGroups.Clear();
Config.ParticleGroupConfigs.Clear();
foreach (var item in ListGroupConfig)
Config.ParticleGroups.Add(item.Config);
Config.ParticleGroupConfigs.Add(item.Config);
}
[LabelText("特效预制")]
......
......@@ -22,7 +22,17 @@ namespace TouchFish.Omphalia.Local
private void Start()
{
OmphaliaUtils.Init(Config.Config);
}
private void Update()
{
OmphaliaUtils.Update(Time.realtimeSinceStartup);
}
private void OnDestroy()
{
OmphaliaUtils.Dispose();
}
}
......
/*
*Copyright(C) 2023 by TouchFinsh All rights reserved.
*Unity版本:2020.3.43f1c1
*作者:Chief
*创建日期: 2023-04-20
*版本: 0.1
*/
using Sirenix.OdinInspector;
using UnityEngine;
namespace TouchFish.Omphalia.Local
{
/// <summary>
/// 本地例子生成器
/// </summary>
public class OmphaliaLocalSpawner : MonoBehaviour
{
[LabelText("目标配置")]
public int ConfigID;
[Button("生成一个")]
[HideInEditorMode]
public void SpawnOne()
{
ParticleGroupSpawnInfo spawnInfo = new ParticleGroupSpawnInfo(transform.position, transform.rotation, transform.localScale, Time.realtimeSinceStartup);
OmphaliaUtils.SpawnParticle(ConfigID, spawnInfo);
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 8d4c370c91d7d6648a83a44062066eb8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -606,7 +606,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!4 &1765665486
Transform:
m_ObjectHideFlags: 0
......@@ -626,6 +626,50 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1938569926
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1938569928}
- component: {fileID: 1938569927}
m_Layer: 0
m_Name: OmphaliaLocalSpawner
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1938569927
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1938569926}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 8d4c370c91d7d6648a83a44062066eb8, type: 3}
m_Name:
m_EditorClassIdentifier:
ConfigID: 0
--- !u!4 &1938569928
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1938569926}
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_Father: {fileID: 0}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &2029928270
PrefabInstance:
m_ObjectHideFlags: 0
......
......@@ -31,7 +31,7 @@ namespace TouchFish.Omphalia
#if ODIN_INSPECTOR
[LabelText("粒子组配置")]
#endif
public List<ParticleGroupConfig> ParticleGroups = new List<ParticleGroupConfig>();
public List<ParticleGroupConfig> ParticleGroupConfigs = new List<ParticleGroupConfig>();
}
}
\ No newline at end of file
......@@ -135,7 +135,7 @@ namespace TouchFish.Omphalia
AxisOfRotation = m_AxisOfRotation,
Rotation = m_Rotation + spawnInfo.Rotation,
AngularVelocity = m_AngularVelocity,
StartSize = m_StartSize + spawnInfo.Scale,
StartSize = m_StartSize * spawnInfo.Scale,
StartColor = m_StartColor,
RandomSeed = m_RandomSeed,
ParentRandomSeed = m_ParentRandomSeed,
......
......@@ -63,6 +63,9 @@ namespace TouchFish.Omphalia
/// </summary>
public void Init()
{
particleSystem?.Clear();
particleSystem.SetParticles(null);
particleSystem.Stop();
SetArrayLength(ParticleCount * ReserveCount);
}
......@@ -89,15 +92,23 @@ namespace TouchFish.Omphalia
m_OmphaliaParticles.CopyTo(m_Particles);
}
private int unityParticleCount;
private Particle[] m_Particles;
#endregion
#region 显示更新
private int unityParticleCount;
private Particle[] m_Particles;
public void UpdateView()
{
if (unityParticleCount <= 0)
{
particleSystem.Stop();
return;
}
if (!particleSystem.isPlaying)
particleSystem.Play();
particleSystem?.SetParticles(m_Particles, unityParticleCount);
}
......
......@@ -7,6 +7,7 @@
*/
using System;
using System.Collections.Generic;
using System.Reflection;
using Unity.Entities;
using UnityEngine;
......@@ -26,6 +27,61 @@ namespace TouchFish.Omphalia
{
Config = config;
OmphaliaFxRoot = new GameObject("OmphaliaFxRoot").transform;
//开始生成所有配置
m_DictParticleGroups.Clear();
CreateAllGroup();
}
private static void CreateAllGroup()
{
m_DictParticleGroups.Clear();
var configs = Config.ParticleGroupConfigs;
foreach (var config in configs)
{
ParticleGroup group = new ParticleGroup();
group.Init(config, true);
m_DictParticleGroups[config.ConfigID]= group;
}
}
private static Dictionary<int, ParticleGroup> m_DictParticleGroups = new Dictionary<int, ParticleGroup>();
public static void Update(float gameTime)
{
GameTime = gameTime;
foreach (var item in m_DictParticleGroups.Values)
{
item.UpdateAll();
}
}
public static void Dispose()
{
}
#endregion
#region 外部调用接口
public static int SpawnParticle(int cfgId, ParticleGroupSpawnInfo spawnInfo)
{
ParticleGroup group;
if (m_DictParticleGroups.TryGetValue(cfgId, out group))
{
return group.Add(spawnInfo);
}
return -1;
}
public static void RemoveParticle(int cfgId, int index)
{
ParticleGroup group;
if (m_DictParticleGroups.TryGetValue(cfgId, out group))
{
group.Remove(index);
}
}
#endregion
......
......@@ -40,8 +40,6 @@ namespace TouchFish.Omphalia
//生成运行时粒子配置
particleSystems = gameObject.GetComponentsInChildren<ParticleSystem>();
foreach (var particle in particleSystems)
particle.Clear();//清空所有默认的粒子
m_InitConfig = true;
......@@ -94,8 +92,9 @@ namespace TouchFish.Omphalia
/// </summary>
private int m_EnableCount;
public int Add(Vector3 pos, Quaternion rot, Vector3 scale, float startTime)
public int Add(ParticleGroupSpawnInfo spawnInfo)
{
m_IsDirty = true;
//找一个空位;
int length = m_SpawnInfos.Count;
for (int i = 0; i < length; i++)
......@@ -103,12 +102,12 @@ namespace TouchFish.Omphalia
var info = m_SpawnInfos[i];
if (!info.Enable)
{
m_SpawnInfos[i] = new ParticleGroupSpawnInfo(pos, rot, scale, startTime);
m_SpawnInfos[i] = spawnInfo;
m_EnableCount++;
return i;
}
}
m_SpawnInfos.Add(new ParticleGroupSpawnInfo(pos, rot, scale, startTime));
m_SpawnInfos.Add(spawnInfo);
m_EnableCount++;
return length;
}
......@@ -120,14 +119,21 @@ namespace TouchFish.Omphalia
m_EnableCount--;
var spawnInfo = m_SpawnInfos[index];
spawnInfo.Enable = false;
m_IsDirty = true;
}
#endregion
#region Update
private bool m_IsDirty = false;
public void UpdateAll()
{
//if (!m_IsDirty)
// return;
//m_IsDirty = false;
UpdateData();
UpdateView();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册