public override void OnInspectorGUI() { base.OnInspectorGUI(); string undoRedoWarningPropertyPath = UndoRedoWarningPropertyPath; grabConfigurationIsDirty = false; EditorGUILayout.Space(); EditorGUILayout.LabelField("Primary Action Settings", EditorStyles.boldLabel); selectedPrimaryActionIndex = EditorGUILayout.Popup(new GUIContent("Primary Action"), currentPrimaryActionIndex, primaryActions); GrabInteractableAction updatedPrimaryAction = UpdateAction(facade, primaryActionsIndexes, currentPrimaryActionIndex, selectedPrimaryActionIndex, facade.Configuration.GrabConfiguration.PrimaryAction, 0); if (facade.Configuration.GrabConfiguration.PrimaryAction != updatedPrimaryAction) { facade.Configuration.GrabConfiguration.PrimaryAction = updatedPrimaryAction; grabConfigurationIsDirty = true; } currentPrimaryActionIndex = selectedPrimaryActionIndex; DrawFollowActionSettings(facade, facade.Configuration.GrabConfiguration.PrimaryAction, undoRedoWarningPropertyPath); EditorGUILayout.Space(); EditorGUILayout.LabelField("Secondary Action Settings", EditorStyles.boldLabel); selectedSecondaryActionIndex = EditorGUILayout.Popup(new GUIContent("Secondary Action"), currentSecondaryActionIndex, secondaryActions); GrabInteractableAction updatedSecondaryAction = UpdateAction(facade, secondaryActionsIndexes, currentSecondaryActionIndex, selectedSecondaryActionIndex, facade.Configuration.GrabConfiguration.SecondaryAction, 1); if (facade.Configuration.GrabConfiguration.SecondaryAction != updatedSecondaryAction) { facade.Configuration.GrabConfiguration.SecondaryAction = updatedSecondaryAction; grabConfigurationIsDirty = true; } currentSecondaryActionIndex = selectedSecondaryActionIndex; DrawFollowActionSettings(facade, facade.Configuration.GrabConfiguration.SecondaryAction, undoRedoWarningPropertyPath); EditorGUILayout.Space(); EditorGUILayout.LabelField("Disallowed Touch Interactor Settings", EditorStyles.boldLabel); EditorGUI.indentLevel++; DrawDisallowedInteractorsList(facade.Configuration.DisallowedTouchInteractors, undoRedoWarningPropertyPath); EditorGUI.indentLevel--; EditorGUILayout.Space(); EditorGUILayout.LabelField("Disallowed Grab Interactor Settings", EditorStyles.boldLabel); EditorGUI.indentLevel++; DrawDisallowedInteractorsList(facade.Configuration.DisallowedGrabInteractors, undoRedoWarningPropertyPath); EditorGUI.indentLevel--; EditorGUILayout.BeginHorizontal("GroupBox"); GUILayout.FlexibleSpace(); if (GUILayout.Button("Show Mesh Container")) { EditorGUIUtility.PingObject(facade.Configuration.MeshContainer); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); if (grabConfigurationIsDirty) { CheckFollowAndControlDirectionPair(updatedPrimaryAction, updatedSecondaryAction); EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); EditorUtility.SetDirty(facade.Configuration.GrabConfiguration); } }
/// <summary> /// Draws the style asset field. /// </summary> /// <param name="property">Property.</param> /// <param name="onSelect">On select.</param> public static void DrawAssetField <T>(Rect position, GUIContent label, SerializedProperty property, Action <T, bool> onSelect) where T : UnityEngine.Object { // Object field. Rect rField = new Rect(position.x, position.y, position.width - 16, position.height); EditorGUI.BeginChangeCheck(); EditorGUI.PropertyField(rField, property, label); if (EditorGUI.EndChangeCheck()) { property.serializedObject.ApplyModifiedProperties(); onSelect(property.objectReferenceValue as T, false); } // Popup to select style asset in project. Rect rPopup = new Rect(position.x + rField.width, position.y + 4, 16, position.height - 4); if (GUI.Button(rPopup, EditorGUIUtility.FindTexture("icon dropdown"), EditorStyles.label)) { // Create style asset. GenericMenu menu = new GenericMenu(); // If asset is ScriptableObject, add item to create new one. if (typeof(ScriptableObject).IsAssignableFrom(typeof(T))) { menu.AddItem(new GUIContent(string.Format("Create New {0}", typeof(T).Name)), false, () => { // Open save file dialog. string filename = AssetDatabase.GenerateUniqueAssetPath(string.Format("Assets/New {0}.asset", typeof(T).Name)); string path = EditorUtility.SaveFilePanelInProject(string.Format("Create New {0}", typeof(T).Name), Path.GetFileName(filename), "asset", ""); if (path.Length == 0) { return; } // Create and save a new builder asset. T asset = ScriptableObject.CreateInstance(typeof(T)) as T; AssetDatabase.CreateAsset(asset, path); AssetDatabase.SaveAssets(); EditorGUIUtility.PingObject(asset); property.objectReferenceValue = asset; property.serializedObject.ApplyModifiedProperties(); property.serializedObject.Update(); onSelect(asset, true); }); menu.AddSeparator(""); } // Unselect style asset. menu.AddItem( new GUIContent("-"), !property.hasMultipleDifferentValues && !property.objectReferenceValue, () => { property.objectReferenceValue = null; property.serializedObject.ApplyModifiedProperties(); property.serializedObject.Update(); onSelect(null, false); } ); // Select style asset. foreach (string path in AssetDatabase.FindAssets("t:" + typeof(T).Name).Select(x => AssetDatabase.GUIDToAssetPath(x))) { string assetName = Path.GetFileNameWithoutExtension(path); string displayedName = assetName.Replace(" - ", "/"); bool active = !property.hasMultipleDifferentValues && property.objectReferenceValue && (property.objectReferenceValue.name == assetName); menu.AddItem( new GUIContent(displayedName), active, x => { T asset = AssetDatabase.LoadAssetAtPath((string)x, typeof(T)) as T; property.objectReferenceValue = asset; property.serializedObject.ApplyModifiedProperties(); property.serializedObject.Update(); onSelect(asset, false); }, path ); } menu.ShowAsContext(); } }
// Pings PhotonServerSettings and makes it selected (show in Inspector) private static void HighlightSettings() { Selection.objects = new UnityEngine.Object[] { PhotonNetwork.PhotonServerSettings }; EditorGUIUtility.PingObject(PhotonNetwork.PhotonServerSettings); }
//绘制动作片段UI private void CameraGUI(JTimelineCamera Cameraline, JCameraTrack linetrack, JClipRenderData[] renderDataList) { GenericMenu contextMenu = new GenericMenu(); ///event 右键点击 bool isContext = UnityEngine.Event.current.type == EventType.MouseDown && UnityEngine.Event.current.button == 1; bool isChoose = UnityEngine.Event.current.type == EventType.MouseDown && UnityEngine.Event.current.button == 0 && UnityEngine.Event.current.clickCount == 1; bool hasBox = false; Rect DisplayAreaTemp = DisplayArea; DisplayAreaTemp.x = 0; DisplayAreaTemp.y = 0; for (int j = 0; j < renderDataList.Length; j++) { JClipRenderData renderdata = renderDataList[j]; JCameraClipData CameraClipData = (JCameraClipData)renderdata.ClipData; JCameraTrack track = CameraClipData.Track; if (linetrack != track) { continue; } var startX = ConvertTimeToXPos(CameraClipData.StartTime); var endX = ConvertTimeToXPos(CameraClipData.StartTime + CameraClipData.PlaybackDuration); var handleWidth = 2.0f; Rect renderRect = new Rect(startX, DisplayArea.y, endX - startX, DisplayArea.height); Rect leftHandle = new Rect(startX, DisplayArea.y, handleWidth * 2.0f, DisplayArea.height); Rect rightHandle = new Rect(endX - (handleWidth * 2.0f), DisplayArea.y, handleWidth * 2.0f, DisplayArea.height); Rect labelRect = new Rect(); Rect renderRecttemp = renderRect; renderRecttemp.x -= DisplayArea.x; renderRecttemp.y = 0; Rect leftHandletemp = leftHandle; leftHandletemp.y = 0; leftHandletemp.x -= DisplayArea.x; Rect rightHandletemp = rightHandle; rightHandletemp.x -= DisplayArea.x; rightHandletemp.y = 0; GUI.color = new Color(70 / 255.0f, 147 / 255.0f, 236 / 255.0f, 1); if (SelectedObjects.Contains(renderdata)) { GUI.color = ColorTools.SelectColor; } GUI.Box(renderRecttemp, "", USEditorUtility.NormalWhiteOutLineBG); GUI.Box(leftHandletemp, ""); GUI.Box(rightHandletemp, ""); labelRect = renderRecttemp; labelRect.width = DisplayArea.width; renderdata.renderRect = renderRect; renderdata.labelRect = renderRect; renderdata.renderPosition = new Vector2(startX, DisplayArea.y); renderdata.leftHandle = leftHandle; renderdata.rightHandle = rightHandle; renderdata.ClipData = CameraClipData; labelRect.x += 4.0f; // Nudge this along a bit so it isn't flush with the side. GUI.color = Color.black; GUI.Label(labelRect, CameraClipData.FriendlyName); GUI.color = Color.white; if (isContext && renderRecttemp.Contains(UnityEngine.Event.current.mousePosition)) { hasBox = true; contextMenu.AddItem(new GUIContent("DeleteClip"), false, (obj) => RemoveCameraClip(((JClipRenderData)((object[])obj)[0])), new object[] { renderdata }); } if (isContext && renderRecttemp.Contains(UnityEngine.Event.current.mousePosition)) { UnityEngine.Event.current.Use(); contextMenu.ShowAsContext(); } } if (!hasBox && isChoose && DisplayAreaTemp.Contains(UnityEngine.Event.current.mousePosition) && (UnityEngine.Event.current.control || UnityEngine.Event.current.command)) { //代码选中hierarchy中的对象 显示inspector 按住Ctrl or command //GameObject go = GameObject.Find(Cameraline.gameObject.name); Selection.activeGameObject = Cameraline.gameObject; EditorGUIUtility.PingObject(Cameraline.gameObject); } if (!hasBox && isContext && DisplayAreaTemp.Contains(UnityEngine.Event.current.mousePosition)) { contextMenu = MenuForCameraTimeLine(Cameraline, linetrack); } if (!hasBox && isContext && DisplayAreaTemp.Contains(UnityEngine.Event.current.mousePosition)) { UnityEngine.Event.current.Use(); contextMenu.ShowAsContext(); } }
public void OnGUI() { using (var scroll = new EditorGUILayout.ScrollViewScope(scrollPosition)) { EditorGUILayout.LabelField("Running mixture instances: (Static)", EditorStyles.boldLabel); // TODO: keep track of all opened mixture window to show a Focus button var mixtureWindows = Resources.FindObjectsOfTypeAll <MixtureGraphWindow>(); foreach (var view in MixtureUpdater.views) { if (view.graph.isRealtime) { continue; } var window = mixtureWindows.FirstOrDefault(w => w.view == view); using (new EditorGUILayout.HorizontalScope()) { EditorGUILayout.LabelField(view.graph.name); if (window == null) { EditorGUILayout.LabelField("Can't find the window for this static mixture !"); } else { if (GUILayout.Button("Focus")) { window.Show(); window.Focus(); } } } } EditorGUILayout.Space(); EditorGUILayout.LabelField("Running mixture instances: (Runtime)", EditorStyles.boldLabel); // TODO: keep track of all opened mixture window to show a Focus button var graphs = Resources.FindObjectsOfTypeAll <MixtureGraph>(); foreach (var graph in graphs) { if (!graph.isRealtime) { continue; } using (new EditorGUILayout.HorizontalScope()) { EditorGUILayout.LabelField(graph.name); var path = AssetDatabase.GetAssetPath(graph); EditorGUILayout.LabelField(path); if (GUILayout.Button("Select")) { var mainAsset = AssetDatabase.LoadAssetAtPath <Texture>(path); EditorGUIUtility.PingObject(mainAsset); Selection.activeObject = mainAsset; } } } EditorGUILayout.Space(); EditorGUILayout.LabelField($"Currently Loaded Custom Render Textures", EditorStyles.boldLabel); foreach (var crt in CustomTextureManager.customRenderTextures.ToList()) { using (new EditorGUILayout.HorizontalScope()) { EditorGUILayout.LabelField($"name: {crt.name}"); EditorGUILayout.LabelField($"HashCode: {crt.GetHashCode()}"); if (GUILayout.Button("Select")) { Selection.activeObject = crt; } if (GUILayout.Button("Unload")) { Resources.UnloadAsset(crt); } } } EditorGUILayout.Space(); EditorGUILayout.LabelField($"Mixture Processors", EditorStyles.boldLabel); foreach (var kp in MixtureGraphProcessor.processorInstances) { var graph = kp.Key; foreach (var processor in kp.Value) { using (new EditorGUILayout.HorizontalScope()) { EditorGUILayout.LabelField($"Processor: {processor.GetHashCode()}"); EditorGUILayout.LabelField($"Target Graph: {processor.graph.name}"); } } } scrollPosition = scroll.scrollPosition; } }
private void DrawProjectFinderEntries(string category) { bool clicked = false; _projectFinderEntriesScroll = EditorGUILayout.BeginScrollView(_projectFinderEntriesScroll, _scrollViewStyle, GUILayout.MaxHeight(position.height)); for (int i = 0; i < CurrentSettings.EntryData.Count; i++) { if (CurrentSettings.EntryData[i].Category == category) { string path = AssetDatabase.GUIDToAssetPath(CurrentSettings.EntryData[i].GUID); bool exists = IOHelper.Exists(path); bool isFolder = IOHelper.IsFolder(path); GUIContent content; if (exists) { content = ContentWithIcon(isFolder ? GetNameForFolder(path) : GetNameForFile(path), path); } else { content = RetrieveGUIContent((isFolder ? GetNameForFolder(path) : GetNameForFile(path)) + "(File is removed, click to remove)", "console.erroricon.sml"); } EditorGUILayout.BeginHorizontal(); if (GUILayout.Button(content, _buttonStyle, GUILayout.MaxHeight(EditorGUIUtility.singleLineHeight + (EditorGUIUtility.singleLineHeight * .5f)))) { if (exists) { if (_pingType == PingTypes.Ping) { if (Selection.activeObject) { Selection.activeObject = null; } EditorGUIUtility.PingObject(AssetDatabase.LoadMainAssetAtPath(path)); } else if (_pingType == PingTypes.Selection) { Selection.activeObject = AssetDatabase.LoadMainAssetAtPath(path); } else if (_pingType == PingTypes.Both) { if (Selection.activeObject) { Selection.activeObject = null; } EditorGUIUtility.PingObject(AssetDatabase.LoadMainAssetAtPath(path)); Selection.activeObject = AssetDatabase.LoadMainAssetAtPath(path); } clicked = true; } else { _objectIndexToBeRemovedDueToDeletedAsset = i; } _reachedToAsset = true; } if (DrawButton("", "ol minus", ButtonTypes.SmallLongHeight)) { _objectIndexToBeRemoved = i; } EditorGUILayout.EndHorizontal(); } } if (_objectIndexToBeRemovedDueToDeletedAsset != -1) { _tempLocations.RemoveAt(_objectIndexToBeRemovedDueToDeletedAsset); _objectIndexToBeRemovedDueToDeletedAsset = -1; SaveChanges(); } if (_objectIndexToBeRemoved != -1) { _tempLocations.RemoveAt(_objectIndexToBeRemoved); _objectIndexToBeRemoved = -1; SaveChanges(); } if (CurrentSettings.EntryData.Count == 0) { EditorGUILayout.LabelField("You can Drag&Drop assets from Project Folder and easily access them here.", _boldLabelStyle); } EditorGUILayout.EndScrollView(); //Older version of unity has issues with FocusProjectWindow being in the middle of the run(before EndXViews). if (clicked) { EditorUtility.FocusProjectWindow(); } }
private void DoCustomAssetGUI(Type assetType, Type importerType, NodeGUI node, NodeGUIEditor editor, Action onValueChanged) { // Custom Settings Asset using (new EditorGUILayout.VerticalScope(GUI.skin.box)) { var newUseCustomAsset = EditorGUILayout.ToggleLeft("Use Custom Setting Asset", m_useCustomSettingAsset); if (newUseCustomAsset != m_useCustomSettingAsset) { using (new RecordUndoScope("Change Custom Setting Asset", node, true)) { m_useCustomSettingAsset = newUseCustomAsset; onValueChanged(); if (m_importerEditor != null) { UnityEngine.Object.DestroyImmediate(m_importerEditor); m_importerEditor = null; } } } if (m_useCustomSettingAsset) { var newObject = EditorGUILayout.ObjectField("Asset", CustomSettingAsset, assetType, false); if (importerType == typeof(ModelImporter) && newObject != null) { // disallow selecting non-model prefab if (PrefabUtility.GetPrefabType(newObject) != PrefabType.ModelPrefab) { newObject = CustomSettingAsset; } } if (importerType == typeof(TrueTypeFontImporter) && newObject != null) { var selectedAssetPath = AssetDatabase.GetAssetPath(newObject); var importer = AssetImporter.GetAtPath(selectedAssetPath); // disallow selecting Custom Font if (importer != null && importer.GetType() != typeof(TrueTypeFontImporter)) { newObject = CustomSettingAsset; } } if (newObject != CustomSettingAsset) { using (new RecordUndoScope("Change Custom Setting Asset", node, true)) { CustomSettingAsset = newObject; onValueChanged(); } } if (CustomSettingAsset != null) { using (new EditorGUILayout.HorizontalScope()) { GUILayout.FlexibleSpace(); if (GUILayout.Button("Highlight in Project Window", GUILayout.Width(180f))) { EditorGUIUtility.PingObject(CustomSettingAsset); } } } } EditorGUILayout.HelpBox( "Custom setting asset is useful when you need specific needs for setting asset; i.e. when configuring with multiple sprite mode.", MessageType.Info); } }
void OnGUI() { bool playerError = false; bool detectionError = false; bool reachError = false; bool tagError = false; playerError = GameObject.FindGameObjectWithTag("Player") == null; if (!playerError) { if (GUILayout.Button(Styles.PlayerTagTrue, Styles.helpbox)) { infoString = "An object with the tag 'Player' was found."; } detectionError = GameObject.FindGameObjectWithTag("Player").GetComponent <DoorDetection>() == null; if (!detectionError) { if (GUILayout.Button(Styles.DetectionTrue, Styles.helpbox)) { infoString = "The detection script component was found attached to the player."; } reachError = GameObject.FindGameObjectWithTag("Player").GetComponent <DoorDetection>().Reach == 0; if (!reachError) { if (GUILayout.Button(Styles.ReachTrue, Styles.helpbox)) { infoString = "The reach variable is not 0. \n"; } } else if (reachError) { if (GUILayout.Button(Styles.ReachFalse, Styles.helpbox)) { infoString = "The reach variable is 0. \n"; EditorGUIUtility.PingObject(GameObject.FindGameObjectWithTag("Player").GetComponent <DoorDetection>()); } } } else if (detectionError) { if (GUILayout.Button(Styles.DetectionFalse, Styles.helpbox)) { EditorGUIUtility.PingObject(GameObject.FindGameObjectWithTag("Player")); infoString = "The player doesn't have the detection script attached to it."; } if (GUILayout.Button(Styles.ReachUnknown, Styles.helpbox)) { infoString = "There is no information on the reach variable."; EditorGUIUtility.PingObject(GameObject.FindGameObjectWithTag("Player")); } } } else if (playerError) { if (GUILayout.Button(Styles.PlayerTagFalse, Styles.helpbox)) { infoString = "There was no object found with the tag 'Player'."; } if (GUILayout.Button(Styles.DetectionUnknown, Styles.helpbox)) { infoString = "There is no information on the detection script."; } if (GUILayout.Button(Styles.ReachUnknown, Styles.helpbox)) { infoString = "There is no information on the reach variable."; } } tagError = TagHelper.DoesDoorTagNotExist(); if (!tagError) { if (GUILayout.Button(Styles.TagTrue, Styles.helpbox)) { infoString = "The tag 'Door' has been created. \n"; } } else if (tagError) { if (GUILayout.Button(Styles.TagFalse, Styles.helpbox)) { infoString = ("The tag 'Door' has not yet been created. \n"); } } if (playerError || tagError || reachError || detectionError) { EditorGUILayout.LabelField(infoString, Styles.helpbox); } else { EditorGUILayout.LabelField("No errors found! \n", Styles.helpbox); } EditorGUILayout.Space(); GUILayout.Label("V1.1.0", Styles.centeredVersionLabel); EditorGUILayout.Space(); }
private void CreateTemplateDescriptionUI(VisualElement rootContainer) { rootContainer.style.flexDirection = FlexDirection.Column; // Thumbnail container m_PreviewArea = new SceneTemplatePreviewArea(k_SceneTemplateThumbnailName, m_LastSelectedTemplate?.thumbnail, m_LastSelectedTemplate?.badge, L10n.Tr("No preview thumbnail available")); var thumbnailElement = m_PreviewArea.Element; rootContainer.Add(thumbnailElement); rootContainer.RegisterCallback <GeometryChangedEvent>(evt => m_PreviewArea?.UpdatePreviewAreaSize()); // Text container var sceneTitleLabel = new Label(); sceneTitleLabel.name = k_SceneTemplateTitleLabelName; sceneTitleLabel.AddToClassList(Styles.classWrappingText); rootContainer.Add(sceneTitleLabel); var assetPathSection = new VisualElement(); assetPathSection.name = k_SceneTemplatePathSection; { var scenePathLabel = new Label(); scenePathLabel.name = k_SceneTemplatePathName; scenePathLabel.AddToClassList(Styles.classWrappingText); assetPathSection.Add(scenePathLabel); var editLocateRow = new VisualElement(); editLocateRow.style.flexDirection = FlexDirection.Row; { var scenePathLocate = new Label(); scenePathLocate.text = L10n.Tr("Locate"); scenePathLocate.AddToClassList(Styles.classTextLink); scenePathLocate.RegisterCallback <MouseDownEvent>(e => { if (string.IsNullOrEmpty(scenePathLabel.text)) { return; } var asset = AssetDatabase.LoadAssetAtPath <SceneTemplateAsset>(scenePathLabel.text); if (!asset) { return; } EditorApplication.delayCall += () => { EditorWindow.FocusWindowIfItsOpen(typeof(ProjectBrowser)); EditorApplication.delayCall += () => EditorGUIUtility.PingObject(asset); }; }); editLocateRow.Add(scenePathLocate); editLocateRow.Add(new Label() { text = " | " }); var scenePathEdit = new Label(); scenePathEdit.name = k_SceneTemplateEditTemplateButtonName; scenePathEdit.text = L10n.Tr("Edit"); scenePathEdit.AddToClassList(Styles.classTextLink); scenePathEdit.RegisterCallback <MouseDownEvent>(e => { OnEditTemplate(m_LastSelectedTemplate); }); editLocateRow.Add(scenePathEdit); } assetPathSection.Add(editLocateRow); } rootContainer.Add(assetPathSection); var descriptionSection = new VisualElement(); descriptionSection.name = k_SceneTemplateDescriptionSection; { var descriptionLabel = new Label(); descriptionLabel.AddToClassList(Styles.classHeaderLabel); descriptionLabel.text = L10n.Tr("Description"); descriptionSection.Add(descriptionLabel); var sceneDescriptionLabel = new Label(); sceneDescriptionLabel.AddToClassList(Styles.classWrappingText); sceneDescriptionLabel.name = k_SceneTemplateDescriptionName; descriptionSection.Add(sceneDescriptionLabel); } rootContainer.Add(descriptionSection); }
//... void OnGUI() { EditorGUILayout.HelpBox("In PlayMode only, you can use this Utility, to search and find GraphOwners in the scene which are actively running.", MessageType.Info); search = EditorUtils.SearchField(search); EditorUtils.BoldSeparator(); scrollPos = EditorGUILayout.BeginScrollView(scrollPos, false, false); var hasResult = false; foreach (var owner in activeOwners) { if (owner == null) { continue; } hasResult = true; var displayName = string.Format("<size=9><b>{0}</b> ({1})</size>", owner.name, owner.graphType.FriendlyName()); if (!string.IsNullOrEmpty(search)) { if (!StringUtils.SearchMatch(search, displayName)) { continue; } } GUILayout.BeginHorizontal(GUI.skin.box); GUILayout.Label(displayName); GUILayout.EndHorizontal(); var elementRect = GUILayoutUtility.GetLastRect(); EditorGUIUtility.AddCursorRect(elementRect, MouseCursor.Link); if (elementRect.Contains(Event.current.mousePosition)) { if (Event.current.type == EventType.MouseMove) { willRepaint = true; } GUI.color = new Color(0.5f, 0.5f, 1, 0.3f); GUI.DrawTexture(elementRect, EditorGUIUtility.whiteTexture); GUI.color = Color.white; if (Event.current.type == EventType.MouseDown) { Selection.activeObject = owner; EditorGUIUtility.PingObject(owner); if (Event.current.clickCount >= 2) { GraphEditor.OpenWindow(owner); } Event.current.Use(); } } } EditorGUILayout.EndScrollView(); if (!hasResult) { ShowNotification(new GUIContent(Application.isPlaying ? "No GraphOwner is actively running." : "Application is not playing.")); } if (Event.current.type == EventType.MouseLeaveWindow) { willRepaint = true; } }
void OnGUI() { if (bookmarkedObjects == null) { bookmarkedObjects = new List <GameObject>(); } else { int i = 0; while (i < bookmarkedObjects.Count) { if (bookmarkedObjects[i] == null) { bookmarkedObjects.RemoveAt(i); } else { i++; } } } EditorGUILayout.BeginHorizontal(); if (Selection.activeGameObject == null) { EditorGUILayout.BeginVertical(); GUILayout.Space(6); GUILayout.Label("No object selected"); EditorGUILayout.EndVertical(); } else if (GUILayout.Button("Bookmark Selected")) //, GUIStyle.none { if (Selection.activeObject != null) { sorted = false; for (int i = 0; i < Selection.gameObjects.Length; i++) { var thisGameObject = Selection.gameObjects[i]; if (!bookmarkedObjects.Contains(thisGameObject)) { bookmarkedObjects.Add(thisGameObject); } else { bookmarkedObjects.Remove(thisGameObject); bookmarkedObjects.Insert(0, thisGameObject); } } } } if (bookmarkedObjects.Count > 1 && !sorted) { if (GUILayout.Button("Sort")) //, GUIStyle.none { sortObjects(); } } soloMode = GUILayout.Toggle(soloMode, "Solo Mode"); GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); GUILayout.Space(10); if (bookmarkedObjects.Count > 0) { for (int i = 0; i < bookmarkedObjects.Count; i++) { EditorGUILayout.BeginHorizontal(); if (GUILayout.Toggle(bookmarkedObjects[i].activeInHierarchy, "")) { bookmarkedObjects[i].SetActive(true); if (soloMode) { for (int k = 0; k < bookmarkedObjects.Count; k++) { if (i != k) { bookmarkedObjects[k].SetActive(false); } } } } else { if (!soloMode) { bookmarkedObjects[i].SetActive(false); } /* else * { for (int k = 0; k < bookmarkedObjects.Count; k++) * { * bookmarkedObjects[k].SetActive(true); * } * * }*/ } if (GUILayout.Button("*", EditorStyles.label)) { EditorGUIUtility.PingObject(bookmarkedObjects[i]); } if (GUILayout.Button("" + bookmarkedObjects[i].name + " ", EditorStyles.miniButton)) { Selection.activeGameObject = bookmarkedObjects[i]; } GUILayout.FlexibleSpace(); if (i > 0) { if (GUILayout.Button("↟", EditorStyles.label)) { GameObject ob = bookmarkedObjects[i]; bookmarkedObjects.RemoveAt(i); bookmarkedObjects.Insert(i - 1, ob); sorted = false; } } if (i < bookmarkedObjects.Count - 1) { if (GUILayout.Button("↡", EditorStyles.label)) { GameObject ob = bookmarkedObjects[i]; bookmarkedObjects.RemoveAt(i); bookmarkedObjects.Insert(i + 1, ob); sorted = false; } } else { GUILayout.Label(" "); } if (GUILayout.Button("X", EditorStyles.miniButton)) { bookmarkedObjects.RemoveAt(i); } EditorGUILayout.EndHorizontal(); } } GUILayout.FlexibleSpace(); if (Selection.activeGameObject != null) { if (Selection.objects != lastSelectionState) { lastSelectionState = Selection.objects; namedTheSameLOnLevel0 = getObjectsNamedTheSameAsCurernt(0); // this is a relatively expensive traversal namedTheSameLOnLevel1 = getObjectsNamedTheSameAsCurernt(1); // so we cache the results namedTheSameLOnLevel2 = getObjectsNamedTheSameAsCurernt(2); // and only do the search if the selection state namedTheSameLOnLevel3 = getObjectsNamedTheSameAsCurernt(3); // is different than on last redraw } string currentName = Selection.activeGameObject.name; if (namedTheSameLOnLevel0.Length > 1 || namedTheSameLOnLevel1.Length > 1 || namedTheSameLOnLevel2.Length > 1 || namedTheSameLOnLevel3.Length > 1) { GUILayout.Label("Found some objects also named \"" + currentName + "\""); EditorGUILayout.BeginHorizontal(); if (namedTheSameLOnLevel0.Length > 1) { if (GUILayout.Button(namedTheSameLOnLevel0.Length + " siblings")) { Selection.objects = namedTheSameLOnLevel0; } } if (namedTheSameLOnLevel1.Length > 1) { if (GUILayout.Button(namedTheSameLOnLevel1.Length + " one level up")) { Selection.objects = namedTheSameLOnLevel1; } } if (namedTheSameLOnLevel2.Length > 1) { if (GUILayout.Button(namedTheSameLOnLevel2.Length + " two levels up")) { Selection.objects = namedTheSameLOnLevel2; } } if (namedTheSameLOnLevel3.Length > 1) { if (GUILayout.Button(namedTheSameLOnLevel3.Length + " three levels up")) { Selection.objects = namedTheSameLOnLevel3; } } EditorGUILayout.EndHorizontal(); } } }
public override void Draw(DrawInfo drawInfo) { base.Draw(drawInfo); if (m_editing) { m_textures = m_proceduralMaterial != null?m_proceduralMaterial.GetGeneratedTextures() : null; if (GUI.Button(m_pickerArea, string.Empty, GUIStyle.none)) { int controlID = EditorGUIUtility.GetControlID(FocusType.Passive); EditorGUIUtility.ShowObjectPicker <ProceduralMaterial>(m_proceduralMaterial, false, "", controlID); } string commandName = Event.current.commandName; UnityEngine.Object newValue = null; if (commandName == "ObjectSelectorUpdated") { newValue = EditorGUIUtility.GetObjectPickerObject(); if (newValue != (UnityEngine.Object)m_proceduralMaterial) { UndoRecordObject("Changing value EditorGUIObjectField on node Substance Sample"); m_proceduralMaterial = newValue != null ? (ProceduralMaterial)newValue : null; m_textures = m_proceduralMaterial != null?m_proceduralMaterial.GetGeneratedTextures() : null; OnNewSubstanceSelected(m_textures); } } else if (commandName == "ObjectSelectorClosed") { newValue = EditorGUIUtility.GetObjectPickerObject(); if (newValue != (UnityEngine.Object)m_proceduralMaterial) { UndoRecordObject("Changing value EditorGUIObjectField on node Substance Sample"); m_proceduralMaterial = newValue != null ? (ProceduralMaterial)newValue : null; m_textures = m_proceduralMaterial != null?m_proceduralMaterial.GetGeneratedTextures() : null; OnNewSubstanceSelected(m_textures); } m_editing = false; } if (GUI.Button(m_previewArea, string.Empty, GUIStyle.none)) { if (m_proceduralMaterial != null) { Selection.activeObject = m_proceduralMaterial; EditorGUIUtility.PingObject(Selection.activeObject); } m_editing = false; } } if (drawInfo.CurrentEventType == EventType.Repaint) { if (!m_editing) { m_textures = m_proceduralMaterial != null?m_proceduralMaterial.GetGeneratedTextures() : null; } if (m_textures != null) { if (m_firstOutputConnected < 0) { CalculateFirstOutputConnected(); } else if (m_textures.Length != m_textureTypes.Length) { OnNewSubstanceSelected(m_textures); } int texCount = m_outputConns.Count; Rect individuals = m_previewArea; individuals.height /= texCount; for (int i = 0; i < texCount; i++) { EditorGUI.DrawPreviewTexture(individuals, m_textures[m_outputConns[i]], null, ScaleMode.ScaleAndCrop); individuals.y += individuals.height; } } else { GUI.Label(m_previewArea, string.Empty, UIUtils.ObjectFieldThumb); } if (ContainerGraph.LodLevel <= ParentGraph.NodeLOD.LOD2) { Rect smallButton = m_previewArea; smallButton.height = 14 * drawInfo.InvertedZoom; smallButton.y = m_previewArea.yMax - smallButton.height - 2; smallButton.width = 40 * drawInfo.InvertedZoom; smallButton.x = m_previewArea.xMax - smallButton.width - 2; if (m_textures == null) { GUI.Label(m_previewArea, "None (Procedural Material)", UIUtils.ObjectFieldThumbOverlay); } GUI.Label(m_pickerArea, "Select", UIUtils.GetCustomStyle(CustomStyle.SamplerButton)); } GUI.Label(m_previewArea, string.Empty, UIUtils.GetCustomStyle(CustomStyle.SamplerFrame)); } }
/// <summary> /// Draws a objectpicker button in the given rect. This one is designed to look good on top of DrawDropZone(). /// </summary> public static object ObjectPickerZone(Rect rect, object value, Type type, bool allowSceneObjects, int id) { var btnId = GUIUtility.GetControlID(FocusType.Passive); var objectPicker = ObjectPicker.GetObjectPicker(type.FullName + "+" + GUIHelper.CurrentWindowInstanceID.ToString() + "+" + id, type); var selectRect = rect.AlignBottom(15).AlignCenter(45); var uObj = value as UnityEngine.Object; selectRect.xMin = Mathf.Max(selectRect.xMin, rect.xMin); var hide = IsDragging || Event.current.type == EventType.Repaint && !rect.Contains(Event.current.mousePosition); if (hide) { GUIHelper.PushColor(new Color(0, 0, 0, 0)); GUIHelper.PushGUIEnabled(false); } bool hideInspectorBtn = !hide && !(uObj); if (hideInspectorBtn) { GUIHelper.PushGUIEnabled(false); GUIHelper.PushColor(new Color(0, 0, 0, 0)); } var inspectBtn = rect.AlignRight(14); inspectBtn.height = 14; SirenixEditorGUI.BeginDrawOpenInspector(inspectBtn, uObj, rect); SirenixEditorGUI.EndDrawOpenInspector(inspectBtn, uObj); if (hideInspectorBtn) { GUIHelper.PopColor(); GUIHelper.PopGUIEnabled(); } if (GUI.Button(selectRect, "select", SirenixGUIStyles.TagButton)) { GUIHelper.RemoveFocusControl(); objectPicker.ShowObjectPicker(value, allowSceneObjects, rect, false); Event.current.Use(); } if (Event.current.keyCode == KeyCode.Return && Event.current.type == EventType.KeyDown && EditorGUIUtility.keyboardControl == id) { objectPicker.ShowObjectPicker(value, allowSceneObjects, rect, false); Event.current.Use(); } if (hide) { GUIHelper.PopColor(); GUIHelper.PopGUIEnabled(); } if (objectPicker.IsReadyToClaim) { GUIHelper.RequestRepaint(); GUI.changed = true; var newValue = objectPicker.ClaimObject(); Event.current.Use(); return(newValue); } if (objectPicker.IsPickerOpen && typeof(UnityEngine.Object).IsAssignableFrom(type)) { return(objectPicker.CurrentSelectedObject); } if (Event.current.keyCode == KeyCode.Delete && Event.current.type == EventType.KeyDown && EditorGUIUtility.keyboardControl == id) { Event.current.Use(); GUI.changed = true; return(null); } if (uObj && Event.current.rawType == EventType.MouseUp && rect.Contains(Event.current.mousePosition) && Event.current.button == 0) { // For components ping the attached game object instead, because then Unity can figure out to ping prefabs in the project window too. UnityEngine.Object pingObj = uObj; if (pingObj is Component) { pingObj = (pingObj as Component).gameObject; } EditorGUIUtility.PingObject(pingObj); } return(value); }
/// <summary> /// displaying each node info /// </summary> public void DisplayNodeInfo(Node node) { if (node != null) { // node name and go, lock button, reset button, add task button GUILayout.BeginHorizontal(); GUILayout.Space(indentLevel * 10); if (GUILayout.Button(node.Name + " (" + (node.GameObject == null?"Missing!": node.GameObject.name) + ")" + (node.Selected?"*":""), "Button")) { EditorGUIUtility.PingObject(node.GameObject); obj.ToggleSelect(node); } // to lock or unlock node for interaction if (GUILayout.Button((node.Locked ? "X" : " "), "Button", GUILayout.Width(20))) { if (node.Locked) { node.Locked = false; } else { obj.Release(); obj.Deselect(node); node.Locked = true; } } // to reset this specific node if (GUILayout.Button("R", "Button", GUILayout.Width(20))) { obj.Reset(node); } // to add a task related to the game object of this node if (GUILayout.Button("Add Task", "Button", GUILayout.Width(100))) { GenericMenu genericMenu = new GenericMenu(); for (int i = 0; i < MultiPartsObjectEditorUtility.TaskTypes().Length; i++) { genericMenu.AddItem(new GUIContent(MultiPartsObjectEditorUtility.TaskTypes()[i]), false, (param) => { int index = (int)param; switch (index) { case 0: { TaskList tl = obj.TaskList; tl.Tasks.Add(new MovingTask(tl, node.GameObject, obj.transform.InverseTransformPoint(node.GameObject.transform.position), Quaternion.Inverse(obj.transform.rotation) * node.GameObject.transform.rotation)); } break; case 1: { TaskList tl = obj.TaskList; tl.Tasks.Add(new ClickingTask(tl, node.GameObject)); } break; } } , i); } genericMenu.ShowAsContext(); } GUILayout.EndHorizontal(); // node details if (node.Selected) { GUILayout.BeginHorizontal(); GUILayout.Space(indentLevel * 10); GUILayout.BeginVertical(EditorStyles.helpBox); // allows to change the name of the node GUILayout.BeginHorizontal(); GUILayout.Label("Name", GUILayout.Width(100)); node.Name = GUILayout.TextField(node.Name); GUILayout.EndHorizontal(); // allows to change the game object of the node GUILayout.BeginHorizontal(); GUILayout.Label("GO", GUILayout.Width(100)); node.GameObject = (GameObject)EditorGUILayout.ObjectField(node.GameObject, typeof(GameObject), true); GUILayout.EndHorizontal(); // go name GUILayout.BeginHorizontal(); GUILayout.Label("GOName", GUILayout.Width(100)); node.GOName = GUILayout.TextField(node.GOName); GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUILayout.EndHorizontal(); } // node childs if (node.Childs.Count > 0) { indentLevel++; GUILayout.BeginVertical(); foreach (var child in node.Childs) { //GUILayout.BeginHorizontal(); //GUILayout.Space(20); DisplayNodeInfo(child); //GUILayout.EndHorizontal(); } GUILayout.EndVertical(); indentLevel--; } } }
public static void NavigateTo_ProjectResource() { var anything = Resources.Load <ReflectionLenProfileContainer>("LenProfiles"); EditorGUIUtility.PingObject(anything); }
void OnGUI() { #region //if (Event.current.type == EventType.Repaint) //{ // ListInternalIconWindow.style.lineStyle.Draw(new Rect(0, 0, 200, 200), "xxx", true, false, true, false); // GUILayout.Label("xxx"); //} m_StrGUID = EditorGUILayout.TextField("GUID", m_StrGUID); if (GUILayout.Button("输出路径")) { m_assetPath = AssetDatabase.GUIDToAssetPath(m_StrGUID); Debug.Log("---------------------- " + m_assetPath + " ----------------------"); m_assetObj = AssetDatabase.LoadAssetAtPath <Object>(m_assetPath); if (m_assetObj != null) { Debug.Log("assetObj.ToString " + m_assetObj.ToString()); Debug.Log("assetObj.GetType " + m_assetObj.GetType()); Debug.Log("assetObj.name " + m_assetObj.name); EditorGUIUtility.PingObject(m_assetObj); } } m_pickObj = EditorGUILayout.ObjectField(m_pickObj, typeof(Object), true); if (GUILayout.Button("输出Obj信息并跳转") && m_pickObj != null) { m_assetObj = m_pickObj; m_assetObj.GetInstanceID(); m_assetPath = AssetDatabase.GetAssetPath(m_assetObj); EditorGUIUtility.PingObject(m_assetObj); } if (GUILayout.Button("跳转", GUILayout.Width(100)) && !string.IsNullOrEmpty(m_StrGUID)) { PingObjectWithGUID(m_StrGUID); } if (m_assetObj != null) { string isMainAsset = GUILayout.TextField("Is Main Asset: " + AssetDatabase.IsMainAsset(m_assetObj)); string isNativeAsset = GUILayout.TextField("Is Native Asset: " + AssetDatabase.IsNativeAsset(m_assetObj)); string isSubAsset = GUILayout.TextField("Is Sub Asset: " + AssetDatabase.IsSubAsset(m_assetObj)); string assetPath = GUILayout.TextField("Asset Path: " + m_assetPath); string textMetaFilePath = GUILayout.TextField("Text Meta File Path: " + AssetDatabase.GetTextMetaFilePathFromAssetPath(m_assetPath)); string assetObjType = GUILayout.TextField("Asset Obj Type: " + m_assetObj.GetType()); StringBuilder sb = new StringBuilder(); Object[] assetObjs = AssetDatabase.LoadAllAssetRepresentationsAtPath(m_assetPath); if (assetObjs != null && assetObjs.Length > 0) { for (int i = 0; i < assetObjs.Length; ++i) { if (assetObjs[i].GetType() != typeof(DefaultAsset)) { sb.Append(assetObjs[i].name).Append(" ").Append(assetObjs[i].GetType().ToString()).Append("\n"); } } } string assets = GUILayout.TextArea(sb.ToString()); } #endregion CalculateMD5(); }
private void DrawTranslations() { var rectA = Reserve(); var rectB = rectA; rectB.xMin += EditorGUIUtility.labelWidth; rectB.xMax -= 37.0f; var rectC = rectA; rectC.xMin = rectC.xMax - 35.0f; EditorGUI.LabelField(rectA, "Translations", EditorStyles.boldLabel); translationFilter = EditorGUI.TextField(rectB, "", translationFilter); EditorGUI.BeginDisabledGroup(string.IsNullOrEmpty(translationFilter) == true || LeanLocalization.CurrentTranslations.ContainsKey(translationFilter) == true); if (GUI.Button(rectC, "Add", EditorStyles.miniButton) == true) { var phrase = LeanLocalization.AddPhraseToFirst(translationFilter); LeanLocalization.UpdateTranslations(); Selection.activeObject = phrase; EditorGUIUtility.PingObject(phrase); } EditorGUI.EndDisabledGroup(); if (LeanLocalization.CurrentTranslations.Count == 0 && string.IsNullOrEmpty(translationFilter) == true) { EditorGUILayout.HelpBox("Type in the name of a translation, and click the 'Add' button. Or, drag and drop a prefab that contains some.", MessageType.Info); } else { var total = 0; EditorGUI.indentLevel++; foreach (var pair in LeanLocalization.CurrentTranslations) { var name = pair.Key; if (string.IsNullOrEmpty(translationFilter) == true || name.IndexOf(translationFilter, System.StringComparison.InvariantCultureIgnoreCase) >= 0) { var translation = pair.Value; var rectT = Reserve(); var expand = EditorGUI.Foldout(new Rect(rectT.x, rectT.y, 20, rectT.height), expandTranslation == translation, ""); if (expand == true) { expandTranslation = translation; } else if (expandTranslation == translation) { expandTranslation = null; } CalculateTranslation(pair.Value); var data = translation.Data; total++; EditorGUI.BeginDisabledGroup(true); BeginError(missing.Count > 0 || clashes.Count > 0); if (data is Object) { EditorGUI.ObjectField(rectT, name, (Object)data, typeof(Object), true); } else { EditorGUI.TextField(rectT, name, data != null ? data.ToString() : ""); } EndError(); if (expand == true) { EditorGUI.indentLevel++; foreach (var entry in translation.Entries) { BeginError(clashes.Contains(entry.Language) == true); EditorGUILayout.ObjectField(entry.Language, entry.Owner, typeof(Object), true); EndError(); } EditorGUI.indentLevel--; } EditorGUI.EndDisabledGroup(); if (expand == true) { foreach (var language in missing) { EditorGUILayout.HelpBox("This translation isn't defined for the " + language + " language.", MessageType.Warning); } foreach (var language in clashes) { EditorGUILayout.HelpBox("This translation is defined multiple times for the " + language + " language.", MessageType.Warning); } } } } EditorGUI.indentLevel--; if (total == 0) { EditorGUILayout.HelpBox("No translation with this name exists, click the 'Add' button to create it.", MessageType.Info); } } }
public static void DrawObjectReference(UnityEngine.Object o, GUIStyle style) { // Read mouse events var cev = Event.current; var mousePos = Vector2.zero; var mouseLeftClick = false; var mouseRightClick = false; var mouseStartDrag = false; if (cev != null) { mousePos = cev.mousePosition; mouseLeftClick = (cev.type == EventType.MouseUp) && cev.button == 0 && cev.clickCount == 1; mouseRightClick = (cev.type == EventType.MouseUp) && cev.button == 1 && cev.clickCount == 1; mouseStartDrag = (cev.type == EventType.MouseDrag) && cev.button == 0; } var guiElement = new GUIContent("impossible!"); var thumbNail = AssetPreview.GetMiniThumbnail(o); guiElement.image = thumbNail; guiElement.text = o != null ? o.name : "<invalid>"; var lineRect = EditorGUILayout.BeginHorizontal(); var baseCol = o != null && EditorUtility.IsPersistent(o) ? Color.cyan : Color.green; var selected = Selection.objects.Contains(o); style.normal.textColor = selected ? baseCol : baseCol * 0.75f; GUILayout.Label(guiElement, style); EditorGUILayout.EndHorizontal(); if (o == null) { return; } // Handle mouse clicks and drags if (lineRect.Contains(mousePos)) { if (mouseStartDrag) { DragAndDrop.PrepareStartDrag(); DragAndDrop.StartDrag(o.name); DragAndDrop.objectReferences = new UnityEngine.Object[] { o }; Event.current.Use(); } else if (mouseRightClick) { EditorGUIUtility.PingObject(o); Event.current.Use(); } else if (mouseLeftClick) { if (Event.current.control) { var list = new List <UnityEngine.Object>(Selection.objects); if (list.Contains(o)) { list.Remove(o); } else { list.Add(o); } Selection.objects = list.ToArray(); } else { Selection.activeObject = o; } Event.current.Use(); } } }
private void DrawSettings() { DrawInnerSettings(); int toBeRemoved = -1; UnityEngine.Object pingedObject = null; _settingScrollPos = EditorGUILayout.BeginScrollView(_settingScrollPos, _scrollViewStyle, GUILayout.MaxHeight(position.height)); //Iterate all found entries - key is path value is type EditorGUILayout.BeginVertical(_boxStyle); EditorGUILayout.LabelField("Manage Registered Assets", _boldLabelStyle); EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); for (int i = 0; i < _tempLocations.Count; i++) { bool exists = IOHelper.Exists(_tempLocations[i].GUID, ExistentialCheckStrategy.GUID); if (_lastlyAddedCount != -1 && i >= _tempLocations.Count - _lastlyAddedCount - 1) { GUI.color = Color.green; } EditorGUILayout.BeginHorizontal(); { EditorGUILayout.BeginVertical(); { string fullPath = exists ? AssetDatabase.GUIDToAssetPath(_tempLocations[i].GUID) : "(Removed)" + AssetDatabase.GUIDToAssetPath(_tempLocations[i].GUID); GUILayout.Space(4); EditorGUILayout.SelectableLabel(fullPath, _textFieldStyle, GUILayout.Height(EditorGUIUtility.singleLineHeight)); } EditorGUILayout.EndVertical(); if (!exists) { GUI.enabled = false; } if (DrawButton("", "ViewToolOrbit", ButtonTypes.SmallNormalHeight)) { pingedObject = AssetDatabase.LoadMainAssetAtPath(AssetDatabase.GUIDToAssetPath(_tempLocations[i].GUID)); if (Selection.activeObject) { Selection.activeObject = null; } if (_pingType == PingTypes.Ping) { EditorGUIUtility.PingObject(pingedObject); } else if (_pingType == PingTypes.Selection) { Selection.activeObject = pingedObject; } else if (_pingType == PingTypes.Both) { EditorGUIUtility.PingObject(pingedObject); Selection.activeObject = pingedObject; } } // if (DrawButton("Assign Selected Object", "TimeLinePingPong", ButtonTypes.Standard)) // { // string s = AssetDatabase.GetAssetPath(Selection.activeObject); // if (s == "" || s == null || Selection.activeObject == null) // { // EditorUtility.DisplayDialog("Empty Selection", "Please select an item from Project Hierarchy.", "Okay"); // } // else // { // _tempLocations[i] = Selection.activeObject; // _changesMade = true; // } // GUI.FocusControl(null); // } //çatecori ///*int categoryIndex*/ = GetIndexOfCategory(_tempPlayerPrefLocations[i].Category); _tempLocations[i].Index = EditorGUILayout.Popup(_tempLocations[i].Index, RetrieveGUIContent(_projectFinderHeaders), _popupStyle, GUILayout.MinHeight(EditorGUIUtility.singleLineHeight), GUILayout.MaxWidth(150)); _tempLocations[i].Category = _projectFinderHeaders[_tempLocations[i].Index]; if (!exists) { GUI.enabled = true; } //Remove Button if (DrawButton("", "ol minus", ButtonTypes.SmallNormalHeight)) { if (_lastlyAddedCount != -1 && i >= _tempLocations.Count - _lastlyAddedCount - 1) { _lastlyAddedCount--; } toBeRemoved = i; } } EditorGUILayout.EndHorizontal(); if (_lastlyAddedCount != -1 && i >= _tempLocations.Count - _lastlyAddedCount - 1) { GUI.color = _defaultGUIColor; } }//endfor if (_tempLocations.Count == 0 && CurrentSettings.EntryData.Count == 0) { EditorGUILayout.LabelField("Start dragging some assets from Project Folder!", _boldLabelStyle); } EditorGUILayout.EndVertical(); EditorGUILayout.EndScrollView(); //Focus to Project window if a ping object is selected. Causes an error if it is directly made within the for loop if (pingedObject != null) { EditorUtility.FocusProjectWindow(); } //Remove item if (toBeRemoved != -1) { _tempLocations.RemoveAt(toBeRemoved); } //-- //Add // if (DrawButton("Add", "ol plus", ButtonTypes.Big)) // { // if (Selection.activeObject != null) // { // _tempLocations.Add(Selection.activeObject); // } // else // { // EditorUtility.DisplayDialog("Empty Selection", "Please select an item from Project Hierarchy.", "Okay"); // } // GUI.FocusControl(null); // } //Save //detect if any change occured, if not reverse the HelpBox if (CurrentSettings.EntryData.Count != _tempLocations.Count) { _changesMade = true; } else { for (int i = 0; i < CurrentSettings.EntryData.Count; i++) { if (CurrentSettings.EntryData[i].GUID != _tempLocations[i].GUID || CurrentSettings.EntryData[i].Category != _tempLocations[i].Category) { _changesMade = true; break; } if (i == CurrentSettings.EntryData.Count - 1) { _changesMade = false; } } } //Show info about saving if (_changesMade) { //if (DrawButton("Save", "redLight", ButtonTypes.Big)) { SaveChanges(); } //EditorGUILayout.HelpBox("Changes are made, you should save changes if you want to keep them.", MessageType.Info); //if (DrawButton("Discard Changes", "", ButtonTypes.Standard)) //{ // _lastlyAddedCount = -1; // _tempLocations.Clear(); // _tempLocations.AddRange(EntryData.Clone(CurrentSettings.EntryData.ToArray())); // _changesMade = false; //} } }
public static void ShowExamples() { EditorGUIUtility.PingObject(AssetDatabase.LoadMainAssetAtPath("Assets/Packages/Curvy Examples/Scenes/00_SplineController.unity")); }
//This is called outside Begin/End Windows from GraphEditor. public static void ShowToolbar(Graph graph) { var owner = graph.agent != null && graph.agent is GraphOwner && (graph.agent as GraphOwner).graph == graph? (GraphOwner)graph.agent : null; GUILayout.BeginHorizontal(EditorStyles.toolbar); GUI.backgroundColor = new Color(1f, 1f, 1f, 0.5f); ///---------------------------------------------------------------------------------------------- ///Left side ///---------------------------------------------------------------------------------------------- if (GUILayout.Button("File", EditorStyles.toolbarDropDown, GUILayout.Width(50))) { GetToolbarMenu_File(graph, owner).ShowAsContext(); } if (GUILayout.Button("Edit", EditorStyles.toolbarDropDown, GUILayout.Width(50))) { GetToolbarMenu_Edit(graph, owner).ShowAsContext(); } if (GUILayout.Button("Prefs", EditorStyles.toolbarDropDown, GUILayout.Width(50))) { GetToolbarMenu_Prefs(graph, owner).ShowAsContext(); } GUILayout.Space(10); if (owner != null && GUILayout.Button("Select Owner", EditorStyles.toolbarButton, GUILayout.Width(80))) { Selection.activeObject = owner; EditorGUIUtility.PingObject(owner); } if (EditorUtility.IsPersistent(graph) && GUILayout.Button("Select Graph", EditorStyles.toolbarButton, GUILayout.Width(80))) { Selection.activeObject = graph; EditorGUIUtility.PingObject(graph); } GUILayout.Space(10); if (GUILayout.Button("Open Console", EditorStyles.toolbarButton, GUILayout.Width(90))) { var type = ReflectionTools.GetType("NodeCanvas.Editor.GraphConsole"); var method = type.GetMethod("ShowWindow"); method.Invoke(null, null); } ///---------------------------------------------------------------------------------------------- ///Mid ///---------------------------------------------------------------------------------------------- GUILayout.Space(10); GUILayout.FlexibleSpace(); //TODO: implement search // EditorUtils.SearchField(null); GUILayout.FlexibleSpace(); GUILayout.Space(10); ///---------------------------------------------------------------------------------------------- ///Right side ///---------------------------------------------------------------------------------------------- //SL------------- //-------------------- if (EditorUtility.IsPersistent(graph) && GUILayout.Button("ClearUselessNestedAssets", EditorStyles.toolbarButton, GUILayout.Width(175))) { if (EditorUtility.DisplayDialog("Clear Useless Nested Assets", "清理当前prefab(包括其子物体)或graph资源中无用的嵌套资源,\n\n(需选中物体的是资源目录下的prefab或主Graph Asset).\n\n注意:prefab实例中的嵌套的存盘资源,如果没有被prefab本体引用,同样也被清除 ", "YES", "NO!")) { NestedUtility.DeleteAllUselessBoundAsset(graph); e.Use(); return; } } GUI.backgroundColor = Color.clear; GUI.color = new Color(1, 1, 1, 0.3f); GUILayout.Label(string.Format("{0} @NodeCanvas Framework v{1}", graph.GetType().Name, NodeCanvas.Framework.Internal.GraphSerializationData.FRAMEWORK_VERSION), EditorStyles.toolbarButton); GUILayout.Space(10); GUI.color = Color.white; GUI.backgroundColor = Color.white; //GRAPHOWNER JUMP SELECTION if (owner != null) { if (GUILayout.Button(string.Format("[{0}]", owner.gameObject.name), EditorStyles.toolbarDropDown, GUILayout.Width(120))) { var menu = new GenericMenu(); foreach (var _o in Object.FindObjectsOfType <GraphOwner>()) { var o = _o; menu.AddItem(new GUIContent(o.GetType().Name + "s/" + o.gameObject.name + " --" + o.graph.GetType().Name), false, () => { Selection.activeGameObject = o.gameObject; SetReferences(o); }); } menu.ShowAsContext(); } } NCPrefs.isLocked = GUILayout.Toggle(NCPrefs.isLocked, "Lock", EditorStyles.toolbarButton); GUILayout.EndHorizontal(); GUI.backgroundColor = Color.white; GUI.color = Color.white; }
/// <summary> /// Create Soft Font, Soft Font Material, Soft Font Texture from SoftEffect Settings, /// </summary> /// <param name="font"></param> private void CreateSoftFont(Font font, bool createNewFolder) // http://answers.unity3d.com/questions/485695/truetypefontimportergenerateeditablefont-does-not.html { // Mkey.Utils.Measure("<<<<<<<<<<<<Summary CreateSoftFontTexture>>>>>>>>>>>>>>>: ", () => { gpuWorker = new GPUWorker(eShader); string dirPath = Path.GetDirectoryName(AssetDatabase.GetAssetPath(font)); //1) load source font asset string path = AssetDatabase.GetAssetPath(font); Font f = font; if (SoftEffects.debuglog) { Debug.Log("Path to Source font: " + path); } font = (Font)AssetDatabase.LoadMainAssetAtPath(path); if (f && !font) { Debug.LogError("Can't use embedded font : " + f.name); return; } //2) Remove old Editable font if (SoftFont && !createNewFolder) { if (SoftEffects.debuglog) { Debug.Log("EditableFont folder: " + Path.GetDirectoryName(AssetDatabase.GetAssetPath(SoftFont))); } if (SoftEffects.debuglog) { Debug.Log("Remove old EditableFont: " + SoftFont.name); } if (SoftFont.material) { AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(SoftFont.material.mainTexture)); AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(SoftFont.material)); } AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(SoftFont)); AssetDatabase.Refresh(); } //3) reimport source font as editable TrueTypeFontImporter fontImporter = AssetImporter.GetAtPath(path) as TrueTypeFontImporter; //source settings int sourceSize = fontImporter.fontSize; int sourcePadding = fontImporter.characterPadding; int sourceSpacing = fontImporter.characterSpacing; FontTextureCase sourceCase = fontImporter.fontTextureCase; string chars = fontImporter.customCharacters; fontImporter.fontSize = GetComponent <Text>().fontSize; fontImporter.characterPadding = Mathf.Clamp(faceOptions.extPixels, 1, 100); fontImporter.characterSpacing = 0; // Mkey.Utils.Measure("Summary PreCreateFontTexture: ", () => { // Mkey.Utils.Measure("Reimport font: ", () => { if (SoftFontTextureCase == FontTextureCase.CustomSet) { if (customCharacters.Length == 0 || customCharacters == " ") { Debug.LogError("Custom Characters string is empty. Set default string."); customCharacters = GetComponent <Text>().text; if (customCharacters.Length == 0 || customCharacters == " ") { customCharacters = "New txt"; } } fontImporter.customCharacters = customCharacters; } else if (SoftFontTextureCase == FontTextureCase.Dynamic) { SoftFontTextureCase = FontTextureCase.ASCII; } fontImporter.fontTextureCase = SoftFontTextureCase; fontImporter.SaveAndReimport(); // }); // Mkey.Utils.Measure("GenerateEditableFont: ", () => { SoftFont = fontImporter.GenerateEditableFont(path); // }); int maxSize = Mathf.Max(font.material.mainTexture.width, font.material.mainTexture.height); // Mkey.Utils.Measure("RenameAsset: ", () => { AssetDatabase.RenameAsset(AssetDatabase.GetAssetPath(SoftFont), font.name + key); AssetDatabase.RenameAsset(AssetDatabase.GetAssetPath(SoftFont.material), font.name + key + "_edit"); AssetDatabase.RenameAsset(AssetDatabase.GetAssetPath(SoftFont.material.mainTexture), font.name + key); AssetDatabase.Refresh(); // }); Shader softShader = Shader.Find("SoftEffects/SoftEditShader"); SoftFont.material.shader = softShader; SoftMaterial = SoftFont.material; if (SoftEffects.debuglog) { Debug.Log("Editable texture size: " + SoftFont.material.mainTexture.width + " x " + SoftFont.material.mainTexture.height); } // Mkey.Utils.Measure("Reimport texture: ", () => { //5) Reimport EditableFont texture as readable SoftFont.material.mainTexture.ReimportTexture(true, maxSize); if (SoftEffects.debuglog) { Debug.Log("Editable texture size after reimport: " + SoftFont.material.mainTexture.width + " x " + SoftFont.material.mainTexture.height); } // }); // }); //5) Generate new Texture for editable font // Mkey.Utils.Measure("faceOptions.RenderFontTexture: ", () => { faceOptions.RenderFontTexture(gpuWorker, SoftFont, cb); //}); // Mkey.Utils.Measure("AfterCreateFontTexture: ", () => { faceOptions.CreateTextureFromRender_ARGB32(true, dirPath + "/" + font.name + key + "_edit" + ".png"); AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(SoftFont.material.mainTexture)); // Remove old texture Texture2D t = (Texture2D)AssetDatabase.LoadMainAssetAtPath(dirPath + "/" + font.name + key + "_edit" + ".png"); // load new texture asset t.ReimportTexture(true); //6 extend verts and uvs // SoftFont.ExtendVertsAndUvs(faceOptions.extPixels); faceOptions.mainTexture = t; AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); // 9) remove editable font to unique folder string targetFolder = AssetDatabase.GUIDToAssetPath(FolderGUID); string fontPath = AssetDatabase.GetAssetPath(SoftFont); string materialPath = AssetDatabase.GetAssetPath(SoftFont.material); string texturePath = AssetDatabase.GetAssetPath(t); if (SoftEffects.debuglog) { Debug.Log("Move file: " + fontPath + " to : " + targetFolder + "/" + Path.GetFileName(fontPath)); } AssetDatabase.MoveAsset(fontPath, targetFolder + "/" + Path.GetFileName(fontPath));// FileUtil.MoveFileOrDirectory(fontPath, targetFolder + "/"+ Path.GetFileName(fontPath)); AssetDatabase.MoveAsset(materialPath, targetFolder + "/" + Path.GetFileName(materialPath)); AssetDatabase.MoveAsset(texturePath, targetFolder + "/" + Path.GetFileName(texturePath)); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); faceOptions.IsCombinedDirty = true; RenderNewTextures(gpuWorker, true); /**/ EditorGUIUtility.PingObject(SoftFont); EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); //revert source settings fontImporter = AssetImporter.GetAtPath(path) as TrueTypeFontImporter; fontImporter.fontSize = sourceSize; fontImporter.fontTextureCase = sourceCase; // fontImporter.characterPadding = sourcePadding; // fontImporter.characterSpacing = sourceSpacing; fontImporter.characterPadding = 1; fontImporter.characterSpacing = 0; if (sourceCase == FontTextureCase.CustomSet) { fontImporter.customCharacters = chars; } fontImporter.SaveAndReimport(); // }); // }); }
public static void CreateDeformerFromAttribute(DeformerAttribute attribute, bool autoAdd) { var selectedGameObjects = Selection.gameObjects; if (selectedGameObjects == null || selectedGameObjects.Length == 0) { var newGameObject = new GameObject(attribute.Name); Undo.RegisterCreatedObjectUndo(newGameObject, "Created Deformer"); newGameObject.AddComponent(attribute.Type); newGameObject.transform.localRotation = Quaternion.Euler(attribute.XRotation, attribute.YRotation, attribute.ZRotation); Selection.activeGameObject = newGameObject; } else { Undo.SetCurrentGroupName("Created Deformer"); var newGameObject = new GameObject(attribute.Name); Undo.RegisterCreatedObjectUndo(newGameObject, "Created Deformer"); EditorGUIUtility.PingObject(newGameObject); var newDeformer = newGameObject.AddComponent(attribute.Type) as Deformer; if (autoAdd) { if (selectedGameObjects.Length == 1) { if (!PrefabUtility.IsPartOfPrefabAsset(Selection.gameObjects[0])) { var parent = selectedGameObjects[0].transform; newGameObject.transform.SetParent(parent, true); newGameObject.transform.position = parent.position; newGameObject.transform.rotation = parent.rotation * Quaternion.Euler(attribute.XRotation, attribute.YRotation, attribute.ZRotation); } } else { var center = GetAverageGameObjectPosition(selectedGameObjects); var rotation = Quaternion.Euler(attribute.XRotation, attribute.YRotation, attribute.ZRotation); newGameObject.transform.SetPositionAndRotation(center, rotation); } var deformables = GetComponents <Deformable> (selectedGameObjects); var groups = GetComponents <GroupDeformer> (selectedGameObjects); var repeaters = GetComponents <RepeaterDeformer> (selectedGameObjects); foreach (var deformable in deformables) { if (deformable != null && !PrefabUtility.IsPartOfPrefabAsset(deformable)) { Undo.RecordObject(deformable, "Added Deformer"); deformable.DeformerElements.Add(new DeformerElement(newDeformer)); } } foreach (var group in groups) { if (group != null && !PrefabUtility.IsPartOfPrefabAsset(group)) { Undo.RecordObject(group, "Added Deformer"); group.DeformerElements.Add(new DeformerElement(newDeformer)); } } foreach (var repeater in repeaters) { if (repeater != null && !PrefabUtility.IsPartOfPrefabAsset(repeater)) { Undo.RecordObject(repeater, "Set Deformer"); repeater.DeformerElement.Component = newDeformer; } } } else { Selection.activeGameObject = newGameObject; } Undo.CollapseUndoOperations(Undo.GetCurrentGroup()); } }
public override void OnGUI(Rect pRect, SerializedProperty pProperty, GUIContent pLabel) { System.Type pType = null; if (null == pProperty.objectReferenceValue) { var strParts = pProperty.propertyPath.Split('.'); var pCurrentType = pProperty.serializedObject.targetObject.GetType(); for (int iLoop = 0; iLoop < strParts.Length; ++iLoop) { if (null == pCurrentType) { break; } var pFileInfo = pCurrentType.GetField(strParts[iLoop], BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.Instance); if (null == pFileInfo) { break; } pCurrentType = pFileInfo.FieldType; } pType = pCurrentType; } else { pType = pProperty.objectReferenceValue.GetType(); } if (true == pType.IsArray) { pType = pType.GetElementType(); } else if (true == pType.IsGenericType) { pType = pType.GetGenericArguments()[0]; } var pRootObject = pProperty.serializedObject.targetObject as Component; var pChildObjects = new List <UnityEngine.Object>(); var strChildNames = new List <string>(); pChildObjects.Add(null); strChildNames.Add("None"); if (typeof(GameObject) == pType) { var pChilds = pRootObject.GetComponentsInChildren(typeof(Transform), true); var strName = ""; foreach (var pChild in pChilds) { strName = "" + strChildNames.Count + ") " + pChild.gameObject.name; pChildObjects.Add(pChild.gameObject); strChildNames.Add(strName); } } else if (true == pType.IsSubclassOf(typeof(Component))) { var pChilds = pRootObject.GetComponentsInChildren(pType, true); var strName = ""; foreach (var pChild in pChilds) { strName = "" + strChildNames.Count + ") " + pChild.gameObject.name; pChildObjects.Add(pChild); strChildNames.Add(strName); } } else { EditorGUI.BeginProperty(pRect, pLabel, pProperty); EditorGUI.HelpBox(pRect, "[SelectOnChildren] can only be used with GameObject or Component", MessageType.Error); EditorGUI.EndProperty(); return; } EditorGUI.BeginProperty(pRect, pLabel, pProperty); var iOldLevel = EditorGUI.indentLevel; EditorStyles.popup.wordWrap = false; EditorGUI.indentLevel = 0; int iIndex = pChildObjects.FindIndex(pItem => (pItem == pProperty.objectReferenceValue)); int iNewIdx = EditorGUI.Popup(EditorGUI.PrefixLabel(pRect, pLabel), iIndex, strChildNames.ToArray()); if (iIndex != iNewIdx) { pProperty.objectReferenceValue = pChildObjects[iNewIdx]; EditorGUIUtility.PingObject(pProperty.objectReferenceValue); } EditorGUI.indentLevel = iOldLevel; EditorGUI.EndProperty(); }
public override void OnUI(bool selected) { #region Key Events if (Event.current.keyCode == KeyCode.Tab && Event.current.type == EventType.keyDown) { if (EULA == false) { EULA = true; } else if (SceneView.lastActiveSceneView.orthographic) { SceneView.lastActiveSceneView.orthographic = false; } else if (Tools.current != UnityEditor.Tool.View) { Tools.current = UnityEditor.Tool.View; } else if (PlatformBase.IO.IsEditor) { if (PlatformBase.Editor.ActiveTransform == null) { PlatformBase.Editor.ActiveTransform = CourseBase.Terrain.transform; } else { PlatformBase.Editor.ActiveTransform = null; } } Event.current.Use(); } #endregion BeginUI(); MoveToRight(); Move(-3, 0); Background(); if (Button(xTexture)) { DisablePerform(); } MoveToLeft(); Background(); if (!ToolLocked) { Move(0, 1); Background(1, Screen.height / BoxSize - 1); Move(0, -1); } Move(1, 0); if (SelectedTool != Tool.None) { Background(Screen.width / BoxSize - 3); } Move(-1, 0); #region Banner Messages if (EULA == false) { if (Button(wwwTexture)) { SelectedTool = SelectedTool; } Move(1, 0); SetColor(HalfGreen); if (Button("End User License Agreement - Press TAB to agree", 8)) { EULA = true; } SetColor(); Move(-1, 0); Move(0, 1); Background(Screen.width / BoxSize - 2, Screen.height / BoxSize - 1); Background(Screen.width / BoxSize - 2, Screen.height / BoxSize - 1); GUIStyle labelStyle = new GUIStyle(GUI.skin.label); labelStyle.wordWrap = true; labelStyle.normal.textColor = Color.white; Rect scrollViewRect = GetRect(Screen.width / BoxSize - 2, (Screen.height - TopBoxHeight) / BoxSize - 1); float textHeight = 0; for (int i = 0; i < eulaText.Length; i += 4096) { string text = eulaText.Substring(i, Mathf.Min(eulaText.Length - i, 4096)); if (text.Contains("\n") && text.Length == 4096) { int index = text.LastIndexOf("\n"); text = eulaText.Substring(i, index); i += index; i -= 4096; } textHeight += labelStyle.CalcHeight(new GUIContent(text), scrollViewRect.width - 20); } Rect textRect = new Rect(0, 0, scrollViewRect.width - 20, textHeight); eulaScrollPos = GUI.BeginScrollView(scrollViewRect, eulaScrollPos, textRect); for (int i = 0; i < eulaText.Length; i += 4096) { string text = eulaText.Substring(i, Mathf.Min(eulaText.Length - i, 4096)); if (text.Contains("\n") && text.Length == 4096) { int index = text.LastIndexOf("\n"); text = eulaText.Substring(i, index); i += index; i -= 4096; } textRect.height = labelStyle.CalcHeight(new GUIContent(text), scrollViewRect.width - 20); SetColor(Black); GUI.Label(new Rect(textRect.x + 1, textRect.y + 1, textRect.width, textRect.height), text, labelStyle); SetColor(); GUI.Label(textRect, text, labelStyle); textRect.y += textRect.height; } GUI.EndScrollView(); Move(0, -1); EndUI(); return; } else if (SceneView.lastActiveSceneView.orthographic) { if (Button(wwwTexture)) { SelectedTool = SelectedTool; } Move(1, 0); SetColor(HalfGreen); if (Button("CourseForge has limited functionality in ISO mode, press TAB to switch back", 14)) { SceneView.lastActiveSceneView.orthographic = false; } SetColor(); Move(-1, 0); EndUI(); return; } else if (Tools.current != UnityEditor.Tool.View) { if (Button(wwwTexture)) { SelectedTool = SelectedTool; } Move(1, 0); SetColor(HalfGreen); if (Button("CourseForge has limited functionality in this view mode, press TAB to switch back", 14)) { Tools.current = UnityEditor.Tool.View; } SetColor(); Move(-1, 0); EndUI(); return; } else if (CourseBase.TerrainSelected) { if (Button(wwwTexture)) { SelectedTool = SelectedTool; } Move(1, 0); SetColor(HalfGreen); if (Button("Terrain Mode - Press TAB to exit", 6)) { PlatformBase.Editor.ActiveTransform = null; } SetColor(); Move(-1, 0); EndUI(); return; } else if (selected) { if (ToolButton(Tool.FileTool, wwwTexture)) { OnCleanup(); } Move(1, 0); if (SelectedTool > Tool.FileTool && Button((ToolName.Length > 8 ? ToolName.Substring(0, 8) + "..." : ToolName), 2)) { GameObject toolObject = GameObject.Find(ToolName); if (toolObject != null) { EditorGUIUtility.PingObject(toolObject); Selection.activeGameObject = toolObject; } } Move(-1, 0); } Move(0, 1); #endregion #region Top if (ToolButton(Tool.SplineTool, freehandTexture)) { OnCleanup(); if (CourseBase.TerrainLowered) { CourseBase.RestoreTerrain(); } } Move(0, 1); if (ToolButton(Tool.PlantTool, plantTexture)) { OnCleanup(); if (CourseBase.TerrainLowered) { CourseBase.RestoreTerrain(); } } Move(0, 1); if (Button(terrainTexture)) { SelectedTool = Tool.None; OnCleanup(); if (PlatformBase.IO.IsEditor) { PlatformBase.Editor.ActiveTransform = CourseBase.Terrain.transform; } } Move(0, 1); if (CourseBase.TerrainLowered) { SetColor(Red); } if (Button(terrainLoweredTexture)) { SelectedTool = Tool.None; OnCleanup(); if (!CourseBase.TerrainLowered) { CourseBase.SaveTerrain(); CourseBase.LowerTerrain(); } else { CourseBase.RestoreTerrain(); } } SetColor(); Move(0, 1); if (Button(updateTexture)) { if (CourseBase.TerrainLowered) { CourseBase.RestoreTerrain(); } CourseBase.RefreshCourse(); } Move(0, 1); if (Button(buildSplinesTexture)) { if (CourseBase.TerrainLowered) { CourseBase.RestoreTerrain(); } PopupToolUI.Clear(); CourseBase.BakeSplines(true); } Move(0, 1); #endregion #region Bottom MoveToBottom(); Move(0, -1); if (HideLines) { SetColor(HalfGrey); } if (Button(splineEyeTexture)) { HideLines = !HideLines; } SetColor(); Move(0, -1); if (AutoHide) { SetColor(HalfGrey); } if (Button(autoEyeTexture)) { AutoHide = !AutoHide; } SetColor(); Move(0, -1); if (HideMeshes) { SetColor(HalfGrey); } if (Button(eyeTexture)) { AutoHide = false; HideMeshes = !HideMeshes; List <SplineBase> splines = CourseBase.Splines; for (int i = 0; i < splines.Count; ++i) { splines[i].Renderer.UpdateVisibility(splines[i], !HideMeshes); } } SetColor(); Move(0, -1); if (MainToolUI.NormalMode) { EditorGUI.BeginDisabledGroup(true); LayerPanel = false; } if (LayerPanel) { SetColor(Green); } if (Button(layersTexture)) { LayerPanel = !LayerPanel; } SetColor(); Move(0, -1); if (MainToolUI.NormalMode) { EditorGUI.EndDisabledGroup(); } #endregion EndUI(); }
public override void OnInspectorGUI() { if (grabbablePose.gameObject.scene.name == null) { EditorGUILayout.LabelField("This must be saved in the scene"); EditorGUILayout.LabelField("-> then use override to prefab"); return; } if (grabbablePose.gameObject != null && PrefabStageUtility.GetPrefabStage(grabbablePose.gameObject) == null) { DrawDefaultInspector(); EditorUtility.SetDirty(grabbablePose); var rect = EditorGUILayout.GetControlRect(); if (grabbablePose.rightPoseSet) { EditorGUI.DrawRect(rect, Color.green); } else { EditorGUI.DrawRect(rect, Color.red); } rect.width -= 4; rect.height -= 2; rect.x += 2; rect.y += 1; if (GUI.Button(rect, "Save Right Pose")) { grabbablePose.EditorSaveGrabPose(grabbablePose.editorHand, false); } rect = EditorGUILayout.GetControlRect(); if (grabbablePose.leftPoseSet) { EditorGUI.DrawRect(rect, Color.green); } else { EditorGUI.DrawRect(rect, Color.red); } rect.x += 2; rect.y += 1; rect.width -= 4; rect.height -= 2; if (GUI.Button(rect, "Save Left Pose")) { grabbablePose.EditorSaveGrabPose(grabbablePose.editorHand, true); } EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); GUILayout.Label(new GUIContent("-------- For tweaking poses --------"), new GUIStyle() { fontStyle = FontStyle.Bold, alignment = TextAnchor.MiddleCenter }); GUILayout.Label(new GUIContent("This will create a copy that should be deleted"), new GUIStyle() { fontStyle = FontStyle.Bold, alignment = TextAnchor.MiddleCenter }); if (GUILayout.Button("Create Copy - Set Pose")) { grabbablePose.EditorCreateCopySetPose(grabbablePose.editorHand); EditorGUIUtility.PingObject(grabbablePose.editorHand); } if (GUILayout.Button("Reset Hand")) { grabbablePose.editorHand.RelaxHand(); } EditorGUILayout.Space(); rect = EditorGUILayout.GetControlRect(); EditorGUI.DrawRect(rect, Color.red); if (GUILayout.Button("Delete Copy")) { if (string.Equals(grabbablePose.editorHand.name, "HAND COPY DELETE")) { DestroyImmediate(grabbablePose.editorHand.gameObject); } else { Debug.LogError("Not a copy - Will not delete"); } } if (GUILayout.Button("Clear Poses")) { grabbablePose.EditorClearPoses(); } } else { GUILayout.Label(new GUIContent(" - This will not work in prefab mode - "), new GUIStyle() { fontStyle = FontStyle.Bold, alignment = TextAnchor.MiddleCenter }); GUILayout.Label(new GUIContent("Use scene to create poses"), new GUIStyle() { alignment = TextAnchor.MiddleCenter }); } }
public static void FindAllReferencesToGameObject() { var go = Selection.activeGameObject; if (go == null) { Debug.LogWarning("No Object selected!"); return; } // Get all MonoBehaviours in the scene List <MonoBehaviour> behaviours = new List <MonoBehaviour>(); for (int i = 0; i < SceneManager.sceneCount; ++i) { var scene = SceneManager.GetSceneAt(i); if (!scene.isLoaded) { continue; } var roots = scene.GetRootGameObjects(); foreach (var root in roots) { behaviours.AddRange(root.GetComponentsInChildren <MonoBehaviour>(true)); } } var foundGameObjects = new List <GameObject>(); foreach (var beh in behaviours) { //Debug.Log("MonoBehaviour: " + beh); if (beh == null) { continue; } Type type = beh.GetType(); var fields = type.GetFields(BindingFlags.Public | BindingFlags.Instance); foreach (var f in fields) { var fieldType = f.FieldType; //Debug.Log("Field: " + f + "type: " + fieldType); if (fieldType == typeof(GameObject)) { var o = f.GetValue(beh) as GameObject; Validate(o, go, beh, foundGameObjects); } else if (fieldType == typeof(GameObject[])) { var array = f.GetValue(beh) as GameObject[]; foreach (var a in array) { Validate(a, go, beh, foundGameObjects); } } else if (fieldType == typeof(Transform)) { var t = f.GetValue(beh) as Transform; if (t != null) { Validate(t.gameObject, go, beh, foundGameObjects); } } else if (f.FieldType == typeof(UnityEvent)) { var e = f.GetValue(beh) as UnityEvent; for (int i = e.GetPersistentEventCount() - 1; i >= 0; --i) { var comp = e.GetPersistentTarget(i) as Component; if (comp != null) { Validate(comp.gameObject, go, beh, foundGameObjects); } } } else if (f.FieldType == typeof(List <GameObject>)) { var list = f.GetValue(beh) as List <GameObject>; if (list != null) { foreach (var l in list) { Validate(l, go, beh, foundGameObjects); } } } else if (f.FieldType == typeof(List <Transform>)) { var list = f.GetValue(beh) as List <Transform>; if (list != null) { foreach (var l in list) { if (l != null) { Validate(l.gameObject, go, beh, foundGameObjects); } } } } } } if (foundGameObjects.Count == 0) { Debug.LogWarning("No references found to " + go); } else { EditorGUIUtility.PingObject(go); Selection.objects = foundGameObjects.ToArray(); } }
public static void CreateMarker() { GameObject markerTarget = new GameObject("Dynamic Marker Target", new System.Type[] { typeof(DynamicMarker) }); EditorGUIUtility.PingObject(markerTarget); }
protected void BuildSelectAssetContextualMenu(ContextualMenuPopulateEvent evt) { evt.menu.AppendAction("Select Asset", (e) => EditorGUIUtility.PingObject(graph), DropdownMenu.MenuAction.AlwaysEnabled); }
void ShowInProject() { EditorGUIUtility.PingObject(graph.mainOutputTexture); ProjectWindowUtil.ShowCreatedAsset(graph.mainOutputTexture); }