以下の内容はhttps://hacchi-man.hatenablog.com/entry/2021/04/24/220000より取得しました。


【Unity】PrefabMode でスクリプトからオブジェクトを選択状態にする

Hierarchy にあるオブジェクトを選択状態にするには

GameObject.Find でパスからオブジェクトを探して、Selection.activeGameObjectに代入するだけでできる

Selection.activeGameObject = GameObject.Find(path);

しかし、PrefabMode の場合 GameObject.Find でパスを指定しても探すことができない

そのため、PrefabStageUtility を利用してオブジェクトを探しだす必要がある

// 現在のPrefabMode の Stage を取得
var stage = PrefabStageUtility.GetCurrentPrefabStage();
 
// Root のオブジェクトを取得
var root = stage.prefabContentsRoot;
 
// パスに Root オブジェクト が含まれているので削除
var index = path.IndexOf("/") + 1;
path = path.Substring(index);
 
// root からパスを辿る
var findChild = root.transform.Find(path);
 
// 見つけたオブジェクトを代入
Selection.activeGameObject = findChild.gameObject;



以上の内容はhttps://hacchi-man.hatenablog.com/entry/2021/04/24/220000より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14