void DisplayPrefab() { if (prefab == null) { return; } stage = PrefabStageUtility.GetCurrentPrefabStage(); if (stage == null || !stage.IsPartOfPrefabContents(prefab)) { if (!AssetDatabase.OpenAsset(prefab)) { throw new Exception("Cant open prefab!"); } stage = PrefabStageUtility.GetCurrentPrefabStage(); } //stage = PrefabStageUtility.GetPrefabStage(prefab); // if(stage == null || !stage.IsPartOfPrefabContents(prefab)) // { // throw new Exception("Cant enter prefab stage!"); // } tabs.ActivateTab(1); }
private static void PlaceUIElementRoot(GameObject element, MenuCommand menuCommand) { GameObject parent = menuCommand.context as GameObject; bool explicitParentChoice = true; if (parent == null) { parent = GetOrCreateCanvasGameObject(); explicitParentChoice = false; // If in Prefab Mode, Canvas has to be part of Prefab contents, // otherwise use Prefab root instead. PrefabStage prefabStage = PrefabStageUtility.GetCurrentPrefabStage(); if (prefabStage != null && !prefabStage.IsPartOfPrefabContents(parent)) { parent = prefabStage.prefabContentsRoot; } } if (parent.GetComponentInParent <Canvas>() == null) { // Create canvas under context GameObject, // and make that be the parent which UI element is added under. GameObject canvas = MenuOptions.CreateNewUI(); canvas.transform.SetParent(parent.transform, false); parent = canvas; } // Setting the element to be a child of an element already in the scene should // be sufficient to also move the element to that scene. // However, it seems the element needs to be already in its destination scene when the // RegisterCreatedObjectUndo is performed; otherwise the scene it was created in is dirtied. SceneManager.MoveGameObjectToScene(element, parent.scene); Undo.RegisterCreatedObjectUndo(element, "Create " + element.name); if (element.transform.parent == null) { Undo.SetTransformParent(element.transform, parent.transform, "Parent " + element.name); } GameObjectUtility.EnsureUniqueNameForSibling(element); // We have to fix up the undo name since the name of the object was only known after reparenting it. Undo.SetCurrentGroupName("Create " + element.name); GameObjectUtility.SetParentAndAlign(element, parent); if (!explicitParentChoice) // not a context click, so center in sceneview { SetPositionVisibleinSceneView(parent.GetComponent <RectTransform>(), element.GetComponent <RectTransform>()); } Selection.activeGameObject = element; }
internal void UpdateGraphView(Connection[] connectionsArray) { //List<LogicNode> oldNodes = new List<LogicNode>(logicNodes.Where(l => !connections.Contains(l.connection))); //foreach (LogicNode l in oldNodes) // DestroyNode(l); var connections = connectionsArray.Where(c => IsVisible(c.transform.position)); PrefabStage stage = PrefabStageUtility.GetCurrentPrefabStage(); if (stage != null) { connections = connections.Where(c => stage.IsPartOfPrefabContents(c.gameObject)); } var removeLogicNodes = new List <LogicNode>(logicNodes.Where(l => l.Destroy || !connections.Any(c => c.Equals(l.connection)))); foreach (LogicNode l in removeLogicNodes) { DestroyNode(l); } var newConnections = connections.Where(c => !logicNodes.Exists(l => l.connection.Equals(c))); foreach (Connection c in newConnections) { GenerateNode(c); } DeleteEdges(); AddEdges(); if (selectionDragger.IsActive) { foreach (LogicNode l in logicNodes) { if (!l.selected) { l.UpdatePosition(); } else { l.UpdatePositionDrag(); } } } else { foreach (LogicNode l in logicNodes) { l.UpdatePosition(); } } viewTransform.position = Vector3.zero; }
private static void CreateGButton(MenuCommand menuCommand) { GameObject element = DefaultControls.CreateButton(GetResource()); var parent = menuCommand.context as GameObject; bool explicitParentChoice = true; if (parent == null) { parent = GetOrCreateCanvasGameObject(); explicitParentChoice = false; PrefabStage prefabStage = PrefabStageUtility.GetCurrentPrefabStage(); if (prefabStage != null && !prefabStage.IsPartOfPrefabContents(parent)) { parent = prefabStage.prefabContentsRoot; } } if (parent.GetComponentsInParent <Canvas>(true).Length == 0) { GameObject canvas = CreateNewUI(); canvas.transform.SetParent(parent.transform, false); parent = canvas; } SceneManager.MoveGameObjectToScene(element, parent.scene); Undo.RegisterCreatedObjectUndo(element, "Create " + element.name); if (element.transform.parent == null) { Undo.SetTransformParent(element.transform, parent.transform, "Parent " + element.name); } GameObjectUtility.EnsureUniqueNameForSibling(element); Undo.SetCurrentGroupName("Create " + element.name); GameObjectUtility.SetParentAndAlign(element, parent); if (!explicitParentChoice) { SetPositionVisibleinSceneView(parent.GetComponent <RectTransform>(), element.GetComponent <RectTransform>()); } Selection.activeGameObject = element; element.AddComponent <GButton>(); element.GetComponent <Button>().transition = Selectable.Transition.None; }
private static void PlaceUIElementRoot(GameObject element, MenuCommand menuCommand) { GameObject parent = menuCommand.context as GameObject; bool explicitParentChoice = true; if (parent == null) { parent = GetOrCreateCanvasGameObject(); explicitParentChoice = false; // If in Prefab Mode, Canvas has to be part of Prefab contents, // otherwise use Prefab root instead. PrefabStage prefabStage = PrefabStageUtility.GetCurrentPrefabStage(); if (prefabStage != null && !prefabStage.IsPartOfPrefabContents(parent)) { parent = prefabStage.prefabContentsRoot; } } if (parent.GetComponentsInParent <Canvas>(true).Length == 0) { // Create canvas under context GameObject, // and make that be the parent which UI element is added under. GameObject canvas = CreateNewUI(); Undo.SetTransformParent(canvas.transform, parent.transform, ""); parent = canvas; } GameObjectUtility.EnsureUniqueNameForSibling(element); SetParentAndAlign(element, parent); if (!explicitParentChoice) // not a context click, so center in sceneview { SetPositionVisibleinSceneView(parent.GetComponent <RectTransform>(), element.GetComponent <RectTransform>()); } // This call ensure any change made to created Objects after they where registered will be part of the Undo. Undo.RegisterFullObjectHierarchyUndo(parent == null ? element : parent, ""); // We have to fix up the undo name since the name of the object was only known after reparenting it. Undo.SetCurrentGroupName("Create " + element.name); Selection.activeGameObject = element; }
// UnityEditor.UI.MenuOptions private static void PlaceUIElementRoot(GameObject element, MenuCommand menuCommand) { GameObject gameObject = menuCommand.context as GameObject; bool flag = true; if (gameObject == null) { gameObject = SpringGUIMenuOptions.GetOrCreateCanvasGameObject(); flag = false; PrefabStage currentPrefabStage = PrefabStageUtility.GetCurrentPrefabStage(); if (currentPrefabStage != null && !currentPrefabStage.IsPartOfPrefabContents(gameObject)) { gameObject = currentPrefabStage.prefabContentsRoot; } } if (gameObject.GetComponentInParent <Canvas>() == null) { GameObject gameObject2 = SpringGUIMenuOptions.CreateNewUI(); gameObject2.transform.SetParent(gameObject.transform, false); gameObject = gameObject2; } SceneManager.MoveGameObjectToScene(element, gameObject.scene); Undo.RegisterCreatedObjectUndo(element, "Create " + element.name); if (element.transform.parent == null) { Undo.SetTransformParent(element.transform, gameObject.transform, "Parent " + element.name); } GameObjectUtility.EnsureUniqueNameForSibling(element); Undo.SetCurrentGroupName("Create " + element.name); GameObjectUtility.SetParentAndAlign(element, gameObject); if (!flag) { SpringGUIMenuOptions.SetPositionVisibleinSceneView(gameObject.GetComponent <RectTransform>(), element.GetComponent <RectTransform>()); } Selection.activeGameObject = element; }
protected static GameObject getSourcePrefab42019(GameObject gameObject, out bool isSceneObject, out GameObject sourceRoot, out string childPath) { GameObject source; PrefabAssetType assetType = PrefabUtility.GetPrefabAssetType(gameObject); PrefabInstanceStatus status = PrefabUtility.GetPrefabInstanceStatus(gameObject); PrefabStage stage = PrefabStageUtility.GetCurrentPrefabStage(); if (stage != null && stage.IsPartOfPrefabContents(gameObject)) { //编辑场景 isSceneObject = false; childPath = stage.prefabContentsRoot.transform.getChildPath(gameObject.transform); sourceRoot = AssetDatabase.LoadAssetAtPath <GameObject>(stage.prefabAssetPath); Transform sourceTransform = sourceRoot.transform.Find(childPath); if (sourceTransform != null) { source = sourceTransform.gameObject; } else { sourceRoot = null; childPath = string.Empty; return(null); } } else if (string.IsNullOrEmpty(gameObject.scene.path)) { //Assets isSceneObject = false; source = gameObject; sourceRoot = source.transform.root.gameObject; childPath = sourceRoot.transform.getChildPath(source.transform); //switch (assetType) //{ // case PrefabAssetType.Regular: // case PrefabAssetType.Variant: // case PrefabAssetType.Model: // case PrefabAssetType.MissingAsset: // case PrefabAssetType.NotAPrefab: // default: // break; //} } else { //场景物体 switch (status) { case PrefabInstanceStatus.Connected: switch (assetType) { case PrefabAssetType.Regular: case PrefabAssetType.Model: isSceneObject = false; source = PrefabUtility.GetCorrespondingObjectFromSource(gameObject); sourceRoot = source.transform.root.gameObject; childPath = sourceRoot.transform.getChildPath(source.transform); break; case PrefabAssetType.Variant: isSceneObject = false; source = PrefabUtility.GetCorrespondingObjectFromSource(gameObject); sourceRoot = source.transform.root.gameObject; childPath = sourceRoot.transform.getChildPath(source.transform); break; case PrefabAssetType.MissingAsset: case PrefabAssetType.NotAPrefab: default: isSceneObject = true; source = gameObject; sourceRoot = null; childPath = null; break; } break; case PrefabInstanceStatus.NotAPrefab: case PrefabInstanceStatus.MissingAsset: case PrefabInstanceStatus.Disconnected: default: isSceneObject = true; source = gameObject; sourceRoot = null; childPath = null; break; } } return(source); }