Decompiled source of Custom Palette v1.0.0
DingZhiTiaoSePan.dll
Decompiled a month ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using DM; using DingZhiTiaoSePan.物品添加类; using DingZhiTiaoSePan.编辑器获取组件; using DingZhiTiaoSePan.色彩编辑器ui添加; using Landfall.TABS; using Landfall.TABS.UnitEditor; using Newtonsoft.Json; using TMPro; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.SceneManagement; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("Mod name")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("made in SFT by FhpSlime")] [assembly: AssemblyCopyright("Copyright © 2022")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("3a45c3cf-230c-4310-952f-0887d4266a22")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] public class ui推拽脚本 : MonoBehaviour, IDragHandler, IEventSystemHandler, IBeginDragHandler, IEndDragHandler { [Header("拖拽设置")] [SerializeField] private bool enableDrag = true; [SerializeField] private bool dragOnAnyArea = true; [SerializeField] private RectTransform dragHandle; [Header("边界限制")] [SerializeField] private bool restrictWithinParent = true; [SerializeField] private bool restrictWithinCanvas = true; [SerializeField] private Vector2 padding = Vector2.zero; [Header("动画效果")] [SerializeField] private bool smoothDrag = false; [SerializeField] private float smoothSpeed = 10f; [Header("重置位置设置")] [SerializeField] private bool enableResetAnimation = true; [SerializeField] private float resetAnimationDuration = 0.3f; [SerializeField] private AnimationCurve resetCurve = AnimationCurve.EaseInOut(0f, 0f, 1f, 1f); [SerializeField] private bool snapToNearestEdge = false; [SerializeField] private Vector2[] presetPositions; private RectTransform rectTransform; private Canvas parentCanvas; private Vector2 originalPosition; private Vector2 dragStartPosition; private Vector2 targetPosition; private bool isDragging = false; private Coroutine resetCoroutine; private int currentPresetIndex = -1; private void Start() { //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) rectTransform = ((Component)this).GetComponent<RectTransform>(); parentCanvas = ((Component)this).GetComponentInParent<Canvas>(); if ((Object)(object)dragHandle == (Object)null && !dragOnAnyArea) { dragHandle = rectTransform; } originalPosition = rectTransform.anchoredPosition; targetPosition = originalPosition; } private void Update() { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) if (smoothDrag && isDragging) { rectTransform.anchoredPosition = Vector2.Lerp(rectTransform.anchoredPosition, targetPosition, smoothSpeed * Time.deltaTime); } } public void OnBeginDrag(PointerEventData eventData) { //IL_005b: Unknown result type (might be due to invalid IL or missing references) if (enableDrag && CanDrag(eventData)) { if (resetCoroutine != null) { ((MonoBehaviour)this).StopCoroutine(resetCoroutine); resetCoroutine = null; } isDragging = true; Transform parent = ((Transform)rectTransform).parent; RectTransformUtility.ScreenPointToLocalPointInRectangle((RectTransform)(object)((parent is RectTransform) ? parent : null), eventData.position, eventData.pressEventCamera, ref dragStartPosition); OnDragStart(); } } public void OnDrag(PointerEventData eventData) { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) if (enableDrag && isDragging) { Transform parent = ((Transform)rectTransform).parent; Vector2 val = default(Vector2); RectTransformUtility.ScreenPointToLocalPointInRectangle((RectTransform)(object)((parent is RectTransform) ? parent : null), eventData.position, eventData.pressEventCamera, ref val); Vector2 val2 = val - dragStartPosition; Vector2 position = rectTransform.anchoredPosition + val2; position = ApplyConstraints(position); if (smoothDrag) { targetPosition = position; } else { rectTransform.anchoredPosition = position; } dragStartPosition = val; OnDragging(); } } public void OnEndDrag(PointerEventData eventData) { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) if (enableDrag) { isDragging = false; if (!smoothDrag) { rectTransform.anchoredPosition = ApplyConstraints(rectTransform.anchoredPosition); } OnDragEnd(); } } private bool CanDrag(PointerEventData eventData) { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) if (dragOnAnyArea) { return true; } if ((Object)(object)dragHandle == (Object)null) { return false; } Vector2 val = default(Vector2); RectTransformUtility.ScreenPointToLocalPointInRectangle(dragHandle, eventData.position, eventData.pressEventCamera, ref val); Rect rect = dragHandle.rect; return ((Rect)(ref rect)).Contains(val); } private Vector2 ApplyConstraints(Vector2 position) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0162: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_014c: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) if (!restrictWithinParent && !restrictWithinCanvas) { return position; } Vector2 val = position; Transform parent = ((Transform)rectTransform).parent; RectTransform val2 = (RectTransform)(object)((parent is RectTransform) ? parent : null); if ((Object)(object)val2 == (Object)null) { return position; } Rect rect = rectTransform.rect; Vector2 size = ((Rect)(ref rect)).size; Vector2 val3 = size * rectTransform.pivot; Vector2 val4; Vector2 val5; if (restrictWithinParent) { val4 = -val3 + padding; rect = val2.rect; val5 = ((Rect)(ref rect)).size - val3 - padding; } else { if (!restrictWithinCanvas || !((Object)(object)parentCanvas != (Object)null)) { return position; } Rect rect2 = ((Component)parentCanvas).GetComponent<RectTransform>().rect; val4 = -val3 + padding; val5 = ((Rect)(ref rect2)).size - val3 - padding; } val.x = Mathf.Clamp(val.x, val4.x, val5.x); val.y = Mathf.Clamp(val.y, val4.y, val5.y); return val; } public void ResetPosition(bool useAnimation = true) { //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) if (((Component)this).gameObject.activeInHierarchy) { if (resetCoroutine != null) { ((MonoBehaviour)this).StopCoroutine(resetCoroutine); resetCoroutine = null; } isDragging = false; Vector2 nearestEdgePosition = originalPosition; if (snapToNearestEdge && !useAnimation) { nearestEdgePosition = GetNearestEdgePosition(); } nearestEdgePosition = ApplyConstraints(nearestEdgePosition); if (enableResetAnimation && useAnimation) { resetCoroutine = ((MonoBehaviour)this).StartCoroutine(AnimateReset(nearestEdgePosition)); return; } rectTransform.anchoredPosition = nearestEdgePosition; targetPosition = nearestEdgePosition; OnResetComplete(); } } public void ResetToPresetPosition(int presetIndex, bool useAnimation = true) { //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) if (presetPositions == null || presetIndex < 0 || presetIndex >= presetPositions.Length) { Debug.LogWarning((object)$"预设位置索引 {presetIndex} 无效!"); return; } if (resetCoroutine != null) { ((MonoBehaviour)this).StopCoroutine(resetCoroutine); resetCoroutine = null; } isDragging = false; currentPresetIndex = presetIndex; Vector2 val = ApplyConstraints(presetPositions[presetIndex]); if (enableResetAnimation && useAnimation) { resetCoroutine = ((MonoBehaviour)this).StartCoroutine(AnimateReset(val)); return; } rectTransform.anchoredPosition = val; targetPosition = val; OnResetComplete(); } public void ResetToCenter() { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) Transform parent = ((Transform)rectTransform).parent; RectTransform val = (RectTransform)(object)((parent is RectTransform) ? parent : null); if (!((Object)(object)val != (Object)null)) { return; } Rect rect = val.rect; Vector2 position = ((Rect)(ref rect)).size * 0.5f; position = ApplyConstraints(position); if (enableResetAnimation) { if (resetCoroutine != null) { ((MonoBehaviour)this).StopCoroutine(resetCoroutine); } resetCoroutine = ((MonoBehaviour)this).StartCoroutine(AnimateReset(position)); } else { rectTransform.anchoredPosition = position; targetPosition = position; } } public void SnapToNearestEdge() { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) Vector2 nearestEdgePosition = GetNearestEdgePosition(); nearestEdgePosition = ApplyConstraints(nearestEdgePosition); if (enableResetAnimation) { if (resetCoroutine != null) { ((MonoBehaviour)this).StopCoroutine(resetCoroutine); } resetCoroutine = ((MonoBehaviour)this).StartCoroutine(AnimateReset(nearestEdgePosition)); } else { rectTransform.anchoredPosition = nearestEdgePosition; targetPosition = nearestEdgePosition; } } private Vector2 GetNearestEdgePosition() { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_0229: Unknown result type (might be due to invalid IL or missing references) //IL_0173: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Unknown result type (might be due to invalid IL or missing references) //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_01b5: Unknown result type (might be due to invalid IL or missing references) //IL_01c2: Unknown result type (might be due to invalid IL or missing references) //IL_0223: Unknown result type (might be due to invalid IL or missing references) //IL_0225: Unknown result type (might be due to invalid IL or missing references) //IL_01f3: Unknown result type (might be due to invalid IL or missing references) //IL_01f9: Unknown result type (might be due to invalid IL or missing references) //IL_0205: Unknown result type (might be due to invalid IL or missing references) Transform parent = ((Transform)rectTransform).parent; RectTransform val = (RectTransform)(object)((parent is RectTransform) ? parent : null); if ((Object)(object)val == (Object)null) { return originalPosition; } Vector2 anchoredPosition = rectTransform.anchoredPosition; Rect rect = val.rect; Vector2 size = ((Rect)(ref rect)).size; rect = rectTransform.rect; Vector2 size2 = ((Rect)(ref rect)).size; float num = Mathf.Abs(anchoredPosition.x + size2.x * rectTransform.pivot.x); float num2 = Mathf.Abs(size.x - (anchoredPosition.x + size2.x * rectTransform.pivot.x)); float num3 = Mathf.Abs(size.y - (anchoredPosition.y + size2.y * rectTransform.pivot.y)); float num4 = Mathf.Abs(anchoredPosition.y + size2.y * rectTransform.pivot.y); float num5 = Mathf.Min(new float[4] { num, num2, num3, num4 }); Vector2 result = anchoredPosition; if (Mathf.Approximately(num5, num)) { result.x = (0f - size2.x) * rectTransform.pivot.x + padding.x; } else if (Mathf.Approximately(num5, num2)) { result.x = size.x - size2.x * rectTransform.pivot.x - padding.x; } if (Mathf.Approximately(num5, num4)) { result.y = (0f - size2.y) * rectTransform.pivot.y + padding.y; } else if (Mathf.Approximately(num5, num3)) { result.y = size.y - size2.y * rectTransform.pivot.y - padding.y; } return result; } private IEnumerator AnimateReset(Vector2 targetPos) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) Vector2 startPos = rectTransform.anchoredPosition; float elapsedTime = 0f; while (elapsedTime < resetAnimationDuration) { elapsedTime += Time.deltaTime; float t = elapsedTime / resetAnimationDuration; float curveValue = resetCurve.Evaluate(t); rectTransform.anchoredPosition = Vector2.Lerp(startPos, targetPos, curveValue); targetPosition = rectTransform.anchoredPosition; yield return null; } rectTransform.anchoredPosition = targetPos; targetPosition = targetPos; resetCoroutine = null; OnResetComplete(); } private void OnResetComplete() { //IL_000c: Unknown result type (might be due to invalid IL or missing references) Debug.Log((object)$"UI面板已重置到位置:{rectTransform.anchoredPosition}"); } public void SetAsOriginalPosition() { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) originalPosition = rectTransform.anchoredPosition; Debug.Log((object)$"已设置新的初始位置:{originalPosition}"); } public bool IsAtOriginalPosition() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) return Vector2.Distance(rectTransform.anchoredPosition, originalPosition) < 0.1f; } public Vector2 GetOriginalPosition() { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) return originalPosition; } public void ResetPosition() { ResetPosition(useAnimation: true); } public void SetPosition(Vector2 newPosition) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) if (resetCoroutine != null) { ((MonoBehaviour)this).StopCoroutine(resetCoroutine); resetCoroutine = null; } newPosition = ApplyConstraints(newPosition); rectTransform.anchoredPosition = newPosition; targetPosition = newPosition; } public void SetDragEnabled(bool enabled) { enableDrag = enabled; } protected virtual void OnDragStart() { Debug.Log((object)"开始拖拽"); } protected virtual void OnDragging() { } protected virtual void OnDragEnd() { Debug.Log((object)"结束拖拽"); } } public class ui点击事件 : MonoBehaviour, IPointerClickHandler, IEventSystemHandler, IPointerDownHandler, IPointerUpHandler { [Header("点击事件设置")] [SerializeField] private ClickMode clickMode = ClickMode.SingleClick; [Header("双击设置")] [SerializeField] private float doubleClickTime = 0.3f; [Header("长按设置")] [SerializeField] private float longPressTime = 0.8f; [SerializeField] private bool triggerLongPressOnUp = false; [SerializeField] private bool continuousLongPress = false; [SerializeField] private float continuousInterval = 0.1f; [Header("视觉反馈")] [SerializeField] private bool provideVisualFeedback = true; [SerializeField] private Color normalColor = Color.white; [SerializeField] private Color pressColor = new Color(0.8f, 0.8f, 0.8f, 1f); [SerializeField] private Color longPressColor = new Color(0.5f, 0.5f, 0.5f, 1f); [Header("音效反馈(可选)")] [SerializeField] private AudioClip clickSound; [SerializeField] private AudioClip doubleClickSound; [SerializeField] private AudioClip longPressSound; [SerializeField] private AudioSource audioSource; [Header("事件响应")] public UnityEvent OnSingleClick; public UnityEvent OnDoubleClick; public UnityEvent OnLongPress; public UnityEvent OnLongPressStart; public UnityEvent OnLongPressEnd; private Image cachedImage; private SpriteRenderer cachedSprite; private float clickTimer = 0f; private float pressTimer = 0f; private bool isPointerDown = false; private bool longPressTriggered = false; private Coroutine continuousLongPressCoroutine; private int clickCount = 0; private void Start() { if (provideVisualFeedback) { cachedImage = ((Component)this).GetComponent<Image>(); if ((Object)(object)cachedImage == (Object)null) { cachedSprite = ((Component)this).GetComponent<SpriteRenderer>(); } } if ((Object)(object)audioSource == (Object)null && ((Object)(object)clickSound != (Object)null || (Object)(object)doubleClickSound != (Object)null || (Object)(object)longPressSound != (Object)null)) { audioSource = ((Component)this).GetComponent<AudioSource>(); if ((Object)(object)audioSource == (Object)null) { audioSource = ((Component)this).gameObject.AddComponent<AudioSource>(); } } ResetColor(); } private void Update() { if (clickTimer > 0f) { clickTimer -= Time.deltaTime; if (clickTimer <= 0f) { clickCount = 0; } } if (isPointerDown && !longPressTriggered && clickMode == ClickMode.LongPress) { pressTimer += Time.deltaTime; if (pressTimer >= longPressTime) { TriggerLongPress(); } } } public void OnPointerDown(PointerEventData eventData) { //IL_0035: Unknown result type (might be due to invalid IL or missing references) if (clickMode == ClickMode.LongPress) { isPointerDown = true; pressTimer = 0f; longPressTriggered = false; if (provideVisualFeedback) { SetColor(pressColor); } } } public void OnPointerUp(PointerEventData eventData) { if (clickMode != ClickMode.LongPress) { return; } isPointerDown = false; if (triggerLongPressOnUp && pressTimer >= longPressTime && !longPressTriggered) { TriggerLongPress(); } if (longPressTriggered) { UnityEvent onLongPressEnd = OnLongPressEnd; if (onLongPressEnd != null) { onLongPressEnd.Invoke(); } } longPressTriggered = false; pressTimer = 0f; if (provideVisualFeedback) { ResetColor(); } } public void OnPointerClick(PointerEventData eventData) { switch (clickMode) { case ClickMode.SingleClick: HandleSingleClick(); break; case ClickMode.DoubleClick: HandleDoubleClick(); break; case ClickMode.LongPress: if (!longPressTriggered && pressTimer < longPressTime) { HandleSingleClick(); } break; } } private void HandleSingleClick() { PlaySound(clickSound); ((MonoBehaviour)this).StartCoroutine(ClickFeedback()); UnityEvent onSingleClick = OnSingleClick; if (onSingleClick != null) { onSingleClick.Invoke(); } Debug.Log((object)("[ui点击事件] " + ((Object)((Component)this).gameObject).name + " 被单击")); } private void HandleDoubleClick() { clickCount++; if (clickCount == 1) { clickTimer = doubleClickTime; } else if (clickCount >= 2) { PlaySound(doubleClickSound); ((MonoBehaviour)this).StartCoroutine(DoubleClickFeedback()); UnityEvent onDoubleClick = OnDoubleClick; if (onDoubleClick != null) { onDoubleClick.Invoke(); } Debug.Log((object)("[ui点击事件] " + ((Object)((Component)this).gameObject).name + " 被双击")); clickCount = 0; clickTimer = 0f; } } private void TriggerLongPress() { //IL_0031: Unknown result type (might be due to invalid IL or missing references) if (longPressTriggered) { return; } longPressTriggered = true; PlaySound(longPressSound); if (provideVisualFeedback) { SetColor(longPressColor); } UnityEvent onLongPress = OnLongPress; if (onLongPress != null) { onLongPress.Invoke(); } UnityEvent onLongPressStart = OnLongPressStart; if (onLongPressStart != null) { onLongPressStart.Invoke(); } Debug.Log((object)("[ui点击事件] " + ((Object)((Component)this).gameObject).name + " 被长按")); if (continuousLongPress) { if (continuousLongPressCoroutine != null) { ((MonoBehaviour)this).StopCoroutine(continuousLongPressCoroutine); } continuousLongPressCoroutine = ((MonoBehaviour)this).StartCoroutine(ContinuousLongPress()); } } private IEnumerator ContinuousLongPress() { while (isPointerDown && longPressTriggered) { UnityEvent onLongPress = OnLongPress; if (onLongPress != null) { onLongPress.Invoke(); } yield return (object)new WaitForSeconds(continuousInterval); } continuousLongPressCoroutine = null; } private IEnumerator ClickFeedback() { if (provideVisualFeedback) { Color originalColor = GetCurrentColor(); SetColor(new Color(0.7f, 0.7f, 0.7f, 1f)); yield return (object)new WaitForSeconds(0.1f); SetColor(originalColor); } } private IEnumerator DoubleClickFeedback() { if (provideVisualFeedback) { Color originalColor = GetCurrentColor(); SetColor(new Color(0.5f, 0.8f, 0.5f, 1f)); yield return (object)new WaitForSeconds(0.15f); SetColor(originalColor); } } private void PlaySound(AudioClip clip) { if ((Object)(object)clip != (Object)null && (Object)(object)audioSource != (Object)null) { audioSource.PlayOneShot(clip); } } private void SetColor(Color color) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)cachedImage != (Object)null) { ((Graphic)cachedImage).color = color; } else if ((Object)(object)cachedSprite != (Object)null) { cachedSprite.color = color; } } private void ResetColor() { //IL_0003: Unknown result type (might be due to invalid IL or missing references) SetColor(normalColor); } private Color GetCurrentColor() { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)cachedImage != (Object)null) { return ((Graphic)cachedImage).color; } if ((Object)(object)cachedSprite != (Object)null) { return cachedSprite.color; } return normalColor; } public void SetClickMode(ClickMode mode) { clickMode = mode; ResetState(); } private void ResetState() { isPointerDown = false; longPressTriggered = false; pressTimer = 0f; clickCount = 0; clickTimer = 0f; if (continuousLongPressCoroutine != null) { ((MonoBehaviour)this).StopCoroutine(continuousLongPressCoroutine); continuousLongPressCoroutine = null; } ResetColor(); } public void SetLongPressTime(float time) { longPressTime = Mathf.Max(0.1f, time); } public void SetDoubleClickTime(float time) { doubleClickTime = Mathf.Max(0.1f, time); } } [Serializable] public enum ClickMode { SingleClick, DoubleClick, LongPress } public class 材质展示脚本 : MonoBehaviour { public MeshRenderer 渲染器物体; public TMP_InputField 输入框内容; public Slider 滑块r; public Slider 滑块g; public Slider 滑块b; public Slider 滑块a; public Slider hdr滑块r; public Slider hdr滑块g; public Slider hdr滑块b; public Slider hdr滑块a; public Slider hdr强度滑块; public TMP_Dropdown 渲染模式枚举; public TMP_InputField 主帖图输入; public TMP_InputField 法线贴图输入; public TMP_InputField 金属光泽图输入; public Slider 金属度滑块; public Slider 光滑度滑块; private RenderMode 默认渲染模式枚举 = RenderMode.Opaque; private Material 当前材质; private string 当前着色器名称 = "Standard"; private bool 图片资源已初始化 = false; private void Start() { 初始化图片资源(); 创建或更新材质(); 添加滑块监听器(); if ((Object)(object)输入框内容 != (Object)null) { ((UnityEvent<string>)(object)输入框内容.onEndEdit).AddListener((UnityAction<string>)On着色器名称改变); } if ((Object)(object)渲染模式枚举 != (Object)null) { 初始化渲染模式下拉框(); ((UnityEvent<int>)(object)渲染模式枚举.onValueChanged).AddListener((UnityAction<int>)On渲染模式改变); } 添加贴图输入框监听器(); } private void OnDestroy() { if ((Object)(object)当前材质 != (Object)null && (Object)(object)当前材质 != (Object)(object)((Renderer)渲染器物体).sharedMaterial) { Object.Destroy((Object)(object)当前材质); } } private void 初始化图片资源() { if (!图片资源已初始化) { 图片资源加载类.初始化(); 图片资源已初始化 = true; Debug.Log((object)"[材质展示脚本] 图片资源加载类已初始化"); } } private void 添加贴图输入框监听器() { if ((Object)(object)主帖图输入 != (Object)null) { ((UnityEvent<string>)(object)主帖图输入.onEndEdit).AddListener((UnityAction<string>)On主贴图改变); ((UnityEvent<string>)(object)主帖图输入.onValueChanged).AddListener((UnityAction<string>)On主贴图实时改变); } if ((Object)(object)法线贴图输入 != (Object)null) { ((UnityEvent<string>)(object)法线贴图输入.onEndEdit).AddListener((UnityAction<string>)On法线贴图改变); ((UnityEvent<string>)(object)法线贴图输入.onValueChanged).AddListener((UnityAction<string>)On法线贴图实时改变); } if ((Object)(object)金属光泽图输入 != (Object)null) { ((UnityEvent<string>)(object)金属光泽图输入.onEndEdit).AddListener((UnityAction<string>)On金属光泽贴图改变); ((UnityEvent<string>)(object)金属光泽图输入.onValueChanged).AddListener((UnityAction<string>)On金属光泽贴图实时改变); } } private void On主贴图改变(string 贴图名称) { 应用主贴图(贴图名称); } private void On主贴图实时改变(string 贴图名称) { } private void On法线贴图改变(string 贴图名称) { 应用法线贴图(贴图名称); } private void On法线贴图实时改变(string 贴图名称) { } private void On金属光泽贴图改变(string 贴图名称) { 应用金属光泽贴图(贴图名称); } private void On金属光泽贴图实时改变(string 贴图名称) { } private void 应用主贴图(string 贴图名称) { if ((Object)(object)当前材质 == (Object)null) { Debug.LogWarning((object)"[材质展示脚本] 材质为空,无法设置主贴图"); } else if (string.IsNullOrEmpty(贴图名称)) { 当前材质.mainTexture = null; Debug.Log((object)"[材质展示脚本] 已移除主贴图"); } else if (图片资源加载类.设置材质纹理(当前材质, "_MainTex", 贴图名称)) { Debug.Log((object)("[材质展示脚本] 主贴图设置成功: " + 贴图名称)); } else { Debug.LogWarning((object)("[材质展示脚本] 主贴图设置失败: " + 贴图名称 + ",请检查图片文件是否存在")); } } private void 应用法线贴图(string 贴图名称) { if ((Object)(object)当前材质 == (Object)null) { Debug.LogWarning((object)"[材质展示脚本] 材质为空,无法设置法线贴图"); return; } if (string.IsNullOrEmpty(贴图名称)) { 当前材质.SetTexture("_BumpMap", (Texture)null); 当前材质.DisableKeyword("_NORMALMAP"); Debug.Log((object)"[材质展示脚本] 已移除法线贴图"); return; } Texture2D val = 图片资源加载类.获取纹理(贴图名称); if ((Object)(object)val != (Object)null) { 当前材质.SetTexture("_BumpMap", (Texture)(object)val); 当前材质.EnableKeyword("_NORMALMAP"); Debug.Log((object)("[材质展示脚本] 法线贴图设置成功: " + 贴图名称)); } else { Debug.LogWarning((object)("[材质展示脚本] 法线贴图设置失败: " + 贴图名称 + ",请检查图片文件是否存在")); } } private void 应用金属光泽贴图(string 贴图名称) { if ((Object)(object)当前材质 == (Object)null) { Debug.LogWarning((object)"[材质展示脚本] 材质为空,无法设置金属光泽贴图"); return; } if (string.IsNullOrEmpty(贴图名称)) { 当前材质.SetTexture("_MetallicGlossMap", (Texture)null); 当前材质.DisableKeyword("_METALLICGLOSSMAP"); Debug.Log((object)"[材质展示脚本] 已移除金属光泽贴图"); return; } Texture2D val = 图片资源加载类.获取纹理(贴图名称); if ((Object)(object)val != (Object)null) { 当前材质.SetTexture("_MetallicGlossMap", (Texture)(object)val); 当前材质.EnableKeyword("_METALLICGLOSSMAP"); Debug.Log((object)("[材质展示脚本] 金属光泽贴图设置成功: " + 贴图名称)); } else { Debug.LogWarning((object)("[材质展示脚本] 金属光泽贴图设置失败: " + 贴图名称 + ",请检查图片文件是否存在")); } } private void 初始化渲染模式下拉框() { if ((Object)(object)渲染模式枚举 == (Object)null) { return; } 渲染模式枚举.ClearOptions(); List<string> list = new List<string>(); foreach (RenderMode value in Enum.GetValues(typeof(RenderMode))) { string text = ""; list.Add(value switch { RenderMode.Opaque => "不透明 (Opaque)", RenderMode.Transparent => "透明 (Transparent)", RenderMode.Cutout => "镂空 (Cutout)", RenderMode.Fade => "淡入淡出 (Fade)", RenderMode.Additive => "叠加发光 (Additive)", _ => value.ToString(), }); } 渲染模式枚举.AddOptions(list); 渲染模式枚举.value = (int)默认渲染模式枚举; 渲染模式枚举.RefreshShownValue(); } private void On渲染模式改变(int 选中索引) { if (!((Object)(object)当前材质 == (Object)null)) { 应用渲染模式((RenderMode)选中索引); } } private void 应用渲染模式(RenderMode 模式) { if (!((Object)(object)当前材质 == (Object)null)) { switch (模式) { case RenderMode.Opaque: 当前材质.SetFloat("_Mode", 0f); 当前材质.SetInt("_SrcBlend", 1); 当前材质.SetInt("_DstBlend", 0); 当前材质.SetInt("_ZWrite", 1); 当前材质.DisableKeyword("_ALPHATEST_ON"); 当前材质.DisableKeyword("_ALPHABLEND_ON"); 当前材质.DisableKeyword("_ALPHAPREMULTIPLY_ON"); 当前材质.renderQueue = -1; break; case RenderMode.Transparent: 当前材质.SetFloat("_Mode", 3f); 当前材质.SetInt("_SrcBlend", 1); 当前材质.SetInt("_DstBlend", 10); 当前材质.SetInt("_ZWrite", 0); 当前材质.DisableKeyword("_ALPHATEST_ON"); 当前材质.DisableKeyword("_ALPHABLEND_ON"); 当前材质.EnableKeyword("_ALPHAPREMULTIPLY_ON"); 当前材质.renderQueue = 3000; break; case RenderMode.Cutout: 当前材质.SetFloat("_Mode", 1f); 当前材质.SetInt("_SrcBlend", 1); 当前材质.SetInt("_DstBlend", 0); 当前材质.SetInt("_ZWrite", 1); 当前材质.EnableKeyword("_ALPHATEST_ON"); 当前材质.DisableKeyword("_ALPHABLEND_ON"); 当前材质.DisableKeyword("_ALPHAPREMULTIPLY_ON"); 当前材质.renderQueue = 2450; break; case RenderMode.Fade: 当前材质.SetFloat("_Mode", 2f); 当前材质.SetInt("_SrcBlend", 5); 当前材质.SetInt("_DstBlend", 10); 当前材质.SetInt("_ZWrite", 0); 当前材质.DisableKeyword("_ALPHATEST_ON"); 当前材质.EnableKeyword("_ALPHABLEND_ON"); 当前材质.DisableKeyword("_ALPHAPREMULTIPLY_ON"); 当前材质.renderQueue = 3000; break; case RenderMode.Additive: 当前材质.SetFloat("_Mode", 4f); 当前材质.SetInt("_SrcBlend", 1); 当前材质.SetInt("_DstBlend", 1); 当前材质.SetInt("_ZWrite", 0); 当前材质.DisableKeyword("_ALPHATEST_ON"); 当前材质.EnableKeyword("_ALPHABLEND_ON"); 当前材质.DisableKeyword("_ALPHAPREMULTIPLY_ON"); 当前材质.renderQueue = 3000; break; } 当前材质.SetOverrideTag("RenderType", 获取渲染类型标签(模式)); } } private string 获取渲染类型标签(RenderMode 模式) { return 模式 switch { RenderMode.Opaque => "Opaque", RenderMode.Transparent => "Transparent", RenderMode.Cutout => "TransparentCutout", RenderMode.Fade => "Transparent", RenderMode.Additive => "Transparent", _ => "Opaque", }; } public void 更新材质() { 创建或更新材质(); 应用所有材质参数(); 应用所有贴图(); 应用金属度和光滑度(); if ((Object)(object)渲染模式枚举 != (Object)null && (Object)(object)当前材质 != (Object)null) { 应用渲染模式((RenderMode)渲染模式枚举.value); } } private void 应用所有贴图() { if ((Object)(object)主帖图输入 != (Object)null && !string.IsNullOrEmpty(主帖图输入.text)) { 应用主贴图(主帖图输入.text); } if ((Object)(object)法线贴图输入 != (Object)null && !string.IsNullOrEmpty(法线贴图输入.text)) { 应用法线贴图(法线贴图输入.text); } if ((Object)(object)金属光泽图输入 != (Object)null && !string.IsNullOrEmpty(金属光泽图输入.text)) { 应用金属光泽贴图(金属光泽图输入.text); } } private void 创建或更新材质() { //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Expected O, but got Unknown if ((Object)(object)渲染器物体 == (Object)null) { return; } TMP_InputField obj = 输入框内容; string text = (string.IsNullOrEmpty((obj != null) ? obj.text : null) ? "Standard" : 输入框内容.text); Shader val = Shader.Find(text); if ((Object)(object)val == (Object)null) { Debug.LogWarning((object)("找不到着色器: " + text + ",使用Standard替代")); val = Shader.Find("Standard"); } if ((Object)(object)当前材质 == (Object)null || 当前着色器名称 != text) { if ((Object)(object)当前材质 != (Object)null && (Object)(object)当前材质 != (Object)(object)((Renderer)渲染器物体).sharedMaterial) { Object.Destroy((Object)(object)当前材质); } 当前材质 = new Material(val); ((Renderer)渲染器物体).material = 当前材质; 当前着色器名称 = text; if ((Object)(object)金属度滑块 != (Object)null) { 应用金属度(); } if ((Object)(object)光滑度滑块 != (Object)null) { 应用光滑度(); } } } private void 添加滑块监听器() { Slider obj = 滑块r; if (obj != null) { ((UnityEvent<float>)(object)obj.onValueChanged).AddListener((UnityAction<float>)delegate { 应用主颜色(); }); } Slider obj2 = 滑块g; if (obj2 != null) { ((UnityEvent<float>)(object)obj2.onValueChanged).AddListener((UnityAction<float>)delegate { 应用主颜色(); }); } Slider obj3 = 滑块b; if (obj3 != null) { ((UnityEvent<float>)(object)obj3.onValueChanged).AddListener((UnityAction<float>)delegate { 应用主颜色(); }); } Slider obj4 = 滑块a; if (obj4 != null) { ((UnityEvent<float>)(object)obj4.onValueChanged).AddListener((UnityAction<float>)delegate { 应用主颜色(); }); } Slider obj5 = hdr滑块r; if (obj5 != null) { ((UnityEvent<float>)(object)obj5.onValueChanged).AddListener((UnityAction<float>)delegate { 应用HDR颜色(); }); } Slider obj6 = hdr滑块g; if (obj6 != null) { ((UnityEvent<float>)(object)obj6.onValueChanged).AddListener((UnityAction<float>)delegate { 应用HDR颜色(); }); } Slider obj7 = hdr滑块b; if (obj7 != null) { ((UnityEvent<float>)(object)obj7.onValueChanged).AddListener((UnityAction<float>)delegate { 应用HDR颜色(); }); } Slider obj8 = hdr滑块a; if (obj8 != null) { ((UnityEvent<float>)(object)obj8.onValueChanged).AddListener((UnityAction<float>)delegate { 应用HDR颜色(); }); } Slider obj9 = hdr强度滑块; if (obj9 != null) { ((UnityEvent<float>)(object)obj9.onValueChanged).AddListener((UnityAction<float>)delegate { 应用HDR颜色(); }); } Slider obj10 = 金属度滑块; if (obj10 != null) { ((UnityEvent<float>)(object)obj10.onValueChanged).AddListener((UnityAction<float>)delegate { 应用金属度(); }); } Slider obj11 = 光滑度滑块; if (obj11 != null) { ((UnityEvent<float>)(object)obj11.onValueChanged).AddListener((UnityAction<float>)delegate { 应用光滑度(); }); } } private void 应用所有材质参数() { if (!((Object)(object)当前材质 == (Object)null)) { 应用主颜色(); 应用HDR颜色(); 应用金属度和光滑度(); } } private void 应用金属度和光滑度() { if (!((Object)(object)当前材质 == (Object)null)) { 应用金属度(); 应用光滑度(); } } private void 应用金属度() { if (!((Object)(object)当前材质 == (Object)null)) { Slider obj = 金属度滑块; float num = ((obj != null) ? obj.value : 0f); 当前材质.SetFloat("_Metallic", num); Debug.Log((object)$"[材质展示脚本] 金属度设置为: {num}"); } } private void 应用光滑度() { if (!((Object)(object)当前材质 == (Object)null)) { Slider obj = 光滑度滑块; float num = ((obj != null) ? obj.value : 0.5f); 当前材质.SetFloat("_Glossiness", num); Debug.Log((object)$"[材质展示脚本] 光滑度设置为: {num}"); } } private void 应用主颜色() { //IL_0087: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)当前材质 == (Object)null)) { Slider obj = 滑块r; float num = ((obj != null) ? obj.value : 1f); Slider obj2 = 滑块g; float num2 = ((obj2 != null) ? obj2.value : 1f); Slider obj3 = 滑块b; float num3 = ((obj3 != null) ? obj3.value : 1f); Slider obj4 = 滑块a; float num4 = ((obj4 != null) ? obj4.value : 1f); Color val = default(Color); ((Color)(ref val))..ctor(num, num2, num3, num4); 当前材质.SetColor("_Color", val); } } private void 应用HDR颜色() { //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)当前材质 == (Object)null)) { Slider obj = hdr滑块r; float num = ((obj != null) ? obj.value : 0f); Slider obj2 = hdr滑块g; float num2 = ((obj2 != null) ? obj2.value : 0f); Slider obj3 = hdr滑块b; float num3 = ((obj3 != null) ? obj3.value : 0f); Slider obj4 = hdr滑块a; float num4 = ((obj4 != null) ? obj4.value : 1f); Slider obj5 = hdr强度滑块; float num5 = ((obj5 != null) ? obj5.value : 1f); Color val = new Color(num, num2, num3, num4) * num5; 当前材质.SetColor("_EmissionColor", val); 当前材质.EnableKeyword("_EMISSION"); 当前材质.globalIlluminationFlags = (MaterialGlobalIlluminationFlags)1; } } private void On着色器名称改变(string 新名称) { 更新材质(); } public Material 获取当前材质() { return 当前材质; } public void 设置金属度(float 金属度值) { if ((Object)(object)当前材质 != (Object)null) { 当前材质.SetFloat("_Metallic", 金属度值); if ((Object)(object)金属度滑块 != (Object)null) { 金属度滑块.value = 金属度值; } } } public void 设置光滑度(float 光滑度值) { if ((Object)(object)当前材质 != (Object)null) { 当前材质.SetFloat("_Glossiness", 光滑度值); if ((Object)(object)光滑度滑块 != (Object)null) { 光滑度滑块.value = 光滑度值; } } } public void 重置所有参数() { if ((Object)(object)滑块r != (Object)null) { 滑块r.value = 1f; } if ((Object)(object)滑块g != (Object)null) { 滑块g.value = 1f; } if ((Object)(object)滑块b != (Object)null) { 滑块b.value = 1f; } if ((Object)(object)滑块a != (Object)null) { 滑块a.value = 1f; } if ((Object)(object)hdr滑块r != (Object)null) { hdr滑块r.value = 0f; } if ((Object)(object)hdr滑块g != (Object)null) { hdr滑块g.value = 0f; } if ((Object)(object)hdr滑块b != (Object)null) { hdr滑块b.value = 0f; } if ((Object)(object)hdr滑块a != (Object)null) { hdr滑块a.value = 1f; } if ((Object)(object)hdr强度滑块 != (Object)null) { hdr强度滑块.value = 1f; } if ((Object)(object)金属度滑块 != (Object)null) { 金属度滑块.value = 0f; } if ((Object)(object)光滑度滑块 != (Object)null) { 光滑度滑块.value = 0.5f; } if ((Object)(object)渲染模式枚举 != (Object)null) { 渲染模式枚举.value = (int)默认渲染模式枚举; } if ((Object)(object)主帖图输入 != (Object)null) { 主帖图输入.text = ""; } if ((Object)(object)法线贴图输入 != (Object)null) { 法线贴图输入.text = ""; } if ((Object)(object)金属光泽图输入 != (Object)null) { 金属光泽图输入.text = ""; } 应用所有材质参数(); 应用所有贴图(); } public void 设置渲染模式(RenderMode 模式) { if ((Object)(object)渲染模式枚举 != (Object)null) { 渲染模式枚举.value = (int)模式; } 应用渲染模式(模式); } public RenderMode 获取当前渲染模式() { if ((Object)(object)渲染模式枚举 != (Object)null) { return (RenderMode)渲染模式枚举.value; } return RenderMode.Opaque; } } public class 滑块更新双向同步脚本 : MonoBehaviour { [Header("组件引用")] [SerializeField] private Slider targetSlider; [SerializeField] private TMP_InputField targetInput; [Header("数值设置")] [SerializeField] private bool useIntegerMode = false; [SerializeField] private int decimalPlaces = 2; [SerializeField] private bool showPercentage = false; [Header("同步设置")] [SerializeField] private bool syncOnStart = true; [SerializeField] private bool syncFromSlider = true; [SerializeField] private bool syncFromInput = true; [Header("数值限制")] [SerializeField] private bool clampInputValue = true; [SerializeField] private float minValue = 0f; [SerializeField] private float maxValue = 100f; private bool isUpdating = false; private void Start() { ValidateComponents(); if ((Object)(object)targetSlider != (Object)null) { minValue = targetSlider.minValue; maxValue = targetSlider.maxValue; if (syncFromSlider) { ((UnityEvent<float>)(object)targetSlider.onValueChanged).AddListener((UnityAction<float>)OnSliderValueChanged); } } if ((Object)(object)targetInput != (Object)null && syncFromInput) { ((UnityEvent<string>)(object)targetInput.onValueChanged).AddListener((UnityAction<string>)OnInputValueChanged); ((UnityEvent<string>)(object)targetInput.onEndEdit).AddListener((UnityAction<string>)OnInputEndEdit); } if (syncOnStart && (Object)(object)targetSlider != (Object)null && (Object)(object)targetInput != (Object)null) { UpdateInputFromSlider(targetSlider.value); } } private void ValidateComponents() { if ((Object)(object)targetSlider == (Object)null) { targetSlider = ((Component)this).GetComponentInParent<Slider>(); if ((Object)(object)targetSlider == (Object)null) { targetSlider = ((Component)this).GetComponent<Slider>(); if ((Object)(object)targetSlider == (Object)null) { Debug.LogWarning((object)("[SliderInputBinder] 在物体 " + ((Object)((Component)this).gameObject).name + " 上未找到Slider组件,请手动指定!")); } } } if (!((Object)(object)targetInput == (Object)null)) { return; } targetInput = ((Component)this).GetComponentInChildren<TMP_InputField>(); if ((Object)(object)targetInput == (Object)null) { targetInput = ((Component)this).GetComponent<TMP_InputField>(); if ((Object)(object)targetInput == (Object)null) { Debug.LogWarning((object)("[SliderInputBinder] 在物体 " + ((Object)((Component)this).gameObject).name + " 上未找到InputField组件,请手动指定!")); } } } private void OnSliderValueChanged(float value) { if (syncFromInput && !isUpdating) { isUpdating = true; UpdateInputFromSlider(value); isUpdating = false; } } private void OnInputValueChanged(string text) { if (syncFromSlider && !isUpdating) { } } private void OnInputEndEdit(string text) { if (syncFromSlider && !isUpdating) { isUpdating = true; UpdateSliderFromInput(text); isUpdating = false; } } private void UpdateInputFromSlider(float sliderValue) { if (!((Object)(object)targetInput == (Object)null)) { string text; if (!showPercentage) { text = ((!useIntegerMode) ? sliderValue.ToString($"F{decimalPlaces}") : Mathf.RoundToInt(sliderValue).ToString()); } else { float num = sliderValue * 100f; text = ((!useIntegerMode) ? (num.ToString($"F{decimalPlaces}") + "%") : $"{Mathf.RoundToInt(num)}%"); } if (targetInput.text != text) { targetInput.SetTextWithoutNotify(text); } } } private void UpdateSliderFromInput(string inputText) { if ((Object)(object)targetSlider == (Object)null) { return; } bool flag = false; float num; float result3; if (showPercentage && inputText.Contains("%")) { string s = inputText.Replace("%", "").Trim(); if (float.TryParse(s, out var result)) { num = result / 100f; flag = true; if (targetSlider.minValue != 0f || targetSlider.maxValue != 1f) { num = MapValue(result / 100f, 0f, 1f, targetSlider.minValue, targetSlider.maxValue); } } else { flag = false; num = targetSlider.value; } } else if (useIntegerMode) { if (int.TryParse(inputText, out var result2)) { num = result2; flag = true; } else { flag = false; num = targetSlider.value; } } else if (float.TryParse(inputText, out result3)) { num = result3; flag = true; } else { flag = false; num = targetSlider.value; } if (!flag) { UpdateInputFromSlider(targetSlider.value); Debug.LogWarning((object)("[SliderInputBinder] 无法解析输入值: " + inputText)); return; } if (clampInputValue) { num = Mathf.Clamp(num, targetSlider.minValue, targetSlider.maxValue); } if (Mathf.Abs(targetSlider.value - num) > 0.001f) { targetSlider.value = num; } UpdateInputFromSlider(num); } private float MapValue(float value, float fromMin, float fromMax, float toMin, float toMax) { return toMin + (value - fromMin) * (toMax - toMin) / (fromMax - fromMin); } public void SyncFromSlider() { if ((Object)(object)targetSlider != (Object)null) { UpdateInputFromSlider(targetSlider.value); } } public void SyncFromInput() { if ((Object)(object)targetInput != (Object)null) { UpdateSliderFromInput(targetInput.text); } } public void SetValue(float newValue) { if (!((Object)(object)targetSlider == (Object)null) && !((Object)(object)targetInput == (Object)null)) { isUpdating = true; newValue = Mathf.Clamp(newValue, targetSlider.minValue, targetSlider.maxValue); targetSlider.value = newValue; UpdateInputFromSlider(newValue); isUpdating = false; } } public float GetValue() { return ((Object)(object)targetSlider != (Object)null) ? targetSlider.value : 0f; } public int GetIntValue() { return Mathf.RoundToInt(GetValue()); } public void SetDecimalPlaces(int places) { decimalPlaces = Mathf.Clamp(places, 0, 6); SyncFromSlider(); } public void SetIntegerMode(bool integerMode) { useIntegerMode = integerMode; SyncFromSlider(); } private void OnDestroy() { if ((Object)(object)targetSlider != (Object)null && syncFromSlider) { ((UnityEvent<float>)(object)targetSlider.onValueChanged).RemoveListener((UnityAction<float>)OnSliderValueChanged); } if ((Object)(object)targetInput != (Object)null && syncFromInput) { ((UnityEvent<string>)(object)targetInput.onValueChanged).RemoveListener((UnityAction<string>)OnInputValueChanged); ((UnityEvent<string>)(object)targetInput.onEndEdit).RemoveListener((UnityAction<string>)OnInputEndEdit); } } } public class 物体切换状态w : MonoBehaviour { [Header("目标物体设置")] public Transform 指定物体; public bool 初始状态 = true; [Header("切换效果")] public bool 使用动画效果 = false; public float 动画时长 = 0.3f; public AnimationCurve 动画曲线 = AnimationCurve.EaseInOut(0f, 0f, 1f, 1f); [Header("其他设置")] public bool 切换按钮自身 = false; public bool 自动记录状态 = true; public string 状态存储键 = "UI状态"; [Header("可选:按钮图片变化")] public Image 按钮图片; public Sprite 展开状态图片; public Sprite 关闭状态图片; private RectTransform 目标RectTransform; private Vector2 原始大小; private bool 当前状态; private Coroutine 动画协程; private Vector3 原始位置; private void Start() { //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) GameObject val = (切换按钮自身 ? ((Component)this).gameObject : (((Object)(object)指定物体 != (Object)null) ? ((Component)指定物体).gameObject : null)); if ((Object)(object)val != (Object)null) { 目标RectTransform = val.GetComponent<RectTransform>(); 原始大小 = (((Object)(object)目标RectTransform != (Object)null) ? 目标RectTransform.sizeDelta : Vector2.zero); 原始位置 = ((Transform)目标RectTransform).localPosition; } if (自动记录状态 && PlayerPrefs.HasKey(状态存储键)) { 当前状态 = PlayerPrefs.GetInt(状态存储键) == 1; } else { 当前状态 = 初始状态; } SetUIState(当前状态, useAnimation: false); UpdateButtonImage(); } public void 切换物体状态() { 当前状态 = !当前状态; SetUIState(当前状态, 使用动画效果); if (自动记录状态) { PlayerPrefs.SetInt(状态存储键, 当前状态 ? 1 : 0); PlayerPrefs.Save(); } UpdateButtonImage(); Debug.Log((object)("UI状态切换为:" + (当前状态 ? "展开" : "关闭"))); } private void SetUIState(bool isOpen, bool useAnimation) { GameObject val = (切换按钮自身 ? ((Component)this).gameObject : (((Object)(object)指定物体 != (Object)null) ? ((Component)指定物体).gameObject : null)); if ((Object)(object)val == (Object)null) { Debug.LogWarning((object)"没有指定要切换的物体!"); return; } if (动画协程 != null) { ((MonoBehaviour)this).StopCoroutine(动画协程); 动画协程 = null; } if (useAnimation && (Object)(object)目标RectTransform != (Object)null) { 动画协程 = ((MonoBehaviour)this).StartCoroutine(动画切换(val, isOpen)); } else { val.SetActive(isOpen); } } private IEnumerator 动画切换(GameObject 目标物体, bool 最终状态) { if (最终状态 && !目标物体.activeSelf) { 目标物体.SetActive(true); if ((Object)(object)目标RectTransform != (Object)null) { ((Transform)目标RectTransform).localScale = new Vector3(1f, 0f, 1f); } } float 当前时间 = 0f; Vector3 起始缩放 = (((Object)(object)目标RectTransform != (Object)null) ? ((Transform)目标RectTransform).localScale : Vector3.one); Vector3 目标缩放 = (最终状态 ? new Vector3(1f, 1f, 1f) : new Vector3(1f, 0f, 1f)); if (!最终状态) { 起始缩放 = (((Object)(object)目标RectTransform != (Object)null) ? ((Transform)目标RectTransform).localScale : Vector3.one); } while (当前时间 < 动画时长) { 当前时间 += Time.deltaTime; float t = 当前时间 / 动画时长; float 曲线值 = 动画曲线.Evaluate(t); if ((Object)(object)目标RectTransform != (Object)null) { ((Transform)目标RectTransform).localScale = Vector3.Lerp(起始缩放, 目标缩放, 曲线值); } yield return null; } if ((Object)(object)目标RectTransform != (Object)null) { ((Transform)目标RectTransform).localScale = 目标缩放; } if (!最终状态) { 目标物体.SetActive(false); } 动画协程 = null; } private void UpdateButtonImage() { if ((Object)(object)按钮图片 != (Object)null) { if (当前状态 && (Object)(object)展开状态图片 != (Object)null) { 按钮图片.sprite = 展开状态图片; } else if (!当前状态 && (Object)(object)关闭状态图片 != (Object)null) { 按钮图片.sprite = 关闭状态图片; } } } public void 展开UI() { if (!当前状态) { 切换物体状态(); } } public void 关闭UI() { if (当前状态) { 切换物体状态(); } } public bool 获取当前状态() { return 当前状态; } public void 重置状态() { //IL_0008: Unknown result type (might be due to invalid IL or missing references) ((Transform)目标RectTransform).localPosition = 原始位置; 当前状态 = 初始状态; SetUIState(当前状态, useAnimation: false); UpdateButtonImage(); if (自动记录状态) { PlayerPrefs.SetInt(状态存储键, 当前状态 ? 1 : 0); PlayerPrefs.Save(); } } } public class 自定义数据ui数据接收类 : MonoBehaviour { public class 自定义数据数据类 { public enum 数据类型 { 浮点值, Color, Vector3, Texture } public string 自定义数据名称; public 数据类型 接收数据类型; public float 浮点数据值; public string 纹理名称数据值; } public TMP_InputField 自定义数据名称输入框; public TMP_InputField 浮点数输入框; public TMP_InputField 纹理名称输入框; public TMP_Dropdown 数据类型枚举; private void Start() { } public 自定义数据数据类 获取自定义数据() { if ((Object)(object)自定义数据名称输入框 != (Object)null && (Object)(object)浮点数输入框 != (Object)null && (Object)(object)纹理名称输入框 != (Object)null && (Object)(object)数据类型枚举 != (Object)null) { float 浮点数据值 = 0f; if (float.TryParse(浮点数输入框.text, out var result)) { 浮点数据值 = result; } else { Debug.LogWarning((object)("转换失败:'" + 浮点数输入框.text + "' 不是有效的数字")); } return new 自定义数据数据类 { 自定义数据名称 = 自定义数据名称输入框.text, 接收数据类型 = (自定义数据数据类.数据类型)数据类型枚举.value, 浮点数据值 = 浮点数据值, 纹理名称数据值 = 纹理名称输入框.text }; } return null; } private void Update() { } } public class 限制写入浮点数 : MonoBehaviour { public TMP_InputField inputField; [Header("限制设置")] public int maxDecimalPlaces = 2; public float minValue = -9999f; public float maxValue = 9999f; private void Start() { if ((Object)(object)inputField == (Object)null) { inputField = ((Component)this).GetComponent<TMP_InputField>(); } ((UnityEvent<string>)(object)inputField.onEndEdit).AddListener((UnityAction<string>)OnEndEdit); } private void OnEndEdit(string inputText) { if (!TryParseFloat(inputText, out var result)) { inputField.text = "0"; Debug.LogWarning((object)"输入无效,已重置为0"); return; } result = Mathf.Clamp(result, minValue, maxValue); string text = result.ToString(CultureInfo.InvariantCulture); if (maxDecimalPlaces >= 0) { text = result.ToString($"F{maxDecimalPlaces}", CultureInfo.InvariantCulture); } if (inputField.text != text) { inputField.SetTextWithoutNotify(text); } } private bool TryParseFloat(string s, out float result) { string s2 = s.Replace(',', '.'); return float.TryParse(s2, NumberStyles.Float, CultureInfo.InvariantCulture, out result); } public float GetFloatValue() { if (TryParseFloat(inputField.text, out var result)) { return Mathf.Clamp(result, minValue, maxValue); } return 0f; } } public class 颜色rgb对应脚本 : MonoBehaviour { public Slider 滑块r; public Slider 滑块g; public Slider 滑块b; public Slider 滑块a; public Image 图片; private void Start() { } private void Update() { //IL_007f: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)图片 != (Object)null && (Object)(object)滑块r != (Object)null && (Object)(object)滑块g != (Object)null && (Object)(object)滑块b != (Object)null && (Object)(object)滑块a != (Object)null) { ((Graphic)图片).color = new Color(滑块r.value, 滑块g.value, 滑块b.value, 滑块a.value); } } } namespace youMod_Name.物品添加类 { public static class 便携添加工具 { public enum 对象类 { 单位模型, 武器, 技能, 服饰, 抛射物 } public static int MYmodid = 228472303; public static int MYmodunitid = 62847203; public static GameObject 注册创建游戏对象自动id分配(GameObject 对象, 对象类 类型 = 对象类.技能) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_0126: Unknown result type (might be due to invalid IL or missing references) switch (类型) { case 对象类.技能: { GameObject result5 = 游戏内容工具.注册能力(懒得发字典添加物品类.Instance.创建物品(((Object)对象).name, 对象, new DatabaseID(-3, MYmodid))); MYmodid++; return result5; } case 对象类.服饰: { GameObject result4 = 游戏内容工具.注册道具(懒得发字典添加物品类.Instance.创建物品(((Object)对象).name, 对象, new DatabaseID(-3, MYmodid))); MYmodid++; return result4; } case 对象类.抛射物: { GameObject result3 = 游戏内容工具.注册投射物(懒得发字典添加物品类.Instance.创建物品(((Object)对象).name, 对象, new DatabaseID(-3, MYmodid))); MYmodid++; return result3; } case 对象类.单位模型: { GameObject result2 = 游戏内容工具.注册单位Base(懒得发字典添加物品类.Instance.创建物品(((Object)对象).name, 对象, new DatabaseID(-3, MYmodid))); MYmodid++; return result2; } case 对象类.武器: { GameObject result = 游戏内容工具.注册武器(懒得发字典添加物品类.Instance.创建物品(((Object)对象).name, 对象, new DatabaseID(-3, MYmodid))); MYmodid++; return result; } default: return null; } } public static void 添加单位到指定派系(UnitBlueprint[] 指定的所有单位, Faction 指定派系, bool 自动排序 = false, bool 去重 = false) { if (指定的所有单位 == null || 指定的所有单位.Length == 0) { return; } List<UnitBlueprint> list = new List<UnitBlueprint>(); if (指定派系.Units != null) { list.AddRange(指定派系.Units); } list.AddRange(指定的所有单位); if (去重) { list = (from unit in list where ((unit != null) ? unit.Entity : null) != null group unit by unit.Entity.GUID into @group select @group.First()).ToList(); } if (自动排序) { list.Sort((UnitBlueprint unit1, UnitBlueprint unit2) => unit1.GetUnitCost(true).CompareTo(unit2.GetUnitCost(true))); } 指定派系.Units = list.ToArray(); } public static void 添加单位到指定派系(UnitBlueprint 指定单位, Faction 指定派系, bool 自动排序 = false, bool 去重 = false) { if (!((Object)(object)指定单位 == (Object)null)) { 添加单位到指定派系((UnitBlueprint[])(object)new UnitBlueprint[1] { 指定单位 }, 指定派系, 自动排序, 去重); } } public static void 设置单位蓝图声音(UnitBlueprint 此单位, string 单位声音, string 单位阵亡声音, float 音调, string 单位脚步声音) { 此单位.SetUnitSounds(单位声音, 单位阵亡声音, 音调, 单位脚步声音); } public static void 设置单位蓝图骑手(UnitBlueprint 此单位, UnitBlueprint[] 骑手组) { 此单位.SetRiders(骑手组); } } public static class UnitBlueprintExtensions { public static bool SetField(this UnitBlueprint blueprint, string fieldName, object value) { if ((Object)(object)blueprint == (Object)null) { Debug.LogError((object)"[SetField] 兵种蓝图为空"); return false; } FieldInfo field = typeof(UnitBlueprint).GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field == null) { PropertyInfo property = typeof(UnitBlueprint).GetProperty(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (property != null && property.CanWrite) { try { if (value != null && !property.PropertyType.IsAssignableFrom(value.GetType())) { value = Convert.ChangeType(value, property.PropertyType); } property.SetValue(blueprint, value); return true; } catch (Exception ex) { Debug.LogError((object)("[SetField] 设置属性 '" + fieldName + "' 失败: " + ex.Message)); return false; } } Debug.LogError((object)("[SetField] 字段/属性 '" + fieldName + "' 不存在")); return false; } try { if (value != null && !field.FieldType.IsAssignableFrom(value.GetType())) { value = Convert.ChangeType(value, field.FieldType); } field.SetValue(blueprint, value); return true; } catch (Exception ex2) { Debug.LogError((object)("[SetField] 设置字段 '" + fieldName + "' 失败: " + ex2.Message)); return false; } } public static T GetField<T>(this UnitBlueprint blueprint, string fieldName) { if ((Object)(object)blueprint == (Object)null) { Debug.LogError((object)"[GetField] 兵种蓝图为空"); return default(T); } FieldInfo field = typeof(UnitBlueprint).GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field == null) { PropertyInfo property = typeof(UnitBlueprint).GetProperty(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (property != null && property.CanRead) { try { object value = property.GetValue(blueprint); return (value != null) ? ((T)value) : default(T); } catch (Exception ex) { Debug.LogError((object)("[GetField] 获取属性 '" + fieldName + "' 失败: " + ex.Message)); return default(T); } } return default(T); } try { object value2 = field.GetValue(blueprint); return (value2 != null) ? ((T)value2) : default(T); } catch (Exception ex2) { Debug.LogError((object)("[GetField] 获取字段 '" + fieldName + "' 失败: " + ex2.Message)); return default(T); } } public static bool SetUnitSounds(this UnitBlueprint blueprint, string vocalSound, string deathSound, float pitch = 1f, string footstepSound = "Footsteps/Minotaur") { if ((Object)(object)blueprint == (Object)null) { Debug.LogError((object)"[SetUnitSounds] 兵种蓝图为空"); return false; } bool result = true; if (!blueprint.SetField("vocalRef", vocalSound)) { result = false; } if (!blueprint.SetField("deathRef", deathSound)) { result = false; } if (!blueprint.SetField("footRef", footstepSound)) { result = false; } if (!blueprint.SetField("voicePitch", pitch)) { result = false; } VoiceBundle field = blueprint.GetField<VoiceBundle>("voiceBundle"); if ((Object)(object)field != (Object)null) { blueprint.SetField("voiceBundle", null); } typeof(UnitBlueprint).GetMethod("Validate", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.Invoke(blueprint, null); return result; } public static bool SetRider(this UnitBlueprint blueprint, UnitBlueprint riderBlueprint) { //IL_003e: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)blueprint == (Object)null) { Debug.LogError((object)"[SetRider] 兵种蓝图为空"); return false; } if ((Object)(object)riderBlueprint == (Object)null) { Debug.LogError((object)"[SetRider] 骑手蓝图为空"); return false; } blueprint.SetCustomRider(riderBlueprint.Entity.GUID); return true; } public static bool SetRiders(this UnitBlueprint blueprint, UnitBlueprint[] riderBlueprints) { if ((Object)(object)blueprint == (Object)null) { Debug.LogError((object)"[SetRiders] 兵种蓝图为空"); return false; } if (riderBlueprints == null || riderBlueprints.Length == 0) { blueprint.SetNoCustomRider(); return blueprint.SetField("Riders", null); } return blueprint.SetField("Riders", riderBlueprints); } public static bool AddRider(this UnitBlueprint blueprint, UnitBlueprint riderBlueprint) { if ((Object)(object)blueprint == (Object)null) { Debug.LogError((object)"[AddRider] 兵种蓝图为空"); return false; } if ((Object)(object)riderBlueprint == (Object)null) { Debug.LogError((object)"[AddRider] 骑手蓝图为空"); return false; } UnitBlueprint[] field = blueprint.GetField<UnitBlueprint[]>("Riders"); UnitBlueprint[] value; if (field == null || field.Length == 0) { value = (UnitBlueprint[])(object)new UnitBlueprint[1] { riderBlueprint }; } else { if (field.Any((UnitBlueprint r) => r.Entity.GUID == riderBlueprint.Entity.GUID)) { Debug.LogWarning((object)("[AddRider] 骑手 '" + riderBlueprint.Name + "' 已存在")); return false; } value = field.Concat((IEnumerable<UnitBlueprint>)(object)new UnitBlueprint[1] { riderBlueprint }).ToArray(); } return blueprint.SetField("Riders", value); } public static bool RemoveRider(this UnitBlueprint blueprint, UnitBlueprint riderBlueprint) { if ((Object)(object)blueprint == (Object)null) { Debug.LogError((object)"[RemoveRider] 兵种蓝图为空"); return false; } if ((Object)(object)riderBlueprint == (Object)null) { Debug.LogError((object)"[RemoveRider] 骑手蓝图为空"); return false; } UnitBlueprint[] field = blueprint.GetField<UnitBlueprint[]>("Riders"); if (field == null || field.Length == 0) { return true; } UnitBlueprint[] array = field.Where((UnitBlueprint r) => r.Entity.GUID != riderBlueprint.Entity.GUID).ToArray(); if (array.Length == field.Length) { Debug.LogWarning((object)("[RemoveRider] 未找到骑手 '" + riderBlueprint.Name + "'")); return false; } if (array.Length == 0) { blueprint.SetNoCustomRider(); return blueprint.SetField("Riders", null); } return blueprint.SetField("Riders", array); } public static bool ClearRiders(this UnitBlueprint blueprint) { if ((Object)(object)blueprint == (Object)null) { Debug.LogError((object)"[ClearRiders] 兵种蓝图为空"); return false; } blueprint.SetNoCustomRider(); return blueprint.SetField("Riders", null); } public static UnitBlueprint[] GetRiders(this UnitBlueprint blueprint) { if ((Object)(object)blueprint == (Object)null) { Debug.LogError((object)"[GetRiders] 兵种蓝图为空"); return Array.Empty<UnitBlueprint>(); } return blueprint.UnitRiders ?? Array.Empty<UnitBlueprint>(); } } public class 懒得发字典添加物品类 { private static 懒得发字典添加物品类 _instance; private GameObject 物品对象池; public static 懒得发字典添加物品类 Instance { get { if (_instance == null) { _instance = new 懒得发字典添加物品类(); } return _instance; } } private 懒得发字典添加物品类() { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected O, but got Unknown Debug.Log((object)"开始创建对象池"); 物品对象池 = new GameObject { hideFlags = (HideFlags)61 }; ((Object)物品对象池).name = "DingZhiTiaoSePan"; 物品对象池.SetActive(false); Debug.Log((object)"对象池创建完毕"); } public GameObject 创建物品(string 名字, GameObject 要复制的物体, DatabaseID 物体标识, Sprite icon = null) { //IL_006a: Unknown result type (might be due to invalid IL or missing references) Debug.Log((object)"开始创建物品"); GameObject val = Object.Instantiate<GameObject>(要复制的物体, 物品对象池.transform); ((Object)val).hideFlags = (HideFlags)52; SetHideFlagsRecursive(val, (HideFlags)52); ((Object)val).name = 名字 + Assembly.GetCallingAssembly().GetName().Name; IDatabaseEntity componentInChildren = val.GetComponentInChildren<IDatabaseEntity>(); if (componentInChildren != null) { CharacterItem val2 = (CharacterItem)(object)((componentInChildren is CharacterItem) ? componentInChildren : null); componentInChildren.Entity.GUID = 物体标识; componentInChildren.Entity.Name = 名字; if ((Object)(object)icon != (Object)null) { componentInChildren.Entity.SpriteIcon = icon; } } Debug.Log((object)("物品创建完毕" + ((Object)val).name)); return val; } private void SetHideFlagsRecursive(GameObject obj, HideFlags flags) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Expected O, but got Unknown //IL_0045: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)obj == (Object)null) { return; } ((Object)obj).hideFlags = flags; foreach (Transform item in obj.transform) { Transform val = item; if ((Object)(object)val != (Object)null) { SetHideFlagsRecursive(((Component)val).gameObject, flags); } } } } public static class 游戏内容工具 { private static LandfallContentDatabase 内容数据库 => ContentDatabase.Instance().LandfallContentDatabase; private static AssetLoader 资源加载器 => ContentDatabase.Instance().AssetLoader; private static Dictionary<DatabaseID, Object> 非流式资源字典 => (Dictionary<DatabaseID, Object>)(typeof(AssetLoader).GetField("m_nonStreamableAssets", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(资源加载器)); public static GameObject 注册单位Base(GameObject 单位基础) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) return 注册游戏对象到数据库(单位基础, 单位基础.GetComponent<Unit>().Entity.GUID, "m_unitBases", (GameObject db) => db.GetComponent<Unit>().Entity.GUID); } public static GameObject 注册武器(GameObject 武器对象) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) return 注册游戏对象到数据库(武器对象, ((CharacterItem)武器对象.GetComponent<WeaponItem>()).Entity.GUID, "m_weapons", (GameObject obj) => ((CharacterItem)obj.GetComponent<WeaponItem>()).Entity.GUID); } public static GameObject 注册能力(GameObject 能力对象) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) return 注册游戏对象到数据库(能力对象, ((CharacterItem)能力对象.GetComponent<SpecialAbility>()).Entity.GUID, "m_combatMoves", (GameObject obj) => ((CharacterItem)obj.GetComponent<SpecialAbility>()).Entity.GUID); } public static GameObject 注册投射物(GameObject 投射物对象) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) return 注册游戏对象到数据库(投射物对象, 投射物对象.GetComponent<ProjectileEntity>().Entity.GUID, "m_projectiles", (GameObject obj) => obj.GetComponent<ProjectileEntity>().Entity.GUID); } public static GameObject 注册道具(GameObject 道具对象) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) return 注册游戏对象到数据库(道具对象, ((CharacterItem)道具对象.GetComponent<PropItem>()).Entity.GUID, "m_characterProps", (GameObject obj) => ((CharacterItem)obj.GetComponent<PropItem>()).Entity.GUID); } private static GameObject 注册游戏对象到数据库(GameObject 游戏对象, DatabaseID 对象ID, string 数据库字段名, Func<GameObject, DatabaseID> 获取ID函数) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) Dictionary<DatabaseID, GameObject> dictionary = 获取字典<GameObject>(数据库字段名); if (!dictionary.ContainsKey(对象ID)) { dictionary.Add(对象ID, 游戏对象); 非流式资源字典.Add(对象ID, (Object)(object)游戏对象); 设置字典值<GameObject>(数据库字段名, dictionary); } return 游戏对象; } public static UnitBlueprint 获取原版单位蓝图(DatabaseID id) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) Dictionary<DatabaseID, UnitBlueprint> dictionary = 获取字典<UnitBlueprint>("m_unitBlueprints"); UnitBlueprint value; return dictionary.TryGetValue(id, out value) ? value : null; } public static Faction 获取原版派系(DatabaseID id) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) Dictionary<DatabaseID, Faction> dictionary = 获取字典<Faction>("m_factions"); Faction value; return dictionary.TryGetValue(id, out value) ? value : null; } public static UnitBlueprint 复制单位(string 名称, UnitBlueprint 源单位蓝图 = null, Faction 所属派系 = null, Sprite 图标 = null, DatabaseID? 自定义ID = null) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)源单位蓝图 == (Object)null) { 源单位蓝图 = 获取原版单位蓝图(new DatabaseID(-1, 1166250463)); } if ((Object)(object)源单位蓝图 == (Object)null) { Debug.LogError((object)"无法获取源单位蓝图"); return null; } Debug.LogWarning((object)"开始创建蓝图"); UnitBlueprint val = Object.Instantiate<UnitBlueprint>(源单位蓝图); val.Entity.GUID = (DatabaseID)(((??)自定义ID) ?? DatabaseID.NewID()); val.Entity.Name = 名称; ((Object)val).name = 名称; if ((Object)(object)图标 != (Object)null) { val.Entity.SpriteIcon = 图标; } Debug.LogWarning((object)"完成蓝图创建并指定ID"); Dictionary<DatabaseID, UnitBlueprint> dictionary = 获取字典<UnitBlueprint>("m_unitBlueprints"); if (!dictionary.ContainsKey(val.Entity.GUID)) { 非流式资源字典.Add(val.Entity.GUID, (Object)(object)val); dictionary.Add(val.Entity.GUID, val); 设置字典值<UnitBlueprint>("m_unitBlueprints", dictionary); Debug.LogWarning((object)"成功添加到数据库"); } if ((Object)(object)所属派系 != (Object)null && (Object)(object)val != (Object)null) { List<UnitBlueprint> list = 所属派系.Units?.ToList() ?? new List<UnitBlueprint>(); if (!list.Contains(val)) { list.Add(val); 所属派系.Units = list.ToArray(); } } return val; } public static Faction 创建派系(string 名称, UnitBlueprint[] 单位列表 = null, Sprite 图标 = null, int 模组ID = 0, int 派系ID = 0) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) Faction val = ScriptableObject.CreateInstance<Faction>(); val.Init(); val.Entity.GUID = (DatabaseID)((模组ID != 0 && 派系ID != 0) ? new DatabaseID(模组ID, 派系ID) : DatabaseID.NewID()); val.Entity.Name = 名称; ((Object)val).name = 名称; val.Units = (UnitBlueprint[])(((object)单位列表) ?? ((object)new UnitBlueprint[0])); val.Entity.SpriteIcon = 图标; Dictionary<DatabaseID, Faction> dictionary = 获取字典<Faction>("m_factions"); if (!dictionary.ContainsKey(val.Entity.GUID)) { 非流式资源字典.Add(val.Entity.GUID, (Object)(object)val); dictionary.Add(val.Entity.GUID, val); List<DatabaseID> list = 获取默认快捷栏派系ID列表(); if (!list.Contains(val.Entity.GUID)) { list.Add(val.Entity.GUID); 排序并设置默认快捷栏列表(list, dictionary); } 设置字典值<Faction>("m_factions", dictionary); } return val; } private static Dictionary<DatabaseID, T> 获取字典<T>(string 字段名) where T : Object { return (Dictionary<DatabaseID, T>)(typeof(LandfallContentDatabase).GetField(字段名, BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(内容数据库)); } private static void 设置字典值<T>(string 字段名, Dictionary<DatabaseID, T> 字典) where T : Object { typeof(LandfallContentDatabase).GetField(字段名, BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(内容数据库, 字典); } private static List<DatabaseID> 获取默认快捷栏派系ID列表() { return (List<DatabaseID>)(typeof(LandfallContentDatabase).GetField("m_defaultHotbarFactionIds", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(内容数据库)); } private static void 排序并设置默认快捷栏列表(List<DatabaseID> 列表, Dictionary<DatabaseID, Faction> 派系字典) { Faction value2; List<DatabaseID> value = 列表.OrderBy((DatabaseID id) => 派系字典.TryGetValue(id, out value2) ? value2.index : int.MaxValue).ToList(); typeof(LandfallContentDatabase).GetField("m_defaultHotbarFactionIds", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(内容数据库, value); } } public static class 获取工具 { private static LandfallContentDatabase 内容数据库 => ContentDatabase.Instance().LandfallContentDatabase; private static AssetLoader 资源加载器 => ContentDatabase.Instance().AssetLoader; private static Dictionary<DatabaseID, Object> 非流式资源字典 => (Dictionary<DatabaseID, Object>)(typeof(AssetLoader).GetField("m_nonStreamableAssets", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(资源加载器)); private static Dictionary<DatabaseID, T> 获取字典<T>(string 字段名) where T : Object { return (Dictionary<DatabaseID, T>)(typeof(LandfallContentDatabase).GetField(字段名, BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(内容数据库)); } public static GameObject 获取原版内容游戏物品(string 字典名, DatabaseID id) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) return 获取字典<GameObject>(字典名)[id]; } } } namespace DingZhiTiaoSePan { [BepInPlugin("DingZhiTiaoassd", "DingZhiTiaoassd", "1.0.0")] internal class Loader : BaseUnityPlugin { private void Awake() { Debug.Log((object)"已加载定制调色盘"); ((MonoBehaviour)this).StartCoroutine(call()); } private IEnumerator call() { yield return (object)new WaitUntil((Func<bool>)(() => (Object)(object)Object.FindObjectOfType<ServiceLocator>() != (Object)null)); yield return (object)new WaitUntil((Func<bool>)(() => ServiceLocator.GetService<ISaveLoaderService>() != null)); GameObject 场景切换管理 = new GameObject("调色盘模组场景切换管理"); 场景切换管理.AddComponent<MOD场景管理器单例>(); 调色板翻译器.添加语言(); 模组资源内容加载.加载场景资源(); Object.DontDestroyOnLoad((Object)(object)场景切换管理); yield return (object)new WaitForSecondsRealtime(30f); UManager.Init(); } } public static class UManager { private static readonly string 配置文件夹名称 = "Your_material_data"; private static string 配置文件夹路径; private static int 成功加载材质数 = 0; private static int 失败加载配置数 = 0; public static void Init() { Debug.Log((object)"========== 开始加载定制调色板Mod =========="); try { 初始化配置文件夹路径(); 图片资源加载类.初始化(); 初始化配置文件夹(); List<MODMaterialConfig> list = 读取所有配置文件(); if (list.Count == 0) { Debug.LogWarning((object)"[定制调色板] 没有找到任何有效的配置文件,已生成示例配置"); return; } 处理并添加材质(list); Debug.Log((object)"========== 定制调色板Mod加载完成 =========="); Debug.Log((object)$"成功加载: {成功加载材质数} 个材质"); Debug.Log((object)$"失败配置: {失败加载配置数} 个文件"); Debug.Log((object)("配置文件夹位置: " + 配置文件夹路径)); } catch (Exception ex) { Debug.LogError((object)("[定制调色板] 初始化失败: " + ex.Message)); Debug.LogError((object)("[定制调色板] 堆栈: " + ex.StackTrace)); } } private static void 初始化配置文件夹路径() { try { string location = Assembly.GetExecutingAssembly().Location; string directoryName = Path.GetDirectoryName(location); 配置文件夹路径 = Path.Combine(directoryName, 配置文件夹名称); Debug.Log((object)("[定制调色板] 程序集位置: " + location)); Debug.Log((object)("[定制调色板] 配置文件夹路径: " + 配置文件夹路径)); } catch (Exception ex) { Debug.LogError((object)("[定制调色板] 初始化配置文件夹路径失败: " + ex.Message)); string text = Path.Combine(Application.dataPath, "..", 配置文件夹名称); Debug.Log((object)("[定制调色板] 使用备用路径: " + text)); 配置文件夹路径 = text; } } private static void 初始化配置文件夹() { try { if (!Directory.Exists(配置文件夹路径)) { Directory.CreateDirectory(配置文件夹路径); Debug.Log((object)("[定制调色板] 创建配置文件夹: " + 配置文件夹路径)); 生成示例配置文件(); } else { Debug.Log((object)("[定制调色板] 配置文件夹已存在: " + 配置文件夹路径)); } } catch (Exception ex) { Debug.LogError((object)("[定制调色板] 初始化配置文件夹失败: " + ex.Message)); throw; } } private static void 生成示例配置文件() { Debug.Log((object)"[定制调色板] 正在生成示例配置文件..."); MODMaterialConfig 配置 = new MODMaterialConfig { Version = 1, ConfigName = "GlowMaterials", Global = new GlobalSettings { OverrideExisting = false, AutoLoadOnStart = true, DefaultParentCategory = "发光材质", DebugMode = false }, Materials = new List<MODMaterialData> { new MODMaterialData { Id = "glow_red_hot", ColorIndex = 990, DisplayName = "炽热红", Description = "高亮度红色发光材质", Enabled = true, ShaderName = "Standard", PrimaryColor = new ColorData(1f, 0f, 0f), IsGlowMaterial = true, GlowMultiplier = 3f, Metallic = 0.8f, Smoothness = 0.3f, ParentCategory = "发光系列", Subcategory = "红色系", SortOrder = 1 }, new MODMaterialData { Id = "glow_red_hot2", ColorIndex = 0, DisplayName = "炽热红2", Description = "高亮度红色发光材质", Enabled = true, ShaderName = "Standard", PrimaryColor = new ColorData(0.5f, 0f, 0f), IsGlowMaterial = true, GlowMultiplier = 1f, Metallic = 0.8f, Smoothness = 0.3f, ParentCategory = "发光系列", Subcategory = "红色系", SortOrder = 1, CustomProperties = new List<CustomProperty> { new CustomProperty { PropertyName = "_Metallic", Type = PropertyType.Float, FloatValue = 1f }, new CustomProperty { PropertyName = "_Glossiness", Type = PropertyType.Float, FloatValue = 1f } } }, new MODMaterialData { Id = "glow_cyan", ColorIndex = 991, DisplayName = "电光青", Description = "明亮的青色发光材质", Enabled = true, ShaderName = "Standard", PrimaryColor = new ColorData(0f, 1f, 1f), IsGlowMaterial = true, GlowMultiplier = 3f, Metallic = 0.5f, Smoothness = 0.5f, ParentCategory = "发光系列", Subcategory = "青色系", SortOrder = 2 }, new MODMaterialData { Id = "glow_purple", ColorIndex = 992, DisplayName = "魔幻紫", Description = "神秘紫色发光材质", Enabled = true, ShaderName = "Standard", PrimaryColor = new ColorData(1f, 0f, 1f), IsGlowMaterial = true, GlowMultiplier = 3f, Metallic = 0.6f, Smoothness = 0.4f, ParentCategory = "发光系列", Subcategory = "紫色系", SortOrder = 3 } } }; MODMaterialConfig 配置2 = new MODMaterialConfig { Version = 1, ConfigName = "MetalMaterials", Global = new GlobalSettings { OverrideExisting = false, AutoLoadOnStart = true, DefaultParentCategory = "金属材质", DebugMode = false }, Materials = new List<MODMaterialData> { new MODMaterialData { Id = "metal_gold", ColorIndex = 993, DisplayName = "黄金", Description = "奢华金色金属材质", Enabled = true, ShaderName = "Standard", PrimaryColor = new ColorData(1f, 0.8f, 0.2f), Metallic = 0.95f, Smoothness = 0.85f, ParentCategory = "金属材质", Subcategory = "贵金属", SortOrder = 1 }, new MODMaterialData { Id = "metal_silver", ColorIndex = 994, DisplayName = "白银", Description = "闪亮银色金属材质", Enabled = true, ShaderName = "Standard", PrimaryColor = new ColorData(0.9f, 0.9f, 1f), Metallic = 0.92f, Smoothness = 0.88f, ParentCategory = "金属材质", Subcategory = "贵金属", SortOrder = 2 }, new MODMaterialData { Id = "metal_bronze", ColorIndex = 995, DisplayName = "青铜", Description = "古朴青铜材质", Enabled = true, ShaderName = "Standard", PrimaryColor = new ColorData(0.8f, 0.5f, 0.2f), Metallic = 0.85f, Smoothness = 0.7f, ParentCategory = "金属材质", Subcategory = "合金", SortOrder = 3 }, new MODMaterialData { Id = "metal_copper", ColorIndex = 996, DisplayName = "铜", Description = "红棕色铜材质", Enabled = true, ShaderName = "Standard", PrimaryColor = new ColorData(0.9f, 0.4f, 0.2f), Metallic = 0.88f, Smoothness = 0.75f, ParentCategory = "金属材质", Subcategory = "合金", SortOrder = 4 } } }; MODMaterialConfig 配置3 = new MODMaterialConfig { Version = 1, ConfigName = "EffectMaterials", Global = new GlobalSettings { OverrideExisting = false, AutoLoadOnStart = true, Defa