Minor work around
This commit is contained in:
8
Assets/Darkmatter/Code/Editor.meta
Normal file
8
Assets/Darkmatter/Code/Editor.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2a01b1f301d474e39808b73160a98677
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 675d955c682824cd9904fb2e96517df1
|
||||
File diff suppressed because one or more lines are too long
@@ -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: {}
|
||||
|
||||
Reference in New Issue
Block a user