fix:风机初始化代码提交
This commit is contained in:
@@ -0,0 +1,184 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
namespace Enviro
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface for a lightning effect.
|
||||
/// </summary>
|
||||
public interface ILightningEffect
|
||||
{
|
||||
/// <summary>
|
||||
/// Casts the bolt.
|
||||
/// </summary>
|
||||
/// <param name="origin">The starting position of the bolt.</param>
|
||||
/// <param name="target">The target position of the bolt.</param>
|
||||
void CastBolt(Vector3 origin, Vector3 target);
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class EnviroLightning
|
||||
{
|
||||
public Lightning prefab;
|
||||
public GameObject customLightningEffect;
|
||||
|
||||
public bool lightningStorm = false;
|
||||
[Range(1f,60f)]
|
||||
public float randomLightingDelay = 10.0f;
|
||||
[Range(0f,10000f)]
|
||||
public float randomSpawnRange = 5000.0f;
|
||||
[Range(0f,10000f)]
|
||||
public float randomTargetRange = 5000.0f;
|
||||
|
||||
[Range(0f,10000f)]
|
||||
public float cloudsLightningRadius = 2500.0f;
|
||||
[Range(.1f,5f)]
|
||||
public float cloudsLightningDuration = 1.0f;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class EnviroLightningModule : EnviroModule
|
||||
{
|
||||
public EnviroLightning Settings;
|
||||
public EnviroLightningModule preset;
|
||||
public bool showLightningControls;
|
||||
private bool spawned = false;
|
||||
|
||||
private float lightningStart = -999f;
|
||||
|
||||
// Update Method
|
||||
public override void UpdateModule ()
|
||||
{
|
||||
if(!active)
|
||||
return;
|
||||
|
||||
if(Application.isPlaying && Settings.lightningStorm && Settings.prefab != null)
|
||||
{
|
||||
CastLightningBoltRandom();
|
||||
}
|
||||
}
|
||||
|
||||
public void CastLightningBolt(Vector3 from, Vector3 to)
|
||||
{
|
||||
if(Settings.prefab != null)
|
||||
{
|
||||
GameObject lightningGameObject;
|
||||
if (Settings.customLightningEffect != null)
|
||||
{
|
||||
lightningGameObject = Instantiate(Settings.customLightningEffect, from, Quaternion.identity);
|
||||
}
|
||||
else
|
||||
{
|
||||
lightningGameObject = Instantiate(Settings.prefab, from, Quaternion.identity).gameObject;
|
||||
}
|
||||
|
||||
var lightningEffect = lightningGameObject.GetComponent<ILightningEffect>();
|
||||
lightningEffect.CastBolt(from, to);
|
||||
|
||||
|
||||
//Play Thunder SFX with delay if Audio module is used.
|
||||
if (EnviroManager.instance.Audio != null)
|
||||
{
|
||||
EnviroManager.instance.StartCoroutine(PlayThunderSFX(0.05f));
|
||||
}
|
||||
|
||||
if(EnviroManager.instance.VolumetricClouds != null)
|
||||
{
|
||||
EnviroManager.instance.StartCoroutine(CloudsFlash(0.25f,from));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Please assign a lightning prefab in your Enviro Ligthning module!");
|
||||
}
|
||||
}
|
||||
|
||||
public void CastLightningBoltRandom()
|
||||
{
|
||||
if(!spawned)
|
||||
{
|
||||
//Calculate some random spawn and target locations.
|
||||
Vector2 circlSpawn = UnityEngine.Random.insideUnitCircle * Settings.randomSpawnRange;
|
||||
Vector2 circlTarget = UnityEngine.Random.insideUnitCircle * Settings.randomTargetRange;
|
||||
float offset = 0f;
|
||||
|
||||
if(EnviroManager.instance.Objects.worldAnchor != null)
|
||||
offset = EnviroManager.instance.Objects.worldAnchor.transform.position.y;
|
||||
|
||||
float altitude = 2000f;
|
||||
|
||||
if(EnviroManager.instance.VolumetricClouds != null)
|
||||
altitude = Mathf.Max(EnviroManager.instance.VolumetricClouds.settingsVolume.bottomCloudsHeight + 1000f, 1000f);
|
||||
|
||||
Vector3 spawnPosition = new Vector3(circlSpawn.x + EnviroManager.instance.transform.position.x, offset + altitude, circlSpawn.y + EnviroManager.instance.transform.position.z);
|
||||
Vector3 targetPosition = new Vector3(circlTarget.x + spawnPosition.x,offset,circlTarget.y + spawnPosition.z);
|
||||
|
||||
EnviroManager.instance.StartCoroutine(LightningStorm(spawnPosition,targetPosition));
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator LightningStorm(Vector3 spwn, Vector3 targ)
|
||||
{
|
||||
spawned = true;
|
||||
CastLightningBolt(spwn,targ);
|
||||
yield return new WaitForSeconds(UnityEngine.Random.Range(Settings.randomLightingDelay, Settings.randomLightingDelay * 2f));
|
||||
spawned = false;
|
||||
}
|
||||
|
||||
private IEnumerator PlayThunderSFX(float delay)
|
||||
{
|
||||
yield return new WaitForSeconds(delay);
|
||||
EnviroManager.instance.Audio.PlayRandomThunderSFX();
|
||||
}
|
||||
private IEnumerator CloudsFlash(float delay, Vector3 from)
|
||||
{
|
||||
yield return new WaitForSeconds(delay);
|
||||
//Clouds
|
||||
lightningStart = Time.time;
|
||||
|
||||
// Pass to shader each frame
|
||||
Shader.SetGlobalVector("_LightningCenter", from);
|
||||
Shader.SetGlobalFloat("_LightningRadius", Settings.cloudsLightningRadius);
|
||||
Shader.SetGlobalFloat("_LightningStart", lightningStart);
|
||||
Shader.SetGlobalFloat("_LightningDuration", Settings.cloudsLightningDuration);
|
||||
}
|
||||
|
||||
//Save and Load
|
||||
public void LoadModuleValues ()
|
||||
{
|
||||
if(preset != null)
|
||||
{
|
||||
Settings = JsonUtility.FromJson<Enviro.EnviroLightning>(JsonUtility.ToJson(preset.Settings));
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Please assign a saved module to load from!");
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveModuleValues ()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
EnviroLightningModule t = ScriptableObject.CreateInstance<EnviroLightningModule>();
|
||||
t.name = "Lightning Preset";
|
||||
t.Settings = JsonUtility.FromJson<Enviro.EnviroLightning>(JsonUtility.ToJson(Settings));
|
||||
|
||||
string assetPathAndName = UnityEditor.AssetDatabase.GenerateUniqueAssetPath(EnviroHelper.assetPath + "/New " + t.name + ".asset");
|
||||
UnityEditor.AssetDatabase.CreateAsset(t, assetPathAndName);
|
||||
UnityEditor.AssetDatabase.SaveAssets();
|
||||
UnityEditor.AssetDatabase.Refresh();
|
||||
#endif
|
||||
}
|
||||
public void SaveModuleValues (EnviroLightningModule module)
|
||||
{
|
||||
module.Settings = JsonUtility.FromJson<Enviro.EnviroLightning>(JsonUtility.ToJson(Settings));
|
||||
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.EditorUtility.SetDirty(module);
|
||||
UnityEditor.AssetDatabase.SaveAssets();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 258de2724c9dfb643a546d0688715ff1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Modules/Lightning/EnviroLightningModule.cs
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,182 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
|
||||
namespace Enviro
|
||||
{
|
||||
|
||||
public class Lightning : MonoBehaviour, ILightningEffect
|
||||
{
|
||||
public void CastBolt(Vector3 origin, Vector3 target)
|
||||
{
|
||||
this.transform.position = origin;
|
||||
this.target = target;
|
||||
this.CastBolt();
|
||||
}
|
||||
|
||||
public float flashIntensity = 50f;
|
||||
public Vector3 target;
|
||||
private LineRenderer lineRend;
|
||||
public Light myLight;
|
||||
public Material planeMat;
|
||||
public int arcs = 20;
|
||||
public float arcLength = 100.0f;
|
||||
public float arcVariation = 1.0f;
|
||||
public float inaccuracy = 0.5f;
|
||||
public int splits = 4;
|
||||
public int maxSplits = 24;
|
||||
private int splitCount = 0;
|
||||
public float splitLength = 100.0f;
|
||||
public float splitVariation = 1.0f;
|
||||
|
||||
public Vector3 toTarget;
|
||||
private bool fadeOut;
|
||||
private float fadeTimer;
|
||||
|
||||
void OnEnable ()
|
||||
{
|
||||
lineRend = gameObject.GetComponent<LineRenderer> ();
|
||||
}
|
||||
|
||||
IEnumerator CreateLightningBolt()
|
||||
{
|
||||
myLight.enabled = false;
|
||||
lineRend.widthMultiplier = 10;
|
||||
planeMat.SetFloat("_Brightness", 1f);
|
||||
|
||||
|
||||
lineRend.SetPosition(0, transform.position);
|
||||
lineRend.positionCount = 2;
|
||||
lineRend.SetPosition(1, transform.position);
|
||||
Vector3 lastPoint = transform.position;
|
||||
float dist = Vector3.Distance(transform.position, target);
|
||||
|
||||
float arcDist = dist / arcs;
|
||||
|
||||
for (int i = 1; i < arcs; i++)
|
||||
{
|
||||
planeMat.SetFloat("_Brightness", Random.Range(0f,2f));
|
||||
lineRend.positionCount = i + 1;
|
||||
Vector3 fwd = target - lastPoint;
|
||||
fwd.Normalize ();
|
||||
Vector3 pos = Randomize (fwd, inaccuracy);
|
||||
pos *= Random.Range (arcLength * arcVariation, arcLength) * (arcDist);
|
||||
pos += lastPoint;
|
||||
lineRend.SetPosition (i, pos);
|
||||
|
||||
if (i % 2 == 0)
|
||||
{
|
||||
for (int s = 0; s <= splits; s++)
|
||||
{
|
||||
if(splitCount < maxSplits)
|
||||
StartCoroutine(CreateSplit(pos, target));
|
||||
}
|
||||
}
|
||||
|
||||
lastPoint = pos;
|
||||
// yield return new WaitForSeconds(Random.Range(0.001f,0.005f));
|
||||
}
|
||||
yield return new WaitForSeconds(Random.Range(0.1f,0.2f));
|
||||
lineRend.SetPosition(arcs-1,target);
|
||||
|
||||
//Animate Light and Main bolt
|
||||
myLight.transform.position = target;
|
||||
|
||||
if(EnviroManager.instance.Camera != null)
|
||||
myLight.transform.LookAt(EnviroManager.instance.Camera.transform.position, Vector3.up);
|
||||
|
||||
lineRend.material.SetFloat("_Brightness", this.flashIntensity);
|
||||
planeMat.SetFloat("_Brightness", 20f);
|
||||
myLight.enabled = true;
|
||||
yield return new WaitForSeconds(Random.Range(0.025f,0.035f));
|
||||
lineRend.material.SetFloat("_Brightness", 1f);
|
||||
planeMat.SetFloat("_Brightness", 1f);
|
||||
myLight.enabled = false;
|
||||
yield return new WaitForSeconds(Random.Range(0.025f,0.035f));
|
||||
lineRend.material.SetFloat("_Brightness", this.flashIntensity);
|
||||
planeMat.SetFloat("_Brightness", 20f);
|
||||
myLight.enabled = true;
|
||||
yield return new WaitForSeconds(Random.Range(0.025f,0.035f));
|
||||
lineRend.material.SetFloat("_Brightness", 1f);
|
||||
planeMat.SetFloat("_Brightness", 1f);
|
||||
myLight.enabled = false;
|
||||
yield return new WaitForSeconds(Random.Range(0.025f,0.035f));
|
||||
lineRend.material.SetFloat("_Brightness", this.flashIntensity);
|
||||
planeMat.SetFloat("_Brightness", 0f);
|
||||
myLight.enabled = true;
|
||||
yield return new WaitForSeconds(Random.Range(0.025f,0.035f));
|
||||
myLight.enabled = false;
|
||||
fadeTimer = 50f;
|
||||
fadeOut = true;
|
||||
}
|
||||
|
||||
IEnumerator CreateSplit(Vector3 pos, Vector3 targetP)
|
||||
{
|
||||
splitCount++;
|
||||
GameObject split = new GameObject();
|
||||
split.transform.SetParent(transform);
|
||||
split.transform.position = pos;
|
||||
LineRenderer splitRenderer = split.AddComponent<LineRenderer>();
|
||||
splitRenderer.material = lineRend.material;
|
||||
splitRenderer.material.SetFloat("_Brightness", flashIntensity * 0.9f);
|
||||
splitRenderer.positionCount = 2;
|
||||
splitRenderer.SetPosition(0, split.transform.position);
|
||||
splitRenderer.SetPosition(1, split.transform.position);
|
||||
|
||||
//Set a random target
|
||||
toTarget = targetP - pos;
|
||||
toTarget = Vector3.Normalize(toTarget);
|
||||
Vector3 posDown = new Vector3(toTarget.x,toTarget.y, toTarget.z * 0.1f);
|
||||
Vector3 targetPos = (Random.insideUnitSphere * 500 + pos + toTarget * 800);
|
||||
|
||||
Vector3 lastPoint = split.transform.position;
|
||||
float dist = Vector3.Distance(split.transform.position, targetPos);
|
||||
|
||||
float arcDist = dist / 32;
|
||||
|
||||
for (int i = 1; i < 16; i++)
|
||||
{
|
||||
splitRenderer.positionCount = i + 1;
|
||||
Vector3 fwd = targetPos - lastPoint;
|
||||
fwd.Normalize ();
|
||||
Vector3 newPos = Randomize (fwd, inaccuracy);
|
||||
|
||||
newPos *= Random.Range (splitLength * splitVariation, splitLength) * (arcDist);
|
||||
newPos += lastPoint;
|
||||
splitRenderer.SetPosition (i, newPos);
|
||||
lastPoint = newPos;
|
||||
yield return new WaitForSeconds(Random.Range(0.004f,0.006f));
|
||||
}
|
||||
splitRenderer.SetPosition(7,targetPos);
|
||||
yield return new WaitForSeconds(Random.Range(0.2f,0.5f));
|
||||
DestroyImmediate(split);
|
||||
}
|
||||
|
||||
public void CastBolt()
|
||||
{
|
||||
lineRend.positionCount = 1;
|
||||
StartCoroutine(CreateLightningBolt());
|
||||
}
|
||||
private Vector3 Randomize (Vector3 newVector, float devation) {
|
||||
newVector += new Vector3(Random.Range(-1.0f, 1.0f), Random.Range(-1.0f, 1.0f), Random.Range(-1.0f, 1.0f)) * devation;
|
||||
newVector.Normalize();
|
||||
return newVector;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if(fadeOut == true)
|
||||
{
|
||||
fadeTimer = Mathf.Lerp(fadeTimer,0f,10f * Time.deltaTime);
|
||||
lineRend.material.SetFloat("_Brightness", fadeTimer);
|
||||
|
||||
if(fadeTimer <= 1f)
|
||||
{
|
||||
lineRend.positionCount = 1;
|
||||
fadeOut = false;
|
||||
DestroyImmediate(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 07501689299c0de43b5f4c0e6edd5bbd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Modules/Lightning/Lightning.cs
|
||||
uploadId: 660896
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 569473d5f2a90ed4194c55a1ec36cd93
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,28 @@
|
||||
%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: 258de2724c9dfb643a546d0688715ff1, type: 3}
|
||||
m_Name: Default Lightning Preset
|
||||
m_EditorClassIdentifier:
|
||||
showModuleInspector: 0
|
||||
showSaveLoad: 0
|
||||
active: 1
|
||||
Settings:
|
||||
prefab: {fileID: 8233971941884837668, guid: 3686e34c2aa90c44e8eab718f3bf99b6, type: 3}
|
||||
customLightningEffect: {fileID: 0}
|
||||
lightningStorm: 0
|
||||
randomLightingDelay: 1
|
||||
randomSpawnRange: 5000
|
||||
randomTargetRange: 5000
|
||||
cloudsLightningRadius: 2000
|
||||
cloudsLightningDuration: 0.5
|
||||
preset: {fileID: 0}
|
||||
showLightningControls: 0
|
||||
@@ -0,0 +1,16 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e9a0f93373ad7014fbe96d77c75cbe4e
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 236601
|
||||
packageName: Enviro 3 - Sky and Weather
|
||||
packageVersion: 3.1.2
|
||||
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Modules/Lightning/Preset/Default
|
||||
Lightning Preset.asset
|
||||
uploadId: 660896
|
||||
Reference in New Issue
Block a user