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(); parentCanvas = ((Component)this).GetComponentInParent(); 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().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(); if ((Object)(object)cachedImage == (Object)null) { cachedSprite = ((Component)this).GetComponent(); } } 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(); if ((Object)(object)audioSource == (Object)null) { audioSource = ((Component)this).gameObject.AddComponent(); } } 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)(object)输入框内容.onEndEdit).AddListener((UnityAction)On着色器名称改变); } if ((Object)(object)渲染模式枚举 != (Object)null) { 初始化渲染模式下拉框(); ((UnityEvent)(object)渲染模式枚举.onValueChanged).AddListener((UnityAction)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)(object)主帖图输入.onEndEdit).AddListener((UnityAction)On主贴图改变); ((UnityEvent)(object)主帖图输入.onValueChanged).AddListener((UnityAction)On主贴图实时改变); } if ((Object)(object)法线贴图输入 != (Object)null) { ((UnityEvent)(object)法线贴图输入.onEndEdit).AddListener((UnityAction)On法线贴图改变); ((UnityEvent)(object)法线贴图输入.onValueChanged).AddListener((UnityAction)On法线贴图实时改变); } if ((Object)(object)金属光泽图输入 != (Object)null) { ((UnityEvent)(object)金属光泽图输入.onEndEdit).AddListener((UnityAction)On金属光泽贴图改变); ((UnityEvent)(object)金属光泽图输入.onValueChanged).AddListener((UnityAction)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 list = new List(); 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)(object)obj.onValueChanged).AddListener((UnityAction)delegate { 应用主颜色(); }); } Slider obj2 = 滑块g; if (obj2 != null) { ((UnityEvent)(object)obj2.onValueChanged).AddListener((UnityAction)delegate { 应用主颜色(); }); } Slider obj3 = 滑块b; if (obj3 != null) { ((UnityEvent)(object)obj3.onValueChanged).AddListener((UnityAction)delegate { 应用主颜色(); }); } Slider obj4 = 滑块a; if (obj4 != null) { ((UnityEvent)(object)obj4.onValueChanged).AddListener((UnityAction)delegate { 应用主颜色(); }); } Slider obj5 = hdr滑块r; if (obj5 != null) { ((UnityEvent)(object)obj5.onValueChanged).AddListener((UnityAction)delegate { 应用HDR颜色(); }); } Slider obj6 = hdr滑块g; if (obj6 != null) { ((UnityEvent)(object)obj6.onValueChanged).AddListener((UnityAction)delegate { 应用HDR颜色(); }); } Slider obj7 = hdr滑块b; if (obj7 != null) { ((UnityEvent)(object)obj7.onValueChanged).AddListener((UnityAction)delegate { 应用HDR颜色(); }); } Slider obj8 = hdr滑块a; if (obj8 != null) { ((UnityEvent)(object)obj8.onValueChanged).AddListener((UnityAction)delegate { 应用HDR颜色(); }); } Slider obj9 = hdr强度滑块; if (obj9 != null) { ((UnityEvent)(object)obj9.onValueChanged).AddListener((UnityAction)delegate { 应用HDR颜色(); }); } Slider obj10 = 金属度滑块; if (obj10 != null) { ((UnityEvent)(object)obj10.onValueChanged).AddListener((UnityAction)delegate { 应用金属度(); }); } Slider obj11 = 光滑度滑块; if (obj11 != null) { ((UnityEvent)(object)obj11.onValueChanged).AddListener((UnityAction)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)(object)targetSlider.onValueChanged).AddListener((UnityAction)OnSliderValueChanged); } } if ((Object)(object)targetInput != (Object)null && syncFromInput) { ((UnityEvent)(object)targetInput.onValueChanged).AddListener((UnityAction)OnInputValueChanged); ((UnityEvent)(object)targetInput.onEndEdit).AddListener((UnityAction)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(); if ((Object)(object)targetSlider == (Object)null) { targetSlider = ((Component)this).GetComponent(); 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(); if ((Object)(object)targetInput == (Object)null) { targetInput = ((Component)this).GetComponent(); 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)(object)targetSlider.onValueChanged).RemoveListener((UnityAction)OnSliderValueChanged); } if ((Object)(object)targetInput != (Object)null && syncFromInput) { ((UnityEvent)(object)targetInput.onValueChanged).RemoveListener((UnityAction)OnInputValueChanged); ((UnityEvent)(object)targetInput.onEndEdit).RemoveListener((UnityAction)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(); 原始大小 = (((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(); } ((UnityEvent)(object)inputField.onEndEdit).AddListener((UnityAction)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 list = new List(); 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(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"); 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("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)(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("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(); } return blueprint.UnitRiders ?? Array.Empty(); } } 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(要复制的物体, 物品对象池.transform); ((Object)val).hideFlags = (HideFlags)52; SetHideFlagsRecursive(val, (HideFlags)52); ((Object)val).name = 名字 + Assembly.GetCallingAssembly().GetName().Name; IDatabaseEntity componentInChildren = val.GetComponentInChildren(); 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 非流式资源字典 => (Dictionary)(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().Entity.GUID, "m_unitBases", (GameObject db) => db.GetComponent().Entity.GUID); } public static GameObject 注册武器(GameObject 武器对象) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) return 注册游戏对象到数据库(武器对象, ((CharacterItem)武器对象.GetComponent()).Entity.GUID, "m_weapons", (GameObject obj) => ((CharacterItem)obj.GetComponent()).Entity.GUID); } public static GameObject 注册能力(GameObject 能力对象) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) return 注册游戏对象到数据库(能力对象, ((CharacterItem)能力对象.GetComponent()).Entity.GUID, "m_combatMoves", (GameObject obj) => ((CharacterItem)obj.GetComponent()).Entity.GUID); } public static GameObject 注册投射物(GameObject 投射物对象) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) return 注册游戏对象到数据库(投射物对象, 投射物对象.GetComponent().Entity.GUID, "m_projectiles", (GameObject obj) => obj.GetComponent().Entity.GUID); } public static GameObject 注册道具(GameObject 道具对象) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) return 注册游戏对象到数据库(道具对象, ((CharacterItem)道具对象.GetComponent()).Entity.GUID, "m_characterProps", (GameObject obj) => ((CharacterItem)obj.GetComponent()).Entity.GUID); } private static GameObject 注册游戏对象到数据库(GameObject 游戏对象, DatabaseID 对象ID, string 数据库字段名, Func 获取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 dictionary = 获取字典(数据库字段名); if (!dictionary.ContainsKey(对象ID)) { dictionary.Add(对象ID, 游戏对象); 非流式资源字典.Add(对象ID, (Object)(object)游戏对象); 设置字典值(数据库字段名, dictionary); } return 游戏对象; } public static UnitBlueprint 获取原版单位蓝图(DatabaseID id) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) Dictionary dictionary = 获取字典("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 dictionary = 获取字典("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(源单位蓝图); 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 dictionary = 获取字典("m_unitBlueprints"); if (!dictionary.ContainsKey(val.Entity.GUID)) { 非流式资源字典.Add(val.Entity.GUID, (Object)(object)val); dictionary.Add(val.Entity.GUID, val); 设置字典值("m_unitBlueprints", dictionary); Debug.LogWarning((object)"成功添加到数据库"); } if ((Object)(object)所属派系 != (Object)null && (Object)(object)val != (Object)null) { List list = 所属派系.Units?.ToList() ?? new List(); 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(); 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 dictionary = 获取字典("m_factions"); if (!dictionary.ContainsKey(val.Entity.GUID)) { 非流式资源字典.Add(val.Entity.GUID, (Object)(object)val); dictionary.Add(val.Entity.GUID, val); List list = 获取默认快捷栏派系ID列表(); if (!list.Contains(val.Entity.GUID)) { list.Add(val.Entity.GUID); 排序并设置默认快捷栏列表(list, dictionary); } 设置字典值("m_factions", dictionary); } return val; } private static Dictionary 获取字典(string 字段名) where T : Object { return (Dictionary)(typeof(LandfallContentDatabase).GetField(字段名, BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(内容数据库)); } private static void 设置字典值(string 字段名, Dictionary 字典) where T : Object { typeof(LandfallContentDatabase).GetField(字段名, BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(内容数据库, 字典); } private static List 获取默认快捷栏派系ID列表() { return (List)(typeof(LandfallContentDatabase).GetField("m_defaultHotbarFactionIds", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(内容数据库)); } private static void 排序并设置默认快捷栏列表(List 列表, Dictionary 派系字典) { Faction value2; List 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 非流式资源字典 => (Dictionary)(typeof(AssetLoader).GetField("m_nonStreamableAssets", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(资源加载器)); private static Dictionary 获取字典(string 字段名) where T : Object { return (Dictionary)(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 获取字典(字典名)[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)(() => (Object)(object)Object.FindObjectOfType() != (Object)null)); yield return (object)new WaitUntil((Func)(() => ServiceLocator.GetService() != null)); GameObject 场景切换管理 = new GameObject("调色盘模组场景切换管理"); 场景切换管理.AddComponent(); 调色板翻译器.添加语言(); 模组资源内容加载.加载场景资源(); 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 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 { 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 { 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 { 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, DefaultParentCategory = "特效材质", DebugMode = false }, Materials = new List { new MODMaterialData { Id = "ice_crystal", ColorIndex = 997, DisplayName = "寒冰", Description = "半透明冰晶材质", Enabled = true, ShaderName = "Standard", PrimaryColor = new ColorData(0.5f, 0.8f, 1f, 0.7f), Alpha = 0.7f, RenderMode = RenderMode.Transparent, Smoothness = 0.9f, Metallic = 0.1f, ParentCategory = "特效材质", Subcategory = "冰系", SortOrder = 1 }, new MODMaterialData { Id = "fire_flame", ColorIndex = 998, DisplayName = "烈焰", Description = "火焰特效材质", Enabled = true, ShaderName = "Standard", PrimaryColor = new ColorData(2f, 0.5f, 0f), EmissionColor = new ColorData(2f, 0.5f, 0f), EmissionIntensity = 1.5f, IsGlowMaterial = true, GlowMultiplier = 2f, ParentCategory = "特效材质", Subcategory = "火系", SortOrder = 2 }, new MODMaterialData { Id = "ghost_ethereal", ColorIndex = 999, DisplayName = "幽灵", Description = "半透明幽灵材质", Enabled = true, ShaderName = "Standard", PrimaryColor = new ColorData(0.7f, 0.9f, 1f, 0.5f), Alpha = 0.5f, RenderMode = RenderMode.Transparent, GlowIntensity = 0.3f, ParentCategory = "特效材质", Subcategory = "灵体", SortOrder = 3 } } }; 保存配置文件(配置, "Example_GlowMaterials.json"); 保存配置文件(配置2, "Example_MetalMaterials.json"); 保存配置文件(配置3, "Example_EffectMaterials.json"); Debug.Log((object)("[定制调色板] 已生成3个示例配置文件到: " + 配置文件夹路径)); } private static void 保存配置文件(MODMaterialConfig 配置, string 文件名) { try { string path = Path.Combine(配置文件夹路径, 文件名); string contents = JsonConvert.SerializeObject((object)配置, (Formatting)1); File.WriteAllText(path, contents); Debug.Log((object)(" - 已生成: " + 文件名)); } catch (Exception ex) { Debug.LogError((object)(" - 生成文件失败 " + 文件名 + ": " + ex.Message)); } } private static List 读取所有配置文件() { List list = new List(); try { string[] files = Directory.GetFiles(配置文件夹路径, "*.json", SearchOption.TopDirectoryOnly); Debug.Log((object)$"[定制调色板] 找到 {files.Length} 个JSON文件"); string[] array = files; foreach (string path in array) { try { string text = File.ReadAllText(path); MODMaterialConfig mODMaterialConfig = JsonConvert.DeserializeObject(text); if (mODMaterialConfig != null && mODMaterialConfig.Materials != null && mODMaterialConfig.Materials.Count > 0) { if (mODMaterialConfig.Version != 1) { Debug.LogWarning((object)$"[定制调色板] 配置文件版本不兼容: {Path.GetFileName(path)} (版本: {mODMaterialConfig.Version})"); } list.Add(mODMaterialConfig); Debug.Log((object)$" - 已加载: {Path.GetFileName(path)} (材质数: {mODMaterialConfig.Materials.Count})"); } else { Debug.LogWarning((object)(" - 配置文件无效或为空: " + Path.GetFileName(path))); 失败加载配置数++; } } catch (Exception ex) { Debug.LogError((object)(" - 解析配置文件失败: " + Path.GetFileName(path))); Debug.LogError((object)(" 错误: " + ex.Message)); 失败加载配置数++; } } } catch (Exception ex2) { Debug.LogError((object)("[定制调色板] 读取配置文件失败: " + ex2.Message)); } return list; } private static void 处理并添加材质(List 所有配置) { //IL_0083: 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_008a: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) try { Dictionary>> dictionary = new Dictionary>>(); foreach (MODMaterialConfig item in 所有配置) { if (!item.Global.AutoLoadOnStart) { Debug.Log((object)("[定制调色板] 跳过自动加载配置: " + item.ConfigName)); continue; } foreach (MODMaterialData material in item.Materials) { if (!material.Enabled) { continue; } try { ColorPaletteData val = 调色板添加类.从配置创建颜色数据(material); if ((Object)(object)val.m_material == (Object)null) { Debug.LogWarning((object)(" - 材质创建失败: " + material.DisplayName)); continue; } string text = (string.IsNullOrEmpty(material.ParentCategory) ? item.Global.DefaultParentCategory : material.ParentCategory); string text2 = (string.IsNullOrEmpty(material.Subcategory) ? "默认" : material.Subcategory); if (!dictionary.ContainsKey(text)) { dictionary[text] = new Dictionary>(); } if (!dictionary[text].ContainsKey(text2)) { dictionary[text][text2] = new List(); } dictionary[text][text2].Add(val); 成功加载材质数++; if (item.Global.DebugMode) { Debug.Log((object)(" - 已创建材质: " + material.DisplayName + " -> " + text + "/" + text2)); } } catch (Exception ex) { Debug.LogError((object)(" - 处理材质失败: " + material.DisplayName + ", 错误: " + ex.Message)); } } } if (成功加载材质数 == 0) { Debug.LogWarning((object)"[定制调色板] 没有加载到任何材质"); } else { 添加到调色板(dictionary); } } catch (Exception ex2) { Debug.LogError((object)("[定制调色板] 处理材质失败: " + ex2.Message)); } } private static void 添加到调色板(Dictionary>> 材质分组) { //IL_0071: 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_0077: 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_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_0124: 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) //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Unknown result type (might be due to invalid IL or missing references) Debug.Log((object)$"[定制调色板] 开始添加材质到调色板,共 {材质分组.Count} 个父分类"); 调色板添加类.初始化(); List list = 调色板添加类.获取父分类列表(); foreach (KeyValuePair>> 父分类 in 材质分组) { Debug.Log((object)(" - 处理父分类: " + 父分类.Key)); ParentCatagories val = 调色板添加类.查找或创建父分类(list, 父分类.Key, null); List list2 = val.colorPaletteCatagories?.ToList() ?? new List(); foreach (KeyValuePair> item2 in 父分类.Value) { Debug.Log((object)$" 子分类: {item2.Key} - 材质数: {item2.Value.Count}"); ColorPaletteCatagory item = new ColorPaletteCatagory { name = item2.Key, Cataogry = (CatagoryType)0, Colors = item2.Value.ToArray(), TeamColors = (TeamColorPaletteData[])(object)new TeamColorPaletteData[0], shardImage = null }; list2.Add(item); } val.colorPaletteCatagories = list2.ToArray(); int num = list.FindIndex((ParentCatagories p) => p.name == 父分类.Key); if (num >= 0) { list[num] = val; } } 调色板添加类.应用更改并刷新(list); Debug.Log((object)"[定制调色板] 调色板添加完成!"); Debug.Log((object)$" - 父分类数: {材质分组.Count}"); Debug.Log((object)$" - 材质总数: {成功加载材质数}"); 调色板添加类.打印调色板信息(); } public static void 重新加载配置() { Debug.Log((object)"[定制调色板] 重新加载配置文件..."); 调色板添加类.重置缓存(); 成功加载材质数 = 0; 失败加载配置数 = 0; Init(); } public static string 获取配置文件夹路径() { return 配置文件夹路径; } } public class MOD场景管理器单例 : MonoBehaviour { public MOD场景管理器单例() { SceneManager.sceneLoaded += SceneLoaded; } public void SceneLoaded(Scene scene, LoadSceneMode loadSceneMode) { if (((Scene)(ref scene)).name == "CustomContentPage") { 色彩编辑器ui添加类.添加(); } } } public static class 模组资源内容加载 { public static AssetBundle ab包_场景; public static AssetBundle ab包_普通资源; public static MapAsset 色彩编辑器场景; public static void 加载场景资源() { Assembly executingAssembly = Assembly.GetExecutingAssembly(); Stream manifestResourceStream = executingAssembly.GetManifestResourceStream("DingZhiTiaoSePan.dingzhitiaoseban"); AssetBundle val = AssetBundle.LoadFromStream(manifestResourceStream); ab包_场景 = val; Assembly executingAssembly2 = Assembly.GetExecutingAssembly(); Stream manifestResourceStream2 = executingAssembly2.GetManifestResourceStream("DingZhiTiaoSePan.mapziy"); AssetBundle val2 = AssetBundle.LoadFromStream(manifestResourceStream2); ab包_普通资源 = val2; MapAsset val3 = ab包_普通资源.LoadAsset("baiaasdx"); 色彩编辑器场景 = val3; } } internal class 调色板翻译器 { public static void 添加语言() { 语言添加("UI_INPUT_TEXT", "输入文字#Input#入力テキスト#Eingabe#Texte#Ввод текста#Texto de entrada#Testo di input"); 语言添加("UI_SHADER_NAME", "着色器名称#Shader#シェーダー名#Shader-Name#Nom du shader#Название шейдера#Nombre del shader#Nome shader"); 语言添加("UI_MATERIAL_NAME", "材质名称#Material#マテリアル名#Materialname#Nom du matériau#Название материала#Nombre del material#Nome materiale"); 语言添加("UI_MATERIAL_DESC", "材质描述#Description#マテリアル説明#Materialbeschreibung#Description du matériau#Описание материала#Descripción del material#Descrizione materiale"); 语言添加("UI_MATERIAL_ID", "材质ID#Material ID#マテリアルID#Material-ID#ID du matériau#ID материала#ID del materiale#ID materiale"); 语言添加("UI_PARENT_NAME", "父级名称#Parent#親名#Übergeordnet#Parent#Родитель#Nombre padre#Nome padre"); 语言添加("UI_CHILD_NAME", "子级名称#Child#子名#Untergeordnet#Enfant#Дочерний#Nombre hijo#Nome figlio"); 语言添加("UI_RENDER_MODE", "渲染模式#Render Mode#レンダーモード#Rendermodus#Mode de rendu#Режим рендеринга#Modo de renderizado#Modalità di rendering"); 语言添加("UI_EXIT", "退出#Exit#終了#Beenden#Quitter#Выход#Salir#Esci"); 语言添加("UI_SAVE", "保存#Save#保存#Speichern#Enregistrer#Сохранить#Guardar#Salva"); } public static void 语言添加(string key, string trans) { //IL_01df: Unknown result type (might be due to invalid IL or missing references) //IL_01e4: Unknown result type (might be due to invalid IL or missing references) //IL_01e9: Unknown result type (might be due to invalid IL or missing references) //IL_01ff: Unknown result type (might be due to invalid IL or missing references) //IL_023e: Unknown result type (might be due to invalid IL or missing references) //IL_0243: Unknown result type (might be due to invalid IL or missing references) //IL_0247: Unknown result type (might be due to invalid IL or missing references) //IL_0281: Unknown result type (might be due to invalid IL or missing references) //IL_0260: Unknown result type (might be due to invalid IL or missing references) if (string.IsNullOrEmpty(key)) { Debug.LogError((object)"翻译键不能为空!"); return; } if (string.IsNullOrEmpty(trans)) { Debug.LogError((object)"翻译内容不能为空!"); return; } string[] array = trans.Split(new string[1] { "#" }, StringSplitOptions.RemoveEmptyEntries); if (array.Length != 8) { Debug.LogError((object)$"翻译格式错误:需要8种语言,但只提供了{array.Length}种。格式应为:中文#英文#日文#德文#法文#俄文#西班牙文#意大利文"); return; } for (int i = 0; i < array.Length; i++) { if (string.IsNullOrWhiteSpace(array[i])) { string[] array2 = new string[8] { "中文", "英文", "日文", "德文", "法文", "俄文", "西班牙文", "意大利文" }; Debug.LogError((object)$"第{i}个位置({array2[i]})的翻译内容为空!"); return; } } try { Dictionary dictionary = new Dictionary(); dictionary.Add(0, (Language)7); dictionary.Add(1, (Language)0); dictionary.Add(2, (Language)8); dictionary.Add(3, (Language)3); dictionary.Add(4, (Language)1); dictionary.Add(5, (Language)6); dictionary.Add(6, (Language)4); dictionary.Add(7, (Language)2); FieldInfo field = typeof(Localizer).GetField("m_localization", BindingFlags.Static | BindingFlags.NonPublic); if (field == null) { Debug.LogError((object)"无法访问Localizer的m_localization字段!"); return; } if (!(field.GetValue(null) is Dictionary> dictionary2)) { Debug.LogError((object)"本地化字典为空或类型不匹配!"); return; } foreach (Language value in dictionary.Values) { if (!dictionary2.ContainsKey(value)) { Debug.LogError((object)$"本地化字典中缺少语言:{value}"); return; } } int num = 0; for (int j = 0; j < dictionary.Count; j++) { Language val = dictionary[j]; if (!dictionary2[val].ContainsKey(key)) { dictionary2[val].Add(key, array[j]); num++; } else { Debug.LogWarning((object)$"语言{val}中已存在键'{key}',跳过添加"); } } field.SetValue(null, dictionary2); if (num > 0) { Debug.Log((object)$"成功为{num}种语言添加了翻译键:{key}"); } else { Debug.Log((object)("所有语言中都已存在键'" + key + "',未添加任何新翻译")); } } catch (Exception ex) { Debug.LogError((object)("添加翻译时发生错误:" + ex.Message + "\n" + ex.StackTrace)); } } } } namespace DingZhiTiaoSePan.色彩编辑器ui添加 { public static class 色彩编辑器ui添加类 { public static void 添加() { GameObject val = GameObject.Find("CustomContent"); if (!((Object)(object)val != (Object)null)) { return; } Transform val2 = val.transform.Find("Title Safe/CanvasUIComponents/ContentBropwser/TABS/TabsContainer/Levels"); Transform val3 = val.transform.Find("Title Safe/CanvasUIComponents/ContentBropwser/TABS/TabsContainer/Dot"); Transform val4 = val.transform.Find("Title Safe/CanvasUIComponents/ContentBropwser/TABS/TabsContainer"); Object.Instantiate(((Component)val3).gameObject, val4); GameObject val5 = Object.Instantiate(((Component)val2).gameObject, val4); Sprite sprite = 模组资源内容加载.ab包_普通资源.LoadAsset("调色板adfa"); Image component = ((Component)val5.transform.GetChild(0).GetChild(1)).GetComponent(); if (Object.op_Implicit((Object)(object)component)) { component.sprite = sprite; } Image component2 = ((Component)val5.transform.GetChild(1).GetChild(1)).GetComponent(); if (Object.op_Implicit((Object)(object)component2)) { component2.sprite = sprite; } LocalizeText component3 = ((Component)val5.transform.GetChild(1).GetChild(0)).GetComponent(); if (Object.op_Implicit((Object)(object)component3)) { component3.LocaleID = "色彩编辑器"; } Toggle componentInChildren = val5.GetComponentInChildren(); if (!Object.op_Implicit((Object)(object)componentInChildren)) { return; } ((UnityEventBase)componentInChildren.onValueChanged).RemoveAllListeners(); ((UnityEvent)(object)componentInChildren.onValueChanged).AddListener((UnityAction)delegate(bool isOn) { if (isOn) { SceneManager.LoadScene("asdkjioweef"); Debug.Log((object)"开关被打开了"); } else { Debug.Log((object)"开关被关闭了"); } }); EventTrigger componentInChildren2 = val5.GetComponentInChildren(); if (Object.op_Implicit((Object)(object)componentInChildren2)) { componentInChildren2.triggers.Clear(); } } } } namespace DingZhiTiaoSePan.编辑器获取组件 { public class 对主摄像机添加简易配置 : MonoBehaviour { } public static class 着色器资源获取类 { public static string[] 所有着色器名称; public static void 初始化着色器列表() { try { Shader[] array = Resources.FindObjectsOfTypeAll(); List list = new List(); Shader[] array2 = array; foreach (Shader val in array2) { if ((Object)(object)val != (Object)null && !string.IsNullOrEmpty(((Object)val).name) && !list.Contains(((Object)val).name)) { list.Add(((Object)val).name); } } list.Sort(); 所有着色器名称 = list.ToArray(); Debug.Log((object)$"初始化完成!共加载 {所有着色器名称.Length} 个着色器"); for (int j = 0; j < Mathf.Min(10, 所有着色器名称.Length); j++) { Debug.Log((object)$"着色器 {j}: {所有着色器名称[j]}"); } } catch (Exception ex) { Debug.LogError((object)("初始化着色器列表失败: " + ex.Message)); 所有着色器名称 = new string[0]; } } public static List 获取着色器名称列表() { if (所有着色器名称 == null) { Debug.LogWarning((object)"着色器列表未初始化,请先调用 初始化着色器列表()"); return new List(); } return new List(所有着色器名称); } public static string 获取着色器名称(int index) { if (所有着色器名称 == null || index < 0 || index >= 所有着色器名称.Length) { return null; } return 所有着色器名称[index]; } public static int 获取着色器索引(string shaderName) { if (所有着色器名称 == null) { return -1; } return Array.IndexOf(所有着色器名称, shaderName); } } public class 色彩编辑器json配置核心 : MonoBehaviour { public TMP_InputField 着色器名称输入框; public TMP_InputField ConfigName配置名称输入框; public TMP_InputField 材质名称输入框; public TMP_InputField 材质描述输入框; public TMP_InputField 材质标识id输入框; public TMP_InputField 父级名称输入框; public TMP_InputField 子级名称输入框; public 材质展示脚本 材质数据获取; private string 配置文件存储路径; private readonly string 配置文件夹名称 = "Your_material_data"; private void Awake() { 初始化路径(); } private void 初始化路径() { try { string location = Assembly.GetExecutingAssembly().Location; string directoryName = Path.GetDirectoryName(location); 配置文件存储路径 = Path.Combine(directoryName, 配置文件夹名称); if (!Directory.Exists(配置文件存储路径)) { Directory.CreateDirectory(配置文件存储路径); } Debug.Log((object)("[色彩编辑器] 配置文件存储路径: " + 配置文件存储路径)); } catch (Exception ex) { Debug.LogError((object)("[色彩编辑器] 初始化路径失败: " + ex.Message)); } } public void 保存配置文件() { Debug.Log((object)"[色彩编辑器] 开始保存配置文件..."); try { if (!验证输入()) { Debug.LogWarning((object)"[色彩编辑器] 输入验证失败,请检查必填项"); return; } MODMaterialData mODMaterialData = 从UI创建材质数据(); if (mODMaterialData == null) { Debug.LogError((object)"[色彩编辑器] 创建材质数据失败"); return; } string text = ConfigName配置名称输入框.text; MODMaterialConfig 配置文件 = 查找或创建配置文件(text); 添加或更新材质(配置文件, mODMaterialData); 保存配置文件到磁盘(配置文件, text); 重新加载资源(); Debug.Log((object)("[色彩编辑器] 配置文件保存成功: " + text)); 显示提示消息("配置文件 \"" + text + "\" 保存成功!"); } catch (Exception ex) { Debug.LogError((object)("[色彩编辑器] 保存配置文件失败: " + ex.Message)); 显示提示消息("保存失败: " + ex.Message); } } private bool 验证输入() { TMP_InputField configName配置名称输入框 = ConfigName配置名称输入框; if (string.IsNullOrEmpty((configName配置名称输入框 != null) ? configName配置名称输入框.text : null)) { Debug.LogWarning((object)"[色彩编辑器] 配置名称不能为空"); return false; } TMP_InputField obj = 材质标识id输入框; if (string.IsNullOrEmpty((obj != null) ? obj.text : null)) { Debug.LogWarning((object)"[色彩编辑器] 材质ID不能为空"); return false; } if ((Object)(object)材质数据获取 == (Object)null) { Debug.LogWarning((object)"[色彩编辑器] 材质数据获取组件未绑定"); return false; } return true; } private MODMaterialData 从UI创建材质数据() { try { MODMaterialData mODMaterialData = new MODMaterialData(); TMP_InputField obj = 材质标识id输入框; mODMaterialData.Id = ((obj != null) ? obj.text : null) ?? ""; TMP_InputField obj2 = 材质名称输入框; mODMaterialData.DisplayName = ((obj2 != null) ? obj2.text : null) ?? "未命名材质"; TMP_InputField obj3 = 材质描述输入框; mODMaterialData.Description = ((obj3 != null) ? obj3.text : null) ?? ""; mODMaterialData.Enabled = true; if ((Object)(object)着色器名称输入框 != (Object)null && !string.IsNullOrEmpty(着色器名称输入框.text)) { mODMaterialData.ShaderName = 着色器名称输入框.text; } else { if ((Object)(object)材质数据获取 != (Object)null) { TMP_InputField 输入框内容 = 材质数据获取.输入框内容; if (!string.IsNullOrEmpty((输入框内容 != null) ? 输入框内容.text : null)) { mODMaterialData.ShaderName = 材质数据获取.输入框内容.text; goto IL_010a; } } mODMaterialData.ShaderName = "Standard"; } goto IL_010a; IL_010a: TMP_InputField obj4 = 父级名称输入框; mODMaterialData.ParentCategory = ((obj4 != null) ? obj4.text : null) ?? ""; TMP_InputField obj5 = 子级名称输入框; mODMaterialData.Subcategory = ((obj5 != null) ? obj5.text : null) ?? "默认"; if ((Object)(object)材质数据获取 != (Object)null) { Slider 滑块r = 材质数据获取.滑块r; float r = ((滑块r != null) ? 滑块r.value : 1f); Slider 滑块g = 材质数据获取.滑块g; float g = ((滑块g != null) ? 滑块g.value : 1f); Slider 滑块b = 材质数据获取.滑块b; float b = ((滑块b != null) ? 滑块b.value : 1f); Slider 滑块a = 材质数据获取.滑块a; mODMaterialData.PrimaryColor = new ColorData(r, g, b, (滑块a != null) ? 滑块a.value : 1f); Slider hdr滑块r = 材质数据获取.hdr滑块r; float r2 = ((hdr滑块r != null) ? hdr滑块r.value : 0f); Slider hdr滑块g = 材质数据获取.hdr滑块g; float g2 = ((hdr滑块g != null) ? hdr滑块g.value : 0f); Slider hdr滑块b = 材质数据获取.hdr滑块b; float b2 = ((hdr滑块b != null) ? hdr滑块b.value : 0f); Slider hdr滑块a = 材质数据获取.hdr滑块a; mODMaterialData.EmissionColor = new ColorData(r2, g2, b2, (hdr滑块a != null) ? hdr滑块a.value : 1f); Slider hdr强度滑块 = 材质数据获取.hdr强度滑块; mODMaterialData.EmissionIntensity = ((hdr强度滑块 != null) ? hdr强度滑块.value : 0f); if ((Object)(object)材质数据获取.渲染模式枚举 != (Object)null) { int value = 材质数据获取.渲染模式枚举.value; mODMaterialData.RenderMode = (RenderMode)value; } else { mODMaterialData.RenderMode = RenderMode.Opaque; } TMP_InputField 主帖图输入 = 材质数据获取.主帖图输入; mODMaterialData.MainTexturePath = ((主帖图输入 != null) ? 主帖图输入.text : null) ?? ""; TMP_InputField 法线贴图输入 = 材质数据获取.法线贴图输入; mODMaterialData.NormalMapPath = ((法线贴图输入 != null) ? 法线贴图输入.text : null) ?? ""; TMP_InputField 金属光泽图输入 = 材质数据获取.金属光泽图输入; mODMaterialData.MetallicMapPath = ((金属光泽图输入 != null) ? 金属光泽图输入.text : null) ?? ""; Slider 金属度滑块 = 材质数据获取.金属度滑块; mODMaterialData.Metallic = ((金属度滑块 != null) ? 金属度滑块.value : 0f); Slider 光滑度滑块 = 材质数据获取.光滑度滑块; mODMaterialData.Smoothness = ((光滑度滑块 != null) ? 光滑度滑块.value : 0.5f); Slider 滑块a2 = 材质数据获取.滑块a; mODMaterialData.Alpha = ((滑块a2 != null) ? 滑块a2.value : 1f); mODMaterialData.IsGlowMaterial = mODMaterialData.EmissionIntensity > 0.1f || mODMaterialData.EmissionColor.R > 0.1f || mODMaterialData.EmissionColor.G > 0.1f || mODMaterialData.EmissionColor.B > 0.1f; if (mODMaterialData.IsGlowMaterial && mODMaterialData.GlowMultiplier <= 1f) { mODMaterialData.GlowMultiplier = ((mODMaterialData.EmissionIntensity > 0f) ? mODMaterialData.EmissionIntensity : 2f); } } return mODMaterialData; } catch (Exception ex) { Debug.LogError((object)("[色彩编辑器] 创建材质数据异常: " + ex.Message)); return null; } } private MODMaterialConfig 查找或创建配置文件(string 配置名称) { string path = Path.Combine(配置文件存储路径, 配置名称 + ".json"); if (File.Exists(path)) { try { string text = File.ReadAllText(path); MODMaterialConfig mODMaterialConfig = JsonConvert.DeserializeObject(text); if (mODMaterialConfig != null) { Debug.Log((object)("[色彩编辑器] 找到已存在的配置文件: " + 配置名称)); return mODMaterialConfig; } } catch (Exception ex) { Debug.LogWarning((object)("[色彩编辑器] 读取配置文件失败,将创建新配置: " + ex.Message)); } } Debug.Log((object)("[色彩编辑器] 创建新配置文件: " + 配置名称)); return new MODMaterialConfig { Version = 1, ConfigName = 配置名称, Global = new GlobalSettings { OverrideExisting = false, AutoLoadOnStart = true, DefaultParentCategory = "自定义材质", DebugMode = false }, Materials = new List() }; } private void 添加或更新材质(MODMaterialConfig 配置文件, MODMaterialData 材质数据) { if (配置文件.Materials == null) { 配置文件.Materials = new List(); } int num = 配置文件.Materials.FindIndex((MODMaterialData m) => m.Id == 材质数据.Id); if (num >= 0) { 配置文件.Materials[num] = 材质数据; Debug.Log((object)("[色彩编辑器] 更新材质: " + 材质数据.DisplayName + " (ID: " + 材质数据.Id + ")")); } else { 配置文件.Materials.Add(材质数据); Debug.Log((object)("[色彩编辑器] 添加新材质: " + 材质数据.DisplayName + " (ID: " + 材质数据.Id + ")")); } if (!string.IsNullOrEmpty(材质数据.ParentCategory) && string.IsNullOrEmpty(配置文件.Global.DefaultParentCategory)) { 配置文件.Global.DefaultParentCategory = 材质数据.ParentCategory; } } private void 保存配置文件到磁盘(MODMaterialConfig 配置文件, string 配置名称) { string text = Path.Combine(配置文件存储路径, 配置名称 + ".json"); string contents = JsonConvert.SerializeObject((object)配置文件, (Formatting)1); File.WriteAllText(text, contents); Debug.Log((object)("[色彩编辑器] 配置文件已保存: " + text)); Debug.Log((object)$"[色彩编辑器] 当前配置包含 {配置文件.Materials.Count} 个材质"); } private void 重新加载资源() { try { 图片资源加载类.重新加载图片(); 调色板添加类.重置缓存(); 调色板添加类.初始化(); 重新加载所有配置到调色板(); Debug.Log((object)"[色彩编辑器] 资源重新加载完成"); } catch (Exception ex) { Debug.LogWarning((object)("[色彩编辑器] 重新加载资源失败: " + ex.Message)); } } private void 重新加载所有配置到调色板() { //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_01d3: Unknown result type (might be due to invalid IL or missing references) try { string[] files = Directory.GetFiles(配置文件存储路径, "*.json", SearchOption.TopDirectoryOnly); List list = new List(); string[] array = files; foreach (string path in array) { try { string text = File.ReadAllText(path); MODMaterialConfig mODMaterialConfig = JsonConvert.DeserializeObject(text); if (mODMaterialConfig != null && mODMaterialConfig.Materials != null && mODMaterialConfig.Materials.Count > 0) { list.Add(mODMaterialConfig); } } catch (Exception ex) { Debug.LogWarning((object)("读取配置文件失败: " + Path.GetFileName(path) + ", 错误: " + ex.Message)); } } Dictionary>> dictionary = new Dictionary>>(); foreach (MODMaterialConfig item in list) { if (!item.Global.AutoLoadOnStart) { continue; } foreach (MODMaterialData material in item.Materials) { if (!material.Enabled) { continue; } ColorPaletteData val = 调色板添加类.从配置创建颜色数据(material); if (!((Object)(object)val.m_material == (Object)null)) { string key = (string.IsNullOrEmpty(material.ParentCategory) ? item.Global.DefaultParentCategory : material.ParentCategory); string key2 = (string.IsNullOrEmpty(material.Subcategory) ? "默认" : material.Subcategory); if (!dictionary.ContainsKey(key)) { dictionary[key] = new Dictionary>(); } if (!dictionary[key].ContainsKey(key2)) { dictionary[key][key2] = new List(); } dictionary[key][key2].Add(val); } } } foreach (KeyValuePair>> item2 in dictionary) { foreach (KeyValuePair> item3 in item2.Value) { 调色板添加类.添加颜色分类(item2.Key, item3.Key, item3.Value); } } Debug.Log((object)$"[色彩编辑器] 重新加载了 {list.Count} 个配置文件"); } catch (Exception ex2) { Debug.LogError((object)("[色彩编辑器] 重新加载配置失败: " + ex2.Message)); } } private void 显示提示消息(string 消息) { Debug.Log((object)("[色彩编辑器提示] " + 消息)); } public void 加载配置到UI(string 配置名称, string 材质ID) { string path = Path.Combine(配置文件存储路径, 配置名称 + ".json"); if (!File.Exists(path)) { Debug.LogWarning((object)("[色彩编辑器] 配置文件不存在: " + 配置名称)); return; } try { string text = File.ReadAllText(path); MODMaterialConfig mODMaterialConfig = JsonConvert.DeserializeObject(text); if (mODMaterialConfig == null || mODMaterialConfig.Materials == null) { Debug.LogWarning((object)"[色彩编辑器] 配置文件解析失败"); return; } MODMaterialData mODMaterialData = mODMaterialConfig.Materials.FirstOrDefault((MODMaterialData m) => m.Id == 材质ID); if (mODMaterialData == null) { Debug.LogWarning((object)("[色彩编辑器] 未找到材质ID: " + 材质ID)); return; } ConfigName配置名称输入框.text = mODMaterialConfig.ConfigName; 材质标识id输入框.text = mODMaterialData.Id; 材质名称输入框.text = mODMaterialData.DisplayName; 材质描述输入框.text = mODMaterialData.Description; 着色器名称输入框.text = mODMaterialData.ShaderName; 父级名称输入框.text = mODMaterialData.ParentCategory; 子级名称输入框.text = mODMaterialData.Subcategory; if ((Object)(object)材质数据获取 != (Object)null) { 材质数据获取.滑块r.value = mODMaterialData.PrimaryColor.R; 材质数据获取.滑块g.value = mODMaterialData.PrimaryColor.G; 材质数据获取.滑块b.value = mODMaterialData.PrimaryColor.B; 材质数据获取.滑块a.value = mODMaterialData.Alpha; 材质数据获取.hdr滑块r.value = mODMaterialData.EmissionColor.R; 材质数据获取.hdr滑块g.value = mODMaterialData.EmissionColor.G; 材质数据获取.hdr滑块b.value = mODMaterialData.EmissionColor.B; 材质数据获取.hdr强度滑块.value = mODMaterialData.EmissionIntensity; 材质数据获取.渲染模式枚举.value = (int)mODMaterialData.RenderMode; 材质数据获取.主帖图输入.text = mODMaterialData.MainTexturePath; 材质数据获取.法线贴图输入.text = mODMaterialData.NormalMapPath; 材质数据获取.金属光泽图输入.text = mODMaterialData.MetallicMapPath; 材质数据获取.金属度滑块.value = mODMaterialData.Metallic; 材质数据获取.光滑度滑块.value = mODMaterialData.Smoothness; } Debug.Log((object)("[色彩编辑器] 已加载配置: " + 配置名称 + "/" + 材质ID)); } catch (Exception ex) { Debug.LogError((object)("[色彩编辑器] 加载配置失败: " + ex.Message)); } } } } namespace DingZhiTiaoSePan.物品添加类 { [Serializable] public class MODMaterialData { [JsonProperty("id")] public string Id = ""; [JsonProperty("ColorIndex")] public int ColorIndex = 999; [JsonProperty("display_name")] public string DisplayName = "新材质"; [JsonProperty("description")] public string Description = ""; [JsonProperty("enabled")] public bool Enabled = true; [JsonProperty("shader_name")] public string ShaderName = "Standard"; [JsonProperty("use_custom_shader")] public bool UseCustomShader = false; [JsonProperty("custom_shader_path")] public string CustomShaderPath = ""; [JsonProperty("primary_color")] public ColorData PrimaryColor = new ColorData(1f, 1f, 1f); [JsonProperty("secondary_color")] public ColorData SecondaryColor = new ColorData(1f, 1f, 1f); [JsonProperty("emission_color")] public ColorData EmissionColor = new ColorData(0f, 0f, 0f); [JsonProperty("emission_intensity")] public float EmissionIntensity = 1f; [JsonProperty("color_blend_mode")] public ColorBlendMode BlendMode = ColorBlendMode.Multiply; [JsonProperty("main_texture_path")] public string MainTexturePath = ""; [JsonProperty("normal_map_path")] public string NormalMapPath = ""; [JsonProperty("metallic_map_path")] public string MetallicMapPath = ""; [JsonProperty("tiling_enabled")] public bool TilingEnabled = false; [JsonProperty("tiling")] public Vector2Data Tiling = new Vector2Data(1f, 1f); [JsonProperty("offset")] public Vector2Data Offset = new Vector2Data(0f, 0f); [JsonProperty("custom_properties")] public List CustomProperties = new List(); [JsonProperty("metallic")] [Range(0f, 1f)] public float Metallic = 0f; [JsonProperty("smoothness")] [Range(0f, 1f)] public float Smoothness = 0.5f; [JsonProperty("alpha")] [Range(0f, 1f)] public float Alpha = 1f; [JsonProperty("glow_intensity")] [Range(0f, 8f)] public float GlowIntensity = 0f; [JsonProperty("render_mode")] public RenderMode RenderMode = RenderMode.Opaque; [JsonProperty("parent_category")] public string ParentCategory = ""; [JsonProperty("subcategory")] public string Subcategory = "自定义材质"; [JsonProperty("category_icon_path")] public string CategoryIconPath = ""; [JsonProperty("copy_from_template")] public bool CopyFromTemplate = true; [JsonProperty("template_material_name")] public string TemplateMaterialName = "4 M_Tabs_Red"; [JsonProperty("is_glow_material")] public bool IsGlowMaterial = false; [JsonProperty("glow_multiplier")] public float GlowMultiplier = 3f; [JsonProperty("sort_order")] public int SortOrder = 0; public bool IsValid() { if (!Enabled) { return false; } if (string.IsNullOrEmpty(DisplayName)) { return false; } if (string.IsNullOrEmpty(ShaderName)) { return false; } return true; } public string GetFullDisplayName() { return string.IsNullOrEmpty(ParentCategory) ? DisplayName : ("[" + ParentCategory + "/" + Subcategory + "] " + DisplayName); } public Color GetEmissionColorWithIntensity() { //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_004a: Unknown result type (might be due to invalid IL or missing references) return new Color(EmissionColor.R * EmissionIntensity, EmissionColor.G * EmissionIntensity, EmissionColor.B * EmissionIntensity, EmissionColor.A); } public Color GetMainColor() { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) return new Color(PrimaryColor.R, PrimaryColor.G, PrimaryColor.B, Alpha); } } [Serializable] public class ColorData { [JsonProperty("r")] [Range(0f, 8f)] public float R = 1f; [JsonProperty("g")] [Range(0f, 8f)] public float G = 1f; [JsonProperty("b")] [Range(0f, 8f)] public float B = 1f; [JsonProperty("a")] [Range(0f, 1f)] public float A = 1f; public ColorData() { } public ColorData(float r, float g, float b, float a = 1f) { R = r; G = g; B = b; A = a; } public Color ToColor() { //IL_0018: Unknown result type (might be due to invalid IL or missing references) return new Color(R, G, B, A); } public static ColorData FromColor(Color color) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) return new ColorData(color.r, color.g, color.b, color.a); } } [Serializable] public class Vector2Data { [JsonProperty("x")] public float X = 0f; [JsonProperty("y")] public float Y = 0f; public Vector2Data() { } public Vector2Data(float x, float y) { X = x; Y = y; } public Vector2 ToVector2() { //IL_000c: Unknown result type (might be due to invalid IL or missing references) return new Vector2(X, Y); } } [Serializable] public class CustomProperty { [JsonProperty("property_name")] public string PropertyName = ""; [JsonProperty("property_type")] public PropertyType Type = PropertyType.Float; [JsonProperty("float_value")] public float FloatValue = 0f; [JsonProperty("color_value")] public ColorData ColorValue = new ColorData(1f, 1f, 1f); [JsonProperty("vector_value")] public Vector2Data VectorValue = new Vector2Data(0f, 0f); [JsonProperty("texture_value")] public string TextureValue = ""; } public enum PropertyType { Float, Color, Vector2, Vector3, Vector4, Texture } public enum ColorBlendMode { Override, Multiply, Add, Subtract } public enum RenderMode { Opaque, Transparent, Cutout, Fade, Additive } [Serializable] public class MODMaterialConfig { [JsonProperty("version")] public int Version = 1; [JsonProperty("config_name")] public string ConfigName = "CustomColorPalette"; [JsonProperty("materials")] public List Materials = new List(); [JsonProperty("global_settings")] public GlobalSettings Global = new GlobalSettings(); public List GetEnabledMaterials() { return Materials.Where((MODMaterialData m) => m.Enabled && m.IsValid()).ToList(); } } [Serializable] public class GlobalSettings { [JsonProperty("override_existing")] public bool OverrideExisting = false; [JsonProperty("auto_load_on_start")] public bool AutoLoadOnStart = true; [JsonProperty("default_parent_category")] public string DefaultParentCategory = "自定义颜色"; [JsonProperty("debug_mode")] public bool DebugMode = false; } public static class 图片资源加载类 { private static readonly string 图片文件夹名称 = "Your_image_resources"; private static string 图片文件夹路径; private static Dictionary _图片资源字典 = new Dictionary(); private static readonly string[] 支持的图片格式 = new string[5] { "*.png", "*.jpg", "*.jpeg", "*.bmp", "*.tga" }; private static bool _是否已初始化 = false; public static void 初始化() { if (_是否已初始化) { return; } try { string location = Assembly.GetExecutingAssembly().Location; string directoryName = Path.GetDirectoryName(location); 图片文件夹路径 = Path.Combine(directoryName, 图片文件夹名称); Debug.Log((object)("[图片资源加载类] 图片资源文件夹路径: " + 图片文件夹路径)); if (!Directory.Exists(图片文件夹路径)) { Directory.CreateDirectory(图片文件夹路径); Debug.Log((object)("[图片资源加载类] 创建图片资源文件夹: " + 图片文件夹路径)); 生成示例图片说明(); } else { Debug.Log((object)("[图片资源加载类] 图片资源文件夹已存在: " + 图片文件夹路径)); } 加载所有图片(); _是否已初始化 = true; } catch (Exception ex) { Debug.LogError((object)("[图片资源加载类] 初始化失败: " + ex.Message)); } } private static void 生成示例图片说明() { try { string path = Path.Combine(图片文件夹路径, "使用说明.txt"); string contents = "=== 自定义图片资源使用说明 ===\r\n\r\n1. 支持的图片格式:PNG、JPG、JPEG、BMP、TGA\r\n\r\n2. 使用方法:\r\n - 将图片文件放入此文件夹\r\n - 在材质配置的 main_texture_path 字段中填写图片文件名(含扩展名)\r\n 例如:main_texture_path = \"我的纹理.png\"\r\n\r\n3.建议:\r\n -纹理尺寸建议为2的幂次方(如256x256、512x512)\r\n -法线贴图建议使用蓝色调的图片\r\n - 金属光泽贴图建议使用灰度图\r\n\r\n4.示例配置文件中的纹理名称:\r\n -main_texture_path: \"armor_texture.png\"\r\n - normal_map_path: \"armor_normal.png\"\r\n - metallic_map_path: \"armor_metallic.png\"\r\n\r\n5.注意事项:\r\n -文件名区分大小写\r\n - 确保文件扩展名正确\r\n - 修改图片后需要重启游戏才能生效\r\n\r\n=================================="; File.WriteAllText(path, contents); Debug.Log((object)"[图片资源加载类] 已生成使用说明文件"); } catch (Exception ex) { Debug.LogWarning((object)("[图片资源加载类] 生成说明文件失败: " + ex.Message)); } } private static void 加载所有图片() { _图片资源字典.Clear(); if (!Directory.Exists(图片文件夹路径)) { Debug.LogWarning((object)("[图片资源加载类] 图片文件夹不存在: " + 图片文件夹路径)); return; } int num = 0; int num2 = 0; string[] array = 支持的图片格式; foreach (string searchPattern in array) { string[] files = Directory.GetFiles(图片文件夹路径, searchPattern, SearchOption.AllDirectories); string[] array2 = files; foreach (string text in array2) { try { string fileName = Path.GetFileName(text); string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(text); Texture2D val = 加载图片从文件(text); if ((Object)(object)val != (Object)null) { _图片资源字典[fileName] = val; if (!_图片资源字典.ContainsKey(fileNameWithoutExtension)) { _图片资源字典[fileNameWithoutExtension] = val; } Debug.Log((object)$" [图片资源加载类] 已加载: {fileName} (尺寸: {((Texture)val).width}x{((Texture)val).height})"); num++; } else { Debug.LogWarning((object)(" [图片资源加载类] 加载失败: " + fileName)); num2++; } } catch (Exception ex) { Debug.LogError((object)(" [图片资源加载类] 加载异常: " + Path.GetFileName(text) + ", 错误: " + ex.Message)); num2++; } } } Debug.Log((object)$"[图片资源加载类] 图片加载完成 - 成功: {num}, 失败: {num2}, 总计: {_图片资源字典.Count} 个纹理资源"); } private static Texture2D 加载图片从文件(string 文件路径) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Expected O, but got Unknown try { byte[] array = File.ReadAllBytes(文件路径); Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false); if (ImageConversion.LoadImage(val, array)) { ((Texture)val).wrapMode = (TextureWrapMode)0; ((Texture)val).filterMode = (FilterMode)1; val.Compress(false); val.Apply(); return val; } Object.Destroy((Object)(object)val); return null; } catch (Exception ex) { Debug.LogError((object)("[图片资源加载类] 加载图片文件失败: " + 文件路径 + ", 错误: " + ex.Message)); return null; } } public static Texture2D 获取纹理(string 图片名称) { if (string.IsNullOrEmpty(图片名称)) { return null; } 确保初始化(); if (_图片资源字典.TryGetValue(图片名称, out var value)) { return value; } string[] array = new string[5] { ".png", ".jpg", ".jpeg", ".bmp", ".tga" }; string[] array2 = array; foreach (string text in array2) { string key = 图片名称 + text; if (_图片资源字典.TryGetValue(key, out var value2)) { return value2; } } string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(图片名称); if (_图片资源字典.TryGetValue(fileNameWithoutExtension, out var value3)) { return value3; } Debug.LogWarning((object)("[图片资源加载类] 找不到纹理: " + 图片名称)); return null; } public static bool 设置材质纹理(Material 材质, string 属性名, string 图片名称) { if ((Object)(object)材质 == (Object)null || string.IsNullOrEmpty(属性名) || string.IsNullOrEmpty(图片名称)) { return false; } Texture2D val = 获取纹理(图片名称); if ((Object)(object)val != (Object)null) { 材质.SetTexture(属性名, (Texture)(object)val); return true; } return false; } public static bool 图片是否存在(string 图片名称) { if (string.IsNullOrEmpty(图片名称)) { return false; } 确保初始化(); return _图片资源字典.ContainsKey(图片名称) || _图片资源字典.ContainsKey(Path.GetFileNameWithoutExtension(图片名称)); } public static List 获取所有图片名称() { 确保初始化(); return _图片资源字典.Keys.Where((string k) => k.Contains(".")).Distinct().ToList(); } public static void 重新加载图片() { Debug.Log((object)"[图片资源加载类] 重新加载所有图片..."); _是否已初始化 = false; _图片资源字典.Clear(); 初始化(); } private static void 确保初始化() { if (!_是否已初始化) { 初始化(); } } public static string 获取图片文件夹路径() { 确保初始化(); return 图片文件夹路径; } public static void 释放所有纹理() { foreach (Texture2D value in _图片资源字典.Values) { if ((Object)(object)value != (Object)null) { Object.Destroy((Object)(object)value); } } _图片资源字典.Clear(); Debug.Log((object)"[图片资源加载类] 已释放所有纹理资源"); } } public static class 调色板添加类 { private static UnitEditorColorPalette 颜色库; private static List _cachedParentCategories; private static bool _isInitialized; private static Material _模板材质; private static LandfallContentDatabase 内容数据库 => ContentDatabase.Instance().LandfallContentDatabase; public static void 初始化() { if ((Object)(object)颜色库 == (Object)null) { LandfallContentDatabase obj = 内容数据库; 颜色库 = ((obj != null) ? obj.GetUnitEditorColorPalette() : null); if ((Object)(object)颜色库 == (Object)null) { 颜色库 = Resources.FindObjectsOfTypeAll().FirstOrDefault(); } if ((Object)(object)颜色库 == (Object)null) { Debug.LogError((object)"[调色板添加类] 无法获取 UnitEditorColorPalette 实例"); return; } } _isInitialized = true; } private static void 确保初始化() { if (!_isInitialized || (Object)(object)颜色库 == (Object)null) { 初始化(); } } public static void 添加颜色分类(string 父分类名, string 子分类名, List 颜色列表, Sprite 分类图标 = null, Sprite 父分类图标 = null) { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005e: 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_0098: 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_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: 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_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Unknown result type (might be due to invalid IL or missing references) 确保初始化(); List list = 获取父分类列表(); ParentCatagories val = 查找或创建父分类(list, 父分类名, 父分类图标); List list2 = val.colorPaletteCatagories?.ToList() ?? new List(); ColorPaletteCatagory val2 = ((IEnumerable)list2).FirstOrDefault((Func)((ColorPaletteCatagory c) => c.name == 子分类名)); if (val2.name != null) { Debug.LogWarning((object)("[调色板添加类] 子分类 '" + 子分类名 + "' 已存在,将覆盖")); list2.Remove(val2); } ColorPaletteCatagory item = new ColorPaletteCatagory { name = 子分类名, Cataogry = (CatagoryType)0, Colors = 颜色列表.ToArray(), TeamColors = (TeamColorPaletteData[])(object)new TeamColorPaletteData[0], shardImage = 分类图标 }; list2.Add(item); val.colorPaletteCatagories = list2.ToArray(); int num = list.FindIndex((ParentCatagories p) => p.name == 父分类名); if (num >= 0) { list[num] = val; } 应用更改并刷新(list); } public static void 向子分类添加颜色(string 父分类名, string 子分类名, List 新颜色列表) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0066: 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) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_009b: 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) 确保初始化(); List list = 获取父分类列表(); ParentCatagories val = 查找父分类(list, 父分类名); if (val.colorPaletteCatagories == null) { Debug.LogError((object)("[调色板添加类] 父分类 '" + 父分类名 + "' 没有子分类")); return; } List list2 = val.colorPaletteCatagories.ToList(); ColorPaletteCatagory val2 = ((IEnumerable)list2).FirstOrDefault((Func)((ColorPaletteCatagory c) => c.name == 子分类名)); if (val2.name == null) { Debug.LogError((object)("[调色板添加类] 子分类 '" + 子分类名 + "' 不存在")); return; } List list3 = val2.Colors?.ToList() ?? new List(); list3.AddRange(新颜色列表); val2.Colors = list3.ToArray(); int index = list2.FindIndex((ColorPaletteCatagory c) => c.name == 子分类名); list2[index] = val2; val.colorPaletteCatagories = list2.ToArray(); 应用更改并刷新(list); } public static void 添加快捷颜色(List 颜色数据列表, string 子分类名 = "自定义颜色") { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_004f: 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_007f: Unknown result type (might be due to invalid IL or missing references) 确保初始化(); List list = 获取父分类列表(); if (list.Count == 0) { Debug.LogError((object)"[调色板添加类] 没有可用的父分类"); return; } ParentCatagories val = list[0]; List list2 = val.colorPaletteCatagories?.ToList() ?? new List(); list2.Add(new ColorPaletteCatagory { name = 子分类名, Cataogry = (CatagoryType)0, Colors = 颜色数据列表.ToArray(), TeamColors = (TeamColorPaletteData[])(object)new TeamColorPaletteData[0] }); val.colorPaletteCatagories = list2.ToArray(); 应用更改并刷新(list); } private static Material 获取模板材质() { //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Expected O, but got Unknown if ((Object)(object)_模板材质 != (Object)null) { return _模板材质; } _模板材质 = new Material(Shader.Find("Standard")); return _模板材质; } public static ColorPaletteData 从材质创建颜色数据(Material 源材质, Color 新颜色, string 新材质名) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Expected O, but got Unknown //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0034: 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_004e: 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_0087: 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_009d: Unknown result type (might be due to invalid IL or missing references) //IL_009e: 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_00a2: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)源材质 == (Object)null) { 源材质 = 获取模板材质(); } Material val = new Material(源材质); ((Object)val).name = 新材质名; val.color = 新颜色; val.mainTexture = null; if (新颜色.r > 1f || 新颜色.g > 1f || 新颜色.b > 1f) { val.EnableKeyword("_EMISSION"); val.SetColor("_EmissionColor", 新颜色); } return new ColorPaletteData { m_color = 新颜色, m_material = val, ColorIndex = 0 }; } public static ColorPaletteData 创建纯色颜色(Color 颜色, string 材质名) { //IL_0008: 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_0012: Unknown result type (might be due to invalid IL or missing references) Material 源材质 = 获取模板材质(); return 从材质创建颜色数据(源材质, 颜色, 材质名); } public static ColorPaletteData 创建发光颜色(Color 颜色, string 材质名, float 发光强度 = 3f) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_0011: 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_0021: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0034: 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) Material 源材质 = 获取模板材质(); Color 新颜色 = default(Color); ((Color)(ref 新颜色))..ctor(颜色.r * 发光强度, 颜色.g * 发光强度, 颜色.b * 发光强度, 颜色.a); return 从材质创建颜色数据(源材质, 新颜色, 材质名); } public static List 创建预设颜色列表() { //IL_0016: 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_0060: 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_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: 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_013e: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Unknown result type (might be due to invalid IL or missing references) //IL_0188: Unknown result type (might be due to invalid IL or missing references) //IL_01ad: Unknown result type (might be due to invalid IL or missing references) //IL_01d2: Unknown result type (might be due to invalid IL or missing references) //IL_01f7: Unknown result type (might be due to invalid IL or missing references) //IL_021c: Unknown result type (might be due to invalid IL or missing references) //IL_024a: Unknown result type (might be due to invalid IL or missing references) //IL_024f: Unknown result type (might be due to invalid IL or missing references) //IL_0259: Unknown result type (might be due to invalid IL or missing references) //IL_0266: Unknown result type (might be due to invalid IL or missing references) List<(Color, string)> list = new List<(Color, string)> { (new Color(1f, 0f, 0f), "纯红"), (new Color(0f, 1f, 0f), "纯绿"), (new Color(0f, 0f, 1f), "纯蓝"), (new Color(1f, 1f, 0f), "纯黄"), (new Color(1f, 0f, 1f), "品红"), (new Color(0f, 1f, 1f), "青色"), (new Color(1f, 0.5f, 0f), "橙色"), (new Color(0.5f, 0f, 0.5f), "紫色"), (new Color(0.5f, 0.5f, 0.5f), "灰色"), (new Color(1f, 1f, 1f), "白色"), (new Color(0f, 0f, 0f), "黑色"), (new Color(1f, 0.75f, 0.8f), "粉红"), (new Color(0.6f, 0.3f, 0f), "棕色"), (new Color(0.2f, 0.6f, 0.2f), "深绿"), (new Color(0.2f, 0.2f, 0.6f), "深蓝") }; List list2 = new List(); foreach (var (颜色, text) in list) { list2.Add(创建纯色颜色(颜色, "Custom_" + text)); } return list2; } public static List 从配置创建颜色列表(List 配置列表) { //IL_002c: 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_0032: 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) List list = new List(); foreach (MODMaterialData item in 配置列表) { if (item.Enabled) { ColorPaletteData val = 从配置创建颜色数据(item); if ((Object)(object)val.m_material != (Object)null) { list.Add(val); } } } return list; } public static ColorPaletteData 从配置创建颜色数据(MODMaterialData 配置) { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0034: 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_0052: 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_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: 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_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: 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_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Unknown result type (might be due to invalid IL or missing references) Material val = 创建配置文件材质(配置); if ((Object)(object)val == (Object)null) { Debug.LogError((object)("[调色板添加类] 创建材质失败: " + 配置.DisplayName)); return new ColorPaletteData { m_color = Color.white, m_material = 获取模板材质(), ColorIndex = 0 }; } Color mainColor = default(Color); if (配置.IsGlowMaterial) { ((Color)(ref mainColor))..ctor(配置.PrimaryColor.R * 配置.GlowMultiplier, 配置.PrimaryColor.G * 配置.GlowMultiplier, 配置.PrimaryColor.B * 配置.GlowMultiplier, 配置.PrimaryColor.A); } else { mainColor = 配置.GetMainColor(); } return new ColorPaletteData { m_color = mainColor, m_material = val, ColorIndex = 配置.ColorIndex }; } public static Material 创建配置文件材质(MODMaterialData 数据) { //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Expected O, but got Unknown //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Expected O, but got Unknown //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_016f: Expected O, but got Unknown //IL_01d2: Unknown result type (might be due to invalid IL or missing references) //IL_01d8: Expected O, but got Unknown //IL_01b3: Unknown result type (might be due to invalid IL or missing references) //IL_01b9: Expected O, but got Unknown if (数据 == null) { Debug.LogError((object)"[调色板添加类] 配置数据为空"); return 获取模板材质(); } Material val = null; if (数据.UseCustomShader && !string.IsNullOrEmpty(数据.CustomShaderPath)) { try { Shader val2 = Resources.Load(数据.CustomShaderPath); if ((Object)(object)val2 != (Object)null) { val = new Material(val2); Debug.Log((object)("[调色板添加类] 使用自定义着色器: " + 数据.CustomShaderPath)); } else { Debug.LogWarning((object)("[调色板添加类] 找不到自定义着色器: " + 数据.CustomShaderPath + ",使用默认着色器")); } } catch (Exception ex) { Debug.LogError((object)("[调色板添加类] 加载自定义着色器失败: " + ex.Message)); } } if ((Object)(object)val == (Object)null && !string.IsNullOrEmpty(数据.ShaderName)) { Shader val3 = Shader.Find(数据.ShaderName); if ((Object)(object)val3 != (Object)null) { val = new Material(val3); Debug.Log((object)("[调色板添加类] 使用着色器: " + 数据.ShaderName)); } else { Debug.LogWarning((object)("[调色板添加类] 找不到着色器: " + 数据.ShaderName + ",尝试使用模板材质")); } } if ((Object)(object)val == (Object)null && 数据.CopyFromTemplate) { Material val4 = 获取模板材质(); if ((Object)(object)val4 != (Object)null) { val = new Material(val4); Debug.Log((object)("[调色板添加类] 使用模板材质复制: " + ((Object)val4).name)); } } if ((Object)(object)val == (Object)null) { Shader val5 = Shader.Find("Standard"); if ((Object)(object)val5 != (Object)null) { val = new Material(val5); Debug.Log((object)"[调色板添加类] 使用Standard着色器作为保底"); } else { val = new Material(Shader.Find("Diffuse")); } } ((Object)val).name = (string.IsNullOrEmpty(数据.DisplayName) ? "CustomMaterial" : 数据.DisplayName); 应用材质属性(val, 数据); return val; } private static void 应用材质属性(Material 材质, MODMaterialData 数据) { //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0077: 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_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_03e2: Unknown result type (might be due to invalid IL or missing references) //IL_0414: Unknown result type (might be due to invalid IL or missing references) //IL_0419: Unknown result type (might be due to invalid IL or missing references) //IL_0461: Unknown result type (might be due to invalid IL or missing references) //IL_0466: Unknown result type (might be due to invalid IL or missing references) //IL_04b3: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_0216: Unknown result type (might be due to invalid IL or missing references) //IL_021b: Unknown result type (might be due to invalid IL or missing references) //IL_022f: Unknown result type (might be due to invalid IL or missing references) //IL_0294: Unknown result type (might be due to invalid IL or missing references) //IL_024e: Unknown result type (might be due to invalid IL or missing references) //IL_02e4: Unknown result type (might be due to invalid IL or missing references) //IL_02e9: Unknown result type (might be due to invalid IL or missing references) //IL_02f1: Unknown result type (might be due to invalid IL or missing references) //IL_02f6: Unknown result type (might be due to invalid IL or missing references) //IL_02fe: Unknown result type (might be due to invalid IL or missing references) //IL_030c: Unknown result type (might be due to invalid IL or missing references) //IL_032c: Unknown result type (might be due to invalid IL or missing references) //IL_033a: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)材质 == (Object)null || 数据 == null) { return; } Color mainColor = default(Color); if (数据.IsGlowMaterial) { ((Color)(ref mainColor))..ctor(数据.PrimaryColor.R * 数据.GlowMultiplier, 数据.PrimaryColor.G * 数据.GlowMultiplier, 数据.PrimaryColor.B * 数据.GlowMultiplier, 数据.PrimaryColor.A); } else { mainColor = 数据.GetMainColor(); } 材质.SetColor("_Color", mainColor); 材质.SetColor("_MainColor", mainColor); 材质.SetColor("_TintColor", mainColor); if ((Object)(object)材质.shader != (Object)null && ((Object)材质.shader).name.Contains("Unlit")) { 材质.SetColor("_MainColor", mainColor); } if (数据.SecondaryColor != null) { Color val = default(Color); ((Color)(ref val))..ctor(数据.SecondaryColor.R, 数据.SecondaryColor.G, 数据.SecondaryColor.B, 数据.SecondaryColor.A); 材质.SetColor("_SecondaryColor", val); 材质.SetColor("_TintColor2", val); } if ((Object)(object)材质.shader != (Object)null && ((Object)材质.shader).name == "Standard") { 材质.SetFloat("_Metallic", 数据.Metallic); 材质.SetFloat("_Glossiness", 数据.Smoothness); } else { if (材质.HasProperty("_Metallic")) { 材质.SetFloat("_Metallic", 数据.Metallic); } if (材质.HasProperty("_Glossiness")) { 材质.SetFloat("_Glossiness", 数据.Smoothness); } if (材质.HasProperty("_Smoothness")) { 材质.SetFloat("_Smoothness", 数据.Smoothness); } } if (数据.EmissionIntensity > 0f || 数据.IsGlowMaterial) { Color emissionColorWithIntensity = 数据.GetEmissionColorWithIntensity(); 材质.EnableKeyword("_EMISSION"); 材质.SetColor("_EmissionColor", emissionColorWithIntensity); if (材质.HasProperty("_Emission")) { 材质.SetColor("_Emission", emissionColorWithIntensity); } if (材质.HasProperty("_EmissionStrength")) { 材质.SetFloat("_EmissionStrength", 数据.EmissionIntensity); } } else if (材质.HasProperty("_EmissionColor")) { 材质.SetColor("_EmissionColor", Color.black); } if (数据.Alpha < 1f || 数据.RenderMode == RenderMode.Transparent) { 设置透明渲染模式(材质, 数据); } 应用纹理(材质, 数据); if (数据.TilingEnabled) { Vector2 val2 = 数据.Tiling.ToVector2(); Vector2 val3 = 数据.Offset.ToVector2(); 材质.SetTextureScale("_MainTex", val2); 材质.SetTextureOffset("_MainTex", val3); if (材质.HasProperty("_DetailAlbedoMap")) { 材质.SetTextureScale("_DetailAlbedoMap", val2); 材质.SetTextureOffset("_DetailAlbedoMap", val3); } } foreach (CustomProperty customProperty in 数据.CustomProperties) { try { switch (customProperty.Type) { case PropertyType.Float: if (材质.HasProperty(customProperty.PropertyName)) { 材质.SetFloat(customProperty.PropertyName, customProperty.FloatValue); } break; case PropertyType.Color: if (材质.HasProperty(customProperty.PropertyName)) { 材质.SetColor(customProperty.PropertyName, customProperty.ColorValue.ToColor()); } break; case PropertyType.Vector2: if (材质.HasProperty(customProperty.PropertyName)) { 材质.SetVector(customProperty.PropertyName, Vector4.op_Implicit(customProperty.VectorValue.ToVector2())); } break; case PropertyType.Vector3: if (材质.HasProperty(customProperty.PropertyName)) { 材质.SetVector(customProperty.PropertyName, Vector4.op_Implicit(new Vector3(customProperty.VectorValue.X, customProperty.VectorValue.Y, 0f))); } break; case PropertyType.Vector4: if (材质.HasProperty(customProperty.PropertyName)) { 材质.SetVector(customProperty.PropertyName, new Vector4(customProperty.VectorValue.X, customProperty.VectorValue.Y, 0f, 0f)); } break; case PropertyType.Texture: if (!string.IsNullOrEmpty(customProperty.TextureValue) && 材质.HasProperty(customProperty.PropertyName)) { Texture2D val4 = 图片资源加载类.获取纹理(customProperty.TextureValue); if ((Object)(object)val4 != (Object)null) { 材质.SetTexture(customProperty.PropertyName, (Texture)(object)val4); } } break; } } catch (Exception ex) { Debug.LogWarning((object)("[调色板添加类] 设置属性失败: " + customProperty.PropertyName + ", 错误: " + ex.Message)); } } } private static void 设置透明渲染模式(Material 材质, MODMaterialData 数据) { //IL_0189: Unknown result type (might be due to invalid IL or missing references) //IL_018e: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Unknown result type (might be due to invalid IL or missing references) switch (数据.RenderMode) { case RenderMode.Transparent: 材质.SetFloat("_Mode", 3f); 材质.SetInt("_SrcBlend", 5); 材质.SetInt("_DstBlend", 10); 材质.SetInt("_ZWrite", 0); 材质.DisableKeyword("_ALPHATEST_ON"); 材质.EnableKeyword("_ALPHABLEND_ON"); 材质.DisableKeyword("_ALPHAPREMULTIPLY_ON"); 材质.renderQueue = 3000; break; case RenderMode.Cutout: 材质.SetFloat("_Mode", 1f); 材质.SetInt("_SrcBlend", 1); 材质.SetInt("_DstBlend", 0); 材质.EnableKeyword("_ALPHATEST_ON"); 材质.DisableKeyword("_ALPHABLEND_ON"); 材质.DisableKeyword("_ALPHAPREMULTIPLY_ON"); 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: 材质.SetInt("_SrcBlend", 1); 材质.SetInt("_DstBlend", 1); 材质.EnableKeyword("_ALPHABLEND_ON"); 材质.DisableKeyword("_ALPHATEST_ON"); break; } Color color = 材质.color; color.a = 数据.Alpha; 材质.color = color; } private static void 应用纹理(Material 材质, MODMaterialData 数据) { if (!string.IsNullOrEmpty(数据.MainTexturePath)) { Texture2D val = 图片资源加载类.获取纹理(数据.MainTexturePath); if ((Object)(object)val != (Object)null) { 材质.SetTexture("_MainTex", (Texture)(object)val); 材质.SetTexture("_MainTexture", (Texture)(object)val); } } if (!string.IsNullOrEmpty(数据.NormalMapPath)) { Texture2D val2 = 图片资源加载类.获取纹理(数据.NormalMapPath); if ((Object)(object)val2 != (Object)null) { 材质.SetTexture("_BumpMap", (Texture)(object)val2); 材质.EnableKeyword("_NORMALMAP"); } } if (!string.IsNullOrEmpty(数据.MetallicMapPath)) { Texture2D val3 = 图片资源加载类.获取纹理(数据.MetallicMapPath); if ((Object)(object)val3 != (Object)null) { 材质.SetTexture("_MetallicGlossMap", (Texture)(object)val3); 材质.EnableKeyword("_METALLICGLOSSMAP"); } } } public static List 从AssetBundle加载材质(string 资源流名称) { //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0066: 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) List list = new List(); try { using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(资源流名称); if (stream == null) { Debug.LogError((object)("[调色板添加类] 找不到嵌入资源: " + 资源流名称)); return list; } AssetBundle val = AssetBundle.LoadFromStream(stream); Material[] array = val.LoadAllAssets(); foreach (Material val2 in array) { list.Add(new ColorPaletteData { m_color = val2.color, m_material = val2, ColorIndex = 0 }); } val.Unload(false); } catch (Exception ex) { Debug.LogError((object)("[调色板添加类] 加载AssetBundle失败: " + ex.Message)); } return list; } public static List 获取父分类列表() { if (_cachedParentCategories != null) { return _cachedParentCategories; } FieldInfo field = typeof(UnitEditorColorPalette).GetField("m_ColorPalleteParentCatagories", BindingFlags.Instance | BindingFlags.NonPublic); if (field == null) { Debug.LogError((object)"[调色板添加类] 无法获取 m_ColorPalleteParentCatagories 字段"); return new List(); } _cachedParentCategories = ((field.GetValue(颜色库) is ParentCatagories[] source) ? source.ToList() : null) ?? new List(); return _cachedParentCategories; } private static ParentCatagories 查找父分类(List 列表, string 名称) { //IL_001b: 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_0021: 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_0046: 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) ParentCatagories val = ((IEnumerable)列表).FirstOrDefault((Func)((ParentCatagories p) => p.name == 名称)); if (val.name == null) { throw new Exception("找不到父分类: " + 名称); } return val; } public static ParentCatagories 查找或创建父分类(List 列表, string 名称, Sprite 色轮图标) { //IL_001b: 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_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0035: 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_0061: 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_007a: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) ParentCatagories val = ((IEnumerable)列表).FirstOrDefault((Func)((ParentCatagories p) => p.name == 名称)); if (val.name != null) { return val; } ParentCatagories item = new ParentCatagories { name = 名称, colorPaletteCatagories = (ColorPaletteCatagory[])(object)new ColorPaletteCatagory[0], colorWheelSprite = 色轮图标 }; 列表.Add(item); return 列表.First((ParentCatagories p) => p.name == 名称); } public static void 应用更改并刷新(List 父分类列表) { FieldInfo field = typeof(UnitEditorColorPalette).GetField("m_ColorPalleteParentCatagories", BindingFlags.Instance | BindingFlags.NonPublic); if (field != null) { field.SetValue(颜色库, 父分类列表.ToArray()); _cachedParentCategories = null; } MethodInfo method = typeof(UnitEditorColorPalette).GetMethod("Initialize", BindingFlags.Instance | BindingFlags.Public); if (method != null) { method.Invoke(颜色库, null); } Debug.Log((object)$"[调色板添加类] 调色板已刷新,当前父分类数: {父分类列表.Count}"); } public static void 打印调色板信息() { //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_005f: Unknown result type (might be due to invalid IL or missing references) //IL_006e: 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_0084: Unknown result type (might be due to invalid IL or missing references) //IL_008c: 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) 确保初始化(); List list = 获取父分类列表(); Debug.Log((object)"=== 调色板信息 ==="); Debug.Log((object)$"父分类数量: {list.Count}"); foreach (ParentCatagories item in list) { Debug.Log((object)(" 父分类: " + item.name)); if (item.colorPaletteCatagories != null) { ColorPaletteCatagory[] colorPaletteCatagories = item.colorPaletteCatagories; foreach (ColorPaletteCatagory val in colorPaletteCatagories) { string name = val.name; ColorPaletteData[] colors = val.Colors; Debug.Log((object)$" 子分类: {name} - 颜色数: {((colors != null) ? colors.Length : 0)}"); } } } } public static void 重置缓存() { _cachedParentCategories = null; _isInitialized = false; 颜色库 = null; _模板材质 = null; } } } namespace DingZhiTiaoSePan.ui组件 { public class 着色器下拉菜单初始化器 : MonoBehaviour { [Header("组件引用")] [SerializeField] private TMP_Dropdown 着色器下拉菜单; [SerializeField] private TMP_InputField 同步到输入框; [Header("设置")] [SerializeField] private bool 在Awake时初始化 = true; [SerializeField] private string 默认选中的着色器 = "Standard"; [SerializeField] private bool 允许手动输入 = true; [SerializeField] private bool 输入时自动匹配下拉选项 = true; [Header("自动完成设置")] [SerializeField] private bool 启用自动完成 = true; [SerializeField] private GameObject 自动完成面板; [SerializeField] private TMP_Text 自动完成提示文本; private List 当前着色器列表; private bool 正在同步 = false; private void Awake() { if (在Awake时初始化) { 初始化下拉菜单(); } } private void OnEnable() { if ((Object)(object)着色器下拉菜单 != (Object)null) { ((UnityEvent)(object)着色器下拉菜单.onValueChanged).AddListener((UnityAction)当下拉菜单选择改变时); } if ((Object)(object)同步到输入框 != (Object)null && 允许手动输入) { ((UnityEvent)(object)同步到输入框.onValueChanged).AddListener((UnityAction)当输入框内容改变时); ((UnityEvent)(object)同步到输入框.onEndEdit).AddListener((UnityAction)当输入框编辑完成时); } } private void OnDisable() { if ((Object)(object)着色器下拉菜单 != (Object)null) { ((UnityEvent)(object)着色器下拉菜单.onValueChanged).RemoveListener((UnityAction)当下拉菜单选择改变时); } if ((Object)(object)同步到输入框 != (Object)null && 允许手动输入) { ((UnityEvent)(object)同步到输入框.onValueChanged).RemoveListener((UnityAction)当输入框内容改变时); ((UnityEvent)(object)同步到输入框.onEndEdit).RemoveListener((UnityAction)当输入框编辑完成时); } } public void 初始化下拉菜单() { //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Expected O, but got Unknown if (着色器资源获取类.所有着色器名称 == null) { 着色器资源获取类.初始化着色器列表(); } if ((Object)(object)着色器下拉菜单 == (Object)null) { 着色器下拉菜单 = ((Component)this).GetComponent(); if ((Object)(object)着色器下拉菜单 == (Object)null) { Debug.LogError((object)"找不到 TMP_Dropdown 组件!"); return; } } 当前着色器列表 = 着色器资源获取类.获取着色器名称列表(); if (当前着色器列表.Count == 0) { Debug.LogWarning((object)"没有找到任何着色器!"); return; } 着色器下拉菜单.ClearOptions(); List list = new List(); foreach (string item in 当前着色器列表) { list.Add(new OptionData(item)); } 着色器下拉菜单.AddOptions(list); int num = 当前着色器列表.IndexOf(默认选中的着色器); if (num >= 0) { 着色器下拉菜单.value = num; Debug.Log((object)("已设置默认选中: " + 默认选中的着色器)); } else { Debug.LogWarning((object)("未找到默认着色器 '" + 默认选中的着色器 + "',已选中第一个选项")); 着色器下拉菜单.value = 0; } 着色器下拉菜单.RefreshShownValue(); 同步到输入框内容(获取当前选中着色器名称()); Debug.Log((object)$"下拉菜单初始化完成,共 {list.Count} 个着色器选项"); } private void 当下拉菜单选择改变时(int index) { if (!正在同步) { 正在同步 = true; string text = 获取当前选中着色器名称(); 同步到输入框内容(text); 当着色器改变时(text); 正在同步 = false; } } private void 当输入框内容改变时(string inputText) { if (允许手动输入 && !正在同步 && 启用自动完成) { 显示自动完成建议(inputText); } } private void 当输入框编辑完成时(string inputText) { //IL_00c1: Unknown result type (might be due to invalid IL or missing references) if (!允许手动输入 || 正在同步) { return; } 正在同步 = true; if (输入时自动匹配下拉选项 && 当前着色器列表 != null) { int num = 查找最匹配的着色器(inputText); if (num >= 0) { 着色器下拉菜单.value = num; 同步到输入框内容(当前着色器列表[num]); Debug.Log((object)("自动匹配到着色器: " + 当前着色器列表[num])); } else { Debug.LogWarning((object)("未找到匹配的着色器: " + inputText)); if ((Object)(object)同步到输入框 != (Object)null) { ((Graphic)同步到输入框.textComponent).color = Color.red; } } } if (启用自动完成) { 隐藏自动完成建议(); } 正在同步 = false; } private void 同步到输入框内容(string content) { //IL_0058: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)同步到输入框 != (Object)null && content != null) { if (同步到输入框.onValueChanged != null) { } 同步到输入框.text = content; if ((Object)(object)同步到输入框 != (Object)null) { ((Graphic)同步到输入框.textComponent).color = Color.white; } } } private int 查找最匹配的着色器(string input) { if (string.IsNullOrEmpty(input) || 当前着色器列表 == null) { return -1; } int num = 当前着色器列表.FindIndex((string name) => name.Equals(input, StringComparison.OrdinalIgnoreCase)); if (num >= 0) { return num; } int num2 = 当前着色器列表.FindIndex((string name) => name.IndexOf(input, StringComparison.OrdinalIgnoreCase) >= 0); if (num2 >= 0) { return num2; } string[] array = input.ToLower().Split(' ', '/', '\\'); int num3 = -1; int num4 = 0; for (int num5 = 0; num5 < 当前着色器列表.Count; num5++) { string text = 当前着色器列表[num5].ToLower(); int num6 = 0; string[] array2 = array; foreach (string value in array2) { if (!string.IsNullOrEmpty(value) && text.Contains(value)) { num6++; } } if (num6 > num4) { num4 = num6; num3 = num5; } } return (num4 > 0) ? num3 : (-1); } private void 显示自动完成建议(string input) { if (string.IsNullOrEmpty(input) || 当前着色器列表 == null) { 隐藏自动完成建议(); return; } List list = 当前着色器列表.Where((string name) => name.IndexOf(input, StringComparison.OrdinalIgnoreCase) >= 0).Take(5).ToList(); if (list.Count > 0 && (Object)(object)自动完成提示文本 != (Object)null) { string text = "建议: " + string.Join(", ", list); 自动完成提示文本.text = text; if ((Object)(object)自动完成面板 != (Object)null) { 自动完成面板.SetActive(true); } } else if ((Object)(object)自动完成面板 != (Object)null) { 自动完成面板.SetActive(false); } } private void 隐藏自动完成建议() { if ((Object)(object)自动完成面板 != (Object)null) { 自动完成面板.SetActive(false); } if ((Object)(object)自动完成提示文本 != (Object)null) { 自动完成提示文本.text = ""; } } public string 获取当前选中着色器名称() { if ((Object)(object)着色器下拉菜单 == (Object)null) { return null; } int value = 着色器下拉菜单.value; return 着色器资源获取类.获取着色器名称(value); } public void 设置当前着色器(string shaderName) { if (当前着色器列表 == null) { 初始化下拉菜单(); } int num = 当前着色器列表.IndexOf(shaderName); if (num >= 0) { 着色器下拉菜单.value = num; return; } Debug.LogWarning((object)("未找到着色器: " + shaderName)); 同步到输入框内容(shaderName); } public void 刷新着色器列表() { 着色器资源获取类.初始化着色器列表(); 初始化下拉菜单(); } protected virtual void 当着色器改变时(string shaderName) { Debug.Log((object)("着色器已改变为: " + shaderName)); } public Shader 获取当前选中的着色器对象() { string text = 获取当前选中着色器名称(); if (!string.IsNullOrEmpty(text)) { return Shader.Find(text); } return null; } } public class 回到主菜单ui工具 : MonoBehaviour { public void 回到主菜单() { TABSSceneManager.LoadMainMenu(); } } }