Minor work around

This commit is contained in:
Savya Bikram Shah
2026-06-25 11:19:01 +05:45
parent cf2f37be0c
commit ab706059c1
5 changed files with 218 additions and 22 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 2a01b1f301d474e39808b73160a98677
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,78 @@
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace Darkmatter.EditorTools
{
public static class AddSelectedPrefabToPaperRoot
{
[MenuItem("Tools/Colorbook/Add Selected Prefab To PaperRoot")]
private static void AddSelected()
{
var prefab = Selection.activeObject as GameObject;
if (prefab == null || PrefabUtility.GetPrefabAssetType(prefab) == PrefabAssetType.NotAPrefab)
{
EditorUtility.DisplayDialog(
"Select a prefab",
"Select a drawing, coloring, or animation prefab in the Project window first.",
"OK");
return;
}
var paperRoot = FindPaperRoot();
if (paperRoot == null)
{
EditorUtility.DisplayDialog(
"PaperRoot not found",
"Open the Gameplay scene and make sure it contains an object named PaperRoot.",
"OK");
return;
}
var instance = PrefabUtility.InstantiatePrefab(prefab, paperRoot.scene) as GameObject;
if (instance == null) return;
Undo.RegisterCreatedObjectUndo(instance, $"Add {prefab.name} to PaperRoot");
Undo.SetTransformParent(instance.transform, paperRoot.transform, "Parent prefab to PaperRoot");
if (instance.transform is RectTransform rectTransform)
{
rectTransform.anchorMin = Vector2.zero;
rectTransform.anchorMax = Vector2.one;
rectTransform.anchoredPosition = Vector2.zero;
rectTransform.sizeDelta = Vector2.zero;
rectTransform.localScale = Vector3.one;
}
else
{
instance.transform.localPosition = Vector3.zero;
instance.transform.localRotation = Quaternion.identity;
instance.transform.localScale = Vector3.one;
}
Selection.activeGameObject = instance;
EditorSceneManager.MarkSceneDirty(paperRoot.scene);
}
[MenuItem("Tools/Colorbook/Add Selected Prefab To PaperRoot", true)]
private static bool ValidateAddSelected()
{
return !EditorApplication.isPlayingOrWillChangePlaymode;
}
private static GameObject FindPaperRoot()
{
var activeScene = SceneManager.GetActiveScene();
foreach (var root in activeScene.GetRootGameObjects())
{
var transforms = root.GetComponentsInChildren<Transform>(true);
foreach (var candidate in transforms)
if (candidate.name == "PaperRoot")
return candidate.gameObject;
}
return null;
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 675d955c682824cd9904fb2e96517df1

File diff suppressed because one or more lines are too long

View File

@@ -795,7 +795,7 @@ PlayerSettings:
webEnableSubmoduleStrippingCompatibility: 0
scriptingDefineSymbols:
Android: SENTIS_ANALYTICS_ENABLED;APP_UI_EDITOR_ONLY
Standalone: SENTIS_ANALYTICS_ENABLED
Standalone: SENTIS_ANALYTICS_ENABLED;APP_UI_EDITOR_ONLY
iPhone: SENTIS_ANALYTICS_ENABLED;APP_UI_EDITOR_ONLY
additionalCompilerArguments: {}
platformArchitecture: {}