-
Notifications
You must be signed in to change notification settings - Fork 117
Open
Description
Hi! I want to add a MonoScript to the file I'm editing but unfortunately its definition doesn't exist in this file, I've tried every other file containing that MonoScript to try to add it to the file I'm editing but it fails. error and not working.
I tried adding like this:
public AssetContainer addMonoBehaviour(string mName, AssetPPtr assetPPtr, AssetTypeValueField newBaseField, long newPathId)
{
var monoBehaviourClassId = (int)AssetClassID.MonoBehaviour;
mainInst.file.Metadata.ScriptTypes.Add(assetPPtr);
var scriptIndex = mainInst.file.Metadata.ScriptTypes.Count - 1;
//
newBaseField["m_GameObject.m_FileID"].AsInt = 0;
newBaseField["m_GameObject.m_PathID"].AsLong = 0;
newBaseField["m_Enabled"].AsByte = 1;
newBaseField["m_Script.m_FileID"].AsInt = assetPPtr.FileId;
newBaseField["m_Script.m_PathID"].AsLong = assetPPtr.PathId;
newBaseField["m_Name"].AsString = mName;
//
var classDatabase = assetsManager.LoadClassDatabaseFromPackage(mainInst.file.Metadata.UnityVersion);
var afile = mainInst.file;
var newInfo = AssetFileInfo.Create(afile, newPathId, monoBehaviourClassId, (ushort)scriptIndex, classDatabase, false);
newInfo.SetNewData(newBaseField);
mainInst.file.Metadata.AddAssetInfo(newInfo);
return new AssetContainer(newInfo, mainInst, newBaseField);
} The two parameters assetsPPtr and newBaseField were taken by me from another file containing the MonoScript I needed.
As a result, when I finished editing the file and tested it again with AssetStudio, I received the error as shown below:

Metadata
Metadata
Assignees
Labels
No labels