public static PrefabType GetPrefabType(Object target) { return(PrefabUtility.GetPrefabType(target)); }
public void OnSceneDrag(SceneView sceneView) { GameObject target = this.target as GameObject; switch (PrefabUtility.GetPrefabType(target)) { case PrefabType.Prefab: case PrefabType.ModelPrefab: { Event current = Event.current; EventType type = current.type; if (type != EventType.DragUpdated) { if (type == EventType.DragPerform) { string uniqueNameForSibling = GameObjectUtility.GetUniqueNameForSibling(null, dragObject.name); dragObject.hideFlags = HideFlags.None; Undo.RegisterCreatedObjectUndo(dragObject, "Place " + dragObject.name); EditorUtility.SetDirty(dragObject); DragAndDrop.AcceptDrag(); Selection.activeObject = dragObject; HandleUtility.ignoreRaySnapObjects = null; EditorWindow.mouseOverWindow.Focus(); dragObject.name = uniqueNameForSibling; dragObject = null; current.Use(); return; } if ((type == EventType.DragExited) && (dragObject != null)) { Object.DestroyImmediate(dragObject, false); HandleUtility.ignoreRaySnapObjects = null; dragObject = null; current.Use(); } } else { if (dragObject == null) { dragObject = (GameObject)PrefabUtility.InstantiatePrefab(PrefabUtility.FindPrefabRoot(target)); HandleUtility.ignoreRaySnapObjects = dragObject.GetComponentsInChildren <Transform>(); dragObject.hideFlags = HideFlags.HideInHierarchy; dragObject.name = target.name; } DragAndDrop.visualMode = DragAndDropVisualMode.Copy; object obj3 = HandleUtility.RaySnap(HandleUtility.GUIPointToWorldRay(current.mousePosition)); if (obj3 != null) { RaycastHit hit = (RaycastHit)obj3; float num = 0f; if (Tools.pivotMode == PivotMode.Center) { float num2 = HandleUtility.CalcRayPlaceOffset(HandleUtility.ignoreRaySnapObjects, hit.normal); if (num2 != float.PositiveInfinity) { num = Vector3.Dot(dragObject.transform.position, hit.normal) - num2; } } dragObject.transform.position = Matrix4x4.identity.MultiplyPoint(hit.point + ((Vector3)(hit.normal * num))); } else { dragObject.transform.position = HandleUtility.GUIPointToWorldRay(current.mousePosition).GetPoint(10f); } if (sceneView.in2DMode) { Vector3 position = dragObject.transform.position; position.z = PrefabUtility.FindPrefabRoot(target).transform.position.z; dragObject.transform.position = position; } current.Use(); } break; } } }
public override void OnInspectorGUI() { Rigidbody2D rigidbody2D = base.target as Rigidbody2D; base.serializedObject.Update(); EditorGUILayout.PropertyField(this.m_BodyType, new GUILayoutOption[0]); EditorGUILayout.PropertyField(this.m_Material, new GUILayoutOption[0]); EditorGUILayout.PropertyField(this.m_Simulated, new GUILayoutOption[0]); if (this.m_BodyType.hasMultipleDifferentValues) { EditorGUILayout.HelpBox("Cannot edit properties that are body type specific when the selection contains different body types.", MessageType.Info); } else { this.m_ShowIsStatic.target = (rigidbody2D.bodyType != RigidbodyType2D.Static); if (EditorGUILayout.BeginFadeGroup(this.m_ShowIsStatic.faded)) { this.m_ShowIsKinematic.target = (rigidbody2D.bodyType != RigidbodyType2D.Kinematic); if (EditorGUILayout.BeginFadeGroup(this.m_ShowIsKinematic.faded)) { EditorGUILayout.PropertyField(this.m_UseAutoMass, new GUILayoutOption[0]); if (!this.m_UseAutoMass.hasMultipleDifferentValues) { if (this.m_UseAutoMass.boolValue) { if (base.targets.Any((UnityEngine.Object x) => PrefabUtility.GetPrefabType(x) == PrefabType.Prefab || !(x as Rigidbody2D).gameObject.activeInHierarchy)) { EditorGUILayout.HelpBox("The auto mass value cannot be displayed for a prefab or if the object is not active. The value will be calculated for a prefab instance and when the object is active.", MessageType.Info); goto IL_161; } } EditorGUI.BeginDisabledGroup(rigidbody2D.useAutoMass); EditorGUILayout.PropertyField(this.m_Mass, new GUILayoutOption[0]); EditorGUI.EndDisabledGroup(); IL_161 :; } EditorGUILayout.PropertyField(this.m_LinearDrag, new GUILayoutOption[0]); EditorGUILayout.PropertyField(this.m_AngularDrag, new GUILayoutOption[0]); EditorGUILayout.PropertyField(this.m_GravityScale, new GUILayoutOption[0]); } Rigidbody2DEditor.FixedEndFadeGroup(this.m_ShowIsKinematic.faded); if (!this.m_ShowIsKinematic.target) { EditorGUILayout.PropertyField(this.m_UseFullKinematicContacts, new GUILayoutOption[0]); } EditorGUILayout.PropertyField(this.m_CollisionDetection, new GUILayoutOption[0]); EditorGUILayout.PropertyField(this.m_SleepingMode, new GUILayoutOption[0]); EditorGUILayout.PropertyField(this.m_Interpolate, new GUILayoutOption[0]); GUILayout.BeginHorizontal(new GUILayoutOption[0]); this.m_Constraints.isExpanded = EditorGUILayout.Foldout(this.m_Constraints.isExpanded, "Constraints", true); GUILayout.EndHorizontal(); RigidbodyConstraints2D intValue = (RigidbodyConstraints2D)this.m_Constraints.intValue; if (this.m_Constraints.isExpanded) { EditorGUI.indentLevel++; this.ToggleFreezePosition(intValue, Rigidbody2DEditor.m_FreezePositionLabel, 0, 1); this.ToggleFreezeRotation(intValue, Rigidbody2DEditor.m_FreezeRotationLabel, 2); EditorGUI.indentLevel--; } if (intValue == RigidbodyConstraints2D.FreezeAll) { EditorGUILayout.HelpBox("Rather than turning on all constraints, you may want to consider removing the Rigidbody2D component which makes any colliders static. This gives far better performance overall.", MessageType.Info); } } Rigidbody2DEditor.FixedEndFadeGroup(this.m_ShowIsStatic.faded); } base.serializedObject.ApplyModifiedProperties(); this.ShowBodyInfoProperties(); }
internal bool DrawInspector(Rect contentRect) { int num5; bool flag4; if (s_styles == null) { s_styles = new Styles(); } base.serializedObject.Update(); GameObject target = this.target as GameObject; EditorGUIUtility.labelWidth = 52f; bool enabled = GUI.enabled; GUI.enabled = true; GUI.Label(new Rect(contentRect.x, contentRect.y, contentRect.width, contentRect.height + 3f), GUIContent.none, EditorStyles.inspectorBig); GUI.enabled = enabled; float width = contentRect.width; float y = contentRect.y; GUIContent goIcon = null; PrefabType none = PrefabType.None; if (this.m_AllOfSamePrefabType) { none = PrefabUtility.GetPrefabType(target); switch (none) { case PrefabType.None: goIcon = s_styles.goIcon; break; case PrefabType.Prefab: case PrefabType.PrefabInstance: case PrefabType.DisconnectedPrefabInstance: goIcon = s_styles.prefabIcon; break; case PrefabType.ModelPrefab: case PrefabType.ModelPrefabInstance: case PrefabType.DisconnectedModelPrefabInstance: goIcon = s_styles.modelIcon; break; case PrefabType.MissingPrefabInstance: goIcon = s_styles.prefabIcon; break; } } else { goIcon = s_styles.typelessIcon; } EditorGUI.ObjectIconDropDown(new Rect(3f, 4f + y, 24f, 24f), base.targets, true, goIcon.image as Texture2D, this.m_Icon); EditorGUI.BeginDisabledGroup(none == PrefabType.ModelPrefab); EditorGUI.PropertyField(new Rect(34f, 4f + y, 14f, 14f), this.m_IsActive, GUIContent.none); float num3 = s_styles.staticFieldToggleWidth + 15f; float num4 = ((width - 52f) - num3) - 5f; EditorGUI.DelayedTextField(new Rect(52f, (4f + y) + 1f, num4, 16f), this.m_Name, GUIContent.none); Rect totalPosition = new Rect(width - num3, 4f + y, s_styles.staticFieldToggleWidth, 16f); EditorGUI.BeginProperty(totalPosition, GUIContent.none, this.m_StaticEditorFlags); EditorGUI.BeginChangeCheck(); Rect position = totalPosition; EditorGUI.showMixedValue |= ShowMixedStaticEditorFlags((StaticEditorFlags)this.m_StaticEditorFlags.intValue); Event current = Event.current; EventType type = current.type; bool flag2 = (current.type == EventType.MouseDown) && (current.button != 0); if (flag2) { current.type = EventType.Ignore; } bool flagValue = EditorGUI.ToggleLeft(position, "Static", target.isStatic); if (flag2) { current.type = type; } EditorGUI.showMixedValue = false; if (EditorGUI.EndChangeCheck()) { SceneModeUtility.SetStaticFlags(base.targets, -1, flagValue); base.serializedObject.SetIsDifferentCacheDirty(); } EditorGUI.EndProperty(); EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = this.m_StaticEditorFlags.hasMultipleDifferentValues; EditorGUI.EnumMaskField(new Rect(totalPosition.x + s_styles.staticFieldToggleWidth, totalPosition.y, 10f, 14f), GameObjectUtility.GetStaticEditorFlags(target), s_styles.staticDropdown, out num5, out flag4); EditorGUI.showMixedValue = false; if (EditorGUI.EndChangeCheck()) { SceneModeUtility.SetStaticFlags(base.targets, num5, flag4); base.serializedObject.SetIsDifferentCacheDirty(); } float num6 = 4f; float num7 = 4f; EditorGUIUtility.fieldWidth = ((((width - num6) - 52f) - s_styles.layerFieldWidth) - num7) / 2f; string tag = null; try { tag = target.tag; } catch (Exception) { tag = "Undefined"; } EditorGUIUtility.labelWidth = s_styles.tagFieldWidth; Rect rect3 = new Rect(52f - EditorGUIUtility.labelWidth, 24f + y, EditorGUIUtility.labelWidth + EditorGUIUtility.fieldWidth, 16f); EditorGUI.BeginProperty(rect3, GUIContent.none, this.m_Tag); EditorGUI.BeginChangeCheck(); string str2 = EditorGUI.TagField(rect3, EditorGUIUtility.TempContent("Tag"), tag); if (EditorGUI.EndChangeCheck()) { this.m_Tag.stringValue = str2; Undo.RecordObjects(base.targets, "Change Tag of " + this.targetTitle); foreach (Object obj3 in base.targets) { (obj3 as GameObject).tag = str2; } } EditorGUI.EndProperty(); EditorGUIUtility.labelWidth = s_styles.layerFieldWidth; rect3 = new Rect((52f + EditorGUIUtility.fieldWidth) + num6, 24f + y, EditorGUIUtility.labelWidth + EditorGUIUtility.fieldWidth, 16f); EditorGUI.BeginProperty(rect3, GUIContent.none, this.m_Layer); EditorGUI.BeginChangeCheck(); int layer = EditorGUI.LayerField(rect3, EditorGUIUtility.TempContent("Layer"), target.layer); if (EditorGUI.EndChangeCheck()) { GameObjectUtility.ShouldIncludeChildren children = GameObjectUtility.DisplayUpdateChildrenDialogIfNeeded(base.targets.OfType <GameObject>(), "Change Layer", "Do you want to set layer to " + InternalEditorUtility.GetLayerName(layer) + " for all child objects as well?"); if (children != GameObjectUtility.ShouldIncludeChildren.Cancel) { this.m_Layer.intValue = layer; this.SetLayer(layer, children == GameObjectUtility.ShouldIncludeChildren.IncludeChildren); } } EditorGUI.EndProperty(); if (!this.m_HasInstance || EditorApplication.isPlayingOrWillChangePlaymode) { goto Label_093F; } float num10 = ((width - 52f) - 5f) / 3f; Rect rect4 = new Rect(52f + (num10 * 0f), 44f + y, num10, 15f); Rect rect5 = new Rect(52f + (num10 * 1f), 44f + y, num10, 15f); Rect rect6 = new Rect(52f + (num10 * 2f), 44f + y, num10, 15f); Rect rect7 = new Rect(52f, 44f + y, num10 * 3f, 15f); GUIContent content2 = (base.targets.Length <= 1) ? s_styles.goTypeLabel[(int)none] : s_styles.goTypeLabelMultiple; if (content2 != null) { float x = GUI.skin.label.CalcSize(content2).x; switch (none) { case PrefabType.DisconnectedModelPrefabInstance: case PrefabType.MissingPrefabInstance: case PrefabType.DisconnectedPrefabInstance: GUI.contentColor = GUI.skin.GetStyle("CN StatusWarn").normal.textColor; if (none == PrefabType.MissingPrefabInstance) { GUI.Label(new Rect(52f, 44f + y, (width - 52f) - 5f, 18f), content2, EditorStyles.whiteLabel); } else { GUI.Label(new Rect((52f - x) - 5f, 44f + y, (width - 52f) - 5f, 18f), content2, EditorStyles.whiteLabel); } GUI.contentColor = Color.white; goto Label_072D; } Rect rect8 = new Rect((52f - x) - 5f, 44f + y, x, 18f); GUI.Label(rect8, content2); } Label_072D: if (base.targets.Length > 1) { GUI.Label(rect7, "Instance Management Disabled", s_styles.instanceManagementInfo); } else { if ((none != PrefabType.MissingPrefabInstance) && GUI.Button(rect4, "Select", "MiniButtonLeft")) { Selection.activeObject = PrefabUtility.GetPrefabParent(this.target); EditorGUIUtility.PingObject(Selection.activeObject); } if (((none == PrefabType.DisconnectedModelPrefabInstance) || (none == PrefabType.DisconnectedPrefabInstance)) && GUI.Button(rect5, "Revert", "MiniButtonMid")) { Undo.RegisterFullObjectHierarchyUndo(target, "Revert to prefab"); PrefabUtility.ReconnectToLastPrefab(target); PrefabUtility.RevertPrefabInstance(target); this.CalculatePrefabStatus(); Undo.RegisterCreatedObjectUndo(target, "Reconnect prefab"); GUIUtility.ExitGUI(); } bool flag5 = GUI.enabled; GUI.enabled = GUI.enabled && !AnimationMode.InAnimationMode(); if (((none == PrefabType.ModelPrefabInstance) || (none == PrefabType.PrefabInstance)) && GUI.Button(rect5, "Revert", "MiniButtonMid")) { Undo.RegisterFullObjectHierarchyUndo(target, "Revert Prefab Instance"); PrefabUtility.RevertPrefabInstance(target); this.CalculatePrefabStatus(); Undo.RegisterCreatedObjectUndo(target, "Revert prefab"); GUIUtility.ExitGUI(); } if ((none == PrefabType.PrefabInstance) || (none == PrefabType.DisconnectedPrefabInstance)) { GameObject source = PrefabUtility.FindValidUploadPrefabInstanceRoot(target); GUI.enabled = (source != null) && !AnimationMode.InAnimationMode(); if (GUI.Button(rect6, "Apply", "MiniButtonRight")) { Object prefabParent = PrefabUtility.GetPrefabParent(source); string assetPath = AssetDatabase.GetAssetPath(prefabParent); string[] assets = new string[] { assetPath }; if (Provider.PromptAndCheckoutIfNeeded(assets, "The version control requires you to check out the prefab before applying changes.")) { PrefabUtility.ReplacePrefab(source, prefabParent, ReplacePrefabOptions.ConnectToPrefab); this.CalculatePrefabStatus(); GUIUtility.ExitGUI(); } } } GUI.enabled = flag5; if (((none == PrefabType.DisconnectedModelPrefabInstance) || (none == PrefabType.ModelPrefabInstance)) && GUI.Button(rect6, "Open", "MiniButtonRight")) { AssetDatabase.OpenAsset(PrefabUtility.GetPrefabParent(this.target)); GUIUtility.ExitGUI(); } } Label_093F: EditorGUI.EndDisabledGroup(); base.serializedObject.ApplyModifiedProperties(); return(true); }