fix:风机初始化代码提交
This commit is contained in:
45
Assets/Scripts/Sluices/ConnectToRealSluicesHeight.cs
Normal file
45
Assets/Scripts/Sluices/ConnectToRealSluicesHeight.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class ConnectToRealSluicesHeight : MonoBehaviour
|
||||
{
|
||||
[Serializable]
|
||||
public class SluicesSliderBinding
|
||||
{
|
||||
public GameObject sluice;
|
||||
public GameObject slider;
|
||||
}
|
||||
|
||||
public List<SluicesSliderBinding> bindings = new List<SluicesSliderBinding>();
|
||||
|
||||
private Dictionary<GameObject, Vector3> sluiceInitialLocalPosition = new Dictionary<GameObject, Vector3>();
|
||||
|
||||
void Start()
|
||||
{
|
||||
foreach (var binding in bindings)
|
||||
{
|
||||
sluiceInitialLocalPosition[binding.sluice] = binding.sluice.transform.localPosition;
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
foreach (var binding in bindings)
|
||||
{
|
||||
Slider sliderComp = binding.slider.GetComponent<Slider>();
|
||||
Vector3 initLocalPos = sluiceInitialLocalPosition[binding.sluice];
|
||||
|
||||
binding.sluice.transform.localPosition = new Vector3(
|
||||
initLocalPos.x,
|
||||
initLocalPos.y + sliderComp.value,
|
||||
initLocalPos.z
|
||||
);
|
||||
|
||||
binding.slider.transform.Find("Text (TMP)").GetComponent<TextMeshProUGUI>().text =
|
||||
binding.slider.name.Substring(6) + "#" + ": " + sliderComp.value.ToString("F1");
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Sluices/ConnectToRealSluicesHeight.cs.meta
Normal file
11
Assets/Scripts/Sluices/ConnectToRealSluicesHeight.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 435a1377c29de3e48a8aff544627f80f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
31
Assets/Scripts/Sluices/ModifySluiceHeightManually.cs
Normal file
31
Assets/Scripts/Sluices/ModifySluiceHeightManually.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class ModifySluiceHeightManually : MonoBehaviour
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
//setHeight("sluice1", 1.5f);
|
||||
//setHeight("sluice2,1.5");
|
||||
//setHeight("sluice1,1.5");
|
||||
//Debug.Log("aaaa");
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
//public void setHeight(string sluiceName,float height)
|
||||
//{
|
||||
// transform.Find("Sliders/" + sluiceName).GetComponent<Slider>().value = height;
|
||||
//}
|
||||
public void setHeight(string sluiceNameAndHeight)
|
||||
{
|
||||
string[] parts = sluiceNameAndHeight.Split(',');
|
||||
transform.Find("Sliders/" + parts[0]).GetComponent<Slider>().value = float.Parse(parts[1]);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Sluices/ModifySluiceHeightManually.cs.meta
Normal file
11
Assets/Scripts/Sluices/ModifySluiceHeightManually.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 82f187734168bad498845ae9a9967cc6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
63
Assets/Scripts/Sluices/OneKeyOperation.cs
Normal file
63
Assets/Scripts/Sluices/OneKeyOperation.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class OneKeyOperation : MonoBehaviour
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
public void AllOpen()
|
||||
{
|
||||
foreach(Transform child in transform.Find("Sliders").transform)
|
||||
{
|
||||
StartCoroutine(SmoothIncreaseToTwo(0.3f, child));
|
||||
}
|
||||
|
||||
}
|
||||
public void AllClose()
|
||||
{
|
||||
foreach (Transform child in transform.Find("Sliders").transform)
|
||||
{
|
||||
StartCoroutine(SmoothDecreaseToZero(0.3f, child));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
IEnumerator SmoothDecreaseToZero(float duration,Transform child )
|
||||
{
|
||||
float startValue = child.GetComponent<Slider>().value;
|
||||
float time = 0f;
|
||||
while (time < duration)
|
||||
{
|
||||
time += Time.deltaTime;
|
||||
startValue = Mathf.Lerp(startValue, 0f, time / duration);
|
||||
child.GetComponent<Slider>().value = startValue;
|
||||
yield return null;
|
||||
}
|
||||
child.GetComponent<Slider>().value = 0f;
|
||||
}
|
||||
|
||||
IEnumerator SmoothIncreaseToTwo(float duration, Transform child)
|
||||
{
|
||||
float startValue = child.GetComponent<Slider>().value;
|
||||
float time = 0f;
|
||||
while (time < duration)
|
||||
{
|
||||
time += Time.deltaTime;
|
||||
startValue = Mathf.Lerp(startValue, 2f, time / duration);
|
||||
child.GetComponent<Slider>().value = startValue;
|
||||
yield return null;
|
||||
}
|
||||
child.GetComponent<Slider>().value = 2f;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Sluices/OneKeyOperation.cs.meta
Normal file
11
Assets/Scripts/Sluices/OneKeyOperation.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8ab7398f0cf55e44982d5db77cffb184
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user