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

        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);//保存

 

posted @ 2023-06-20 14:51  三页菌  阅读(21)  评论(0编辑  收藏  举报