private static void SetSceneCell(GridLayout grid, Transform parent, Vector3Int position, GameObject go, Vector3 offset, Vector3 scale, Quaternion orientation) { if (parent == null || go == null) { return; } GameObject instance = null; if (PrefabUtility.IsPartOfAnyPrefab(go)) { instance = (GameObject)PrefabUtility.InstantiatePrefab(go); } else { instance = Instantiate(go); instance.hideFlags = HideFlags.None; instance.name = go.name; } Undo.RegisterCreatedObjectUndo(instance, "Paint GameObject"); instance.transform.SetParent(parent); instance.transform.position = grid.LocalToWorld(grid.CellToLocalInterpolated(new Vector3Int(position.x, position.y, position.z) + new Vector3(.5f, .5f, .5f))); instance.transform.localRotation = orientation; instance.transform.localScale = scale; instance.transform.Translate(offset); }
private bool CheckIfChild(Object subEmitter) { ParticleSystem root = ParticleSystemEditorUtils.GetRoot(m_ParticleSystemUI.m_ParticleSystems[0]); ParticleSystem ps = subEmitter as ParticleSystem; if (IsChild(ps, root)) { return(true); } if (PrefabUtility.IsPartOfAnyPrefab(ps.gameObject) && !PrefabUtility.IsAnyPrefabInstanceRoot(ps.gameObject)) { string kPrefabReparentWarn = $"The assigned sub emitter is not part of the current effect because it is not a child of the current root Particle System GameObject: '{root.gameObject.name}'. The Particle System cannot be moved because it is a child of a Prefab instance."; EditorUtility.WarnPrefab(ps.gameObject, "Reparent GameObjects", kPrefabReparentWarn, "OK"); return(false); } string kReparentText = string.Format("The assigned sub emitter is not a child of the current root particle system GameObject: '{0}' and is therefore NOT considered a part of the current effect. Do you want to reparent it?", root.gameObject.name); if (EditorUtility.DisplayDialog( "Reparent GameObjects", kReparentText, "Yes, Reparent", "No, Remove")) { if (EditorUtility.IsPersistent(subEmitter)) { var newGo = Object.Instantiate(subEmitter) as GameObject; if (newGo != null) { newGo.transform.parent = m_ParticleSystemUI.m_ParticleSystems[0].transform; newGo.transform.localPosition = Vector3.zero; newGo.transform.localRotation = Quaternion.identity; } } else { if (ps != null) { Undo.SetTransformParent(ps.gameObject.transform.transform, m_ParticleSystemUI.m_ParticleSystems[0].transform, "Reparent sub emitter"); } } return(true); } else if (ps != null) { // Clear sub-emitters that have been deselected, to avoid having their particles left paused in the Scene View (case 946999) ps.Clear(true); } return(false); }
void SetPrefabModeButtonVisibility(GameObjectTreeViewItem item) { item.showPrefabModeButton = false; GameObject go = item.objectPPTR as GameObject; if (go == null) { return; } if (!PrefabUtility.IsPartOfAnyPrefab(go)) { return; } if (!PrefabUtility.IsAnyPrefabInstanceRoot(go)) { return; } // Don't show button if prefab asset is missing if (PrefabUtility.GetPrefabInstanceStatus(go) == PrefabInstanceStatus.Connected) { var source = PrefabUtility.GetOriginalSourceOrVariantRoot(go); if (source == null) { return; } // Don't show buttons for model prefabs but allow buttons for other immutables if (PrefabUtility.IsPartOfModelPrefab(source)) { return; } } else if (PrefabUtility.GetPrefabInstanceHandle(go) == null) { return; } else { var assetPath = PrefabUtility.GetAssetPathOfSourcePrefab(go); var broken = AssetDatabase.LoadMainAssetAtPath(assetPath) as BrokenPrefabAsset; if (broken == null || !broken.isPrefabFileValid) { return; } } item.showPrefabModeButton = true; }
void SetPrefabModeButtonVisibility(GameObjectTreeViewItem item) { item.showPrefabModeButton = false; GameObject go = item.objectPPTR as GameObject; if (go == null) { return; } if (!PrefabUtility.IsPartOfAnyPrefab(go)) { return; } if (!PrefabUtility.IsAnyPrefabInstanceRoot(go)) { return; } // Don't show button for disconnected prefab instances and if prefab asset is missing if (PrefabUtility.GetPrefabInstanceStatus(go) != PrefabInstanceStatus.Connected) { return; } var source = PrefabUtility.GetOriginalSourceOrVariantRoot(go); if (source == null) { return; } // Don't show buttons for model prefabs but allow buttons for other immutables if (PrefabUtility.IsPartOfModelPrefab(source)) { return; } item.showPrefabModeButton = true; }
void SetPrefabModeButtonVisibility(GameObjectTreeViewItem item) { item.showPrefabModeButton = false; GameObject go = item.objectPPTR as GameObject; if (go == null) { return; } if (!PrefabUtility.IsPartOfAnyPrefab(go)) { return; } if (!PrefabUtility.IsAnyPrefabInstanceRoot(go)) { return; } // Don't show button for disconnected prefab instances and if prefab asset is missing if (PrefabUtility.GetPrefabInstanceStatus(go) != PrefabInstanceStatus.Connected) { return; } // We can't simply check if the go is part of an immutable prefab, since that would check the asset of the // outermost prefab this go is part of. Instead we have to check original source or variant root // - the same one that would get opened if clicking the arrow. var source = PrefabUtility.GetOriginalSourceOrVariantRoot(go); if (source == null || PrefabUtility.IsPartOfImmutablePrefab(source)) { return; } item.showPrefabModeButton = true; }