更改文件架构
This commit is contained in:
22
Packages/Common~/Scripts/VFXManager/BITKit.VFX.asmdef
Normal file
22
Packages/Common~/Scripts/VFXManager/BITKit.VFX.asmdef
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "VFXManager",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:a209c53514018594f9f482516f2a6781",
|
||||
"GUID:9e24947de15b9834991c9d8411ea37cf",
|
||||
"GUID:84651a3751eca9349aac36a66bba901b",
|
||||
"GUID:49b49c76ee64f6b41bf28ef951cb0e50",
|
||||
"GUID:be17a8778dbfe454890ed8279279e153",
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
|
||||
"GUID:9400d40641bab5b4a9702f65bf5c6eb5"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ea5474181b324dd49a5976cd68f44f18
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
16
Packages/Common~/Scripts/VFXManager/VFX.cs
Normal file
16
Packages/Common~/Scripts/VFXManager/VFX.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
namespace BITKit
|
||||
{
|
||||
public class VFX : BITKitSO, IObjectElement<string, Transform>
|
||||
{
|
||||
public string[] tags;
|
||||
public Transform[] prefabs;
|
||||
public AudioClip[] clips;
|
||||
public Transform GetValue() => prefabs.Random();
|
||||
public Transform prefab=>prefabs.Random();
|
||||
public bool IsMatch(string[] key)=>MathE.Contains(key,tags);
|
||||
}
|
||||
}
|
11
Packages/Common~/Scripts/VFXManager/VFX.cs.meta
Normal file
11
Packages/Common~/Scripts/VFXManager/VFX.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fdd387d83e4ca1e42ac03c3aa9700ffb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
29
Packages/Common~/Scripts/VFXManager/VFXPlayer.cs
Normal file
29
Packages/Common~/Scripts/VFXManager/VFXPlayer.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
namespace BITKit
|
||||
{
|
||||
public class VFXPlayer : MonoBehaviour, IAction
|
||||
{
|
||||
public Optional<ParticleSystem[]> allowParticles;
|
||||
public Optional<Light> allowLight;
|
||||
public void Excute()
|
||||
{
|
||||
if(allowParticles.Allow)
|
||||
{
|
||||
foreach (var particle in allowParticles.Value)
|
||||
{
|
||||
particle.time = 0;
|
||||
particle.Play(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#if UNITY_EDITOR
|
||||
[UnityEditor.CustomEditor(typeof(VFXPlayer))]
|
||||
public class VFXPlayerInspector:BITInspector<VFXPlayer>
|
||||
{
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
11
Packages/Common~/Scripts/VFXManager/VFXPlayer.cs.meta
Normal file
11
Packages/Common~/Scripts/VFXManager/VFXPlayer.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4daf805c91d04d6409660f7675cbdb52
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
65
Packages/Common~/Scripts/VFXManager/VFXService.cs
Normal file
65
Packages/Common~/Scripts/VFXManager/VFXService.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using BITKit;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.Pool;
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
public struct VFXMessage
|
||||
{
|
||||
public string path;
|
||||
public Location location;
|
||||
}
|
||||
//[CreateOnStart(BITAppForUnity.Path.Services,nameof(VFXService))]
|
||||
public class VFXService : MonoBehaviour, IObjectMatcher<string, Transform>
|
||||
{
|
||||
static VFXService sinleton;
|
||||
public VFX[] vfxs;
|
||||
Dictionary<string, UnityPool<Transform>> pools = new();
|
||||
void Awake()
|
||||
{
|
||||
sinleton = this;
|
||||
DI.Register(this);
|
||||
}
|
||||
public Transform Spawn(VFXMessage message)
|
||||
{
|
||||
if (Data.TryGetValue<Transform>(message.path, out var vfx))
|
||||
{
|
||||
return Instantiate(vfx, message.location, message.location);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public Transform Spawn(Location location, params string[] keyWords)
|
||||
{
|
||||
if (TryMatch(out var prefab, keyWords))
|
||||
{
|
||||
var pool = pools.Get(prefab.name);
|
||||
var instance = pool.Get(prefab,transform);
|
||||
instance.SetPositionAndRotation(location, location);
|
||||
instance.forward = location.forward;
|
||||
return instance;
|
||||
}
|
||||
else
|
||||
{
|
||||
BIT4Log.Log<VFXService>($"未找到:{JsonHelper.Get(keyWords)}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryMatch(out Transform value, params string[] key)
|
||||
{
|
||||
foreach (var vfx in vfxs)
|
||||
{
|
||||
if (vfx.IsMatch(key))
|
||||
{
|
||||
value = vfx.prefab;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
value = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
11
Packages/Common~/Scripts/VFXManager/VFXService.cs.meta
Normal file
11
Packages/Common~/Scripts/VFXManager/VFXService.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c754132856288ea4180e46d87fc46be9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user