unity 编辑器修改 prefab 的 私有字段

发布时间 2023-06-20 15:01:17作者: 三页菌
        string prefabPath = idcardFunctionalPath;
        GameObject prefabInstance = PrefabUtility.LoadPrefabContents(prefabPath);
        SerializedObject serializedObject = new SerializedObject(prefabInstance.GetComponent<MyCube>());
        serializedObject.FindProperty("str").stringValue = "xxxxx";//字符串类型
        serializedObject.ApplyModifiedProperties();//应用修改
        PrefabUtility.SaveAsPrefabAsset(prefabInstance, prefabPath);//保存