fix:1
This commit is contained in:
8
Assets/Scripts/Anim.meta
Normal file
8
Assets/Scripts/Anim.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 865482701515db54887ac07ebb2a1533
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
145
Assets/Scripts/Anim/AnimExtension.cs
Normal file
145
Assets/Scripts/Anim/AnimExtension.cs
Normal file
@@ -0,0 +1,145 @@
|
||||
using DG.Tweening;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
//动画扩展类
|
||||
public static class AnimExtension
|
||||
{
|
||||
//数字格式化
|
||||
private static string Format(double num, string format = "f1", bool symbol = false, string unit = "")
|
||||
{
|
||||
if (num > 0 && symbol)
|
||||
{
|
||||
return "+" + num.ToString(format) + unit;
|
||||
}
|
||||
else
|
||||
{
|
||||
return num.ToString(format) + unit;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 文本动画
|
||||
/// </summary>
|
||||
/// <param name="text">文本组件</param>
|
||||
/// <param name="num">目标数值</param>
|
||||
/// <param name="format">显示格式</param>
|
||||
/// <param name="duration">持续时间</param>
|
||||
/// <param name="delay">延迟时间</param>
|
||||
/// <param name="symbol">正数前是否显示"+"号</param>
|
||||
public static Tweener DOTextAnim(this Text text, double num, float duration = 1f, string format = "f1", float delay = 0f, string unit = "", bool symbol = false)
|
||||
{
|
||||
if (text == null) return null;
|
||||
double data = 0;
|
||||
text.text = Format(data, format, symbol, unit);
|
||||
return DOTween.To(() => data, (x) => { data = x; text.text = Format(data, format, symbol, unit); }, num, duration).SetDelay(delay);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 文本动画
|
||||
/// </summary>
|
||||
/// <param name="text">文本组件</param>
|
||||
/// <param name="fromNum">起始数值</param>
|
||||
/// <param name="toNum">目标数值</param>
|
||||
/// <param name="duration">持续时间</param>
|
||||
/// <param name="format">显示格式</param>
|
||||
/// <param name="delay">延迟事件</param>
|
||||
/// <param name="unit">单位</param>
|
||||
/// <param name="symbol">是否显示"+"号</param>
|
||||
public static Tweener DOTextAnim(this Text text, double fromNum, double toNum, float duration = 1f, string format = "f1", float delay = 0f, string unit = "", bool symbol = false)
|
||||
{
|
||||
if (text == null) return null;
|
||||
double data = fromNum;
|
||||
text.text = Format(data, format, symbol);
|
||||
return DOTween.To(() => data, (x) => { data = x; text.text = Format(data, format, symbol); }, toNum, duration).SetDelay(delay);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Slider 动画
|
||||
/// </summary>
|
||||
/// <param name="slider">Slider 组件</param>
|
||||
/// <param name="num">目标数值</param>
|
||||
/// <param name="duration">持续时间</param>
|
||||
/// <param name="delay">延迟时间</param>
|
||||
public static Tweener DOSliderAnim(this Slider slider, float num, float duration = 1f, float delay = 0f)
|
||||
{
|
||||
if (slider == null) return null;
|
||||
slider.value = 0;
|
||||
return DOTween.To(() => slider.value, (x) => slider.value = x, num, duration).SetDelay(delay);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Image 的 fillAmount 动画
|
||||
/// </summary>
|
||||
/// <param name="image">Image组件</param>
|
||||
/// <param name="num">目标数值</param>
|
||||
/// <param name="duration">持续时间</param>
|
||||
/// <param name="delay">延迟时间</param>
|
||||
public static Tweener DOFillAnim(this Image image, float num, float duration = 1f, float delay = 0f)
|
||||
{
|
||||
if (image == null) return null;
|
||||
image.fillAmount = 0;
|
||||
return image.DOFillAmount(num, duration).SetDelay(delay);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scroll 垂直滚动动画
|
||||
/// </summary>
|
||||
/// <param name="scroll">Scroll 组件</param>
|
||||
/// <param name="duration">持续时间</param>
|
||||
/// <param name="delay">延迟时间</param>
|
||||
public static Tweener DOVerticalAnim(this ScrollRect scroll, float duration = 30f, float delay = 1f)
|
||||
{
|
||||
scroll.DOKill();
|
||||
scroll.verticalNormalizedPosition = 1f;
|
||||
return scroll.DOVerticalNormalizedPos(0, duration).SetEase(Ease.Linear).SetLoops(-1, LoopType.Restart).SetDelay(delay);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scroll 水平滚动动画
|
||||
/// </summary>
|
||||
/// <param name="scroll">Scroll 组件</param>
|
||||
/// <param name="duration">持续时间</param>
|
||||
/// <param name="delay">延迟时间</param>
|
||||
public static Tweener DOHorizontalAnim(this ScrollRect scroll, float duration = 30f, float delay = 1f)
|
||||
{
|
||||
scroll.DOKill();
|
||||
scroll.horizontalNormalizedPosition = 0f;
|
||||
return scroll.DOHorizontalNormalizedPos(1, duration).SetEase(Ease.Linear).SetLoops(-1, LoopType.Restart).SetDelay(delay);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 材质动画
|
||||
/// </summary>
|
||||
/// <param name="material">材质对象</param>
|
||||
/// <param name="property">属性名称</param>
|
||||
/// <param name="endValue">目标值</param>
|
||||
/// <param name="startValue">初始值</param>
|
||||
/// <param name="duration">动画时间</param>
|
||||
/// <param name="delay">延迟</param>
|
||||
public static Tweener DoPropertyAnim(this Material material, string property, float endValue, float startValue = 0f, float duration = 1f, float delay = 0f)
|
||||
{
|
||||
if (material == null) { return null; }
|
||||
if (!material.HasProperty(property)) { return null; }
|
||||
material.SetFloat(property, startValue);
|
||||
float data = startValue;
|
||||
return DOTween.To(() => data, (x) => { data = x; material.SetFloat(property, x); }, endValue, duration).SetDelay(delay);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 材质颜色动画
|
||||
/// </summary>
|
||||
/// <param name="material">材质对象</param>
|
||||
/// <param name="property">属性名称</param>
|
||||
/// <param name="endColor">目标颜色</param>
|
||||
/// <param name="duration">动画时间</param>
|
||||
/// <param name="delay">延迟</param>
|
||||
public static Tweener DoColorAnim(this Material material, string property, Color endColor, float duration = 1f, float delay = 0f)
|
||||
{
|
||||
if (material == null) { return null; }
|
||||
if (!material.HasProperty(property)) { return null; }
|
||||
Color color = material.GetColor(property);
|
||||
return DOTween.To(() => color, (x) => { color = x; material.SetColor(property, color); }, endColor, duration).SetDelay(delay);
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/Scripts/Anim/AnimExtension.cs.meta
Normal file
11
Assets/Scripts/Anim/AnimExtension.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1483d41b00daaed4abe2a326f5fcc36a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
88
Assets/Scripts/Anim/SpriteAnim.cs
Normal file
88
Assets/Scripts/Anim/SpriteAnim.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class SpriteAnim : MonoBehaviour
|
||||
{
|
||||
public bool isLoop = true;
|
||||
public float timer = 0.1f;
|
||||
public Sprite[] frames;
|
||||
|
||||
private int index = 0;
|
||||
|
||||
private SpriteRenderer spriteRender;
|
||||
private Image image;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
spriteRender = GetComponent<SpriteRenderer>();
|
||||
image = GetComponent<Image>();
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
index = 0;
|
||||
Play();
|
||||
}
|
||||
|
||||
|
||||
public void Play()
|
||||
{
|
||||
CancelInvoke("PlayAnim");
|
||||
InvokeRepeating("PlayAnim", 0f, timer);
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
CancelInvoke("PlayAnim");
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
if (index >= frames.Length)
|
||||
{
|
||||
CancelInvoke("PlayAnim");
|
||||
return;
|
||||
}
|
||||
index = 0;
|
||||
if (spriteRender != null)
|
||||
{
|
||||
spriteRender.sprite = frames[index];
|
||||
}
|
||||
if (image != null)
|
||||
{
|
||||
image.sprite = frames[index];
|
||||
}
|
||||
}
|
||||
|
||||
void PlayAnim()
|
||||
{
|
||||
|
||||
if (index >= frames.Length)
|
||||
{
|
||||
CancelInvoke("PlayAnim");
|
||||
return;
|
||||
}
|
||||
if (spriteRender != null)
|
||||
{
|
||||
spriteRender.sprite = frames[index];
|
||||
}
|
||||
if (image != null)
|
||||
{
|
||||
image.sprite = frames[index];
|
||||
}
|
||||
index++;
|
||||
if (index >= frames.Length)
|
||||
{
|
||||
if (isLoop)
|
||||
{
|
||||
index = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
CancelInvoke("PlayAnim");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Anim/SpriteAnim.cs.meta
Normal file
11
Assets/Scripts/Anim/SpriteAnim.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f79db764f82d97540b4fa307731a557b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
203
Assets/Scripts/Anim/TweenAlpha.cs
Normal file
203
Assets/Scripts/Anim/TweenAlpha.cs
Normal file
@@ -0,0 +1,203 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using DG.Tweening;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class TweenAlpha : MonoBehaviour
|
||||
{
|
||||
[Range(0f, 1f)]
|
||||
public float from = 0f;
|
||||
[Range(0f, 1f)]
|
||||
public float to = 1f;
|
||||
|
||||
public TweenStyle playStyle = TweenStyle.Once;
|
||||
|
||||
public AnimationCurve curve = new AnimationCurve(new Keyframe(0f, 0f, 0f, 1f), new Keyframe(1f, 1f, 1f, 0f));
|
||||
|
||||
public float timer = 1f;
|
||||
|
||||
private Tween tweener = null;
|
||||
|
||||
private SpriteRenderer spriteRender;
|
||||
private Image image;
|
||||
private Text text;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
spriteRender = GetComponent<SpriteRenderer>();
|
||||
image = GetComponent<Image>();
|
||||
text = GetComponent<Text>();
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
PlayForward();
|
||||
}
|
||||
|
||||
public void PlayForward()
|
||||
{
|
||||
ResetToBegining();
|
||||
switch (playStyle)
|
||||
{
|
||||
case TweenStyle.Once:
|
||||
if (spriteRender != null)
|
||||
{
|
||||
tweener = spriteRender.DOFade(to, timer).SetEase(curve);
|
||||
}
|
||||
if (image != null)
|
||||
{
|
||||
tweener = image.DOFade(to, timer).SetEase(curve);
|
||||
}
|
||||
if (text != null)
|
||||
{
|
||||
tweener = text.DOFade(to, timer).SetEase(curve);
|
||||
}
|
||||
break;
|
||||
case TweenStyle.Loop:
|
||||
if (spriteRender != null)
|
||||
{
|
||||
tweener = spriteRender.DOFade(to, timer).SetEase(curve).SetLoops(-1);
|
||||
}
|
||||
if (image != null)
|
||||
{
|
||||
tweener = image.DOFade(to, timer).SetEase(curve).SetLoops(-1);
|
||||
}
|
||||
if (text != null)
|
||||
{
|
||||
tweener = text.DOFade(to, timer).SetEase(curve).SetLoops(-1);
|
||||
}
|
||||
break;
|
||||
case TweenStyle.PingPong:
|
||||
if (spriteRender != null)
|
||||
{
|
||||
tweener = spriteRender.DOFade(to, timer).SetEase(curve).SetLoops(-1, LoopType.Yoyo);
|
||||
}
|
||||
if (image != null)
|
||||
{
|
||||
tweener = image.DOFade(to, timer).SetEase(curve).SetLoops(-1, LoopType.Yoyo);
|
||||
}
|
||||
if (text != null)
|
||||
{
|
||||
tweener = text.DOFade(to, timer).SetEase(curve).SetLoops(-1, LoopType.Yoyo);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayReverse()
|
||||
{
|
||||
ResetToEnding();
|
||||
switch (playStyle)
|
||||
{
|
||||
case TweenStyle.Once:
|
||||
if (spriteRender != null)
|
||||
{
|
||||
tweener = spriteRender.DOFade(from, timer).SetEase(curve);
|
||||
}
|
||||
if (image != null)
|
||||
{
|
||||
tweener = image.DOFade(from, timer).SetEase(curve);
|
||||
}
|
||||
if (text != null)
|
||||
{
|
||||
tweener = text.DOFade(from, timer).SetEase(curve);
|
||||
}
|
||||
break;
|
||||
case TweenStyle.Loop:
|
||||
if (spriteRender != null)
|
||||
{
|
||||
tweener = spriteRender.DOFade(from, timer).SetEase(curve).SetLoops(-1);
|
||||
}
|
||||
if (image != null)
|
||||
{
|
||||
tweener = image.DOFade(from, timer).SetEase(curve).SetLoops(-1);
|
||||
}
|
||||
if (text != null)
|
||||
{
|
||||
tweener = text.DOFade(from, timer).SetEase(curve).SetLoops(-1);
|
||||
}
|
||||
break;
|
||||
case TweenStyle.PingPong:
|
||||
if (spriteRender != null)
|
||||
{
|
||||
tweener = spriteRender.DOFade(from, timer).SetEase(curve).SetLoops(-1, LoopType.Yoyo);
|
||||
}
|
||||
if (image != null)
|
||||
{
|
||||
tweener = image.DOFade(from, timer).SetEase(curve).SetLoops(-1, LoopType.Yoyo);
|
||||
}
|
||||
if (text != null)
|
||||
{
|
||||
tweener = text.DOFade(from, timer).SetEase(curve).SetLoops(-1, LoopType.Yoyo);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Kill();
|
||||
}
|
||||
}
|
||||
|
||||
public void Pause()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Pause();
|
||||
}
|
||||
}
|
||||
|
||||
public void Play()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Play();
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetToBegining()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Kill();
|
||||
}
|
||||
if (spriteRender != null)
|
||||
{
|
||||
spriteRender.DOFade(from, 0f);
|
||||
}
|
||||
if (image != null)
|
||||
{
|
||||
image.DOFade(from, 0f);
|
||||
}
|
||||
if (text != null)
|
||||
{
|
||||
text.DOFade(from, 0f);
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetToEnding()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Kill();
|
||||
}
|
||||
if (spriteRender != null)
|
||||
{
|
||||
spriteRender.DOFade(to, 0f);
|
||||
}
|
||||
if (image != null)
|
||||
{
|
||||
image.DOFade(to, 0f);
|
||||
}
|
||||
if (text != null)
|
||||
{
|
||||
text.DOFade(to, 0f);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
11
Assets/Scripts/Anim/TweenAlpha.cs.meta
Normal file
11
Assets/Scripts/Anim/TweenAlpha.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a50bb6b8f89d76648bff834c0bd96926
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
199
Assets/Scripts/Anim/TweenColor.cs
Normal file
199
Assets/Scripts/Anim/TweenColor.cs
Normal file
@@ -0,0 +1,199 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using DG.Tweening;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class TweenColor : MonoBehaviour
|
||||
{
|
||||
public Color from = Color.white;
|
||||
public Color to = Color.white;
|
||||
|
||||
public TweenStyle playStyle = TweenStyle.Once;
|
||||
|
||||
public AnimationCurve curve = new AnimationCurve(new Keyframe(0f, 0f, 0f, 1f), new Keyframe(1f, 1f, 1f, 0f));
|
||||
|
||||
public float timer = 1f;
|
||||
|
||||
private Tween tweener = null;
|
||||
|
||||
private SpriteRenderer spriteRender;
|
||||
private Image image;
|
||||
private Text text;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
spriteRender = GetComponent<SpriteRenderer>();
|
||||
image = GetComponent<Image>();
|
||||
text = GetComponent<Text>();
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
PlayForward();
|
||||
}
|
||||
|
||||
public void PlayForward()
|
||||
{
|
||||
ResetToBegining();
|
||||
switch (playStyle)
|
||||
{
|
||||
case TweenStyle.Once:
|
||||
if (spriteRender != null)
|
||||
{
|
||||
tweener = spriteRender.DOColor(to, timer).SetEase(curve);
|
||||
}
|
||||
if (image != null)
|
||||
{
|
||||
tweener = image.DOColor(to, timer).SetEase(curve);
|
||||
}
|
||||
if (text != null)
|
||||
{
|
||||
tweener = text.DOColor(to, timer).SetEase(curve);
|
||||
}
|
||||
break;
|
||||
case TweenStyle.Loop:
|
||||
if (spriteRender != null)
|
||||
{
|
||||
tweener = spriteRender.DOColor(to, timer).SetEase(curve).SetLoops(-1);
|
||||
}
|
||||
if (image != null)
|
||||
{
|
||||
tweener = image.DOColor(to, timer).SetEase(curve).SetLoops(-1);
|
||||
}
|
||||
if (text != null)
|
||||
{
|
||||
tweener = text.DOColor(to, timer).SetEase(curve).SetLoops(-1);
|
||||
}
|
||||
break;
|
||||
case TweenStyle.PingPong:
|
||||
if (spriteRender != null)
|
||||
{
|
||||
tweener = spriteRender.DOColor(to, timer).SetEase(curve).SetLoops(-1, LoopType.Yoyo);
|
||||
}
|
||||
if (image != null)
|
||||
{
|
||||
tweener = image.DOColor(to, timer).SetEase(curve).SetLoops(-1, LoopType.Yoyo);
|
||||
}
|
||||
if (text != null)
|
||||
{
|
||||
tweener = text.DOColor(to, timer).SetEase(curve).SetLoops(-1, LoopType.Yoyo);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayReverse()
|
||||
{
|
||||
ResetToEnding();
|
||||
switch (playStyle)
|
||||
{
|
||||
case TweenStyle.Once:
|
||||
if (spriteRender != null)
|
||||
{
|
||||
tweener = spriteRender.DOColor(from, timer).SetEase(curve);
|
||||
}
|
||||
if (image != null)
|
||||
{
|
||||
tweener = image.DOColor(from, timer).SetEase(curve);
|
||||
}
|
||||
if (text != null)
|
||||
{
|
||||
tweener = text.DOColor(from, timer).SetEase(curve);
|
||||
}
|
||||
break;
|
||||
case TweenStyle.Loop:
|
||||
if (spriteRender != null)
|
||||
{
|
||||
tweener = spriteRender.DOColor(from, timer).SetEase(curve).SetLoops(-1);
|
||||
}
|
||||
if (image != null)
|
||||
{
|
||||
tweener = image.DOColor(from, timer).SetEase(curve).SetLoops(-1);
|
||||
}
|
||||
if (text != null)
|
||||
{
|
||||
tweener = text.DOColor(from, timer).SetEase(curve).SetLoops(-1);
|
||||
}
|
||||
break;
|
||||
case TweenStyle.PingPong:
|
||||
if (spriteRender != null)
|
||||
{
|
||||
tweener = spriteRender.DOColor(from, timer).SetEase(curve).SetLoops(-1, LoopType.Yoyo);
|
||||
}
|
||||
if (image != null)
|
||||
{
|
||||
tweener = image.DOColor(from, timer).SetEase(curve).SetLoops(-1, LoopType.Yoyo);
|
||||
}
|
||||
if (text != null)
|
||||
{
|
||||
tweener = text.DOColor(from, timer).SetEase(curve).SetLoops(-1, LoopType.Yoyo);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Kill();
|
||||
}
|
||||
}
|
||||
|
||||
public void Pause()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Pause();
|
||||
}
|
||||
}
|
||||
|
||||
public void Play()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Play();
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetToBegining()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Kill();
|
||||
}
|
||||
if (spriteRender != null)
|
||||
{
|
||||
spriteRender.color = from;
|
||||
}
|
||||
if (image != null)
|
||||
{
|
||||
image.color = from;
|
||||
}
|
||||
if (text != null)
|
||||
{
|
||||
text.color = from;
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetToEnding()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Kill();
|
||||
}
|
||||
if (spriteRender != null)
|
||||
{
|
||||
spriteRender.color = to;
|
||||
}
|
||||
if (image != null)
|
||||
{
|
||||
image.color = to;
|
||||
}
|
||||
if (text != null)
|
||||
{
|
||||
text.color = to;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Anim/TweenColor.cs.meta
Normal file
11
Assets/Scripts/Anim/TweenColor.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c823cb77710c56146b251bac920e7022
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
117
Assets/Scripts/Anim/TweenPosition.cs
Normal file
117
Assets/Scripts/Anim/TweenPosition.cs
Normal file
@@ -0,0 +1,117 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using DG.Tweening;
|
||||
|
||||
public enum TweenStyle
|
||||
{
|
||||
Once,
|
||||
Loop,
|
||||
PingPong,
|
||||
}
|
||||
|
||||
public class TweenPosition : MonoBehaviour
|
||||
{
|
||||
|
||||
#if UNITY_EDITOR
|
||||
private void Reset()
|
||||
{
|
||||
from = transform.localPosition;
|
||||
to = transform.localPosition;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
public Vector3 from;
|
||||
public Vector3 to;
|
||||
|
||||
public TweenStyle playStyle = TweenStyle.Once;
|
||||
|
||||
public AnimationCurve curve = new AnimationCurve(new Keyframe(0f, 0f, 0f, 1f), new Keyframe(1f, 1f, 1f, 0f));
|
||||
|
||||
public float timer = 1f;
|
||||
|
||||
private Tween tweener = null;
|
||||
|
||||
// Use this for initialization
|
||||
void Start()
|
||||
{
|
||||
PlayForward();
|
||||
}
|
||||
|
||||
public void PlayForward()
|
||||
{
|
||||
ResetToBegining();
|
||||
switch (playStyle)
|
||||
{
|
||||
case TweenStyle.Once:
|
||||
tweener = transform.DOLocalMove(to, timer).SetEase(curve);
|
||||
break;
|
||||
case TweenStyle.Loop:
|
||||
tweener = transform.DOLocalMove(to, timer).SetEase(curve).SetLoops(-1);
|
||||
break;
|
||||
case TweenStyle.PingPong:
|
||||
tweener = transform.DOLocalMove(to, timer).SetEase(curve).SetLoops(-1, LoopType.Yoyo);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayReverse()
|
||||
{
|
||||
ResetToEnding();
|
||||
switch (playStyle)
|
||||
{
|
||||
case TweenStyle.Once:
|
||||
tweener = transform.DOLocalMove(from, timer).SetEase(curve);
|
||||
break;
|
||||
case TweenStyle.Loop:
|
||||
tweener = transform.DOLocalMove(from, timer).SetEase(curve).SetLoops(-1);
|
||||
break;
|
||||
case TweenStyle.PingPong:
|
||||
tweener = transform.DOLocalMove(from, timer).SetEase(curve).SetLoops(-1, LoopType.Yoyo);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Kill();
|
||||
}
|
||||
}
|
||||
|
||||
public void Pause()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Pause();
|
||||
}
|
||||
}
|
||||
|
||||
public void Play()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Play();
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetToBegining()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Kill();
|
||||
}
|
||||
transform.localPosition = from;
|
||||
}
|
||||
|
||||
public void ResetToEnding()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Kill();
|
||||
}
|
||||
transform.localPosition = to;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Anim/TweenPosition.cs.meta
Normal file
11
Assets/Scripts/Anim/TweenPosition.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c3b49052cf29a8940b63eb802280c4c8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
109
Assets/Scripts/Anim/TweenRotation.cs
Normal file
109
Assets/Scripts/Anim/TweenRotation.cs
Normal file
@@ -0,0 +1,109 @@
|
||||
using DG.Tweening;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class TweenRotation : MonoBehaviour
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
private void Reset()
|
||||
{
|
||||
from = transform.localEulerAngles;
|
||||
to = transform.localEulerAngles;
|
||||
}
|
||||
#endif
|
||||
|
||||
public Vector3 from = Vector3.zero;
|
||||
public Vector3 to = Vector3.zero;
|
||||
|
||||
public TweenStyle playStyle = TweenStyle.Once;
|
||||
|
||||
public AnimationCurve curve = new AnimationCurve(new Keyframe(0f, 0f, 0f, 1f), new Keyframe(1f, 1f, 1f, 0f));
|
||||
|
||||
public float timer = 1f;
|
||||
|
||||
private Tween tweener = null;
|
||||
|
||||
|
||||
// Use this for initialization
|
||||
void Start()
|
||||
{
|
||||
PlayForward();
|
||||
}
|
||||
|
||||
public void PlayForward()
|
||||
{
|
||||
ResetToBegining();
|
||||
switch (playStyle)
|
||||
{
|
||||
case TweenStyle.Once:
|
||||
tweener = transform.DOLocalRotate(to, timer, RotateMode.FastBeyond360).SetEase(curve);
|
||||
break;
|
||||
case TweenStyle.Loop:
|
||||
tweener = transform.DOLocalRotate(to, timer, RotateMode.FastBeyond360).SetEase(curve).SetLoops(-1);
|
||||
break;
|
||||
case TweenStyle.PingPong:
|
||||
tweener = transform.DOLocalRotate(to, timer, RotateMode.FastBeyond360).SetEase(curve).SetLoops(-1, LoopType.Yoyo);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayReverse()
|
||||
{
|
||||
ResetToEnding();
|
||||
switch (playStyle)
|
||||
{
|
||||
case TweenStyle.Once:
|
||||
tweener = transform.DOLocalRotate(from, timer, RotateMode.FastBeyond360).SetEase(curve);
|
||||
break;
|
||||
case TweenStyle.Loop:
|
||||
tweener = transform.DOLocalRotate(from, timer, RotateMode.FastBeyond360).SetEase(curve).SetLoops(-1);
|
||||
break;
|
||||
case TweenStyle.PingPong:
|
||||
tweener = transform.DOLocalRotate(from, timer, RotateMode.FastBeyond360).SetEase(curve).SetLoops(-1, LoopType.Yoyo);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Kill();
|
||||
}
|
||||
}
|
||||
|
||||
public void Pause()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Pause();
|
||||
}
|
||||
}
|
||||
|
||||
public void Play()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Play();
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetToBegining()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Kill();
|
||||
}
|
||||
transform.localEulerAngles = from;
|
||||
}
|
||||
|
||||
public void ResetToEnding()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Kill();
|
||||
}
|
||||
transform.localEulerAngles = to;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Anim/TweenRotation.cs.meta
Normal file
11
Assets/Scripts/Anim/TweenRotation.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ee5bbb9e760a3c14298e6856bcf949b6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
109
Assets/Scripts/Anim/TweenScale.cs
Normal file
109
Assets/Scripts/Anim/TweenScale.cs
Normal file
@@ -0,0 +1,109 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using DG.Tweening;
|
||||
|
||||
public class TweenScale : MonoBehaviour
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
private void Reset()
|
||||
{
|
||||
from = transform.localScale;
|
||||
to = transform.localScale;
|
||||
}
|
||||
#endif
|
||||
|
||||
public Vector3 from = Vector3.one;
|
||||
public Vector3 to = Vector3.one;
|
||||
|
||||
public TweenStyle playStyle = TweenStyle.Once;
|
||||
|
||||
public AnimationCurve curve = new AnimationCurve(new Keyframe(0f, 0f, 0f, 1f), new Keyframe(1f, 1f, 1f, 0f));
|
||||
|
||||
public float timer = 1f;
|
||||
|
||||
private Tween tweener = null;
|
||||
|
||||
// Use this for initialization
|
||||
void Start()
|
||||
{
|
||||
PlayForward();
|
||||
}
|
||||
|
||||
public void PlayForward()
|
||||
{
|
||||
ResetToBegining();
|
||||
switch (playStyle)
|
||||
{
|
||||
case TweenStyle.Once:
|
||||
tweener = transform.DOScale(to, timer).SetEase(curve);
|
||||
break;
|
||||
case TweenStyle.Loop:
|
||||
tweener = transform.DOScale(to, timer).SetEase(curve).SetLoops(-1);
|
||||
break;
|
||||
case TweenStyle.PingPong:
|
||||
tweener = transform.DOScale(to, timer).SetEase(curve).SetLoops(-1, LoopType.Yoyo);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayReverse()
|
||||
{
|
||||
ResetToEnding();
|
||||
switch (playStyle)
|
||||
{
|
||||
case TweenStyle.Once:
|
||||
tweener = transform.DOScale(from, timer).SetEase(curve);
|
||||
break;
|
||||
case TweenStyle.Loop:
|
||||
tweener = transform.DOScale(from, timer).SetEase(curve).SetLoops(-1);
|
||||
break;
|
||||
case TweenStyle.PingPong:
|
||||
tweener = transform.DOScale(from, timer).SetEase(curve).SetLoops(-1, LoopType.Yoyo);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Kill();
|
||||
}
|
||||
}
|
||||
|
||||
public void Pause()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Pause();
|
||||
}
|
||||
}
|
||||
|
||||
public void Play()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Play();
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetToBegining()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Kill();
|
||||
}
|
||||
transform.localScale = from;
|
||||
|
||||
}
|
||||
|
||||
public void ResetToEnding()
|
||||
{
|
||||
if (tweener != null)
|
||||
{
|
||||
tweener.Kill();
|
||||
}
|
||||
transform.localScale = to;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Anim/TweenScale.cs.meta
Normal file
11
Assets/Scripts/Anim/TweenScale.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1c462947f207e664f940b431335486bc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/App.meta
Normal file
8
Assets/Scripts/App.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b388b8bd8a5fa414f99a3e37995e71dd
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
239
Assets/Scripts/App/AppCache.cs
Normal file
239
Assets/Scripts/App/AppCache.cs
Normal file
@@ -0,0 +1,239 @@
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
public class AppCache
|
||||
{
|
||||
|
||||
public enum MonitorType
|
||||
{
|
||||
GNSS,
|
||||
EnvironmentalMonitoring,
|
||||
CrackMonitoring,
|
||||
VibrationMonitoring,
|
||||
SurfaceStrainMonitoring
|
||||
}
|
||||
public static int screenWidth = 1920;
|
||||
public static int screenHeight = 1080;
|
||||
|
||||
public static string url = "https://api.zk.gzckgc.cn";
|
||||
|
||||
//界面
|
||||
public static PageType cameraType = PageType.Camera1;
|
||||
public static PageType pageType = PageType.PnlPage1;
|
||||
//点位gnss
|
||||
public static List<IconData> iconPointList01;
|
||||
//相机点位gnss
|
||||
public static List<Transform> iconCameraList01 = new List<Transform>();
|
||||
//点位环境监测
|
||||
public static List<IconData> iconPointList02;
|
||||
//相机点位环境检测
|
||||
public static List<Transform> iconCameraList02 = new List<Transform>();
|
||||
//点位裂缝监测
|
||||
public static List<IconData> iconPointList03;
|
||||
//相机点位裂缝监测
|
||||
public static List<Transform> iconCameraList03 = new List<Transform>();
|
||||
//点位加速度震动监测
|
||||
public static List<IconData> iconPointList04;
|
||||
//相机点位加速度震动监测
|
||||
public static List<Transform> iconCameraList04 = new List<Transform>();
|
||||
//点位表面应变监测
|
||||
public static List<IconData> iconPointList05;
|
||||
//相机点位表面应变监测
|
||||
public static List<Transform> iconCameraList05 = new List<Transform>();
|
||||
public static List<Vector3> areaPointList01 = new List<Vector3>();
|
||||
public static List<Vector3> areaPointList02 = new List<Vector3>();
|
||||
|
||||
|
||||
//初始化
|
||||
public static void Init()
|
||||
{
|
||||
//分辨率设置
|
||||
if (Application.platform == RuntimePlatform.WindowsPlayer)
|
||||
{
|
||||
float height = Screen.width * (screenHeight / (float)screenWidth);
|
||||
Screen.SetResolution(Screen.width, (int)height, true);
|
||||
|
||||
//Screen.SetResolution(screenWidth, screenHeight, true);
|
||||
}
|
||||
//初始化
|
||||
cameraType = PageType.Camera1;
|
||||
pageType = PageType.PnlPage1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#region 页面管理
|
||||
|
||||
//已打开页面列表
|
||||
private static List<PageType> pageList = new List<PageType>();
|
||||
|
||||
//打开页面
|
||||
public static void OpenPage(PageType page)
|
||||
{
|
||||
if (page != PageType.Null)
|
||||
{
|
||||
ActionCenter.Instance.DoAction(GameEvent.OpenPage, page);
|
||||
if (!pageList.Contains(page))
|
||||
{
|
||||
pageList.Add(page);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//打开页面
|
||||
public static void OpenDialog<T>(PageType page, T t)
|
||||
{
|
||||
if (page != PageType.Null)
|
||||
{
|
||||
ActionCenter.Instance.DoAction(GameEvent.OpenDialog, page, t);
|
||||
if (!pageList.Contains(page))
|
||||
{
|
||||
pageList.Add(page);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//delay秒后打开页面
|
||||
public static void OpenPageDelay(PageType page, float delay)
|
||||
{
|
||||
ActionCenter.Instance.DoActionDelay(OpenPage, delay, page);
|
||||
}
|
||||
|
||||
//关闭页面
|
||||
public static void ClosePage(PageType page)
|
||||
{
|
||||
|
||||
if (pageList.Contains(page) && page != PageType.Null)
|
||||
{
|
||||
ActionCenter.Instance.DoAction(GameEvent.ClosePage, page);
|
||||
pageList.Remove(page);
|
||||
}
|
||||
}
|
||||
|
||||
//关闭页面
|
||||
public static void ClosePage(List<PageType> list)
|
||||
{
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
if (pageList.Contains(list[i]) && list[i] != PageType.Null)
|
||||
{
|
||||
ActionCenter.Instance.DoAction(GameEvent.ClosePage, list[i]);
|
||||
pageList.Remove(list[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//关闭页面,参数为保留页面
|
||||
public static void CloseAllPage(PageType page = PageType.Null)
|
||||
{
|
||||
for (int i = 0; i < pageList.Count; i++)
|
||||
{
|
||||
if (pageList[i] != page)
|
||||
{
|
||||
ActionCenter.Instance.DoAction(GameEvent.ClosePage, pageList[i]);
|
||||
}
|
||||
}
|
||||
pageList.Clear();
|
||||
if (page != PageType.Null)
|
||||
{
|
||||
pageList.Add(page);
|
||||
}
|
||||
}
|
||||
|
||||
//关闭页面,参数为保留页面
|
||||
public static void CloseAllPage(List<PageType> list)
|
||||
{
|
||||
//保留页面
|
||||
List<PageType> saveList = new List<PageType>();
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
if (list[i] != PageType.Null && pageList.Contains(list[i]))
|
||||
{
|
||||
saveList.Add(list[i]);
|
||||
}
|
||||
}
|
||||
//关闭现有页面
|
||||
for (int i = 0; i < pageList.Count; i++)
|
||||
{
|
||||
if (!saveList.Contains(pageList[i]))
|
||||
{
|
||||
ActionCenter.Instance.DoAction(GameEvent.ClosePage, pageList[i]);
|
||||
}
|
||||
}
|
||||
pageList.Clear();
|
||||
//当前页面更新
|
||||
for (int i = 0; i < saveList.Count; i++)
|
||||
{
|
||||
pageList.Add(list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
// 根据device_sn查找在AppCache.iconCameraList01中的下标
|
||||
public static int FindIndexInIconCameraList(string deviceSn)
|
||||
{
|
||||
if (AppCache.iconCameraList01 == null)
|
||||
return -1;
|
||||
|
||||
// 遍历列表查找匹配的下标
|
||||
for (int i = 0; i < AppCache.iconCameraList01.Count; i++)
|
||||
{
|
||||
// 从name中提取device_sn部分(去掉"_Camera"后缀)
|
||||
string nameWithoutSuffix = AppCache.iconCameraList01[i].name.Split('_')[0];
|
||||
|
||||
if (nameWithoutSuffix == deviceSn)
|
||||
{
|
||||
return i; // 找到匹配的下标
|
||||
}
|
||||
}
|
||||
|
||||
return -1; // 未找到
|
||||
}
|
||||
|
||||
public static List<IconData> GetIconPointListByType(MonitorType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case MonitorType.GNSS:
|
||||
return iconPointList01;
|
||||
case MonitorType.EnvironmentalMonitoring:
|
||||
return iconPointList02;
|
||||
case MonitorType.CrackMonitoring:
|
||||
return iconPointList03;
|
||||
case MonitorType.VibrationMonitoring:
|
||||
return iconPointList04;
|
||||
case MonitorType.SurfaceStrainMonitoring:
|
||||
return iconPointList05;
|
||||
default:
|
||||
Debug.LogError("未知的监测类型: " + type);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Transform> GetIconCameraListByType(MonitorType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case MonitorType.GNSS:
|
||||
return iconCameraList01;
|
||||
case MonitorType.EnvironmentalMonitoring:
|
||||
return iconCameraList02;
|
||||
case MonitorType.CrackMonitoring:
|
||||
return iconCameraList03;
|
||||
case MonitorType.VibrationMonitoring:
|
||||
return iconCameraList04;
|
||||
case MonitorType.SurfaceStrainMonitoring:
|
||||
return iconCameraList05;
|
||||
default:
|
||||
Debug.LogError("未知的监测类型: " + type);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/Scripts/App/AppCache.cs.meta
Normal file
11
Assets/Scripts/App/AppCache.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f4021aed31c4794419d8b529321a2aad
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
37
Assets/Scripts/App/AppMain.cs
Normal file
37
Assets/Scripts/App/AppMain.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class AppMain : MonoBehaviour
|
||||
{
|
||||
public static AppMain Instance;
|
||||
|
||||
public List<Transform> pointList = new List<Transform>();
|
||||
|
||||
public Color color1;
|
||||
public Color color2;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
//单例对象
|
||||
Instance = this;
|
||||
//初始化
|
||||
AppCache.Init();
|
||||
ActionCenter.Instance.Init();
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
//初始化主页
|
||||
// AppCache.OpenPage(PageType.PnlMain);
|
||||
AppCache.OpenPage(AppCache.cameraType);
|
||||
// AppCache.OpenPageDelay(AppCache.pageType, 0.3f);
|
||||
AppCache.OpenPageDelay(PageType.Icon01, 2f);
|
||||
// AppCache.OpenPageDelay(PageType.Area01, 2f);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/App/AppMain.cs.meta
Normal file
11
Assets/Scripts/App/AppMain.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0601b8b59d626c24ab98ed17184b97df
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
305
Assets/Scripts/App/CameraControl.cs
Normal file
305
Assets/Scripts/App/CameraControl.cs
Normal file
@@ -0,0 +1,305 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class CameraControl : MonoBehaviour
|
||||
{
|
||||
[Header("移动速度")]
|
||||
public float moveSpeed = 1.2f;
|
||||
[Header("旋转速度")]
|
||||
public float rotateSpeed = 45f;
|
||||
[Header("缩放速度")]
|
||||
public float zoomSpeed = 0.2f;
|
||||
[Header("最小高度")]
|
||||
public float minHeight = 0.1f;
|
||||
[Header("最大高度")]
|
||||
public float maxHeight = 100f;
|
||||
[Header("地图中心")]
|
||||
public Vector3 mapCenter = Vector3.zero;
|
||||
[Header("最大距离")]
|
||||
public float maxDistance = 3000f;
|
||||
[Header("最小角度")]
|
||||
public float minAngleX = -60f;
|
||||
[Header("最大角度")]
|
||||
public float maxAngleX = 88f;
|
||||
[Header("射线检测提前量")]
|
||||
public float raycastOffset = 0.1f; // 射线检测提前量
|
||||
|
||||
|
||||
//控制变量
|
||||
private Vector3 viewPos_0; //鼠标左键初始坐标
|
||||
private Vector3 viewPos_1; //鼠标右键初始坐标
|
||||
|
||||
private Vector3 startCameraPos; //相机初始位置
|
||||
private Vector3 targetCameraPos; //相机目标位置
|
||||
|
||||
private Vector2 startCameraEuler; //初始角度
|
||||
private Vector2 targetCameraEuler; //目标角度
|
||||
|
||||
//相机控制
|
||||
private Camera mainCamera;
|
||||
private bool isCameraCtrl = true; //相机是否可控制
|
||||
private float screenAdapter = 1f; //屏幕长度比
|
||||
|
||||
//相机操作有效性判断
|
||||
private bool isClickUI = false;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
mainCamera = Camera.main;
|
||||
screenAdapter = Screen.width / (float)Screen.height;
|
||||
targetCameraPos = transform.position;
|
||||
targetCameraEuler = transform.eulerAngles;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
//相机控制
|
||||
if (isCameraCtrl)
|
||||
{
|
||||
//操作有效性判断
|
||||
if (EventSystem.current != null)
|
||||
{
|
||||
if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1) || Input.GetMouseButtonDown(2))
|
||||
{
|
||||
isClickUI = EventSystem.current.IsPointerOverGameObject();
|
||||
}
|
||||
if (Input.GetMouseButtonUp(0) || Input.GetMouseButtonUp(1) || Input.GetMouseButtonUp(2))
|
||||
{
|
||||
isClickUI = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isClickUI)
|
||||
{
|
||||
//平移控制
|
||||
if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(2))
|
||||
{
|
||||
viewPos_0 = mainCamera.ScreenToViewportPoint(Input.mousePosition);
|
||||
startCameraPos = transform.position;
|
||||
startCameraEuler = transform.eulerAngles;
|
||||
}
|
||||
if (Input.GetMouseButton(0) || Input.GetMouseButton(2))
|
||||
{
|
||||
Vector3 currentViewPos = mainCamera.ScreenToViewportPoint(Input.mousePosition);
|
||||
Vector3 dis = currentViewPos - viewPos_0;
|
||||
dis = dis * GetMoveSpeed();
|
||||
|
||||
// 获取相机的右向量和上向量
|
||||
Vector3 right = transform.right;
|
||||
Vector3 up = transform.up;
|
||||
|
||||
// 分别计算水平和垂直方向的位移
|
||||
float horizontalDis = -dis.x * screenAdapter;
|
||||
float verticalDis = -dis.y * screenAdapter;
|
||||
|
||||
// 根据相机的右向量和上向量计算最终位移
|
||||
Vector3 finalDis = right * horizontalDis + up * verticalDis;
|
||||
|
||||
// targetCameraPos = startCameraPos + finalDis;
|
||||
Vector3 newTargetPos = startCameraPos + finalDis;
|
||||
newTargetPos = CheckCollisionOnMove(transform.position, newTargetPos);
|
||||
targetCameraPos = newTargetPos;
|
||||
}
|
||||
//旋转控制
|
||||
if (Input.GetMouseButtonDown(1))
|
||||
{
|
||||
|
||||
viewPos_1 = mainCamera.ScreenToViewportPoint(Input.mousePosition);
|
||||
startCameraPos = transform.position;
|
||||
startCameraEuler = transform.eulerAngles;
|
||||
}
|
||||
if (Input.GetMouseButton(1))
|
||||
{
|
||||
Vector2 angle = (mainCamera.ScreenToViewportPoint(Input.mousePosition) - viewPos_1) * rotateSpeed;
|
||||
angle = new Vector3(-angle.y, angle.x * screenAdapter);
|
||||
targetCameraEuler = startCameraEuler + angle;
|
||||
}
|
||||
//缩进控制
|
||||
if (Input.mouseScrollDelta != Vector2.zero)
|
||||
{
|
||||
// float moveSpeed = GetMoveSpeed() * 0.2f;
|
||||
// targetCameraPos += transform.forward * moveSpeed * Input.mouseScrollDelta.y;
|
||||
float moveSpeed = GetMoveSpeed() * zoomSpeed;
|
||||
Vector3 newTargetPos = targetCameraPos + transform.forward * moveSpeed * Input.mouseScrollDelta.y;
|
||||
newTargetPos = CheckCollisionOnMove(transform.position, newTargetPos);
|
||||
targetCameraPos = newTargetPos;
|
||||
}
|
||||
|
||||
//相机运动
|
||||
LimitCamera();
|
||||
// CheckCollision(); // 检查碰撞
|
||||
//控制相机运动
|
||||
// 控制相机运动
|
||||
if (Vector3.Distance(transform.position, targetCameraPos) > 0.1f)
|
||||
{
|
||||
transform.position = Vector3.Lerp(transform.position, targetCameraPos, 5f * Time.deltaTime);
|
||||
// Debug.Log("position"+transform.position);
|
||||
}
|
||||
|
||||
// 控制相机旋转
|
||||
if (Quaternion.Angle(transform.rotation, Quaternion.Euler(targetCameraEuler)) > 0.1f)
|
||||
{
|
||||
transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(targetCameraEuler), 5f * Time.deltaTime);
|
||||
// Debug.Log("rotation"+transform.eulerAngles);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//开启相机控制
|
||||
// public void StartCameraControl()
|
||||
// {
|
||||
// isCameraCtrl = true;
|
||||
// isClickUI = false;
|
||||
// viewPos_0 = mainCamera.ScreenToViewportPoint(Input.mousePosition);
|
||||
// viewPos_1 = mainCamera.ScreenToViewportPoint(Input.mousePosition);
|
||||
// startCameraPos = transform.position;
|
||||
// startCameraEuler = transform.eulerAngles;
|
||||
// targetCameraPos = transform.position;
|
||||
|
||||
// targetCameraEuler = transform.eulerAngles;
|
||||
// }
|
||||
|
||||
//停止相机控制
|
||||
// public void StopCameraControl()
|
||||
// {
|
||||
// isCameraCtrl = false;
|
||||
// }
|
||||
|
||||
|
||||
//获取相机移动速度
|
||||
float GetMoveSpeed()
|
||||
{
|
||||
|
||||
float highDis = (transform.position.y - minHeight);
|
||||
float speed = moveSpeed + moveSpeed * highDis;
|
||||
speed = Mathf.RoundToInt(speed);
|
||||
return speed;
|
||||
}
|
||||
|
||||
//限制相机位置,角度
|
||||
void LimitCamera()
|
||||
{
|
||||
//位置限制
|
||||
targetCameraPos.y = Mathf.Clamp(targetCameraPos.y, minHeight, maxHeight);
|
||||
|
||||
float dis = Vector3.Distance(targetCameraPos, mapCenter);
|
||||
|
||||
if (dis > maxDistance)
|
||||
{
|
||||
Vector3 dir = (targetCameraPos - mapCenter).normalized;
|
||||
targetCameraPos = mapCenter + dir * maxDistance;
|
||||
}
|
||||
//角度限制
|
||||
if (targetCameraEuler.x > 180) { targetCameraEuler.x -= 360f; }
|
||||
if (targetCameraEuler.x < -180) { targetCameraEuler.x += 360; }
|
||||
if (targetCameraEuler.y > 180) { targetCameraEuler.y -= 360f; }
|
||||
if (targetCameraEuler.y < -180) { targetCameraEuler.y += 360; }
|
||||
targetCameraEuler.x = Mathf.Clamp(targetCameraEuler.x, minAngleX, maxAngleX);
|
||||
}
|
||||
|
||||
// // 检查碰撞
|
||||
// void CheckCollisionOnMove(Vector3 startPos, Vector3 targetPos)
|
||||
// {
|
||||
// RaycastHit hit;
|
||||
// Vector3 direction = targetCameraPos - transform.position;
|
||||
// float distance = direction.magnitude;
|
||||
|
||||
// if (Physics.Raycast(transform.position, direction.normalized, out hit, distance))
|
||||
// {
|
||||
// targetCameraPos = hit.point;
|
||||
// }
|
||||
// }
|
||||
// 修改CheckCollisionOnMove方法,增加垂直方向检测
|
||||
Vector3 CheckCollisionOnMove(Vector3 startPos, Vector3 targetPos)
|
||||
{
|
||||
Vector3 direction = targetPos - startPos;
|
||||
float distance = direction.magnitude;
|
||||
|
||||
// 存储最终的安全位置
|
||||
Vector3 safePosition = targetPos;
|
||||
|
||||
// 1. 检测移动路径上的障碍物(包括水平和垂直方向)
|
||||
if (distance > 0)
|
||||
{
|
||||
float sphereRadius = 0.1f; // 根据相机碰撞体大小调整
|
||||
|
||||
// 计算起点和终点的包围盒
|
||||
Bounds startBounds = new Bounds(startPos, Vector3.one * sphereRadius * 2);
|
||||
Bounds endBounds = new Bounds(targetPos, Vector3.one * sphereRadius * 2);
|
||||
|
||||
// 创建从起点到终点的包围盒移动路径
|
||||
Bounds movementBounds = new Bounds();
|
||||
movementBounds.Encapsulate(startBounds);
|
||||
movementBounds.Encapsulate(endBounds);
|
||||
|
||||
// 使用多个方向的射线检测全方位碰撞
|
||||
bool collisionDetected = false;
|
||||
|
||||
// 主方向检测
|
||||
if (Physics.SphereCast(startPos, sphereRadius, direction.normalized, out RaycastHit hit, distance + raycastOffset))
|
||||
{
|
||||
float safeDistance = hit.distance - raycastOffset - sphereRadius;
|
||||
safePosition = startPos + direction.normalized * Mathf.Max(safeDistance, 0);
|
||||
collisionDetected = true;
|
||||
}
|
||||
|
||||
// 如果是向上移动,增加顶部检测
|
||||
if (direction.y > 0.1f) // 设置一个阈值,只在明显向上移动时检测
|
||||
{
|
||||
Vector3 topStart = startPos + Vector3.up * sphereRadius;
|
||||
Vector3 topDirection = Vector3.up * (endBounds.max.y - startBounds.max.y);
|
||||
|
||||
if (Physics.SphereCast(topStart, sphereRadius, topDirection.normalized, out hit, topDirection.magnitude + raycastOffset))
|
||||
{
|
||||
float verticalSafeDistance = hit.distance - raycastOffset - sphereRadius;
|
||||
safePosition.y = startPos.y + verticalSafeDistance;
|
||||
collisionDetected = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (collisionDetected)
|
||||
{
|
||||
// 声明地面检测变量(移到这里避免作用域冲突)
|
||||
Ray groundRay1;
|
||||
float maxGroundDistance1;
|
||||
RaycastHit groundHit1;
|
||||
|
||||
// 如果检测到碰撞,进行地面高度验证
|
||||
groundRay1 = new Ray(safePosition + Vector3.up, Vector3.down);
|
||||
maxGroundDistance1 = 0.5f;
|
||||
|
||||
if (Physics.Raycast(groundRay1, out groundHit1, maxGroundDistance1))
|
||||
{
|
||||
float minSafeHeight = groundHit1.point.y + minHeight;
|
||||
if (safePosition.y < minSafeHeight)
|
||||
{
|
||||
safePosition.y = minSafeHeight;
|
||||
}
|
||||
}
|
||||
|
||||
return safePosition;
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 如果没有检测到碰撞,只进行地面高度验证
|
||||
// 重用之前声明的变量
|
||||
Ray groundRay = new Ray(targetPos + Vector3.up, Vector3.down);
|
||||
float maxGroundDistance = 0.5f;
|
||||
|
||||
if (Physics.Raycast(groundRay, out RaycastHit groundHit, maxGroundDistance))
|
||||
{
|
||||
float minSafeHeight = groundHit.point.y + minHeight;
|
||||
if (targetPos.y < minSafeHeight)
|
||||
{
|
||||
targetPos.y = minSafeHeight;
|
||||
}
|
||||
}
|
||||
|
||||
return targetPos;
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/Scripts/App/CameraControl.cs.meta
Normal file
11
Assets/Scripts/App/CameraControl.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8428addbd23d2d346969c8fd6e13d738
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
263
Assets/Scripts/App/CameraRover.cs
Normal file
263
Assets/Scripts/App/CameraRover.cs
Normal file
@@ -0,0 +1,263 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using DG.Tweening;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.AI;
|
||||
using System.Linq;
|
||||
public class CameraRover : ActionBase
|
||||
{
|
||||
private CameraControl cameraCtr2;
|
||||
private ControlMove cameraCtrl;
|
||||
private Vector3 targetPos = Vector3.zero; //视角坐标
|
||||
|
||||
private bool isLookAt = false; //视角是否朝向目标
|
||||
private string currentAnim = "";
|
||||
|
||||
// 私有变量,用于存储飞行完成状态
|
||||
private bool _isFlightCompleted = false;
|
||||
|
||||
// 公共属性,用于获取飞行完成状态
|
||||
public bool isFlightCompleted
|
||||
{
|
||||
get { return _isFlightCompleted; }
|
||||
}
|
||||
|
||||
// 公共方法,用于修改飞行完成状态
|
||||
public void SetFlightCompleted(bool value)
|
||||
{
|
||||
_isFlightCompleted = value;
|
||||
}
|
||||
|
||||
public LayerMask obstacleLayer; // 障碍物层
|
||||
|
||||
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
cameraCtr2 = GetComponent<CameraControl>();
|
||||
cameraCtrl = GetComponent<ControlMove>();
|
||||
|
||||
currentAnim = "";
|
||||
isLookAt = false;
|
||||
}
|
||||
|
||||
public override void RegisterAction()
|
||||
{
|
||||
GameEvent.OpenPage += OpenPage;
|
||||
GameEvent.StartCameraControl += StartCameraCtrl;
|
||||
GameEvent.StopCameraControl += StopCameraCtrl;
|
||||
}
|
||||
|
||||
public override void RemoveAction()
|
||||
{
|
||||
GameEvent.OpenPage -= OpenPage;
|
||||
GameEvent.StartCameraControl -= StartCameraCtrl;
|
||||
GameEvent.StopCameraControl -= StopCameraCtrl;
|
||||
}
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
if (isLookAt)
|
||||
{
|
||||
transform.LookAt(targetPos);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenPage(PageType type)
|
||||
{
|
||||
Debug.Log(type);
|
||||
switch (type)
|
||||
{
|
||||
case PageType.Camera1:
|
||||
CameraBreak();
|
||||
StartCoroutine("CameraAnim_1");
|
||||
break;
|
||||
case PageType.Camera2:
|
||||
CameraBreak();
|
||||
StartCoroutine("CameraAnim_2");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void StartCameraCtrl()
|
||||
{
|
||||
cameraCtrl.StartCameraControl();
|
||||
}
|
||||
|
||||
void StopCameraCtrl()
|
||||
{
|
||||
cameraCtrl.StopCameraControl();
|
||||
}
|
||||
|
||||
public void SetTargetPosition(Vector3 position)
|
||||
{
|
||||
cameraCtrl.GetInScriptCore(position);
|
||||
}
|
||||
|
||||
//打断当前相机操作
|
||||
void CameraBreak()
|
||||
{
|
||||
StopCoroutine(currentAnim);
|
||||
isLookAt = false;
|
||||
transform.DOKill();
|
||||
}
|
||||
|
||||
//相机点位-1
|
||||
IEnumerator CameraAnim_1()
|
||||
{
|
||||
currentAnim = "CameraAnim_1";
|
||||
StopCameraCtrl();
|
||||
cameraCtrl.GetInScriptCore();
|
||||
yield return new WaitForEndOfFrame();
|
||||
transform.DOMove(new Vector3(853.45f, 56.79f, 775.12f), 2f);
|
||||
transform.DORotate(new Vector3(10.39f, 184.72f, 0f), 2f);
|
||||
yield return new WaitForSeconds(2f);
|
||||
StartCameraCtrl();
|
||||
}
|
||||
|
||||
//相机点位-2
|
||||
IEnumerator CameraAnim_2()
|
||||
{
|
||||
currentAnim = "CameraAnim_2";
|
||||
StopCameraCtrl();
|
||||
cameraCtrl.GetInScriptCore(new Vector3(849f, 27f, 560f));
|
||||
yield return new WaitForEndOfFrame();
|
||||
transform.DOMove(new Vector3(850.61f, 65.11f, 524.99f), 2f);
|
||||
transform.DORotate(new Vector3(36.65f, 7.09f, 0f), 2f);
|
||||
|
||||
yield return new WaitForSeconds(2f);
|
||||
StartCameraCtrl();
|
||||
|
||||
}
|
||||
|
||||
|
||||
Vector3[] GetRoundPath(Vector3 pos, Vector3 pivot)
|
||||
{
|
||||
Vector3[] path = new Vector3[10];
|
||||
Vector3 dir = pos - pivot;
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
Vector3 rotatedDir = Quaternion.AngleAxis(40f * i, Vector3.up) * dir;
|
||||
path[i] = pivot + rotatedDir;
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
// 暴露给 JavaScript 的静态方法
|
||||
public void CallOpenPage(int typeIndex)
|
||||
{
|
||||
PageType pageType = (PageType)typeIndex;
|
||||
ActionCenter.Instance.DoAction(GameEvent.OpenPage, pageType);
|
||||
}
|
||||
|
||||
public void WebCallOpenItem(string objectName)
|
||||
{
|
||||
// 定义要搜索的所有相机图标列表
|
||||
List<List<Transform>> allCameraLists = new List<List<Transform>>
|
||||
{
|
||||
AppCache.iconCameraList01,
|
||||
AppCache.iconCameraList02,
|
||||
AppCache.iconCameraList03,
|
||||
AppCache.iconCameraList04,
|
||||
AppCache.iconCameraList05
|
||||
};
|
||||
|
||||
// 在所有列表中查找具有指定名称的 Transform
|
||||
Transform foundTransform = null;
|
||||
|
||||
foreach (var cameraList in allCameraLists)
|
||||
{
|
||||
if (cameraList == null) continue;
|
||||
|
||||
// 查找匹配名称的 Transform
|
||||
foundTransform = cameraList.Find(transform =>
|
||||
transform != null && transform.name == objectName);
|
||||
|
||||
if (foundTransform != null) break;
|
||||
}
|
||||
|
||||
// 如果找到对应的 Transform,则执行飞行逻辑
|
||||
if (foundTransform != null)
|
||||
{
|
||||
StartCoroutine(flyItem(foundTransform));
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"未找到名称为 '{objectName}' 的相机图标!");
|
||||
}
|
||||
}
|
||||
|
||||
// 公共协程方法 - 处理相机移动的核心逻辑(带自动避障)
|
||||
private IEnumerator MoveCameraCore(Transform targetTransform, string animName)
|
||||
{
|
||||
currentAnim = animName;
|
||||
StopCameraCtrl();
|
||||
yield return new WaitForEndOfFrame();
|
||||
|
||||
Vector3 targetPosition = targetTransform.position;
|
||||
Vector3 targetRotation = targetTransform.eulerAngles;
|
||||
|
||||
float distance = Vector3.Distance(transform.position, targetPosition);
|
||||
float speed = 5f;
|
||||
float flightTime = distance / speed;
|
||||
float maxFlightTime = 2f;
|
||||
|
||||
flightTime = Mathf.Max(flightTime, 0.1f);
|
||||
flightTime = Mathf.Min(flightTime, maxFlightTime);
|
||||
RaycastHit hit;
|
||||
// 射线检测是否有障碍物
|
||||
if (Physics.Raycast(transform.position, targetPosition - transform.position, out hit, distance, obstacleLayer))
|
||||
{
|
||||
// 有障碍物
|
||||
// Debug.Log("有障碍物,使用绕行路径");
|
||||
|
||||
Vector3 stopPosition = hit.point - (targetPosition - transform.position).normalized * 0.1f;
|
||||
|
||||
float stopDistance = Vector3.Distance(transform.position, stopPosition);
|
||||
float stopFlightTime = stopDistance / speed;
|
||||
stopFlightTime = Mathf.Max(stopFlightTime, 0.1f);
|
||||
stopFlightTime = Mathf.Min(stopFlightTime, maxFlightTime);
|
||||
|
||||
transform.DOMove(stopPosition, stopFlightTime);
|
||||
transform.DORotate(Quaternion.LookRotation(targetPosition - transform.position).eulerAngles, stopFlightTime);
|
||||
yield return new WaitForSeconds(stopFlightTime);
|
||||
transform.position = targetPosition;
|
||||
transform.DORotate(targetRotation, stopFlightTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 无障碍物
|
||||
// Debug.Log("无障碍物,使用直接路径");
|
||||
transform.DOMove(targetPosition, flightTime);
|
||||
transform.DORotate(targetRotation, flightTime);
|
||||
|
||||
}
|
||||
|
||||
yield return new WaitForSeconds(flightTime);
|
||||
StartCameraCtrl();
|
||||
}
|
||||
|
||||
|
||||
public IEnumerator flyItem(Transform targetTransform)
|
||||
{
|
||||
return MoveCameraCore(targetTransform, "CameraAnim_4");
|
||||
}
|
||||
|
||||
|
||||
public IEnumerator CallOpenItem(Transform targetTransform)
|
||||
{
|
||||
SetFlightCompleted(false);
|
||||
|
||||
// 执行公共相机移动逻辑
|
||||
yield return StartCoroutine(MoveCameraCore(targetTransform, "CameraAnim_3"));
|
||||
|
||||
SetFlightCompleted(true);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
11
Assets/Scripts/App/CameraRover.cs.meta
Normal file
11
Assets/Scripts/App/CameraRover.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 56eadf24a6164ef4db2623b73dc84937
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
239
Assets/Scripts/App/ControlMove.cs
Normal file
239
Assets/Scripts/App/ControlMove.cs
Normal file
@@ -0,0 +1,239 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class ControlMove : MonoBehaviour
|
||||
{
|
||||
|
||||
private float moveSpeed = 50f; // 右键平移速度
|
||||
|
||||
[Header("滚轮缩放速度系数")]
|
||||
public float zoomSpeed = 10f; // 滚轮缩放速度
|
||||
|
||||
[Header("相机与水库中心的最大距离")]
|
||||
public float maxDistance = 600f; // 最大缩放距离
|
||||
|
||||
[Header("相机的最大高度限制")]
|
||||
public float maxHeight = 220f; // 最大高度限制
|
||||
|
||||
[Header("右键键平移速度衰减系数")]
|
||||
public float rightClickPanSpeed = 100f; // 右键平移速度除数
|
||||
|
||||
private Vector3 inScript; // 引用焦点脚本,提供 core
|
||||
|
||||
[Header("左键拖拽旋转灵敏度系数")]
|
||||
public float rotationSensitivity = 0.5f; // 左键拖拽旋转灵敏度
|
||||
|
||||
private Camera cam; // 主相机引用
|
||||
private bool isRotating = false; // 是否正在旋转标志
|
||||
private Vector2 lastMousePos; // 上次鼠标位置(用于旋转计算)
|
||||
|
||||
[Header("初始距离中心")]
|
||||
public Vector3 reservoirCenter; // 水库中心坐标
|
||||
|
||||
[Header("初始旋转中心")]
|
||||
public Vector3 startinScript; // 初始焦点位置
|
||||
|
||||
private Rigidbody rb; // 刚体组件(如需要物理模拟)
|
||||
private bool isCameraCtrl = true; // 相机是否可控制
|
||||
|
||||
//相机操作有效性判断
|
||||
private bool isClickUI = false;
|
||||
|
||||
private float pitchDelta; // 刚体组件(如需要物理模拟)
|
||||
void Start()
|
||||
{
|
||||
rb = GetComponent<Rigidbody>();
|
||||
cam = Camera.main;
|
||||
if (inScript == Vector3.zero)
|
||||
{
|
||||
GetInScriptCore();
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (isCameraCtrl)
|
||||
{
|
||||
//操作有效性判断
|
||||
if (EventSystem.current != null)
|
||||
{
|
||||
if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1) || Input.GetMouseButtonDown(2))
|
||||
{
|
||||
isClickUI = EventSystem.current.IsPointerOverGameObject();
|
||||
}
|
||||
if (Input.GetMouseButtonUp(0) || Input.GetMouseButtonUp(1) || Input.GetMouseButtonUp(2))
|
||||
{
|
||||
isClickUI = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isClickUI)
|
||||
{
|
||||
Vector3 core = inScript;
|
||||
// —— 右键平移 ——
|
||||
if (Input.GetMouseButton(1))
|
||||
{
|
||||
moveSpeed = Vector3.Distance(core, transform.position) / 2f;
|
||||
float mx = Input.GetAxis("Mouse X");
|
||||
float my = Input.GetAxis("Mouse Y");
|
||||
|
||||
Vector3 desiredPosition = transform.position + (-transform.right * mx + -transform.up * my) * moveSpeed / rightClickPanSpeed;
|
||||
|
||||
// 判断是否与障碍物发生碰撞
|
||||
if (!WillCollideWithObstacle(desiredPosition))
|
||||
{
|
||||
transform.position = desiredPosition;
|
||||
}
|
||||
}
|
||||
|
||||
// —— 滚轮缩放 ——
|
||||
float scroll = Input.GetAxis("Mouse ScrollWheel");
|
||||
if (Mathf.Abs(scroll) > 0.001f)
|
||||
{
|
||||
Vector3 desiredPosition = transform.position + transform.forward * scroll * zoomSpeed;
|
||||
|
||||
// 判断是否与障碍物发生碰撞
|
||||
if (!WillCollideWithObstacle(desiredPosition))
|
||||
{
|
||||
transform.position = desiredPosition;
|
||||
}
|
||||
}
|
||||
|
||||
// —— 左键开始/结束旋转 ——
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
isRotating = true;
|
||||
lastMousePos = Input.mousePosition;
|
||||
}
|
||||
if (Input.GetMouseButtonUp(0))
|
||||
{
|
||||
isRotating = false;
|
||||
}
|
||||
|
||||
// —— 左键拖拽:RotateAround 实现 + 俯仰限制 ——
|
||||
if (isRotating && Input.GetMouseButton(0))
|
||||
{
|
||||
Vector2 curr = Input.mousePosition;
|
||||
Vector2 delta = (curr - lastMousePos) * rotationSensitivity;
|
||||
lastMousePos = curr;
|
||||
|
||||
/*
|
||||
|
||||
*/
|
||||
// 1. 水平绕世界 Y 轴旋转
|
||||
//Vector3 desiredPosition = transform.position;
|
||||
//transform.RotateAround(core, Vector3.up, delta.x);
|
||||
|
||||
Vector3 localPosHorizonal = transform.position - core;
|
||||
Quaternion rotationHorizonal = Quaternion.AngleAxis(delta.x, Vector3.up);
|
||||
Vector3 newLocalPosHorizonal = rotationHorizonal * localPosHorizonal;
|
||||
Vector3 newPosHorizonal = core + newLocalPosHorizonal;
|
||||
|
||||
|
||||
// 检查旋转后是否发生碰撞
|
||||
if (!WillCollideWithObstacle(newPosHorizonal))
|
||||
{
|
||||
// 如果没有碰撞,执行旋转
|
||||
transform.RotateAround(core, Vector3.up, delta.x);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 如果碰撞了,撤销旋转,恢复到原来的位置
|
||||
|
||||
}
|
||||
|
||||
// 2. 俯仰旋转
|
||||
Vector3 dir = (transform.position - core).normalized;
|
||||
Vector3 flat = new Vector3(dir.x, 0f, dir.z).normalized;
|
||||
float selfFlatX = transform.forward.x;
|
||||
float selfFlatZ = transform.forward.z;
|
||||
Vector3 selfFlat = new Vector3(selfFlatX, 0f, selfFlatZ).normalized;
|
||||
float selfPitch = Vector3.SignedAngle(selfFlat, transform.forward, transform.right);
|
||||
|
||||
|
||||
|
||||
if (selfPitch <= 80f && selfPitch >= 0f)
|
||||
{
|
||||
pitchDelta = delta.y * -1f;
|
||||
|
||||
|
||||
Vector3 localPosVertical = transform.position - core;
|
||||
Quaternion rotationVertical = Quaternion.AngleAxis(pitchDelta, transform.right);
|
||||
Vector3 newPosVertical = core + rotationVertical * localPosVertical;
|
||||
|
||||
|
||||
if (!WillCollideWithObstacle(newPosVertical))
|
||||
{
|
||||
transform.RotateAround(core, transform.right, pitchDelta);
|
||||
}
|
||||
|
||||
}
|
||||
else if (selfPitch > 80f)
|
||||
{
|
||||
pitchDelta = delta.y * -1f;
|
||||
if (pitchDelta < 0f)
|
||||
{
|
||||
transform.RotateAround(core, transform.right, pitchDelta);
|
||||
}
|
||||
}
|
||||
else if (selfPitch < 0f)
|
||||
{
|
||||
pitchDelta = delta.y * -1f;
|
||||
if (pitchDelta > 0f)
|
||||
{
|
||||
transform.RotateAround(core, transform.right, pitchDelta);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 碰撞检测方法
|
||||
bool WillCollideWithObstacle(Vector3 targetPosition)
|
||||
{
|
||||
// 计算从当前位置到目标位置的方向和距离
|
||||
Vector3 moveDir = targetPosition - transform.position;
|
||||
float moveDist = moveDir.magnitude;
|
||||
|
||||
// 使用 SphereCast 检查即将到达的位置是否会与障碍物发生碰撞
|
||||
RaycastHit hit;
|
||||
if (Physics.SphereCast(transform.position, 0.5f, moveDir.normalized, out hit, moveDist, LayerMask.GetMask("Default"), QueryTriggerInteraction.Collide))
|
||||
{
|
||||
// 如果检测到碰撞,返回 true
|
||||
// Debug.Log("collider");
|
||||
return true;
|
||||
}
|
||||
else if (Vector3.Distance(targetPosition, reservoirCenter) < maxDistance && targetPosition.y < maxHeight)
|
||||
{
|
||||
// 如果在范围内,返回 false
|
||||
return false;
|
||||
}
|
||||
else
|
||||
// Debug.Log("outRange");
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void GetInScriptCore()
|
||||
{
|
||||
inScript = startinScript;
|
||||
}
|
||||
public void GetInScriptCore(Vector3 position)
|
||||
{
|
||||
inScript = position;
|
||||
}
|
||||
|
||||
public void StartCameraControl()
|
||||
{
|
||||
isCameraCtrl = true;
|
||||
isClickUI = false;
|
||||
}
|
||||
|
||||
//停止相机控制
|
||||
public void StopCameraControl()
|
||||
{
|
||||
isCameraCtrl = false;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/App/ControlMove.cs.meta
Normal file
11
Assets/Scripts/App/ControlMove.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1a1e76e08ccc2f0488913f8e95f574e9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
159
Assets/Scripts/App/GameDto.cs
Normal file
159
Assets/Scripts/App/GameDto.cs
Normal file
@@ -0,0 +1,159 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
//界面
|
||||
public enum PageType
|
||||
{
|
||||
Null,
|
||||
//镜头
|
||||
Camera1, //镜头-1
|
||||
Camera2, //镜头-2
|
||||
|
||||
//页面
|
||||
PnlMain, //主界面
|
||||
PnlPage1, //界面-1
|
||||
PnlPage2, //界面-2
|
||||
|
||||
//Icon
|
||||
Icon01,
|
||||
Icon02,
|
||||
Icon03,
|
||||
Icon04,
|
||||
Icon05,
|
||||
|
||||
//Effect
|
||||
Area01,
|
||||
Area02,
|
||||
|
||||
//Dialog
|
||||
DlgInfo01,
|
||||
DlgInfo02,
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#region 网络数据
|
||||
// 状态信息
|
||||
[System.Serializable]
|
||||
public class Status
|
||||
{
|
||||
public int code;
|
||||
public string msg;
|
||||
}
|
||||
// 设备列表返回数据
|
||||
[System.Serializable]
|
||||
public class JsonData
|
||||
{
|
||||
public Status status;
|
||||
public Result result;
|
||||
}
|
||||
// 设备详情返回数据
|
||||
[System.Serializable]
|
||||
public class JsonDetails
|
||||
{
|
||||
public Status status;
|
||||
public ResultDetails result;
|
||||
}
|
||||
|
||||
// 设备列表结果
|
||||
[System.Serializable]
|
||||
public class Result
|
||||
{
|
||||
public List<Device> device_list;
|
||||
}
|
||||
|
||||
// 设备详情结果
|
||||
[System.Serializable]
|
||||
public class ResultDetails
|
||||
{
|
||||
public int device_id;
|
||||
public string device_sn;
|
||||
public string device_name;
|
||||
public string online_status;
|
||||
public string pic;
|
||||
public string status;
|
||||
public string address;
|
||||
public string location;
|
||||
public DataPoints data_points;
|
||||
}
|
||||
|
||||
|
||||
// 设备信息
|
||||
[System.Serializable]
|
||||
public class Device
|
||||
{
|
||||
public int device_id;
|
||||
public string device_sn;
|
||||
public string device_name;
|
||||
public string online_status;
|
||||
public int project_id;
|
||||
public string pic;
|
||||
}
|
||||
|
||||
// 数据点信息
|
||||
[System.Serializable]
|
||||
public class Timeseries
|
||||
{
|
||||
public string point_id;
|
||||
public string name;
|
||||
public string alias;
|
||||
public string identifier;
|
||||
public string unitName;
|
||||
public string unitIdentifier;
|
||||
public string accessMode;
|
||||
public string dataType;
|
||||
public List<object> propertyEnum;
|
||||
public string value;
|
||||
public string callback_time;
|
||||
}
|
||||
|
||||
// 数据点信息
|
||||
[System.Serializable]
|
||||
public class DataPoints
|
||||
{
|
||||
public List<object> control;
|
||||
public List<Timeseries> timeseries;
|
||||
}
|
||||
|
||||
//传值web。把模型名称传过去
|
||||
[System.Serializable]
|
||||
public class DataToSend
|
||||
{
|
||||
public ResultDetails dataItem;
|
||||
public string iconName;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class IconData
|
||||
{
|
||||
public string device_sn;
|
||||
public string iconName;
|
||||
public string identifier;
|
||||
public Transform iconTransform;
|
||||
|
||||
public string cameraName;
|
||||
public Transform cameraTransform;
|
||||
|
||||
public IconData(string device_sn, string iconName, string identifier, Transform iconTransform,string cameraName,Transform cameraTransform)
|
||||
{
|
||||
this.device_sn = device_sn;
|
||||
this.iconName = iconName;
|
||||
this.identifier = identifier;
|
||||
this.iconTransform = iconTransform;
|
||||
this.cameraName = cameraName;
|
||||
this.cameraTransform = cameraTransform;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
11
Assets/Scripts/App/GameDto.cs.meta
Normal file
11
Assets/Scripts/App/GameDto.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 04fa43d151cecb34d88b22f73ec60687
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
19
Assets/Scripts/App/GameEvent.cs
Normal file
19
Assets/Scripts/App/GameEvent.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class GameEvent
|
||||
{
|
||||
//相机控制
|
||||
public static UnityAction StartCameraControl;
|
||||
public static UnityAction StopCameraControl;
|
||||
|
||||
//UI页面控制
|
||||
public static UnityAction<PageType> OpenPage;
|
||||
public static UnityAction<PageType> ClosePage;
|
||||
public static UnityAction RefreshPage;
|
||||
|
||||
public static UnityAction<PageType, object> OpenDialog;
|
||||
|
||||
}
|
||||
11
Assets/Scripts/App/GameEvent.cs.meta
Normal file
11
Assets/Scripts/App/GameEvent.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ad594012b3427174cabb304db86ce09a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
95
Assets/Scripts/App/SceneUtil.cs
Normal file
95
Assets/Scripts/App/SceneUtil.cs
Normal file
@@ -0,0 +1,95 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
public class SceneUtil : ActionBase
|
||||
{
|
||||
public Color color01;
|
||||
public Color color02;
|
||||
|
||||
// 辅助方法,用于初始化图标和相机列表
|
||||
private void InitializeIconAndCameraLists(string iconName, string cameraName, List<IconData> iconList, List<Transform> cameraList, string[] deviceSns, string[] iconNames, string[] identifiers)
|
||||
{
|
||||
iconList.Clear();
|
||||
cameraList.Clear();
|
||||
|
||||
Transform icon = transform.Find(iconName);
|
||||
Transform iconCamera = transform.Find(cameraName);
|
||||
|
||||
if (icon != null && iconCamera != null)
|
||||
{
|
||||
int count = Mathf.Min(icon.childCount, deviceSns.Length, iconNames.Length);
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
Transform currentIcon = icon.GetChild(i);
|
||||
Transform currentCamera = iconCamera.GetChild(i);
|
||||
|
||||
// 获取当前索引对应的设备信息
|
||||
string deviceSn = deviceSns[i];
|
||||
string name = iconNames[i];
|
||||
string identifier = identifiers[i];
|
||||
// 创建 IconData 实例并添加到 iconList
|
||||
IconData iconData = new IconData(deviceSn, name, identifier, currentIcon, currentCamera.name, currentCamera);
|
||||
iconList.Add(iconData);
|
||||
|
||||
cameraList.Add(currentCamera);
|
||||
}
|
||||
|
||||
icon.gameObject.SetActive(false);
|
||||
iconCamera.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
// 确保 AppCache 中的列表类型为 List<IconData>
|
||||
if (AppCache.iconPointList01 == null) AppCache.iconPointList01 = new List<IconData>();
|
||||
if (AppCache.iconPointList02 == null) AppCache.iconPointList02 = new List<IconData>();
|
||||
if (AppCache.iconPointList03 == null) AppCache.iconPointList03 = new List<IconData>();
|
||||
if (AppCache.iconPointList04 == null) AppCache.iconPointList04 = new List<IconData>();
|
||||
if (AppCache.iconPointList05 == null) AppCache.iconPointList05 = new List<IconData>();
|
||||
|
||||
// 初始化 GNSS 相关列表(12个设备)
|
||||
InitializeIconAndCameraLists("GNSS", "GNSS视角", AppCache.iconPointList01, AppCache.iconCameraList01,
|
||||
new string[] { "MS3P1475041092", "MS3P1475041038", "MS3P1475041023", "MS3P1475041053", "MS3P1475041070", "MS3P1475041068", "MS3P1475041098", "MS3P1475041020", "MS3P1475041030", "MS3P1475041014", "MS3P1475041096", "MS3P1475041084" },
|
||||
new string[] { "GNSS基准点1", "GNSS监测点1", "GNSS监测点2", "GNSS监测点3", "GNSS监测点4", "GNSS监测点5", "GNSS监测点6", "GNSS监测点7", "GNSS监测点8", "GNSS监测点9", "GNSS监测点10", "GNSS基准点2" },
|
||||
new string[] { "", "", "", "", "", "", "", "", "", "", "", "" });
|
||||
|
||||
// 初始化环境量监测相关列表(1个设备)
|
||||
InitializeIconAndCameraLists("环境量监测", "环境量监测视角", AppCache.iconPointList02, AppCache.iconCameraList02,
|
||||
new string[] { "2025042109" },
|
||||
new string[] { "环境量监测" },
|
||||
new string[] { "" });
|
||||
|
||||
// 初始化测缝针监测相关列表(9个设备)
|
||||
InitializeIconAndCameraLists("测缝针监测", "测缝计监测视角", AppCache.iconPointList03, AppCache.iconCameraList03,
|
||||
new string[] { "2025042106", "2025042103", "2025042105", "2025042104", "2025042107", "2025042102", "20250421A2", "20250421A1", "2025042101","2025042108" },
|
||||
new string[] { "测缝计1", "测缝计2", "测缝计3", "测缝计4", "测缝计5", "测缝计6", "测缝计7", "测缝计8", "测缝计9","测缝计10" },
|
||||
new string[] { "ff01", "ff01", "ff01", "ff01", "ff01", "ff01", "ff01", "ff01", "ff01","ff01" });
|
||||
|
||||
// 初始化加速度振动监测相关列表(6个设备)
|
||||
InitializeIconAndCameraLists("加速度振动监测", "加速度振动监测视角", AppCache.iconPointList04, AppCache.iconCameraList04,
|
||||
new string[] { "2025042106", "2025042103", "2025042107", "2025042102", "2025042101", "2025042108" },
|
||||
new string[] { "振动加速度1", "振动加速度2", "振动加速度3", "振动加速度4", "振动加速度5", "振动加速度6" },
|
||||
new string[] { "ff03,ff04,ff05", "ff03,ff04,ff05", "ff03,ff04,ff05", "ff03,ff04,ff05", "ff03,ff04,ff05", "ff03,ff04,ff05" });
|
||||
|
||||
// 初始化应变计监测相关列表(2个设备)
|
||||
InitializeIconAndCameraLists("应变计监测", "应变计监测视角", AppCache.iconPointList05, AppCache.iconCameraList05,
|
||||
new string[] { "20250421A2", "20250421A1", "20250421A2", "20250421A1", "20250421A2", "20250421A1" },
|
||||
new string[] { "6号桥墩表面应变监测", "3号桥墩表面应变监测", "5号桥墩表面应变监测", "2号桥墩表面应变监测", "4号桥墩表面应变监测", "1号桥墩表面应变监测" },
|
||||
new string[] { "ff20,ff21", "ff20,ff21", "ff26,ff27", "ff26,ff27", "ff24,ff25", "ff24,ff25" });
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
|
||||
public override void RegisterAction()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void RemoveAction()
|
||||
{
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/App/SceneUtil.cs.meta
Normal file
11
Assets/Scripts/App/SceneUtil.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cac2717237eedc240969c5d04866da82
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/Core.meta
Normal file
8
Assets/Scripts/Core.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 392ff487dcc7f074c9b1974b421f8611
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
23
Assets/Scripts/Core/ActionBase.cs
Normal file
23
Assets/Scripts/Core/ActionBase.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.UI;
|
||||
using DG.Tweening;
|
||||
|
||||
public abstract class ActionBase : MonoBehaviour
|
||||
{
|
||||
public abstract void Init();
|
||||
public abstract void RegisterAction();
|
||||
public abstract void RemoveAction();
|
||||
|
||||
public T GetChildComponent<T>(string path) where T : MonoBehaviour
|
||||
{
|
||||
GameObject go = transform.Find(path).gameObject;
|
||||
T t = go.GetComponent<T>();
|
||||
if (t == null)
|
||||
{
|
||||
t = go.AddComponent<T>();
|
||||
}
|
||||
return t;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Core/ActionBase.cs.meta
Normal file
11
Assets/Scripts/Core/ActionBase.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7a772b5c480e09141843b6ab5f8abb51
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
158
Assets/Scripts/Core/ActionCenter.cs
Normal file
158
Assets/Scripts/Core/ActionCenter.cs
Normal file
@@ -0,0 +1,158 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Events;
|
||||
|
||||
public class ActionCenter : MonoBehaviour
|
||||
{
|
||||
private static ActionCenter _instance;
|
||||
|
||||
public static ActionCenter Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
string name = "ActionCenter";
|
||||
GameObject obj = GameObject.Find(name);
|
||||
if (obj == null)
|
||||
{
|
||||
obj = new GameObject(name);
|
||||
_instance = obj.AddComponent<ActionCenter>();
|
||||
}
|
||||
else
|
||||
{
|
||||
_instance = obj.GetComponent<ActionCenter>();
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = obj.AddComponent<ActionCenter>();
|
||||
}
|
||||
}
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
//场景中所有ActionBase对象列表
|
||||
private List<ActionBase> actionList = new List<ActionBase>();
|
||||
|
||||
//初始化,场景加载完成后调用
|
||||
public void Init()
|
||||
{
|
||||
ActionBase[] arr = Resources.FindObjectsOfTypeAll<ActionBase>();
|
||||
for (int i = 0; i < arr.Length; i++)
|
||||
{
|
||||
if (arr[i].gameObject.scene.buildIndex >= 0)
|
||||
{
|
||||
arr[i].Init();
|
||||
arr[i].RegisterAction();
|
||||
actionList.Add(arr[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void AddAction(ActionBase action)
|
||||
{
|
||||
actionList.Add(action);
|
||||
action.Init();
|
||||
action.RegisterAction();
|
||||
}
|
||||
|
||||
public void RemoveAction(ActionBase action)
|
||||
{
|
||||
if (actionList.Contains(action))
|
||||
{
|
||||
actionList.Remove(action);
|
||||
}
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
for (int i = 0; i < actionList.Count; i++)
|
||||
{
|
||||
actionList[i].RemoveAction();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#region 执行事件
|
||||
|
||||
//执行事件
|
||||
public void DoAction(UnityAction action)
|
||||
{
|
||||
action?.Invoke();
|
||||
}
|
||||
|
||||
//执行事件
|
||||
public void DoAction<T>(UnityAction<T> action, T t)
|
||||
{
|
||||
|
||||
action?.Invoke(t);
|
||||
}
|
||||
|
||||
//执行事件
|
||||
public void DoAction<T, U>(UnityAction<T, U> action, T t, U u)
|
||||
{
|
||||
action?.Invoke(t, u);
|
||||
}
|
||||
|
||||
//执行事件
|
||||
public void DoAction<T, U, V>(UnityAction<T, U, V> action, T t, U u, V v)
|
||||
{
|
||||
action?.Invoke(t, u, v);
|
||||
}
|
||||
|
||||
|
||||
//delay秒后,执行事件
|
||||
public void DoActionDelay(UnityAction action, float delay)
|
||||
{
|
||||
StartCoroutine(DoActionDelayCor(action, delay));
|
||||
}
|
||||
|
||||
IEnumerator DoActionDelayCor(UnityAction action, float delay)
|
||||
{
|
||||
yield return new WaitForSeconds(delay);
|
||||
action?.Invoke();
|
||||
}
|
||||
|
||||
|
||||
//delay秒后,执行事件
|
||||
public void DoActionDelay<T>(UnityAction<T> action, float delay, T t)
|
||||
{
|
||||
StartCoroutine(DoActionDelayCor(action, delay, t));
|
||||
}
|
||||
|
||||
IEnumerator DoActionDelayCor<T>(UnityAction<T> action, float delay, T t)
|
||||
{
|
||||
yield return new WaitForSeconds(delay);
|
||||
action?.Invoke(t);
|
||||
}
|
||||
|
||||
|
||||
//delay秒后,执行事件
|
||||
public void DoActionDelay<T, U>(UnityAction<T, U> action, float delay, T t, U u)
|
||||
{
|
||||
StartCoroutine(DoActionDelayCor(action, delay, t, u));
|
||||
}
|
||||
|
||||
IEnumerator DoActionDelayCor<T, U>(UnityAction<T, U> action, float delay, T t, U u)
|
||||
{
|
||||
yield return new WaitForSeconds(delay);
|
||||
action?.Invoke(t, u);
|
||||
}
|
||||
|
||||
|
||||
//delay秒后,执行事件
|
||||
public void DoActionDelay<T, U, V>(UnityAction<T, U, V> action, float delay, T t, U u, V v)
|
||||
{
|
||||
StartCoroutine(DoActionDelayCor(action, delay, t, u, v));
|
||||
}
|
||||
|
||||
IEnumerator DoActionDelayCor<T, U, V>(UnityAction<T, U, V> action, float delay, T t, U u, V v)
|
||||
{
|
||||
yield return new WaitForSeconds(delay);
|
||||
action?.Invoke(t, u, v);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
11
Assets/Scripts/Core/ActionCenter.cs.meta
Normal file
11
Assets/Scripts/Core/ActionCenter.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 676ee6ef05572ae488fa5f16644f4a70
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
446
Assets/Scripts/Core/EventListener.cs
Normal file
446
Assets/Scripts/Core/EventListener.cs
Normal file
@@ -0,0 +1,446 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.Events;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class EventListener
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 添加指针进入事件监听
|
||||
/// </summary>
|
||||
public static void AddPointerEnterListener(GameObject obj, UnityAction<PointerEventData> callback)
|
||||
{
|
||||
PointerEnterEvent trigger = obj.GetComponent<PointerEnterEvent>();
|
||||
if (trigger == null)
|
||||
{
|
||||
trigger = obj.AddComponent<PointerEnterEvent>();
|
||||
}
|
||||
trigger.AddListener(callback);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加指针离开事件监听
|
||||
/// </summary>
|
||||
public static void AddPointerExitListener(GameObject obj, UnityAction<PointerEventData> callback)
|
||||
{
|
||||
PointerExitEvent trigger = obj.GetComponent<PointerExitEvent>();
|
||||
if (trigger == null)
|
||||
{
|
||||
trigger = obj.AddComponent<PointerExitEvent>();
|
||||
}
|
||||
trigger.AddListener(callback);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加指针按下事件监听
|
||||
/// </summary>
|
||||
public static void AddPointerDownListener(GameObject obj, UnityAction<PointerEventData> callback)
|
||||
{
|
||||
PointerDownEvent trigger = obj.GetComponent<PointerDownEvent>();
|
||||
if (trigger == null)
|
||||
{
|
||||
trigger = obj.AddComponent<PointerDownEvent>();
|
||||
}
|
||||
trigger.AddListener(callback);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加指针抬起事件监听
|
||||
/// </summary>
|
||||
public static void AddPointerUpListener(GameObject obj, UnityAction<PointerEventData> callback)
|
||||
{
|
||||
PointerUpEvent trigger = obj.GetComponent<PointerUpEvent>();
|
||||
if (trigger == null)
|
||||
{
|
||||
trigger = obj.AddComponent<PointerUpEvent>();
|
||||
}
|
||||
trigger.AddListener(callback);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 添加指针点击事件监听
|
||||
/// </summary>
|
||||
public static void AddPointerClickListener(GameObject obj, UnityAction<PointerEventData> callback)
|
||||
{
|
||||
PointerClickEvent trigger = obj.GetComponent<PointerClickEvent>();
|
||||
if (trigger == null)
|
||||
{
|
||||
trigger = obj.AddComponent<PointerClickEvent>();
|
||||
}
|
||||
trigger.AddListener(callback);
|
||||
}
|
||||
|
||||
public static void AddPointerPressListener(GameObject obj, UnityAction<PointerEventData> callback)
|
||||
{
|
||||
PointerPressEvent trigger = obj.GetComponent<PointerPressEvent>();
|
||||
if (trigger == null)
|
||||
{
|
||||
trigger = obj.AddComponent<PointerPressEvent>();
|
||||
}
|
||||
trigger.AddListener(callback);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 添加开始拖拽事件监听
|
||||
/// </summary>
|
||||
public static void AddBeginDragListener(GameObject obj, UnityAction<PointerEventData> callback)
|
||||
{
|
||||
BeginDragEvent trigger = obj.GetComponent<BeginDragEvent>();
|
||||
if (trigger == null)
|
||||
{
|
||||
trigger = obj.AddComponent<BeginDragEvent>();
|
||||
}
|
||||
trigger.AddListener(callback);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加拖拽事件监听
|
||||
/// </summary>
|
||||
public static void AddDragListener(GameObject obj, UnityAction<PointerEventData> callback)
|
||||
{
|
||||
DragEvent trigger = obj.GetComponent<DragEvent>();
|
||||
if (trigger == null)
|
||||
{
|
||||
trigger = obj.AddComponent<DragEvent>();
|
||||
}
|
||||
trigger.AddListener(callback);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加停止拖拽事件监听
|
||||
/// </summary>
|
||||
public static void AddEndDragListener(GameObject obj, UnityAction<PointerEventData> callback)
|
||||
{
|
||||
EndDragEvent trigger = obj.GetComponent<EndDragEvent>();
|
||||
if (trigger == null)
|
||||
{
|
||||
trigger = obj.AddComponent<EndDragEvent>();
|
||||
}
|
||||
trigger.AddListener(callback);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 添加鼠标按下事件监听
|
||||
/// </summary>
|
||||
public static void AddMouseDownListener(GameObject obj, UnityAction<GameObject> callback)
|
||||
{
|
||||
MousePointEvent tigger = obj.GetComponent<MousePointEvent>();
|
||||
if (tigger == null)
|
||||
{
|
||||
tigger = obj.AddComponent<MousePointEvent>();
|
||||
}
|
||||
tigger.AddMouseDownListener(callback);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加鼠标抬起事件监听
|
||||
/// </summary>
|
||||
public static void AddMouseUpListener(GameObject obj, UnityAction<GameObject> callback)
|
||||
{
|
||||
MousePointEvent tigger = obj.GetComponent<MousePointEvent>();
|
||||
if (tigger == null)
|
||||
{
|
||||
tigger = obj.AddComponent<MousePointEvent>();
|
||||
}
|
||||
tigger.AddMouseUpListener(callback);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加鼠标进入事件监听
|
||||
/// </summary>
|
||||
public static void AddMouseEnterListener(GameObject obj, UnityAction<GameObject> callback)
|
||||
{
|
||||
MousePointEvent tigger = obj.GetComponent<MousePointEvent>();
|
||||
if (tigger == null)
|
||||
{
|
||||
tigger = obj.AddComponent<MousePointEvent>();
|
||||
}
|
||||
tigger.AddMouseEnterListener(callback);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加鼠标离开事件监听
|
||||
/// </summary>
|
||||
public static void AddMouseExitListener(GameObject obj, UnityAction<GameObject> callback)
|
||||
{
|
||||
MousePointEvent tigger = obj.GetComponent<MousePointEvent>();
|
||||
if (tigger == null)
|
||||
{
|
||||
tigger = obj.AddComponent<MousePointEvent>();
|
||||
}
|
||||
tigger.AddMouseExitListener(callback);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//进入事件
|
||||
public class PointerEnterEvent : MonoBehaviour, IPointerEnterHandler
|
||||
{
|
||||
private UnityAction<PointerEventData> action;
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
if (action != null)
|
||||
{
|
||||
action.Invoke(eventData);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddListener(UnityAction<PointerEventData> callback)
|
||||
{
|
||||
action = callback;
|
||||
}
|
||||
}
|
||||
|
||||
//按下事件
|
||||
public class PointerDownEvent : MonoBehaviour, IPointerDownHandler
|
||||
{
|
||||
private UnityAction<PointerEventData> action;
|
||||
|
||||
public void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
if (action != null)
|
||||
{
|
||||
action.Invoke(eventData);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddListener(UnityAction<PointerEventData> callback)
|
||||
{
|
||||
action = callback;
|
||||
}
|
||||
}
|
||||
|
||||
//抬起事件
|
||||
public class PointerUpEvent : MonoBehaviour, IPointerUpHandler
|
||||
{
|
||||
private UnityAction<PointerEventData> action;
|
||||
|
||||
public void OnPointerUp(PointerEventData eventData)
|
||||
{
|
||||
if (action != null)
|
||||
{
|
||||
action.Invoke(eventData);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddListener(UnityAction<PointerEventData> callback)
|
||||
{
|
||||
action = callback;
|
||||
}
|
||||
}
|
||||
|
||||
//离开事件
|
||||
public class PointerExitEvent : MonoBehaviour, IPointerExitHandler
|
||||
{
|
||||
private UnityAction<PointerEventData> action;
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
if (action != null)
|
||||
{
|
||||
action.Invoke(eventData);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddListener(UnityAction<PointerEventData> callback)
|
||||
{
|
||||
action = callback;
|
||||
}
|
||||
}
|
||||
|
||||
//点击事件
|
||||
public class PointerClickEvent : MonoBehaviour, IPointerClickHandler
|
||||
{
|
||||
private UnityAction<PointerEventData> action;
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
if (action != null)
|
||||
{
|
||||
action.Invoke(eventData);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddListener(UnityAction<PointerEventData> callback)
|
||||
{
|
||||
action = callback;
|
||||
}
|
||||
}
|
||||
|
||||
public class PointerPressEvent : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
|
||||
{
|
||||
private bool isPress = false;
|
||||
private UnityAction<PointerEventData> action;
|
||||
private PointerEventData data;
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (isPress && action != null)
|
||||
{
|
||||
action.Invoke(data);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
data = eventData;
|
||||
isPress = true;
|
||||
}
|
||||
|
||||
public void OnPointerUp(PointerEventData eventData)
|
||||
{
|
||||
isPress = false;
|
||||
}
|
||||
|
||||
public void AddListener(UnityAction<PointerEventData> callback)
|
||||
{
|
||||
action = callback;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//开始拖拽事件
|
||||
public class BeginDragEvent : MonoBehaviour, IBeginDragHandler
|
||||
{
|
||||
private UnityAction<PointerEventData> action;
|
||||
|
||||
public void OnBeginDrag(PointerEventData eventData)
|
||||
{
|
||||
if (action != null)
|
||||
{
|
||||
action.Invoke(eventData);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddListener(UnityAction<PointerEventData> callback)
|
||||
{
|
||||
action = callback;
|
||||
}
|
||||
}
|
||||
|
||||
//拖拽事件
|
||||
public class DragEvent : MonoBehaviour, IDragHandler
|
||||
{
|
||||
private UnityAction<PointerEventData> action;
|
||||
|
||||
public void OnDrag(PointerEventData eventData)
|
||||
{
|
||||
if (action != null)
|
||||
{
|
||||
action.Invoke(eventData);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddListener(UnityAction<PointerEventData> callback)
|
||||
{
|
||||
action = callback;
|
||||
}
|
||||
}
|
||||
|
||||
//停止拖拽事件
|
||||
public class EndDragEvent : MonoBehaviour, IEndDragHandler
|
||||
{
|
||||
private UnityAction<PointerEventData> action;
|
||||
|
||||
public void OnEndDrag(PointerEventData eventData)
|
||||
{
|
||||
if (action != null)
|
||||
{
|
||||
action.Invoke(eventData);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddListener(UnityAction<PointerEventData> callback)
|
||||
{
|
||||
action = callback;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 鼠标操作事件
|
||||
/// </summary>
|
||||
public class MousePointEvent : MonoBehaviour
|
||||
{
|
||||
private UnityAction<GameObject> mouseDownAction;
|
||||
private UnityAction<GameObject> mouseUpAction;
|
||||
private UnityAction<GameObject> mouseEnterAction;
|
||||
private UnityAction<GameObject> mouseExitAction;
|
||||
|
||||
void OnMouseDown()
|
||||
{
|
||||
if (mouseDownAction != null)
|
||||
{
|
||||
mouseDownAction.Invoke(this.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
void OnMouseUp()
|
||||
{
|
||||
if (mouseUpAction != null)
|
||||
{
|
||||
mouseUpAction.Invoke(this.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
void OnMouseEnter()
|
||||
{
|
||||
if (mouseEnterAction != null)
|
||||
{
|
||||
mouseEnterAction.Invoke(this.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
void OnMouseExit()
|
||||
{
|
||||
if (mouseExitAction != null)
|
||||
{
|
||||
mouseExitAction.Invoke(this.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddMouseDownListener(UnityAction<GameObject> callback)
|
||||
{
|
||||
mouseDownAction = callback;
|
||||
}
|
||||
|
||||
public void AddMouseUpListener(UnityAction<GameObject> callback)
|
||||
{
|
||||
mouseUpAction = callback;
|
||||
}
|
||||
|
||||
public void AddMouseEnterListener(UnityAction<GameObject> callback)
|
||||
{
|
||||
mouseEnterAction = callback;
|
||||
}
|
||||
|
||||
public void AddMouseExitListener(UnityAction<GameObject> callback)
|
||||
{
|
||||
mouseExitAction = callback;
|
||||
}
|
||||
}
|
||||
|
||||
11
Assets/Scripts/Core/EventListener.cs.meta
Normal file
11
Assets/Scripts/Core/EventListener.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 273071f04b6f4b14ca18e0130f072bbc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
302
Assets/Scripts/Core/PoolManager.cs
Normal file
302
Assets/Scripts/Core/PoolManager.cs
Normal file
@@ -0,0 +1,302 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
/// <summary>
|
||||
/// 对象池管理类,日常使用一下两个方法即可
|
||||
/// 取对象Spawn(name/Prefab),回收对象Unspawn(name/Prefab)
|
||||
/// </summary>
|
||||
public class PoolManager : MonoBehaviour
|
||||
{
|
||||
private static readonly object lockObj = new object();
|
||||
|
||||
private static PoolManager _instance;
|
||||
|
||||
public static PoolManager Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
lock (lockObj)
|
||||
{
|
||||
PoolManager[] objs = FindObjectsOfType<PoolManager>();
|
||||
if (objs != null)
|
||||
{
|
||||
for (int i = 0; i < objs.Length; i++)
|
||||
{
|
||||
DestroyImmediate(objs[i].gameObject);
|
||||
}
|
||||
}
|
||||
GameObject go = new GameObject("PoolManager");
|
||||
DontDestroyOnLoad(go);
|
||||
_instance = go.AddComponent<PoolManager>();
|
||||
}
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
|
||||
//预制ID-对象池 集合
|
||||
private Dictionary<int, ObjectPool> poolDic = new Dictionary<int, ObjectPool>();
|
||||
//对象ID-对象池ID 集合
|
||||
private Dictionary<int, int> itemDic = new Dictionary<int, int>();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 取对象,通过对象实例
|
||||
/// </summary>
|
||||
public GameObject Spawn(GameObject prefab)
|
||||
{
|
||||
if (!poolDic.ContainsKey(prefab.GetInstanceID()))
|
||||
{
|
||||
CreateNewPool(prefab);
|
||||
}
|
||||
GameObject item = poolDic[prefab.GetInstanceID()].Spawn();
|
||||
if (!itemDic.ContainsKey(item.GetInstanceID()))
|
||||
{
|
||||
itemDic.Add(item.GetInstanceID(), prefab.GetInstanceID());
|
||||
}
|
||||
else
|
||||
{
|
||||
itemDic[item.GetInstanceID()] = prefab.GetInstanceID();
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 回收对象
|
||||
/// </summary>
|
||||
public void Unspawn(GameObject go)
|
||||
{
|
||||
if (itemDic.ContainsKey(go.GetInstanceID()))
|
||||
{
|
||||
int id = itemDic[go.GetInstanceID()];
|
||||
if (poolDic.ContainsKey(id))
|
||||
{
|
||||
poolDic[id].Unspawn(go);
|
||||
itemDic.Remove(go.GetInstanceID());
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("回收对象失败 : " + go.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 回收某个对象池中所有对象
|
||||
/// </summary>
|
||||
public void ClearPool(GameObject prefab)
|
||||
{
|
||||
int id = prefab.GetInstanceID();
|
||||
if (poolDic.ContainsKey(id))
|
||||
{
|
||||
poolDic[id].UnspawnAll();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("清空对象池失败 : " + prefab.name);
|
||||
}
|
||||
|
||||
List<int> list = new List<int>();
|
||||
foreach (int key in itemDic.Keys)
|
||||
{
|
||||
if (itemDic[key] == id)
|
||||
{
|
||||
list.Add(key);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
itemDic.Remove(list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 回收所有对象池
|
||||
/// </summary>
|
||||
public void ClearAll()
|
||||
{
|
||||
foreach (ObjectPool pool in poolDic.Values)
|
||||
{
|
||||
pool.UnspawnAll();
|
||||
}
|
||||
itemDic.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建一个新的对象池
|
||||
/// </summary>
|
||||
public void CreateNewPool(GameObject prefab)
|
||||
{
|
||||
if (poolDic.ContainsKey(prefab.GetInstanceID()))
|
||||
{
|
||||
Debug.LogError("无法创建新的对象池,当前对象池已存在 : " + prefab.name);
|
||||
return;
|
||||
}
|
||||
ObjectPool pool = new ObjectPool(prefab);
|
||||
poolDic.Add(prefab.GetInstanceID(), pool);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建一个新的对象池,并初始化
|
||||
/// </summary>
|
||||
public void CreateNewPool(GameObject prefab, int initSize)
|
||||
{
|
||||
if (poolDic.ContainsKey(prefab.GetInstanceID()))
|
||||
{
|
||||
Debug.LogError("无法创建新的对象池,当前对象池已存在 : " + prefab.name);
|
||||
return;
|
||||
}
|
||||
ObjectPool pool = new ObjectPool(prefab);
|
||||
pool.InitPool(initSize);
|
||||
poolDic.Add(prefab.GetInstanceID(), pool);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建一个新的对象池,并初始化,同时设定对象池最大容量
|
||||
/// </summary>
|
||||
public void CreateNewPool(GameObject prefab, int initSize, int maxSize)
|
||||
{
|
||||
if (poolDic.ContainsKey(prefab.GetInstanceID()))
|
||||
{
|
||||
Debug.LogError("无法创建新的对象池,当前对象池已存在 : " + prefab.name);
|
||||
return;
|
||||
}
|
||||
ObjectPool pool = new ObjectPool(prefab, maxSize);
|
||||
pool.InitPool(initSize);
|
||||
poolDic.Add(prefab.GetInstanceID(), pool);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 对象池-子池
|
||||
/// </summary>
|
||||
public class ObjectPool
|
||||
{
|
||||
//对象池元素
|
||||
public GameObject prefab;
|
||||
|
||||
//对象池最大容量,此值小于等于0时,对象池动态增加,不设上限
|
||||
private int maxSize;
|
||||
|
||||
//对象池名称
|
||||
public string Name
|
||||
{
|
||||
get { return prefab.name; }
|
||||
}
|
||||
|
||||
//对象池当前容量
|
||||
private int CurrentSize
|
||||
{
|
||||
get { return activeObjectList.Count + inactiveObjectList.Count; }
|
||||
}
|
||||
|
||||
private List<GameObject> activeObjectList = new List<GameObject>(); //已用对象列表
|
||||
private List<GameObject> inactiveObjectList = new List<GameObject>(); //待用对象列表
|
||||
|
||||
public ObjectPool(GameObject obj)
|
||||
{
|
||||
this.prefab = obj;
|
||||
maxSize = -1;
|
||||
}
|
||||
|
||||
public ObjectPool(GameObject obj, int maxCount)
|
||||
{
|
||||
this.prefab = obj;
|
||||
maxSize = maxCount;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化对象池
|
||||
/// </summary>
|
||||
public void InitPool(int initSize)
|
||||
{
|
||||
if (maxSize > 0 && initSize > maxSize)
|
||||
{
|
||||
Debug.LogError("对象池初始容量不能超过其最大容量!!");
|
||||
for (int i = 0; i < maxSize; i++)
|
||||
{
|
||||
GameObject go = GameObject.Instantiate(prefab);
|
||||
go.name = prefab.name;
|
||||
go.SetActive(false);
|
||||
inactiveObjectList.Add(go);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < initSize; i++)
|
||||
{
|
||||
GameObject go = GameObject.Instantiate(prefab);
|
||||
go.name = prefab.name;
|
||||
go.SetActive(false);
|
||||
inactiveObjectList.Add(go);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取对象
|
||||
/// </summary>
|
||||
public GameObject Spawn()
|
||||
{
|
||||
if (inactiveObjectList.Count == 0)
|
||||
{
|
||||
if (maxSize > 0 && CurrentSize >= maxSize)
|
||||
{
|
||||
Debug.LogError("警告:对象池 " + Name + " 当前容量已达到最大设定值 : " + maxSize);
|
||||
GameObject go = activeObjectList[0];
|
||||
return go;
|
||||
}
|
||||
else
|
||||
{
|
||||
GameObject go = GameObject.Instantiate(prefab);
|
||||
go.SetActive(true);
|
||||
activeObjectList.Add(go);
|
||||
return go;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GameObject go = inactiveObjectList[0];
|
||||
go.SetActive(true);
|
||||
inactiveObjectList.RemoveAt(0);
|
||||
activeObjectList.Add(go);
|
||||
return go;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 回收对象
|
||||
/// </summary>
|
||||
public void Unspawn(GameObject go)
|
||||
{
|
||||
if (activeObjectList.Contains(go))
|
||||
{
|
||||
go.SetActive(false);
|
||||
activeObjectList.Remove(go);
|
||||
inactiveObjectList.Add(go);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("回收对象异常,当前对象不在对象列表中!!");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 回收池中所有对象
|
||||
/// </summary>
|
||||
public void UnspawnAll()
|
||||
{
|
||||
//回收修改
|
||||
int count = activeObjectList.Count;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
if (activeObjectList.Count >= 1)
|
||||
{
|
||||
Unspawn(activeObjectList[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Core/PoolManager.cs.meta
Normal file
11
Assets/Scripts/Core/PoolManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8908e1646c88df14a8dc814b707d228e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
309
Assets/Scripts/Core/WebService.cs
Normal file
309
Assets/Scripts/Core/WebService.cs
Normal file
@@ -0,0 +1,309 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.UI;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class WebService : MonoBehaviour
|
||||
{
|
||||
private static WebService _instance;
|
||||
public static WebService Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
string name = "WebService";
|
||||
GameObject obj = GameObject.Find(name);
|
||||
if (obj == null)
|
||||
{
|
||||
obj = new GameObject(name);
|
||||
_instance = obj.AddComponent<WebService>();
|
||||
}
|
||||
else
|
||||
{
|
||||
_instance = obj.GetComponent<WebService>();
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = obj.AddComponent<WebService>();
|
||||
}
|
||||
}
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
|
||||
//网络图片资源缓存
|
||||
private Dictionary<int, Texture2D> textureCache = new Dictionary<int, Texture2D>();
|
||||
//图片下载
|
||||
private Queue<LoadTextureTask> textureQueue = new Queue<LoadTextureTask>();
|
||||
//图片加载完成
|
||||
private bool isTextureQueueFinish = true;
|
||||
|
||||
|
||||
void Awake()
|
||||
{
|
||||
DontDestroyOnLoad(this.gameObject);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//获取本地数据
|
||||
public void GetLocalData<T>(Action<T> callback, string code = null) where T : class
|
||||
{
|
||||
StartCoroutine(GetLocalDataCor(callback, code));
|
||||
}
|
||||
|
||||
IEnumerator GetLocalDataCor<T>(Action<T> callback, string code) where T : class
|
||||
{
|
||||
string name = "JsonData/" + typeof(T).Name;
|
||||
if (code != null)
|
||||
{
|
||||
name += "_" + code;
|
||||
}
|
||||
TextAsset textAsset = Resources.Load<TextAsset>(name);
|
||||
yield return new WaitForEndOfFrame();
|
||||
T t = null;
|
||||
if (textAsset != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
t = JsonUtility.FromJson<T>(textAsset.text);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError("Json反序列化异常, type = " + typeof(T) + ", Exception : " + e.ToString());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogErrorFormat("{0}.json is not found.", typeof(T).Name);
|
||||
}
|
||||
if (callback != null)
|
||||
{
|
||||
callback.Invoke(t);
|
||||
}
|
||||
}
|
||||
|
||||
public void GetText(string url, Action<string> callback)
|
||||
{
|
||||
StartCoroutine(GetTextCor(url, callback));
|
||||
}
|
||||
|
||||
IEnumerator GetTextCor(string url, Action<string> callback)
|
||||
{
|
||||
UnityWebRequest unityWeb = UnityWebRequest.Get(url);
|
||||
unityWeb.downloadHandler = new DownloadHandlerBuffer();
|
||||
unityWeb.SetRequestHeader("Authorization", "tenantCode=YBSKDQ&accessToken=7972b3c028682bb5aaeb6b388d30637656a2021c");
|
||||
|
||||
yield return unityWeb.SendWebRequest();
|
||||
if (unityWeb.result != UnityWebRequest.Result.ConnectionError && unityWeb.result != UnityWebRequest.Result.ProtocolError)
|
||||
{
|
||||
callback?.Invoke(unityWeb.downloadHandler.text);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Web请求失败, Error : " + unityWeb.error);
|
||||
}
|
||||
unityWeb.Dispose();
|
||||
}
|
||||
|
||||
//Get通信
|
||||
public void Get<T>(string url, Action<T> callback) where T : class
|
||||
{
|
||||
StartCoroutine(GetCor(url, callback));
|
||||
}
|
||||
|
||||
IEnumerator GetCor<T>(string url, Action<T> callback) where T : class
|
||||
{
|
||||
UnityWebRequest unityWeb = UnityWebRequest.Get(url);
|
||||
unityWeb.downloadHandler = new DownloadHandlerBuffer();
|
||||
unityWeb.SetRequestHeader("Authorization", "tenantCode=YBSKDQ&accessToken=7972b3c028682bb5aaeb6b388d30637656a2021c");
|
||||
|
||||
yield return unityWeb.SendWebRequest();
|
||||
T t = null;
|
||||
if (unityWeb.result != UnityWebRequest.Result.ConnectionError && unityWeb.result != UnityWebRequest.Result.ProtocolError)
|
||||
{
|
||||
try
|
||||
{
|
||||
t = JsonUtility.FromJson<T>(unityWeb.downloadHandler.text);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError("Json反序列化异常, type = " + typeof(T) + ", Exception : " + e.ToString());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Web请求失败, type = " + typeof(T) + ", Error : " + unityWeb.error);
|
||||
}
|
||||
if (callback != null)
|
||||
{
|
||||
callback.Invoke(t);
|
||||
}
|
||||
unityWeb.Dispose();
|
||||
}
|
||||
|
||||
//Post通信
|
||||
public void Post<T>(string url, object obj, Action<T> callback) where T : class
|
||||
{
|
||||
StartCoroutine(PostCor(url, obj, callback));
|
||||
}
|
||||
|
||||
IEnumerator PostCor<T>(string url, object obj, Action<T> callback) where T : class
|
||||
{
|
||||
UnityWebRequest unityWeb = new UnityWebRequest(url, "POST");
|
||||
if (obj != null)
|
||||
{
|
||||
string json = JsonUtility.ToJson(obj);
|
||||
byte[] data = System.Text.Encoding.UTF8.GetBytes(json);
|
||||
unityWeb.uploadHandler = new UploadHandlerRaw(data);
|
||||
}
|
||||
|
||||
unityWeb.downloadHandler = new DownloadHandlerBuffer();
|
||||
unityWeb.SetRequestHeader("Content-Type", "application/json;charset=utf-8");
|
||||
yield return unityWeb.SendWebRequest();
|
||||
T t = null;
|
||||
if (unityWeb.result != UnityWebRequest.Result.ConnectionError && unityWeb.result != UnityWebRequest.Result.ProtocolError)
|
||||
{
|
||||
try
|
||||
{
|
||||
t = JsonUtility.FromJson<T>(unityWeb.downloadHandler.text);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError("Json反序列化异常, type = " + typeof(T) + ", Exception : " + e.ToString());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Web请求失败, type = " + typeof(T) + ", Error : " + unityWeb.error);
|
||||
}
|
||||
|
||||
if (callback != null)
|
||||
{
|
||||
callback.Invoke(t);
|
||||
}
|
||||
unityWeb.Dispose();
|
||||
}
|
||||
|
||||
//加载图片资源
|
||||
public void GetTexture(string url, RawImage image, bool isCache = true)
|
||||
{
|
||||
if (url.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int code = url.GetHashCode();
|
||||
//缓存数据
|
||||
if (textureCache.ContainsKey(code))
|
||||
{
|
||||
image.gameObject.SetActive(true);
|
||||
image.texture = textureCache[code];
|
||||
return;
|
||||
}
|
||||
//加入队列
|
||||
LoadTextureTask task = new LoadTextureTask(url, image, isCache);
|
||||
textureQueue.Enqueue(task);
|
||||
//下载图片
|
||||
if (isTextureQueueFinish)
|
||||
{
|
||||
StartCoroutine(GetTextureCor());
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator GetTextureCor()
|
||||
{
|
||||
isTextureQueueFinish = false;
|
||||
LoadTextureTask task = textureQueue.Dequeue();
|
||||
UnityWebRequest unityWeb = UnityWebRequestTexture.GetTexture(task.url);
|
||||
yield return unityWeb.SendWebRequest();
|
||||
if (unityWeb.result != UnityWebRequest.Result.ConnectionError && unityWeb.result != UnityWebRequest.Result.ProtocolError)
|
||||
{
|
||||
Texture2D texture = ((DownloadHandlerTexture)unityWeb.downloadHandler).texture;
|
||||
//Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
|
||||
task.image.gameObject.SetActive(true);
|
||||
task.image.texture = texture;
|
||||
//缓存
|
||||
if (task.cache)
|
||||
{
|
||||
if (textureCache.ContainsKey(task.url.GetHashCode()))
|
||||
{
|
||||
textureCache[task.url.GetHashCode()] = texture;
|
||||
}
|
||||
else
|
||||
{
|
||||
textureCache.Add(task.url.GetHashCode(), texture);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("图片加载失败失败, url : " + task.url + " error : " + unityWeb.error);
|
||||
}
|
||||
unityWeb.Dispose();
|
||||
//递归
|
||||
if (textureQueue.Count > 0)
|
||||
{
|
||||
StartCoroutine(GetTextureCor());
|
||||
}
|
||||
else
|
||||
{
|
||||
isTextureQueueFinish = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//获取AssetBundle
|
||||
public void GetAssetBundle(string url, Action<AssetBundle> callback)
|
||||
{
|
||||
StartCoroutine(GetAssetBundleCor(url, callback));
|
||||
}
|
||||
|
||||
IEnumerator GetAssetBundleCor(string url, Action<AssetBundle> callback)
|
||||
{
|
||||
UnityWebRequest unityWeb = UnityWebRequestAssetBundle.GetAssetBundle(url);
|
||||
yield return unityWeb.SendWebRequest();
|
||||
AssetBundle bundle = null;
|
||||
if (unityWeb.result != UnityWebRequest.Result.ConnectionError && unityWeb.result != UnityWebRequest.Result.ProtocolError)
|
||||
{
|
||||
bundle = DownloadHandlerAssetBundle.GetContent(unityWeb);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Web请求失败, type = AssetBundle, Error : " + unityWeb.error);
|
||||
}
|
||||
if (callback != null)
|
||||
{
|
||||
callback.Invoke(bundle);
|
||||
}
|
||||
unityWeb.Dispose();
|
||||
}
|
||||
|
||||
//判断是否在WebGL平台运行
|
||||
public static bool IsRunningInWebGL()
|
||||
{
|
||||
return Application.platform == RuntimePlatform.WebGLPlayer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
//图片加载任务
|
||||
public class LoadTextureTask
|
||||
{
|
||||
public string url;
|
||||
public RawImage image;
|
||||
public bool cache;
|
||||
|
||||
public LoadTextureTask(string _url, RawImage _image, bool _cache)
|
||||
{
|
||||
url = _url;
|
||||
image = _image;
|
||||
cache = _cache;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Core/WebService.cs.meta
Normal file
11
Assets/Scripts/Core/WebService.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0e679bd9f5777b04bb36e9b3402a0f9e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/Tools.meta
Normal file
8
Assets/Scripts/Tools.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8b23f08c8531c334d8abf36cf30c9a00
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
68
Assets/Scripts/Tools/IconFollow2D.cs
Normal file
68
Assets/Scripts/Tools/IconFollow2D.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using DG.Tweening;
|
||||
using UnityEngine.EventSystems; // 添加这一行
|
||||
public class IconFollow2D : MonoBehaviour
|
||||
{
|
||||
//目标对象
|
||||
public Transform target;
|
||||
//目标位置
|
||||
public Vector3 targetPos;
|
||||
|
||||
|
||||
|
||||
private Camera mainCamera;
|
||||
private CanvasGroup canvas;
|
||||
|
||||
|
||||
|
||||
void Awake()
|
||||
{
|
||||
mainCamera = Camera.main;
|
||||
canvas = GetComponent<CanvasGroup>();
|
||||
if (canvas == null)
|
||||
{
|
||||
canvas = gameObject.AddComponent<CanvasGroup>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
if (mainCamera != null)
|
||||
{
|
||||
if (target != null)
|
||||
{
|
||||
Vector3 pos = mainCamera.WorldToScreenPoint(target.position);
|
||||
pos = new Vector3(pos.x, pos.y, pos.z);
|
||||
transform.position = pos;
|
||||
}
|
||||
else if (targetPos != null)
|
||||
{
|
||||
Vector3 pos = mainCamera.WorldToScreenPoint(targetPos);
|
||||
pos = new Vector3(pos.x, pos.y, pos.z);
|
||||
transform.position = pos;
|
||||
}
|
||||
if (Time.frameCount % 5 == 0)
|
||||
{
|
||||
ResetAlpha();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ResetAlpha()
|
||||
{
|
||||
if (transform.position.z > 0f && canvas.alpha < 0.1f)
|
||||
{
|
||||
canvas.alpha = 1f;
|
||||
}
|
||||
else if (transform.position.z < 0f && canvas.alpha > 0.9f)
|
||||
{
|
||||
canvas.alpha = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/Scripts/Tools/IconFollow2D.cs.meta
Normal file
11
Assets/Scripts/Tools/IconFollow2D.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e6616d2c1d0fdef45b0bcab0d086666d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
118
Assets/Scripts/Tools/IconFollow3D.cs
Normal file
118
Assets/Scripts/Tools/IconFollow3D.cs
Normal file
@@ -0,0 +1,118 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using DG.Tweening;
|
||||
|
||||
/// <summary>
|
||||
/// 3DUI跟随相机
|
||||
/// </summary>
|
||||
public class IconFollow3D : MonoBehaviour
|
||||
{
|
||||
public enum LookAtTye
|
||||
{
|
||||
//看向相机坐标
|
||||
CameraPos,
|
||||
//看向相机平面
|
||||
CameraPlane
|
||||
}
|
||||
|
||||
public enum RotateAxis
|
||||
{
|
||||
Any,
|
||||
X,
|
||||
Y,
|
||||
Z
|
||||
}
|
||||
|
||||
public LookAtTye lookAtTye = LookAtTye.CameraPlane;
|
||||
public RotateAxis rotateAxis = RotateAxis.Any;
|
||||
|
||||
private bool isFollow;
|
||||
private Transform mainCamera;
|
||||
private Transform followTarget;
|
||||
|
||||
private Vector3 lookAtPos;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
isFollow = true;
|
||||
mainCamera = Camera.main.transform;
|
||||
}
|
||||
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (isFollow)
|
||||
{
|
||||
if (followTarget != null)
|
||||
{
|
||||
transform.position = followTarget.position;
|
||||
}
|
||||
switch (lookAtTye)
|
||||
{
|
||||
case LookAtTye.CameraPos:
|
||||
lookAtPos = mainCamera.position;
|
||||
break;
|
||||
case LookAtTye.CameraPlane:
|
||||
lookAtPos = transform.position - mainCamera.forward;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
switch (rotateAxis)
|
||||
{
|
||||
case (RotateAxis.Any):
|
||||
break;
|
||||
case (RotateAxis.X):
|
||||
lookAtPos.x = transform.position.x;
|
||||
break;
|
||||
case (RotateAxis.Y):
|
||||
lookAtPos.y = transform.position.y;
|
||||
break;
|
||||
case (RotateAxis.Z):
|
||||
lookAtPos.z = transform.position.z;
|
||||
break;
|
||||
}
|
||||
transform.LookAt(lookAtPos);
|
||||
}
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
isFollow = true;
|
||||
}
|
||||
|
||||
void OnBecameVisible()
|
||||
{
|
||||
isFollow = true;
|
||||
}
|
||||
|
||||
void OnBecameInvisible()
|
||||
{
|
||||
isFollow = false;
|
||||
}
|
||||
|
||||
//设置跟随相机
|
||||
public void SetCamera(Transform followCamera)
|
||||
{
|
||||
mainCamera = followCamera;
|
||||
}
|
||||
|
||||
//设置Icon坐标
|
||||
public void SetIconPos(Vector3 pos)
|
||||
{
|
||||
transform.position = pos;
|
||||
}
|
||||
|
||||
//设置跟随对象
|
||||
public void SetFollowTarget(Transform target)
|
||||
{
|
||||
followTarget = target;
|
||||
if (target.Find("iconPos") != null)
|
||||
{
|
||||
followTarget = target.Find("iconPos");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
11
Assets/Scripts/Tools/IconFollow3D.cs.meta
Normal file
11
Assets/Scripts/Tools/IconFollow3D.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aed7fea4c9a968744860ad541ef69f0b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/Ui.meta
Normal file
8
Assets/Scripts/Ui.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 20569bb7951d9b243bc22d722d2fd937
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
33
Assets/Scripts/Ui/LookAt.cs
Normal file
33
Assets/Scripts/Ui/LookAt.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class LookAt : MonoBehaviour
|
||||
{
|
||||
private GameObject Player;
|
||||
private CameraRover cameraRover;
|
||||
void Awake()
|
||||
{
|
||||
Player = GameObject.Find("Player");
|
||||
if (Player != null)
|
||||
{
|
||||
// 获取 Player 上挂载的 CameraRover 脚本实例
|
||||
cameraRover = Player.GetComponent<CameraRover>();
|
||||
}
|
||||
}
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void OnMouseDown() {
|
||||
cameraRover.WebCallOpenItem("iconCameraBlue_1");
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Ui/LookAt.cs.meta
Normal file
11
Assets/Scripts/Ui/LookAt.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 457ab5f9ce79cc3489ce5e76abaf8cc5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
337
Assets/Scripts/Ui/PnlIcon.cs
Normal file
337
Assets/Scripts/Ui/PnlIcon.cs
Normal file
@@ -0,0 +1,337 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
public class IconDataHolder : MonoBehaviour
|
||||
{
|
||||
public IconData Data;
|
||||
}
|
||||
|
||||
public class PnlIcon : ActionBase
|
||||
{
|
||||
private Dictionary<PageType, List<GameObject>> iconLists = new Dictionary<PageType, List<GameObject>>
|
||||
{
|
||||
{ PageType.Icon01, new List<GameObject>() },
|
||||
{ PageType.Icon02, new List<GameObject>() },
|
||||
{ PageType.Icon03, new List<GameObject>() },
|
||||
{ PageType.Icon04, new List<GameObject>() },
|
||||
{ PageType.Icon05, new List<GameObject>() }
|
||||
};
|
||||
private Dictionary<PageType, List<IconData>> appCacheLists;
|
||||
private void InitializeAppCacheLists()
|
||||
{
|
||||
appCacheLists = new Dictionary<PageType, List<IconData>>
|
||||
{
|
||||
{ PageType.Icon01, AppCache.iconPointList01 },
|
||||
{ PageType.Icon02, AppCache.iconPointList02 },
|
||||
{ PageType.Icon03, AppCache.iconPointList03 },
|
||||
{ PageType.Icon04, AppCache.iconPointList04 },
|
||||
{ PageType.Icon05, AppCache.iconPointList05 }
|
||||
};
|
||||
}
|
||||
|
||||
private Dictionary<PageType, string> textPrefixes = new Dictionary<PageType, string>
|
||||
{
|
||||
{ PageType.Icon01, "gnss监测" },
|
||||
{ PageType.Icon02, "环境监测" },
|
||||
{ PageType.Icon03, "裂缝监测" },
|
||||
{ PageType.Icon04, "加速度振动监测" },
|
||||
{ PageType.Icon05, "应变计监测" }
|
||||
};
|
||||
|
||||
private Dictionary<PageType, string> prefabPaths = new Dictionary<PageType, string>
|
||||
{
|
||||
{ PageType.Icon01, "Icon2D/iconPrefab" },
|
||||
{ PageType.Icon02, "Icon2D/iconPrefab" },
|
||||
{ PageType.Icon03, "Icon2D/iconPrefab" },
|
||||
{ PageType.Icon04, "Icon2D/iconPrefab" },
|
||||
{ PageType.Icon05, "Icon2D/iconPrefab" }
|
||||
};
|
||||
|
||||
private static readonly Dictionary<PageType, string> IconMapping = new Dictionary<PageType, string>
|
||||
{
|
||||
{ PageType.Icon01, "MT013" },
|
||||
{ PageType.Icon02, "MT035" },
|
||||
{ PageType.Icon03, "MT015" },
|
||||
{ PageType.Icon04, "MT025" },
|
||||
{ PageType.Icon05, "MT019" }
|
||||
};
|
||||
private GameObject Player;
|
||||
private CameraRover cameraRover;
|
||||
void Awake()
|
||||
{
|
||||
Player = GameObject.Find("Player");
|
||||
if (Player != null)
|
||||
{
|
||||
// 获取 Player 上挂载的 CameraRover 脚本实例
|
||||
cameraRover = Player.GetComponent<CameraRover>();
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
}
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
public override void RegisterAction()
|
||||
{
|
||||
GameEvent.OpenPage += Open;
|
||||
GameEvent.ClosePage += Close;
|
||||
}
|
||||
|
||||
public override void RemoveAction()
|
||||
{
|
||||
GameEvent.OpenPage -= Open;
|
||||
GameEvent.ClosePage -= Close;
|
||||
}
|
||||
|
||||
void Open(PageType type)
|
||||
{
|
||||
// Debug.Log(type);
|
||||
OpenIcon(type);
|
||||
}
|
||||
|
||||
void Close(PageType type)
|
||||
{
|
||||
CloseIcon(type);
|
||||
}
|
||||
// void OpenIcon(PageType type)
|
||||
// { // 确保 AppCache 列表已初始化
|
||||
// if (!IsAppCacheInitialized())
|
||||
// {
|
||||
// // Debug.LogError("AppCache 列表未初始化!");
|
||||
// return;
|
||||
// }
|
||||
|
||||
// // 确保 appCacheLists 已初始化
|
||||
// if (appCacheLists == null)
|
||||
// {
|
||||
// InitializeAppCacheLists();
|
||||
// }
|
||||
|
||||
// if (!appCacheLists.ContainsKey(type) || appCacheLists[type] == null)
|
||||
// {
|
||||
// // Debug.LogError($"类型 {type} 的列表为空或不存在!");
|
||||
// return;
|
||||
// }
|
||||
|
||||
// List<IconData> iconDataList = appCacheLists[type];
|
||||
// string prefabPath = prefabPaths[type];
|
||||
// string textPrefix = textPrefixes[type];
|
||||
|
||||
// for (int i = 0; i < iconDataList.Count; i++)
|
||||
// {
|
||||
// IconData iconData = iconDataList[i];
|
||||
|
||||
// // 确保数据有效
|
||||
// if (iconData == null || iconData.iconTransform == null)
|
||||
// continue;
|
||||
|
||||
// // 预制体对象
|
||||
// GameObject prefab = Resources.Load<GameObject>(prefabPath);
|
||||
// GameObject icon = PoolManager.Instance.Spawn(prefab);
|
||||
|
||||
// // 使用 iconTransform 的 name 和 position
|
||||
// icon.name = iconData.iconName;
|
||||
// icon.transform.SetParent(transform);
|
||||
// icon.transform.localScale = Vector3.one * 0.8f;
|
||||
// icon.GetComponent<IconFollow2D>().targetPos = iconData.iconTransform.position;
|
||||
|
||||
// Transform txtMsgTransform = FindChildRecursive(icon.transform, "txtMsg");
|
||||
// Text textComponent = txtMsgTransform.GetComponent<Text>();
|
||||
// textComponent.text = icon.name;
|
||||
// iconLists[type].Add(icon);
|
||||
// EventListener.AddPointerClickListener(icon, (clickEventData) => OnIconClick(iconData)); ;
|
||||
// }
|
||||
// }
|
||||
|
||||
void OpenIcon(PageType type)
|
||||
{
|
||||
if (!IsAppCacheInitialized())
|
||||
{
|
||||
// Debug.LogError("AppCache 列表未初始化!");
|
||||
return;
|
||||
}
|
||||
|
||||
// 确保 appCacheLists 已初始化
|
||||
if (appCacheLists == null)
|
||||
{
|
||||
InitializeAppCacheLists();
|
||||
}
|
||||
|
||||
if (!appCacheLists.ContainsKey(type) || appCacheLists[type] == null)
|
||||
{
|
||||
// Debug.LogError($"类型 {type} 的列表为空或不存在!");
|
||||
return;
|
||||
}
|
||||
|
||||
List<IconData> iconDataList = appCacheLists[type];
|
||||
string prefabPath = prefabPaths[type];
|
||||
|
||||
// 1. 提前加载预制体和精灵资源,避免重复加载
|
||||
GameObject prefab = Resources.Load<GameObject>(prefabPath);
|
||||
Sprite iconSprite = Resources.Load<Sprite>($"icons/{IconMapping[type]}");
|
||||
|
||||
// 检查资源是否成功加载
|
||||
if (prefab == null || iconSprite == null)
|
||||
{
|
||||
Debug.LogError($"资源加载失败: Prefab={prefabPath}, Sprite=icons/{IconMapping[type]}");
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. 初始化列表(如果需要)
|
||||
if (iconLists[type] == null)
|
||||
iconLists[type] = new List<GameObject>();
|
||||
|
||||
// 3. 使用协程分帧创建对象,减少单帧压力
|
||||
StartCoroutine(CreateIconsOverTime(type, iconDataList, prefab, iconSprite));
|
||||
}
|
||||
|
||||
IEnumerator CreateIconsOverTime(PageType type, List<IconData> iconDataList, GameObject prefab, Sprite iconSprite)
|
||||
{
|
||||
int batchSize = 5; // 每帧创建的对象数量
|
||||
int framesBetweenBatches = 1; // 创建批次之间的帧数
|
||||
|
||||
for (int i = 0; i < iconDataList.Count; i++)
|
||||
{
|
||||
IconData iconData = iconDataList[i];
|
||||
if (iconData == null || iconData.iconTransform == null)
|
||||
continue;
|
||||
|
||||
// 从对象池生成图标
|
||||
GameObject icon = PoolManager.Instance.Spawn(prefab);
|
||||
SetupIcon(icon, iconData, iconSprite);
|
||||
iconLists[type].Add(icon);
|
||||
|
||||
// 控制创建速率
|
||||
if ((i + 1) % batchSize == 0)
|
||||
{
|
||||
// 每创建batchSize个对象后等待几帧
|
||||
for (int f = 0; f < framesBetweenBatches; f++)
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
|
||||
// 4. 加载完成后强制垃圾回收
|
||||
yield return new WaitForSeconds(0.5f);
|
||||
Resources.UnloadUnusedAssets();
|
||||
System.GC.Collect();
|
||||
}
|
||||
|
||||
void SetupIcon(GameObject icon, IconData iconData, Sprite iconSprite)
|
||||
{
|
||||
// 设置图标基本属性
|
||||
icon.name = iconData.iconName;
|
||||
icon.transform.SetParent(transform);
|
||||
icon.transform.localScale = Vector3.one * 0.8f;
|
||||
icon.GetComponent<IconFollow2D>().targetPos = iconData.iconTransform.position;
|
||||
|
||||
// 获取并设置文本组件
|
||||
Transform txtMsgTransform = FindChildRecursive(icon.transform, "txtMsg");
|
||||
Text textComponent = txtMsgTransform.GetComponent<Text>();
|
||||
textComponent.text = icon.name;
|
||||
|
||||
// 设置图标背景
|
||||
Transform iconBgTransform = FindChildRecursive(icon.transform, "iconBg");
|
||||
Image iconBgImage = iconBgTransform.GetComponent<Image>();
|
||||
iconBgImage.sprite = iconSprite;
|
||||
|
||||
// 添加点击事件
|
||||
EventListener.AddPointerClickListener(icon, (clickEventData) => OnIconClick(iconData));
|
||||
}
|
||||
|
||||
|
||||
private bool IsAppCacheInitialized()
|
||||
{
|
||||
return AppCache.iconPointList01 != null &&
|
||||
AppCache.iconPointList02 != null &&
|
||||
AppCache.iconPointList03 != null &&
|
||||
AppCache.iconPointList04 != null &&
|
||||
AppCache.iconPointList05 != null;
|
||||
}
|
||||
|
||||
void CloseIcon(PageType type)
|
||||
{
|
||||
if (!iconLists.ContainsKey(type))
|
||||
{
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < iconLists[type].Count; i++)
|
||||
{
|
||||
PoolManager.Instance.Unspawn(iconLists[type][i]);
|
||||
}
|
||||
iconLists[type].Clear();
|
||||
}
|
||||
|
||||
private Transform FindChildRecursive(Transform parent, string name)
|
||||
{
|
||||
foreach (Transform child in parent)
|
||||
{
|
||||
if (child.name == name)
|
||||
return child;
|
||||
|
||||
// 递归查找子对象的子对象
|
||||
Transform found = FindChildRecursive(child, name);
|
||||
if (found != null)
|
||||
return found;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void OnIconClick(IconData iconData)
|
||||
{
|
||||
|
||||
if (iconData != null && cameraRover != null)
|
||||
{
|
||||
cameraRover.StartCoroutine(cameraRover.CallOpenItem(iconData.cameraTransform));
|
||||
cameraRover.SetTargetPosition(iconData.iconTransform.position);
|
||||
// Debug.Log($"点击的图标信息:");
|
||||
// Debug.Log($"device_sn: {iconData.device_sn}");
|
||||
// Debug.Log($"iconName: {iconData.iconName}");
|
||||
// Debug.Log($"identifier: {iconData.identifier}");
|
||||
// Debug.Log($"iconTransform: {iconData.iconTransform}");
|
||||
// Debug.Log($"cameraName: {iconData.cameraName}");
|
||||
// Debug.Log($"cameraTransform: {iconData.cameraTransform.position}");
|
||||
|
||||
StartCoroutine(WaitForFlightCompletion(iconData));
|
||||
cameraRover.StartCoroutine(cameraRover.CallOpenItem(iconData.cameraTransform));
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("点击的图标没有关联的 IconData!");
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator WaitForFlightCompletion(IconData iconData)
|
||||
{
|
||||
|
||||
// 等待飞行结束
|
||||
while (!cameraRover.isFlightCompleted)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
// 飞行结束,执行网络请求和数据发送操作
|
||||
string BASE_URL = "/api.php/Device/deviceDetail?device_sn=" + iconData.device_sn + "&identifier=" + iconData.identifier;
|
||||
string url = WebService.IsRunningInWebGL() ? BASE_URL : AppCache.url + BASE_URL;
|
||||
WebService.Instance.Get<JsonDetails>(url, delegate (JsonDetails details)
|
||||
{
|
||||
var dataToSend = new DataToSend
|
||||
{
|
||||
dataItem = details.result,
|
||||
iconName = iconData.iconName
|
||||
};
|
||||
string jsonData = JsonConvert.SerializeObject(dataToSend);
|
||||
// Debug.Log("序列化后的JSON: " + jsonData);
|
||||
Application.ExternalCall("sendDataToVue", jsonData);
|
||||
cameraRover.SetFlightCompleted(false);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
11
Assets/Scripts/Ui/PnlIcon.cs.meta
Normal file
11
Assets/Scripts/Ui/PnlIcon.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b2d4fefc0e1a17941b74b60a5e05e76f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
173
Assets/Scripts/Ui/PnlMain.cs
Normal file
173
Assets/Scripts/Ui/PnlMain.cs
Normal file
@@ -0,0 +1,173 @@
|
||||
using DG.Tweening;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class PnlMain : ActionBase
|
||||
{
|
||||
private const int ButtonCount = 6;
|
||||
private List<Button> buttons = new List<Button>();
|
||||
private GameObject Player;
|
||||
private ControlMove ControlMove;
|
||||
private List<Action> clickActions = new List<Action>();
|
||||
|
||||
// 定义一个结构体来存储动态参数
|
||||
private struct PageActionParams
|
||||
{
|
||||
public List<PageType> closePageTypes; // 存储需要关闭的所有页面类型
|
||||
public List<PageType> openPageType; // 存储需要打开的所有页面类型
|
||||
public PageType actionPageType;
|
||||
public float openDelay;
|
||||
public string buttonName; // 存储按钮名称,避免复杂的条件判断
|
||||
}
|
||||
|
||||
private List<PageActionParams> pageActionParamsList = new List<PageActionParams>
|
||||
{
|
||||
new PageActionParams
|
||||
{
|
||||
closePageTypes = new List<PageType> { PageType.Icon01,PageType.Icon02, PageType.Icon03, PageType.Icon04, PageType.Icon05 },
|
||||
openPageType = new List<PageType> { PageType.Icon01,PageType.Icon02, PageType.Icon03, PageType.Icon04, PageType.Icon05 },
|
||||
actionPageType = PageType.Camera1,
|
||||
openDelay = 1f,
|
||||
buttonName = "all"
|
||||
},
|
||||
new PageActionParams
|
||||
{
|
||||
closePageTypes = new List<PageType> { PageType.Icon01,PageType.Icon02, PageType.Icon03, PageType.Icon04, PageType.Icon05 },
|
||||
openPageType = new List<PageType> { PageType.Icon01 },
|
||||
actionPageType = PageType.Camera1,
|
||||
openDelay = 1f,
|
||||
buttonName = "gnss"
|
||||
},
|
||||
new PageActionParams
|
||||
{
|
||||
closePageTypes = new List<PageType> { PageType.Icon01,PageType.Icon02, PageType.Icon03, PageType.Icon04, PageType.Icon05 },
|
||||
openPageType = new List<PageType> { PageType.Icon02 },
|
||||
actionPageType = PageType.Camera1,
|
||||
openDelay = 1f,
|
||||
buttonName = "环境量监测"
|
||||
},
|
||||
new PageActionParams
|
||||
{
|
||||
closePageTypes = new List<PageType> { PageType.Icon01, PageType.Icon02,PageType.Icon03, PageType.Icon04, PageType.Icon05 },
|
||||
openPageType = new List<PageType> { PageType.Icon03 },
|
||||
actionPageType = PageType.Camera1,
|
||||
openDelay = 1f,
|
||||
buttonName = "测缝针监测"
|
||||
},
|
||||
new PageActionParams
|
||||
{
|
||||
closePageTypes = new List<PageType> { PageType.Icon01, PageType.Icon02, PageType.Icon03,PageType.Icon04, PageType.Icon05 },
|
||||
openPageType = new List<PageType> { PageType.Icon04 },
|
||||
actionPageType = PageType.Camera1,
|
||||
openDelay = 1f,
|
||||
buttonName = "加速度振动监测"
|
||||
},
|
||||
new PageActionParams
|
||||
{
|
||||
closePageTypes = new List<PageType> { PageType.Icon01, PageType.Icon02, PageType.Icon03, PageType.Icon04,PageType.Icon05 },
|
||||
openPageType = new List<PageType> { PageType.Icon05 },
|
||||
actionPageType = PageType.Camera2,
|
||||
openDelay = 1f,
|
||||
buttonName = "应变计监测"
|
||||
}
|
||||
};
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
Player = GameObject.Find("Player");
|
||||
if (Player != null)
|
||||
{
|
||||
// 获取 Player 上挂载的 CameraRover 脚本实例
|
||||
ControlMove = Player.GetComponent<ControlMove>();
|
||||
}
|
||||
for (int i = 1; i <= ButtonCount; i++)
|
||||
{
|
||||
string buttonName = $"btnPage{i}";
|
||||
Button button = transform.Find(buttonName).GetComponent<Button>();
|
||||
buttons.Add(button);
|
||||
|
||||
int index = i - 1;
|
||||
button.onClick.AddListener(() => OnButtonClick(index));
|
||||
}
|
||||
|
||||
for (int i = 0; i < ButtonCount; i++)
|
||||
{
|
||||
int index = i;
|
||||
clickActions.Add(() =>
|
||||
{
|
||||
Debug.Log($"我点击了按钮{pageActionParamsList[index].buttonName}");
|
||||
OnButtonClickCommon(index);
|
||||
});
|
||||
}
|
||||
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
void OnButtonClick(int index)
|
||||
{
|
||||
for (int i = 0; i < buttons.Count; i++)
|
||||
{
|
||||
buttons[i].interactable = i != index;
|
||||
}
|
||||
|
||||
if (index < clickActions.Count)
|
||||
{
|
||||
clickActions[index].Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
void OnButtonClickCommon(int index)
|
||||
{
|
||||
if (index < pageActionParamsList.Count)
|
||||
{
|
||||
var paramsData = pageActionParamsList[index];
|
||||
|
||||
// 关闭所有需要关闭的页面
|
||||
if (paramsData.closePageTypes != null && paramsData.closePageTypes.Count > 0)
|
||||
{
|
||||
foreach (var pageType in paramsData.closePageTypes)
|
||||
{
|
||||
AppCache.ClosePage(pageType);
|
||||
}
|
||||
}
|
||||
|
||||
// 打开所有需要打开的页面
|
||||
if (paramsData.openPageType != null && paramsData.openPageType.Count > 0)
|
||||
{
|
||||
foreach (var pageType in paramsData.openPageType)
|
||||
{
|
||||
AppCache.OpenPageDelay(pageType, paramsData.openDelay);
|
||||
}
|
||||
}
|
||||
|
||||
if (paramsData.actionPageType != default(PageType))
|
||||
{
|
||||
ActionCenter.Instance.DoAction(GameEvent.OpenPage, paramsData.actionPageType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void TriggerButtonClick(string buttonName)
|
||||
{
|
||||
for (int i = 0; i < pageActionParamsList.Count; i++)
|
||||
{
|
||||
if (pageActionParamsList[i].buttonName == buttonName)
|
||||
{
|
||||
OnButtonClick(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void RegisterAction()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void RemoveAction()
|
||||
{
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Ui/PnlMain.cs.meta
Normal file
11
Assets/Scripts/Ui/PnlMain.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 95a397fbdc452114986777f431e4b707
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user