跳转到内容
Drug Factory

Unity Roguelite 原型 #1

Roguelite 场景占位图 图 1:走廊与房间预制体

  • ScriptableObject 定义道具与敌人参数;
  • 使用 Addressables 动态加载房间与怪物;
  • 基于 URP 自定义光照与描边。
ItemDef.cs
using UnityEngine;
[CreateAssetMenu(menuName="Defs/Item")]
public class ItemDef : ScriptableObject
{
public string Id;
public string DisplayName;
public Sprite Icon; // [!code highlight]
[TextArea] public string Desc;// [!code highlight]
public int Rarity;
}
Spawner.cs
using UnityEngine;
using UnityEngine.AddressableAssets;
public class Spawner : MonoBehaviour
{
public AssetReferenceGameObject EnemyRef;
async void Start()
{
var handle = EnemyRef.InstantiateAsync(transform.position, Quaternion.identity);
await handle.Task; // [!code highlight]
}
}
SimpleOutline.hlsl
float4 OutlineFrag (v2f i) : SV_Target
{
float3 col = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, i.uv).rgb;
float edge = 1.0 - step(0.2, length(i.normalWS)); // [!code warning]
return float4(lerp(col, float3(0,0,0), edge * _OutlineStrength), 1);
}

引用:Addressables 避免场景冗大构建;ScriptableObject 让配置逻辑解耦。

Spawner.cs
await handle.Task;
try {
await handle.Task; // [!code highlight]
} catch (System.Exception ex) {
Debug.LogError($"Spawn failed: {ex.Message}"); // [!code error]
}

常见问题

  • Addressables Group 未标记可远程加载;
  • URP 渲染队列/深度写入设置不当导致描边穿透
CI: Unity batchmode Windows 构建
Unity.exe -batchmode -quit -projectPath . -buildTarget Win64 -executeMethod Build.Perform

展开:掉落表与权重 使用加权随机(alias method)~O(1) 采样,将稀有度映射到概率区间。

系统进度备注
房间生成规则+模板
敌人池🚧待补远程表
装备⏸️等待美术