fix:风机初始化代码提交
This commit is contained in:
76
Assets/Scripts/LightManager/LightManager.cs
Normal file
76
Assets/Scripts/LightManager/LightManager.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using Enviro;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using static UnityEngine.Rendering.DebugUI.Table;
|
||||
|
||||
public class LightManager : MonoBehaviour
|
||||
{
|
||||
public enum SwitchCondition { turnON,turnOFF};
|
||||
|
||||
|
||||
|
||||
SwitchCondition currentCondition;
|
||||
SwitchCondition lightCondition;
|
||||
private List<Light> streetLightingAndAutomativeLighting;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
var streetLightings=GameObject.FindGameObjectsWithTag("StreetLighting");
|
||||
var automativeLightings = GameObject.FindGameObjectsWithTag("AutomativeLighting");
|
||||
streetLightingAndAutomativeLighting = new List<Light>();
|
||||
for (int i = 0; i < streetLightings.Length; i++)
|
||||
{
|
||||
streetLightingAndAutomativeLighting.Add(streetLightings[i].GetComponent<Light>());
|
||||
}
|
||||
for (int i = 0; i < automativeLightings.Length; i++)
|
||||
{
|
||||
streetLightingAndAutomativeLighting.Add(automativeLightings[i].GetComponent<Light>());
|
||||
}
|
||||
|
||||
UpdateLight();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
//System.DateTime now = System.DateTime.Now;
|
||||
int hour = Enviro.EnviroManager.instance.Time.hours;
|
||||
if (hour >= 6 && hour <= 18)
|
||||
{
|
||||
currentCondition = SwitchCondition.turnOFF;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentCondition = SwitchCondition.turnON;
|
||||
}
|
||||
|
||||
if (currentCondition != lightCondition)
|
||||
{
|
||||
UpdateLight();
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateLight()
|
||||
{
|
||||
|
||||
int hour = Enviro.EnviroManager.instance.Time.hours;
|
||||
//System.DateTime now = System.DateTime.Now;
|
||||
if (hour >= 6 && hour <= 18)//°×Ìì
|
||||
{
|
||||
lightCondition = SwitchCondition.turnOFF;
|
||||
foreach (var light in streetLightingAndAutomativeLighting)
|
||||
{
|
||||
light.enabled = false;
|
||||
}
|
||||
}
|
||||
else//ÍíÉÏ
|
||||
{
|
||||
lightCondition = SwitchCondition.turnON;
|
||||
foreach (var light in streetLightingAndAutomativeLighting)
|
||||
{
|
||||
light.enabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/LightManager/LightManager.cs.meta
Normal file
11
Assets/Scripts/LightManager/LightManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 826a15849d68a714f8520ec9a1584c39
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user