【发布时间】:2021-01-22 15:28:25
【问题描述】:
最初的目标是制作一个编辑器脚本,并且仅在将单声道脚本附加到一个对象以使其生成新的 guid 但不确定如何执行时。所以现在我使用的是 ExecuteInEditMode 属性。
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[ExecuteInEditMode]
public class GenerateAutomaticGuid : MonoBehaviour
{
public string guid;
private Guid uniqueID;
// Start is called before the first frame update
void Start()
{
uniqueID = new System.Guid();
guid = uniqueID.ToString();
}
// Update is called once per frame
void Update()
{
}
}
字符串中的结果是:00000000-0000-0000-0000-000000000000 它在返回编辑器时执行,而不仅仅是在将脚本附加到游戏对象时执行。
主要目标是为脚本将附加到的每个游戏对象生成一个唯一的 ID。
我需要它,因为每次我加载保存的游戏时,游戏对象实例 ID 都会发生变化。 unity为objects生成新的id和保存的游戏文件上的id/s不一样。
【问题讨论】:
-
这能回答你的问题吗? Guid is all 0's (zeros)?