feat(gameplay): 更新单位属性和材质配置 - 调整多个单位的基础生命值和攻击力数值平衡 - 修改CoreBattleGround材质的纹理缩放比例 - 更新地砖材质颜色为白色 - 优化纹理资源设置,调整最大纹理尺寸并添加PlayableAds平台支持 - 修复弓箭手技能目标查找逻辑,改用统一的敌人检测方法 - 为水晶矿添加中立阵营设置和光球视觉效果同步 - 调整预制体中的全局缩放参数 - 为狼人和石巨人添加NavMeshAgent组件支持 - 优化水晶矿血条显示位置计算方式 ```
81 lines
3.1 KiB
C#
81 lines
3.1 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Codely.Microsoft.CodeAnalysis;
|
|
using Codely.Microsoft.CodeAnalysis.CSharp;
|
|
using Codely.Microsoft.CodeAnalysis.CSharp.Syntax;
|
|
using UnityEngine;
|
|
using SyntaxTree = Codely.Microsoft.CodeAnalysis.SyntaxTree;
|
|
|
|
using UnityTcp.Editor.Helpers;
|
|
namespace UnityTcp.Editor.Tools
|
|
{
|
|
// Handles CS0103 for common UnityEngine.Object static methods called without qualification
|
|
// in Roslyn scripting context (e.g., FindObjectOfType<T>() → UnityEngine.Object.FindObjectOfType<T>()).
|
|
//
|
|
// In MonoBehaviour scripts these methods are inherited and can be called unqualified,
|
|
// but Roslyn scripting has no base class, so they must be explicitly qualified.
|
|
internal class FixUnqualifiedUnityStaticMethod : ScriptFixProvider
|
|
{
|
|
static readonly HashSet<string> k_UnityObjectMethods = new HashSet<string>
|
|
{
|
|
"FindObjectOfType",
|
|
"FindObjectsOfType",
|
|
"FindAnyObjectByType",
|
|
"FindObjectsByType",
|
|
"Instantiate",
|
|
"Destroy",
|
|
"DestroyImmediate",
|
|
"DontDestroyOnLoad"
|
|
};
|
|
|
|
const string k_Qualifier = "UnityEngine.Object.";
|
|
|
|
public override bool CanFix(Diagnostic diagnostic)
|
|
{
|
|
if (diagnostic.Id != "CS0103")
|
|
return false;
|
|
|
|
var message = diagnostic.GetMessage();
|
|
return k_UnityObjectMethods.Any(m => message.Contains($"'{m}'"));
|
|
}
|
|
|
|
public override bool ApplyFix(ref SyntaxTree tree, Diagnostic diagnostic, ScriptFixContext context)
|
|
{
|
|
// Extract method name from diagnostic message
|
|
var message = diagnostic.GetMessage();
|
|
string methodName = null;
|
|
foreach (var m in k_UnityObjectMethods)
|
|
{
|
|
if (message.Contains($"'{m}'"))
|
|
{
|
|
methodName = m;
|
|
break;
|
|
}
|
|
}
|
|
if (methodName == null)
|
|
return false;
|
|
|
|
// Locate the exact node via diagnostic span. Spans are always fresh here because
|
|
// CompileAndAutoFix recompiles after every tree-modifying fix before calling ApplyFix again.
|
|
var root = tree.GetRoot();
|
|
var spanNode = root.FindNode(diagnostic.Location.SourceSpan, getInnermostNodeForTie: true);
|
|
|
|
SyntaxNode target = null;
|
|
for (var n = spanNode; n != null; n = n.Parent)
|
|
{
|
|
if (n is IdentifierNameSyntax id && id.Identifier.Text == methodName) { target = n; break; }
|
|
if (n is GenericNameSyntax gen && gen.Identifier.Text == methodName) { target = n; break; }
|
|
}
|
|
|
|
if (target == null || target.Parent is MemberAccessExpressionSyntax)
|
|
return false;
|
|
|
|
var source = tree.GetText().ToString();
|
|
tree = SyntaxFactory.ParseSyntaxTree(source.Insert(target.SpanStart, k_Qualifier));
|
|
|
|
CodelyLogger.Log($"[FixUnqualifiedUnityStaticMethod] Qualified '{methodName}' → '{k_Qualifier}{methodName}'");
|
|
return true;
|
|
}
|
|
}
|
|
}
|