public void IsExternalEditMarker_RightTagWithWrongAttributes() { var array = new[] {"dog", "cat"}; foreach (var item in array) { var tag = new VsTextAdornmentTag {myAttributeId = item}; Assert.IsFalse(_adapter.IsExternalEditTag(tag)); } }
public void RightTagWithWrongAttributes() { Create(""); var array = new[] { "dog", "cat" }; foreach (var item in array) { var tag = new VsTextAdornmentTag { myAttributeId = item }; Assert.False(_reSharperUtil.IsExternalEditTag(tag)); } }
public void IsExternalEditMarker_OtherTypesAreNotExternalEdits() { Create("cat", "dog", "tree"); var array = new[] {150, 160, 260, 25}; foreach (var item in array) { var span = _textBuffer.GetLineRange(0).Extent.ToTextSpan(); var marker = MockObjectFactory.CreateVsTextLineMarker(span, item, _factory); Assert.False(_adapterRaw.IsExternalEditMarker(marker.Object)); } }
public void IsExternalEditMarker_RightTagWithAttributes() { var array = new[] { ResharperExternalEditAdapter.ExternalEditAttribute1, ResharperExternalEditAdapter.ExternalEditAttribute2, ResharperExternalEditAdapter.ExternalEditAttribute3, }; foreach (var item in array) { var tag = new VsTextAdornmentTag {myAttributeId = item}; Assert.IsTrue(_adapter.IsExternalEditTag(tag)); } }
public void RightTagWithAttributes() { Create(""); _adapterRaw.SetReSharperVersion(ReSharperVersion.Version7AndEarlier); var array = new[] { ReSharperEditTagDetectorBase.ExternalEditAttribute1, ReSharperEditTagDetectorBase.ExternalEditAttribute2, ReSharperEditTagDetectorBase.ExternalEditAttribute3, }; foreach (var item in array) { var tag = new VsTextAdornmentTag { myAttributeId = item }; Assert.True(_adapter.IsExternalEditTag(tag)); } }
public void EventPattern_Not() { var all = new[] { new { Text = "new EventHandler(foo", NameLength = 3 }, new { Text = "+= EventHandler(foo", NameLength = 3 }, new { Text = "+= someExpr", NameLength = 8 } }; var textView = CreateCSharpTextView(); foreach (var item in all) { var text = item.Text; textView.SetText(text); var span = new SnapshotSpan(textView.TextSnapshot, text.Length - item.NameLength, item.NameLength); textView.Selection.Select(span, isReversed: false); Assert.False(_adapter.IsInsertModePreferred(textView)); } }
public void IsInsertModePreferred_EventPattern_Is() { var all = new[] { new { Text = "foo += new EventHandler(bar)", NameLength = 3 }, new { Text = "foo += new EventHandler(bar_foo)", NameLength = 7 }, new { Text = "foo += new Event.Handler(bar)", NameLength = 3 }, new { Text = "foo += new Event.Handler(bar_foo)", NameLength = 7 }, new { Text = "foo+=new Event.Handler(bar_foo)", NameLength = 7 }, new { Text = "+= new EventHandler(bar)", NameLength = 3 }, }; var textView = CreateCSharpTextView(); foreach (var item in all) { var text = item.Text; textView.SetText(text); var span = new SnapshotSpan(textView.TextSnapshot, text.Length - item.NameLength - 1, item.NameLength); textView.Selection.Select(span, isReversed: false); Assert.True(_adapter.IsInsertModePreferred(textView)); } }
private static void Enable() { EditorUtils.SetEnabled(DEFINE_KEY, true); }
private void showArrowAndPosition(Vector3 pos) { EditorUtils.showArrows(pos); Handles.Label(pos + (Vector3.up * 2), pos.ToString()); }
public static void Editor_CreateGraph() { var newGraph = EditorUtils.AddScriptableComponent <DialogueTree>(new GameObject("DialogueTree")); UnityEditor.Selection.activeObject = newGraph; }
//... void DoExposedVariablesMapping() { if (owner.graph == null) { return; } var separatorDrawn = false; var subTreeVariables = owner.graph.blackboard.variables.Values; foreach (var variable in subTreeVariables) { if (variable is Variable <VariableSeperator> ) { continue; } if (!variable.isExposedPublic || variable.isPropertyBound) { continue; } if (!separatorDrawn) { separatorDrawn = true; EditorUtils.Separator(); EditorGUILayout.HelpBox("Exposed Graph Variables. Use the arrows button to override/parametrize the variable. Doing this will not change the graph serialization. Prefab overrides are also supported.", MessageType.None); } if (owner.exposedParameters == null) { owner.exposedParameters = new System.Collections.Generic.List <ExposedParameter>(); } var exposedParam = owner.exposedParameters.Find(x => x.targetVariableID == variable.ID); if (exposedParam == null) { GUILayout.BeginHorizontal(); GUI.enabled = false; EditorUtils.DrawEditorFieldDirect(new GUIContent(variable.name, "This is an Exposed Public variable of the graph local blackboard. You can use the arrows button on the right side to override/parametrize the default value."), variable.value, variable.varType, default(InspectedFieldInfo)); GUI.enabled = true; if (GUILayout.Button(EditorUtils.GetTempContent("▽△", null, "Override Variable"), Styles.centerLabel, GUILayout.Width(24))) { UndoUtility.RecordObject(owner, "Add Override"); exposedParam = ExposedParameter.CreateInstance(variable); owner.exposedParameters.Add(exposedParam); // DISABLE: was creating confusion when editing multiple graphowner instances using asset graphs and having different variable overrides // exposedParam.Bind(owner.graph.blackboard); UndoUtility.SetDirty(owner); } EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link); GUILayout.EndHorizontal(); continue; } GUILayout.BeginHorizontal(); var info = new InspectedFieldInfo(); info.unityObjectContext = owner; exposedParam.valueBoxed = EditorUtils.DrawEditorFieldDirect(new GUIContent(variable.name), exposedParam.valueBoxed, variable.varType, info); if (GUILayout.Button(EditorUtils.GetTempContent("▼▲", null, "Remove Override"), Styles.centerLabel, GUILayout.Width(24))) { UndoUtility.RecordObject(owner, "Remove Override"); // DISABLE: was creating confusion when editing multiple graphowner instances using asset graphs and having different variable overrides // exposedParam.UnBind(owner.graph.blackboard); owner.exposedParameters.Remove(exposedParam); UndoUtility.SetDirty(owner); continue; } EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link); GUILayout.EndHorizontal(); var index = owner.exposedParameters.IndexOf(exposedParam); var serProp = exposeParamsProp.GetArrayElementAtIndex(index); var isPrefabOverride = serProp.prefabOverride; if (isPrefabOverride) { var rect = GUILayoutUtility.GetLastRect(); EditorUtils.MarkLastFieldOverride(); if (rect.Contains(Event.current.mousePosition) && Event.current.type == EventType.ContextClick) { var prefabAssetPath = PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(owner); var asset = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(prefabAssetPath); var menu = new GenericMenu(); menu.AddItem(new GUIContent($"Apply to Prefab '{asset.name}'"), false, () => { UndoUtility.RecordObject(owner, "Apply Exposed Parameter"); UndoUtility.RecordObject(asset, "Apply Exposed Parameter"); PrefabUtility.ApplyPropertyOverride(serProp, prefabAssetPath, InteractionMode.UserAction); UndoUtility.SetDirty(owner); UndoUtility.SetDirty(asset); }); menu.AddItem(new GUIContent("Revert"), false, () => { UndoUtility.RecordObject(owner, "Revert Exposed Parameter"); PrefabUtility.RevertPropertyOverride(serProp, InteractionMode.UserAction); UndoUtility.SetDirty(owner); }); menu.ShowAsContext(); } } } if (separatorDrawn) { EditorUtils.Separator(); } //cleanup if (owner.exposedParameters != null) { for (var i = owner.exposedParameters.Count; i-- > 0;) { var exposedParam = owner.exposedParameters[i]; var variable = owner.graph.blackboard.GetVariableByID(exposedParam.targetVariableID); if (variable == null || !variable.isExposedPublic || variable.isPropertyBound) { owner.exposedParameters.RemoveAt(i); UndoUtility.SetDirty(owner); } } } }
static public void ToolsOpenPerisitentData() { EditorUtils.ExplorerFolder(Application.persistentDataPath); }
///---------------------------------------------------------------------------------------------- ///---------------------------------------UNITY EDITOR------------------------------------------- #if UNITY_EDITOR protected override void OnTaskInspectorGUI() { if (!Application.isPlaying && GUILayout.Button("Select Method")) { var menu = new UnityEditor.GenericMenu(); if (agent != null) { foreach (var comp in agent.GetComponents(typeof(Component)).Where(c => c.hideFlags != HideFlags.HideInInspector)) { menu = EditorUtils.GetInstanceMethodSelectionMenu(comp.GetType(), typeof(object), typeof(object), SetMethod, 6, false, false, menu); } menu.AddSeparator("/"); } foreach (var t in TypePrefs.GetPreferedTypesList(typeof(object))) { menu = EditorUtils.GetStaticMethodSelectionMenu(t, typeof(object), typeof(object), SetMethod, 6, false, false, menu); if (typeof(UnityEngine.Component).IsAssignableFrom(t)) { menu = EditorUtils.GetInstanceMethodSelectionMenu(t, typeof(object), typeof(object), SetMethod, 6, false, false, menu); } } menu.ShowAsBrowser("Select Method", this.GetType()); Event.current.Use(); } var m = targetMethod; if (m != null) { GUILayout.BeginVertical("box"); UnityEditor.EditorGUILayout.LabelField("Type", targetMethod.RTReflectedType().FriendlyName()); UnityEditor.EditorGUILayout.LabelField("Method", m.Name); UnityEditor.EditorGUILayout.LabelField("Returns", m.ReturnType.FriendlyName()); UnityEditor.EditorGUILayout.HelpBox(DocsByReflection.GetMemberSummary(targetMethod), UnityEditor.MessageType.None); if (m.ReturnType == typeof(IEnumerator)) { GUILayout.Label("<b>This will execute as a Coroutine!</b>"); } GUILayout.EndVertical(); var paramNames = m.GetParameters().Select(p => p.Name.SplitCamelCase()).ToArray(); var variables = functionWrapper.GetVariables(); if (m.ReturnType == typeof(void)) { for (var i = 0; i < paramNames.Length; i++) { NodeCanvas.Editor.BBParameterEditor.ParameterField(paramNames[i], variables[i]); } } else { for (var i = 0; i < paramNames.Length; i++) { NodeCanvas.Editor.BBParameterEditor.ParameterField(paramNames[i], variables[i + 1]); } if (m.ReturnType != typeof(IEnumerator)) { NodeCanvas.Editor.BBParameterEditor.ParameterField("Save Return Value", variables[0], true); } } } }
static void CreateDebugController() { EditorUtils.CreateAsset <PlayerInfoSetting>(PlayerInfoSettingPath); }
protected virtual IOperation CreateOperationFromEditor(Vector3 worldPosition, TerrainToolEditor editor) { var voxelType = EditorUtils.GetVoxelTypeFromIndex(VoxelTypeIndex, editor.Terrain.VoxelTypeSet); return(AxisAlignedCube.CreateFromUnityWorld(editor.Terrain, Dig, worldPosition, Size, voxelType)); }
public virtual void OnInspector(TerrainToolEditor editor) { Dig = EditorGUILayout.ToggleLeft("Dig", Dig); Size = editor.SizeField("Size:", Size, true); VoxelTypeIndex = EditorUtils.VoxelTypeField("Voxel type:", VoxelTypeIndex, editor.Terrain.VoxelTypeSet); }
static void CreateItemDataList() { EditorUtils.CreateScriptable <AssetBundlesConfig>(); }
protected IOperation CreateOperationFromEditor(Vector3 worldPosition, TerrainToolEditor editor) { var voxelType = EditorUtils.GetVoxelTypeFromIndex(VoxelTypeIndex, editor.Terrain.VoxelTypeSet); return(FlattenAxisAlignedCube.CreateFromUnityWorld(editor.Terrain, UpsideDown, worldPosition, Size, DesiredHeight, voxelType)); }
protected override void OnNodeInspectorGUI() { isDynamic = UnityEditor.EditorGUILayout.Toggle("Dynamic", isDynamic); EditorUtils.Separator(); }
public override void FormatLines(ITextView textView, EditorUtils.SnapshotLineRange range) { }
public override void OnInspectorGUI() { var defaultColor = GUI.color; serializedObject.Update(); // LOGO GUILayout.Space(10); EditorUtils.DrawLogo(); GUILayout.Space(5); EditorGUI.BeginChangeCheck(); // SETTINGS BLOCK EditorGUILayout.LabelField("Terrain 2D", EditorStyles.boldLabel); GUILayout.BeginVertical("box"); // TERRAIN SETTINGS BOX EditorGUILayout.LabelField("Terrain Settings:", EditorStyles.boldLabel); GUILayout.BeginVertical("box"); // WIDTH EditorGUILayout.PropertyField(_widthProperty, _widthContent); // HEIGHT EditorGUILayout.PropertyField(_heightProperty, _heightContent); // LINE WIDTH EditorGUILayout.PropertyField(_lineWidthProperty, _lineWifthContent); // QUALITY EditorGUILayout.PropertyField(_qualityProperty, _qualityContent); // Collider Type EditorGUILayout.PropertyField(_colliderTypeProperty, _colliderTypeContent); // TERRAIN SETTINGS BOX END EditorGUILayout.EndVertical(); // UV SETTINGS BOX EditorGUILayout.LabelField("Terrain UV Settings:", EditorStyles.boldLabel); GUILayout.BeginVertical("box"); // WIDTH EditorGUILayout.PropertyField(_groundUVOffsetProperty, _groundUVOffsetContent); // HEIGHT EditorGUILayout.PropertyField(_groundUVScaleProperty, _groundUVScaleContent); // UV SETTINGS BOX END EditorGUILayout.EndVertical(); if (targets.Length == 1) { EditorGUILayout.LabelField("KeyPoints:", EditorStyles.boldLabel); GUILayout.BeginVertical("box"); GUILayout.BeginHorizontal("box"); var buttonSettings = new GUILayoutOption[] { GUILayout.Width(25f), GUILayout.Height(25f) }; var labelSettings = new GUILayoutOption[] { GUILayout.Height(23f) }; var prevButton = GUILayout.Button("<", buttonSettings); GUILayout.BeginHorizontal("box", labelSettings); if (_selectedIndex >= 0) { GUILayout.Label(string.Format("{0}/{1}", _selectedIndex + 1, _terrain.GetKeyPointsCount()), CustomEditorStyles.CenterLabel); } else { GUILayout.Label("Select KeyPoint in SceneView.", CustomEditorStyles.CenterLabel); } GUILayout.EndHorizontal(); var nextButton = GUILayout.Button(">", buttonSettings); GUILayout.EndVertical(); if (prevButton || nextButton) { SwitchId(prevButton, nextButton); } // KEYPOINT SETTINGS BOX EditorGUILayout.LabelField("Settings:", EditorStyles.boldLabel); GUILayout.BeginVertical("box"); if (_selectedIndex < 0) { var height = EditorGUIUtility.singleLineHeight * 3 + EditorGUIUtility.standardVerticalSpacing; GUILayout.Space(height / 2f); EditorGUILayout.LabelField("- none -", CustomEditorStyles.CenterLabel); GUILayout.Space(height / 2f); } else { DrawKeyPointSettings(_selectedIndex); } // KEYPOINT SETTINGS BOX END EditorGUILayout.EndVertical(); GUILayout.EndVertical(); } // SETTINGS BLOCK END EditorGUILayout.EndVertical(); if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); } }
static public void ToolsToolsOpenOutput() { string outputPath = PackageUtils.GetCurBuildSettingOutputPath(); EditorUtils.ExplorerFolder(outputPath); }
void OnGUI() { Repaint(); EditorGUILayout.HelpBox("Here you can configure commonly used types for your game for easier access wherever you need to select a type\nFor example when setting the type of an Object variable as well as when setting the agent type in any 'Script Control' Task", MessageType.Info); scrollPos = GUILayout.BeginScrollView(scrollPos); EditorUtils.ReorderableList(typeList, delegate(int i){ GUILayout.BeginHorizontal("box"); EditorGUILayout.LabelField(typeList[i].Name, typeList[i].Namespace); if (GUILayout.Button("X", GUILayout.Width(18))) { typeList.RemoveAt(i); Save(); } GUILayout.EndHorizontal(); }); if (GUILayout.Button("Add New Type")) { GenericMenu.MenuFunction2 Selected = delegate(object t){ if (!typeList.Contains((System.Type)t)) { typeList.Add((System.Type)t); Save(); } else { ShowNotification(new GUIContent("Type already in list")); } }; var menu = new UnityEditor.GenericMenu(); foreach (System.Type t in EditorUtils.GetAssemblyTypes(typeof(object))) { var friendlyName = t.Assembly.GetName().Name + "/" + (string.IsNullOrEmpty(t.Namespace)? "No Namespace/" : t.Namespace.Replace(".", "/") + "/") + EditorUtils.TypeName(t); var category = "Classes/"; if (t.IsInterface) { category = "Interfaces/"; } if (t.IsEnum) { category = "Enumerations/"; } menu.AddItem(new GUIContent(category + friendlyName), false, Selected, t); } menu.ShowAsContext(); Event.current.Use(); } if (GUILayout.Button("RESET DEFAULTS")) { NCPrefs.ResetTypeConfiguration(); OnEnable(); } GUILayout.EndScrollView(); }
//... void DoValidGraphControls() { //Graph comments ONLY if Bound graph else readonly if (owner.graph != null) { if (owner.graphIsBound) { GUI.contentColor = Color.white.WithAlpha(0.6f); owner.graph.comments = GUILayout.TextArea(owner.graph.comments, GUILayout.Height(45)); GUI.contentColor = Color.white; EditorUtils.CommentLastTextField(owner.graph.comments, "Graph comments..."); } else { GUI.enabled = false; GUILayout.TextArea(owner.graph.comments, GUILayout.Height(45)); GUI.enabled = true; } } if (!isBoundGraphOnPrefabRoot) { //Open behaviour GUI.backgroundColor = Colors.lightBlue; if (GUILayout.Button(("Edit " + owner.graphType.Name.SplitCamelCase()).ToUpper())) { GraphEditor.OpenWindow(owner); } GUI.backgroundColor = Color.white; } else { EditorGUILayout.HelpBox("Bound Graphs on prefabs can only be edited by opening the prefab in the prefab editor.", MessageType.Info); //Open prefab and behaviour GUI.backgroundColor = Colors.lightBlue; if (GUILayout.Button(("Open Prefab And Edit " + owner.graphType.Name.SplitCamelCase()).ToUpper())) { AssetDatabase.OpenAsset(owner); GraphEditor.OpenWindow(owner); } GUI.backgroundColor = Color.white; } //bind asset or delete bound graph if (!Application.isPlaying) { if (!owner.graphIsBound) { if (GUILayout.Button("Bind Graph")) { if (EditorUtility.DisplayDialog("Bind Graph", "This will make a local copy of the graph, bound to the owner.\n\nThis allows you to make local changes and assign scene object references directly.\n\nNote that you can also use scene object references through the use of Blackboard Variables.\n\nBind Graph?", "YES", "NO")) { AssetToBound(); } } } else { if (GUILayout.Button("Delete Bound Graph")) { if (EditorUtility.DisplayDialog("Delete Bound Graph", "Are you sure?", "YES", "NO")) { Object.DestroyImmediate(owner.graph, true); UndoUtility.RecordObject(owner, "Delete Bound Graph"); owner.SetBoundGraphReference(null); UndoUtility.SetDirty(owner); } } } } }
static void Editor_CreateGraph() { var newGraph = EditorUtils.CreateAsset <BehaviourTree>(); UnityEditor.Selection.activeObject = newGraph; }
public static object PropertyField(object obj, GUIContent label, ref bool dataChanged, GUIStyle style, params GUILayoutOption[] options) { LocalisedStringRef localisedString = (LocalisedStringRef)obj; bool editorCollapsed = !EditorGUILayout.Foldout(!localisedString._editorCollapsed, label); if (editorCollapsed != localisedString._editorCollapsed) { localisedString._editorCollapsed = editorCollapsed; dataChanged = true; } if (!editorCollapsed) { int origIndent = EditorGUI.indentLevel; EditorGUI.indentLevel++; //Draw list of possible keys int currentKeyIndex = 0; { string[] keys = Localisation.GetStringKeys(); string currentKey = localisedString.GetLocalisationKey(); for (int i = 0; i < keys.Length; i++) { if (keys[i] == currentKey) { currentKeyIndex = i; break; } } EditorGUI.BeginChangeCheck(); currentKeyIndex = EditorGUILayout.Popup("Localisation Key", currentKeyIndex, keys); //If key has changed if (EditorGUI.EndChangeCheck()) { if (currentKeyIndex == 0) { localisedString = new LocalisedStringRef(); } else { localisedString = new LocalisedStringRef(keys[currentKeyIndex]); } dataChanged = true; } } //Draw buttons for adding new key if (currentKeyIndex == 0) { string[] folders = Localisation.GetStringFolders(); int currentFolderIndex = 0; string keyWithoutFolder; Localisation.GetFolderIndex(localisedString.GetLocalisationKey(), out currentFolderIndex, out keyWithoutFolder); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.LabelField(new GUIContent("New Key"), GUILayout.Width(EditorUtils.GetLabelWidth())); string editorParentName = localisedString.GetAutoNameParentName(); EditorGUI.BeginChangeCheck(); int newFolderIndex = EditorGUILayout.Popup(currentFolderIndex, folders); string currentFolder = newFolderIndex == 0 ? "" : folders[newFolderIndex]; if (EditorGUI.EndChangeCheck()) { if (newFolderIndex != 0) { localisedString = new LocalisedStringRef(currentFolder + "/" + keyWithoutFolder); localisedString.SetAutoNameParentName(editorParentName); dataChanged = true; } } EditorGUILayout.LabelField(new GUIContent("/"), GUILayout.Width(44)); EditorGUI.BeginChangeCheck(); keyWithoutFolder = EditorGUILayout.TextField(keyWithoutFolder); if (EditorGUI.EndChangeCheck()) { localisedString = new LocalisedStringRef(currentFolder + "/" + keyWithoutFolder); localisedString.SetAutoNameParentName(editorParentName); dataChanged = true; } if (GUILayout.Button("Auto", GUILayout.Width(36))) { string newKey = localisedString.GetAutoKey(); localisedString = new LocalisedStringRef(newKey); localisedString.SetAutoNameParentName(editorParentName); dataChanged = true; } if (GUILayout.Button("Add", GUILayout.Width(32)) && !string.IsNullOrEmpty(localisedString.GetLocalisationKey())) { if (!Localisation.Exists(localisedString.GetLocalisationKey())) { Localisation.Set(localisedString.GetLocalisationKey(), Localisation.GetCurrentLanguage(), string.Empty); LocalisationEditorWindow.EditString(localisedString.GetLocalisationKey()); } dataChanged = true; } } EditorGUILayout.EndHorizontal(); } //Draw actual localised text (can be edited to update localisation file) { string currentKey = localisedString.GetLocalisationKey(); //Only display if have a valid key if (!string.IsNullOrEmpty(currentKey) && Localisation.Exists(currentKey)) { EditorGUI.BeginChangeCheck(); string text; if (style != null) { text = EditorGUILayout.TextArea(Localisation.GetRawString(currentKey), style); } else { text = EditorGUILayout.TextArea(Localisation.GetRawString(currentKey)); } if (EditorGUI.EndChangeCheck()) { Localisation.Set(currentKey, Localisation.GetCurrentLanguage(), text); } } } EditorGUI.indentLevel = origIndent; } return(localisedString); }
public override bool DrawGui(Object target, bool asFoldout, bool includeScriptField, bool initializeAsOpen = true, bool asWindow = false) { bool isExpanded = base.DrawGui(target, asFoldout, includeScriptField, initializeAsOpen, asWindow); bool isHierarchyMode = EditorGUIUtility.hierarchyMode; if (!asFoldout || isExpanded) { SerializedObject soTarget = new SerializedObject(Single); SerializedProperty tags = soTarget.FindProperty("hitGroupTags"); //Rect boxrect = EditorGUILayout.BeginVertical(); //EditorGUI.LabelField(boxrect, GUIContent.none, (GUIStyle)"flow overlay box"); EditorGUILayout.Space(); Rect rt = EditorGUILayout.GetControlRect(); float padding = 5f; float xButtonWidth = 16f; float fieldLeft = rt.xMin + EditorGUIUtility.labelWidth - padding; // rt.width - EditorGUIUtility.fieldWidth; float fieldWidth = rt.width - fieldLeft - padding - (isHierarchyMode ? 0 : xButtonWidth); // EditorGUIUtility.fieldWidth; // Default tag will always be 0 and 'Default' EditorGUI.LabelField(new Rect(rt.xMin + padding, rt.yMin, rt.width - padding * 2 - xButtonWidth, rt.height), "Hit Group 0", DEF_NAME); EditorGUI.BeginChangeCheck(); soTarget.Update(); for (int i = 1; i < tags.arraySize; i++) { rt = EditorGUILayout.GetControlRect(); EditorGUI.LabelField(new Rect(rt.xMin + padding, rt.yMin, rt.width - padding * 2 - xButtonWidth, rt.height), "Hit Group " + i); SerializedProperty tag = tags.GetArrayElementAtIndex(i); tag.stringValue = EditorGUI.TextField(new Rect(fieldLeft, rt.yMin, fieldWidth, rt.height), GUIContent.none, tag.stringValue); bool isRepeat = IsTagAlreadyUsed(tag.stringValue, i); if (isRepeat) { EditorUtils.CreateErrorIconF(EditorGUIUtility.labelWidth - 2, rt.yMin, "Each name can only be used once, repeats will be discarded at build time which cause some unpedictable results when looking up by name."); } if (GUI.Button(new Rect(rt.xMin + rt.width - xButtonWidth - padding, rt.yMin, xButtonWidth, rt.height), "X")) { tags.DeleteArrayElementAtIndex(i); } } soTarget.ApplyModifiedProperties(); rt = EditorGUI.IndentedRect(EditorGUILayout.GetControlRect()); if (hitGroupTags.Count < 32) { if (GUI.Button(new Rect(rt.xMin + 8, rt.yMin + 3, rt.width - 14, rt.height + 4), "Add Hitbox Group")) { string newtag = "HitGroup" + hitGroupTags.Count; while (IsTagAlreadyUsed(newtag, hitGroupTags.Count)) { newtag += "X"; } Undo.RecordObject(Single, "Add Hit Group"); hitGroupTags.Add(newtag); EditorUtility.SetDirty(this); AssetDatabase.SaveAssets(); soTarget.Update(); } } rt = EditorGUILayout.GetControlRect(); //EditorGUILayout.EndVertical(); EditorGUILayout.HelpBox( "These tags are used by NSTHitboxGroupTag to assign colliders to hitbox groups, for things like headshots and critical hits.", MessageType.None); //EditorGUILayout.HelpBox(BitTools.BitsNeededForMaxValue((uint)(hitGroupTags.Count - 1)) + " bits per hit used for Rewind Cast hitmasks.", MessageType.None); EditorGUILayout.HelpBox(((hitGroupTags.Count > 1) ? hitGroupTags.Count : 0) + " bits per hit used for Rewind Cast hitmasks.", MessageType.None); if (EditorGUI.EndChangeCheck()) { AssetDatabase.SaveAssets(); } } return(isExpanded); }
public override void OnInspectorGUI() { UndoManager.CheckUndo(owner, "Graph Owner Inspector"); var ownerPeristant = EditorUtility.IsPersistent(owner); var label = owner.graphType.Name.SplitCamelCase(); if (owner.graph == null) { EditorGUILayout.HelpBox(owner.GetType().Name + " needs a " + label + ".\nAssign or Create a new one...", MessageType.Info); if (!Application.isPlaying && GUILayout.Button("CREATE NEW")) { Graph newGraph = null; if (EditorUtility.DisplayDialog("Create Graph", "Create a Bound or an Asset Graph?\n\n" + "Bound Graph is saved with the GraphOwner and you can use direct scene references within it.\n\n" + "Asset Graph is an asset file and can be reused amongst any number of GraphOwners.\n\n" + "You can convert from one type to the other at any time.", "Bound", "Asset")) { newGraph = NewAsLocal(); } else { newGraph = NewAsAsset(); } if (newGraph != null) { GraphEditor.OpenWindow(owner); } } owner.graph = (Graph)EditorGUILayout.ObjectField(label, owner.graph, owner.graphType, false); return; } GUILayout.Space(10); //Graph comments ONLY if Bound graph if (owner.graphIsLocal) { owner.graph.graphComments = GUILayout.TextArea(owner.graph.graphComments, GUILayout.Height(45)); EditorUtils.TextFieldComment(owner.graph.graphComments, "Graph comments..."); } //Open behaviour GUI.backgroundColor = EditorUtils.lightBlue; if (GUILayout.Button(("Edit " + owner.graphType.Name.SplitCamelCase()).ToUpper())) { GraphEditor.OpenWindow(owner); } GUI.backgroundColor = Color.white; if (!Application.isPlaying) { if (!owner.graphIsLocal && GUILayout.Button("Bind Graph")) { if (EditorUtility.DisplayDialog("Bind Graph", "This will make a local copy of the graph, bound to the owner.\n\nThis allows you to make local changes and assign scene object references directly.\n\nNote that you can also use scene references through the Blackboard Variables\n\nBind Graph?", "YES", "NO")) { AssetToLocal(); } } //Reference graph if (!owner.graphIsLocal) { owner.graph = (Graph)EditorGUILayout.ObjectField(label, owner.graph, owner.graphType, true); } else { if (GUILayout.Button("Delete Bound Graph")) { if (EditorUtility.DisplayDialog("Delete Bound Graph", "Are you sure?", "YES", "NO")) { Undo.DestroyObjectImmediate(owner.graph); Undo.RecordObject(owner, "Delete Bound"); owner.graph = null; EditorUtility.SetDirty(owner); } } } } //basic options // owner.blackboard = (Blackboard)EditorGUILayout.ObjectField("Blackboard", owner.blackboard as Blackboard, typeof(Blackboard), true); owner.enableAction = (GraphOwner.EnableAction)EditorGUILayout.EnumPopup("On Enable", owner.enableAction); owner.disableAction = (GraphOwner.DisableAction)EditorGUILayout.EnumPopup("On Disable", owner.disableAction); EditorUtils.Separator(); //derived GUI OnExtraOptions(); //execution debug controls if (Application.isPlaying && owner.graph != null && !ownerPeristant) { var pressed = new GUIStyle(GUI.skin.GetStyle("button")); pressed.normal.background = GUI.skin.GetStyle("button").active.background; GUILayout.BeginHorizontal("box"); GUILayout.FlexibleSpace(); if (GUILayout.Button(EditorUtils.playIcon, owner.isRunning || owner.isPaused? pressed : (GUIStyle)"button")) { if (owner.isRunning || owner.isPaused) { owner.StopBehaviour(); } else { owner.StartBehaviour(); } } if (GUILayout.Button(EditorUtils.pauseIcon, owner.isPaused? pressed : (GUIStyle)"button")) { if (owner.isPaused) { owner.StartBehaviour(); } else { owner.PauseBehaviour(); } } OnGrapOwnerControls(); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } EditorUtils.ShowAutoEditorGUI(owner); EditorUtils.EndOfInspector(); UndoManager.CheckDirty(owner); if (GUI.changed) { EditorUtility.SetDirty(owner); if (owner.graph != null) { EditorUtility.SetDirty(owner.graph); } } }
///Draw an automatic editor inspector for this node. protected void DrawDefaultInspector() { EditorUtils.ReflectedObjectInspector(this); }
bool Initialise(SerializedProperty property) { if (initialised) { return(true); } hidesFirstEnum = fieldInfo.GetCustomAttribute <HideFirstEnumValue>() != null; Type inheritingType = fieldInfo.FieldType.BaseType; Type[] genericArguments = inheritingType.GetGenericArguments(); Type enumType = genericArguments[0]; string[] names = Enum.GetNames(enumType); Array enumValues = Enum.GetValues(enumType); Dictionary <int, string> valuesToNames = new Dictionary <int, string>(); dictionary = inheritingType.GetGenericTypeDefinition() == typeof(EnumToValueDictionary <,>); SerializedProperty values = property.FindPropertyRelative("values"); SerializedProperty hidesFirstEnumProp = property.FindPropertyRelative("hidesFirstEnum"); if (dictionary) { //Remove any enum names that have duplicate indices. for (int i = 0; i < names.Length; i++) { int value = (int)enumValues.GetValue(i); string name = names[i]; if (valuesToNames.ContainsKey(value)) { valuesToNames[value] = $"{valuesToNames[value]}/{name}"; } else { valuesToNames.Add(value, name); } } enumNames = valuesToNames.Values.ToArray(); SerializedProperty keys = property.FindPropertyRelative("keys"); //Get the values currently stored on the object and make sure they're set to the correct indices in the resized list. FieldInfo valuesField = inheritingType.GetField("values", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo keysField = inheritingType.GetField("keys", BindingFlags.Instance | BindingFlags.NonPublic); //Collect former values var dictionaryOldValues = new Dictionary <int, object>(); object parent = EditorUtils.GetObjectFromProperty(property, out _, out _); Array valuesArray = (Array)valuesField.GetValue(parent); for (int i = 0; i < keys.arraySize; i++) { int key = keys.GetArrayElementAtIndex(i).intValue; if (dictionaryOldValues.ContainsKey(key)) { continue; } dictionaryOldValues.Add(key, valuesArray.GetValue(i)); } //Resize the arrays int length = valuesToNames.Count; keys.arraySize = length; values.arraySize = length; property.serializedObject.ApplyModifiedPropertiesWithoutUndo(); //Apply the old dictionary values to the new arrays. Array valuesArrayFinal = (Array)valuesField.GetValue(parent); Array keysArrayFinal = (Array)keysField.GetValue(parent); int index = 0; foreach (KeyValuePair <int, string> valueToName in valuesToNames) { keysArrayFinal.SetValue(valueToName.Key, index); if (dictionaryOldValues.TryGetValue(valueToName.Key, out var @object)) { valuesArrayFinal.SetValue(@object, index); } index++; } EditorUtility.SetDirty(property.serializedObject.targetObject); property.serializedObject.Update(); } else { //Remove any enum names that have duplicate indices. int current = 0; foreach (string name in names) { int index = (int)Enum.Parse(enumType, name); if (index > current) { Debug.LogWarning("EnumToValue does not support non-consecutive enum values use an EnumToValueDictionary instead." + $"{enumType} in {property.serializedObject.targetObject}"); return(false); } if (valuesToNames.ContainsKey(index)) { valuesToNames[index] = $"{valuesToNames[index]}/{name}"; continue; } valuesToNames.Add(index, name); current++; } enumNames = valuesToNames.Values.ToArray(); values.arraySize = enumNames.Length; } tooltips = new GUIContent[valuesToNames.Count]; int j = 0; foreach (KeyValuePair <int, string> valuesToName in valuesToNames) { tooltips[j++] = new GUIContent(string.Empty, valuesToName.Key.ToString()); } List <float> heights = new List <float>(); totalPropertyHeight = 0; property = values.GetArrayElementAtIndex(0); if (property.hasChildren && property.propertyType == SerializedPropertyType.Generic) { multiLine = true; SerializedProperty end = property.GetEndProperty(); bool enterChildren = true; while (property.NextVisible(enterChildren) && !SerializedProperty.EqualContents(property, end)) { float height = EditorGUI.GetPropertyHeight(property, false); heights.Add(height); totalPropertyHeight += height + EditorGUIUtility.standardVerticalSpacing; enterChildren = false; } } else { multiLine = false; float height = EditorGUI.GetPropertyHeight(property, false); heights.Add(height); totalPropertyHeight = height + EditorGUIUtility.standardVerticalSpacing; } propertyHeights = heights.ToArray(); hidesFirstEnumProp.boolValue = hidesFirstEnum; hidesFirstEnumProp.serializedObject.ApplyModifiedPropertiesWithoutUndo(); initialised = true; return(true); }
///Editor. Draw the connections line from this node, to all of its children. This is the default hierarchical tree style. Override in each system's base node class. virtual protected void DrawNodeConnections(Rect drawCanvas, bool fullDrawPass, Vector2 canvasMousePos, float zoomFactor) { var e = Event.current; //Receive connections first if (clickedPort != null && e.type == EventType.MouseUp && e.button == 0) { if (rect.Contains(e.mousePosition)) { graph.ConnectNodes(clickedPort.parent, this, clickedPort.portIndex); clickedPort = null; e.Use(); } else { dragDropMisses++; if (dragDropMisses == graph.allNodes.Count && clickedPort != null) { var source = clickedPort.parent; var index = clickedPort.portIndex; var pos = e.mousePosition; clickedPort = null; System.Action <System.Type> Selected = delegate(System.Type type) { var newNode = graph.AddNode(type, pos); graph.ConnectNodes(source, newNode, index); GraphEditorUtility.activeElement = newNode; }; var menu = EditorUtils.GetTypeSelectionMenu(graph.baseNodeType, Selected); if (zoomFactor == 1) { menu.ShowAsBrowser(string.Format("Add {0} Node", graph.GetType().Name), graph.baseNodeType); } else { GraphEditorUtility.PostGUI += () => { menu.ShowAsContext(); }; } e.Use(); } } } if (maxOutConnections == 0) { return; } if (fullDrawPass || drawCanvas.Overlaps(rect)) { var nodeOutputBox = new Rect(rect.x, rect.yMax - 4, rect.width, 12); GUI.Box(nodeOutputBox, string.Empty, StyleSheet.nodePortContainer); //draw the ports if (outConnections.Count < maxOutConnections || maxOutConnections == -1) { for (var i = 0; i < outConnections.Count + 1; i++) { var portRect = new Rect(0, 0, 10, 10); portRect.center = new Vector2(((rect.width / (outConnections.Count + 1)) * (i + 0.5f)) + rect.xMin, rect.yMax + 6); GUI.Box(portRect, string.Empty, StyleSheet.nodePortEmpty); if (collapsed) { continue; } if (GraphEditorUtility.allowClick) { //start a connection by clicking a port EditorGUIUtility.AddCursorRect(portRect, MouseCursor.ArrowPlus); if (e.type == EventType.MouseDown && e.button == 0 && portRect.Contains(e.mousePosition)) { dragDropMisses = 0; clickedPort = new GUIPort(i, this, portRect.center); e.Use(); } } } } } //draw the new drag&drop connection line if (clickedPort != null && clickedPort.parent == this) { var tangA = default(Vector2); var tangB = default(Vector2); ParadoxNotion.CurveUtils.ResolveTangents(clickedPort.pos, e.mousePosition, 0.5f, PlanarDirection.Vertical, out tangA, out tangB); Handles.DrawBezier(clickedPort.pos, e.mousePosition, clickedPort.pos + tangA, e.mousePosition + tangB, StyleSheet.GetStatusColor(Status.Resting).WithAlpha(0.8f), null, 3); } //draw all connected lines for (var i = 0; i < outConnections.Count; i++) { var connection = outConnections[i]; if (connection != null) { var sourcePos = new Vector2(((rect.width / (outConnections.Count + 1)) * (i + 1)) + rect.xMin, rect.yMax + 6); var targetPos = new Vector2(connection.targetNode.rect.center.x, connection.targetNode.rect.y); var sourcePortRect = new Rect(0, 0, 12, 12); sourcePortRect.center = sourcePos; var targetPortRect = new Rect(0, 0, 15, 15); targetPortRect.center = targetPos; var boundRect = RectUtils.GetBoundRect(sourcePortRect, targetPortRect); if (fullDrawPass || drawCanvas.Overlaps(boundRect)) { GUI.Box(sourcePortRect, string.Empty, StyleSheet.nodePortConnected); if (collapsed || connection.targetNode.isHidden) { continue; } connection.DrawConnectionGUI(sourcePos, targetPos); if (GraphEditorUtility.allowClick) { //On right click disconnect connection from the source. if (e.type == EventType.ContextClick && sourcePortRect.Contains(e.mousePosition)) { graph.RemoveConnection(connection); e.Use(); return; } //On right click disconnect connection from the target. if (e.type == EventType.ContextClick && targetPortRect.Contains(e.mousePosition)) { graph.RemoveConnection(connection); e.Use(); return; } } } } } }
private static void Disable() { EditorUtils.SetEnabled(DEFINE_KEY, false); }
//Handles events, Mouse downs, ups etc. static void HandleEvents(Node node, Event e) { //Node click if (e.type == EventType.MouseDown && GraphEditorUtility.allowClick && e.button != 2) { Undo.RegisterCompleteObjectUndo(node.graph, "Move Node"); if (!e.control) { GraphEditorUtility.activeElement = node; } if (e.control) { if (node.isSelected) { GraphEditorUtility.activeElements.Remove(node); } else { GraphEditorUtility.activeElements.Add(node); } } if (e.button == 0) { node.nodeIsPressed = true; } //Double click if (e.button == 0 && e.clickCount == 2) { if (node is IGraphAssignable && (node as IGraphAssignable).nestedGraph != null) { node.graph.currentChildGraph = (node as IGraphAssignable).nestedGraph; node.nodeIsPressed = false; } else if (node is ITaskAssignable && (node as ITaskAssignable).task != null) { EditorUtils.OpenScriptOfType((node as ITaskAssignable).task.GetType()); } else { EditorUtils.OpenScriptOfType(node.GetType()); } e.Use(); } node.OnNodePicked(); } //Mouse up if (e.type == EventType.MouseUp) { if (node.nodeIsPressed) { node.TrySortConnectionsByPositionX(); } node.nodeIsPressed = false; node.OnNodeReleased(); } }
public override void FormatLines(ITextView textView, EditorUtils.SnapshotLineRange range) { throw new NotImplementedException(); }
public static void BatchCreateArtistFont() { string dirName = ""; string fntname = EditorUtils.SelectObjectPathInfo(ref dirName).Split('.')[0]; Debug.Log(fntname); Debug.Log(dirName); string fntFileName = dirName + fntname + ".fnt"; Font CustomFont = new Font(); { AssetDatabase.CreateAsset(CustomFont, dirName + fntname + ".fontsettings"); AssetDatabase.SaveAssets(); } TextAsset BMFontText = null; { BMFontText = AssetDatabase.LoadAssetAtPath(fntFileName, typeof(TextAsset)) as TextAsset; } //Debug.Log(BMFontText.ToString().Replace("\"", "\'")); Debug.Log(BMFontText.text); JsonString js = JsonMapper.ToObject <JsonString>(BMFontText.text); //JsonString js = JsonUtility.FromJson<JsonString>(BMFontText.text); Debug.Log(js.file); BMFont mbFont = new BMFont(); BMFontReader.Load(mbFont, BMFontText.name, BMFontText.bytes); // 借用NGUI封装的读取类 CharacterInfo[] characterInfo = new CharacterInfo[mbFont.glyphs.Count]; for (int i = 0; i < mbFont.glyphs.Count; i++) { BMGlyph bmInfo = mbFont.glyphs[i]; CharacterInfo info = new CharacterInfo(); info.index = bmInfo.index; Rect r = new Rect(); r.x = (float)bmInfo.x / (float)mbFont.texWidth; r.y = 1 - (float)bmInfo.y / (float)mbFont.texHeight; r.width = (float)bmInfo.width / (float)mbFont.texWidth; r.height = -1f * (float)bmInfo.height / (float)mbFont.texHeight; info.uvBottomLeft = new Vector2(r.xMin, r.yMin); info.uvBottomRight = new Vector2(r.xMax, r.yMin); info.uvTopLeft = new Vector2(r.xMin, r.yMax); info.uvTopRight = new Vector2(r.xMax, r.yMax); //info.uv.x = (float)bmInfo.x / (float)mbFont.texWidth; //info.uv.y = 1 - (float)bmInfo.y / (float)mbFont.texHeight; //info.uv.width = (float)bmInfo.width / (float)mbFont.texWidth; //info.uv.height = -1f * (float)bmInfo.height / (float)mbFont.texHeight; r.x = (float)bmInfo.offsetX; r.y = (float)bmInfo.offsetY; r.width = (float)bmInfo.width; r.height = (float)bmInfo.height; //info.vert.x = (float)bmInfo.offsetX; //info.vert.y = (float)bmInfo.offsetY; //info.vert.width = (float)bmInfo.width; //info.vert.height = (float)bmInfo.height; info.minX = (int)r.xMin; info.maxX = (int)r.xMax; info.minY = (int)r.yMax; info.maxY = (int)r.yMin; info.advance = (int)bmInfo.advance; characterInfo[i] = info; } CustomFont.characterInfo = characterInfo; string textureFilename = dirName + mbFont.spriteName + ".png"; Material mat = null; { Shader shader = Shader.Find("Transparent/Diffuse"); mat = new Material(shader); Texture tex = AssetDatabase.LoadAssetAtPath(textureFilename, typeof(Texture)) as Texture; mat.SetTexture("_MainTex", tex); AssetDatabase.CreateAsset(mat, dirName + fntname + ".mat"); AssetDatabase.SaveAssets(); } CustomFont.material = mat; }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(position, label, property); SerializedProperty valueProperty = property.FindPropertyRelative("_value"); SerializedProperty sourceObjectProp = property.FindPropertyRelative("_sourceObject"); SerializedProperty editorTypeProperty = property.FindPropertyRelative("_editorType"); SerializedProperty editorFoldoutProp = property.FindPropertyRelative("_editorFoldout"); SerializedProperty editorHeightProp = property.FindPropertyRelative("_editorHeight"); Rect foldoutPosition = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight); editorFoldoutProp.boolValue = EditorGUI.Foldout(foldoutPosition, editorFoldoutProp.boolValue, label != null ? label.text : property.displayName); editorHeightProp.floatValue = EditorGUIUtility.singleLineHeight; if (editorFoldoutProp.boolValue) { int origIndent = EditorGUI.indentLevel; EditorGUI.indentLevel++; Rect typePosition = new Rect(position.x, position.y + editorHeightProp.floatValue, position.width, EditorGUIUtility.singleLineHeight); ValueSource <T> .eEdtiorType sourceType = (ValueSource <T> .eEdtiorType)editorTypeProperty.intValue; bool tempOverrideType = sourceType == ValueSource <T> .eEdtiorType.Static && EditorUtils.GetDraggingComponent <IValueSource <T> >() != null; if (tempOverrideType) { sourceType = ValueSource <T> .eEdtiorType.Source; } EditorGUI.BeginChangeCheck(); ValueSource <T> .eEdtiorType edtiorType = (ValueSource <T> .eEdtiorType)EditorGUI.EnumPopup(typePosition, "Source Type", sourceType); editorHeightProp.floatValue += EditorGUIUtility.singleLineHeight; if (EditorGUI.EndChangeCheck()) { sourceObjectProp.objectReferenceValue = null; editorTypeProperty.intValue = Convert.ToInt32(edtiorType); } Rect valuePosition = new Rect(position.x, position.y + editorHeightProp.floatValue, position.width, EditorGUIUtility.singleLineHeight); switch (sourceType) { case ValueSource <T> .eEdtiorType.Source: { Component currentComponent = sourceObjectProp.objectReferenceValue as Component; float height; Component selectedComponent = EditorUtils.ComponentField <IValueSource <T> >(new GUIContent("Value Source"), valuePosition, currentComponent, out height); editorHeightProp.floatValue += height; if (currentComponent != selectedComponent) { sourceObjectProp.objectReferenceValue = selectedComponent; editorTypeProperty.intValue = Convert.ToInt32(ValueSource <T> .eEdtiorType.Source); } } break; case ValueSource <T> .eEdtiorType.Static: { editorHeightProp.floatValue += DrawValueField(valuePosition, valueProperty); } break; } EditorGUI.indentLevel = origIndent; } EditorGUI.EndProperty(); }
public override void OnConnectionInspectorGUI(int i) { EditorUtils.BBParameterField("Weight", childWeights[i]); }
///---------------------------------------------------------------------------------------------- #if UNITY_EDITOR //Shows blackboard variables mapping public static void ShowVariablesMappingGUI(this IGraphAssignable assignable) { if (assignable.subGraph == null || !assignable.subGraph.allowBlackboardOverrides) { assignable.variablesMap = null; return; } ParadoxNotion.Design.EditorUtils.Separator(); ParadoxNotion.Design.EditorUtils.CoolLabel("SubGraph Variables Mapping"); var subTreeVariables = assignable.subGraph.blackboard.variables.Values; if (subTreeVariables.Count == 0 || !subTreeVariables.Any(v => v.isExposedPublic)) { UnityEditor.EditorGUILayout.HelpBox("SubGraph has no exposed public variables. You can make variables exposed public through the 'gear' menu of a variable.", UnityEditor.MessageType.Info); assignable.variablesMap = null; return; } UnityEditor.EditorGUILayout.HelpBox("Map SubGraph exposed variables to this graph variables.\nUse the arrow buttons on the right of each parameter to enable Write (In) and/or Read (Out) and thus override the default value. Write In takes place when the SubGraph starts.\nRead Out takes place when the SubGraph ends.", UnityEditor.MessageType.Info); foreach (var variable in subTreeVariables) { if (variable is Variable <VariableSeperator> ) { continue; } if (!variable.isExposedPublic || variable.isPropertyBound) { continue; } if (assignable.variablesMap == null) { assignable.variablesMap = new System.Collections.Generic.List <BBMappingParameter>(); } var bbParam = assignable.variablesMap.Find(x => x.targetSubGraphVariableID == variable.ID); if (bbParam == null) { GUILayout.BeginHorizontal(); GUI.enabled = false; EditorUtils.DrawEditorFieldDirect(new GUIContent(variable.name), variable.value, variable.varType, default(InspectedFieldInfo)); GUI.enabled = true; int tmp = 0; if (GUILayout.Button(EditorUtils.GetTempContent("▽", null, "Write (In)"), Styles.centerLabel, GUILayout.Width(12))) { tmp = 1; } UnityEditor.EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), UnityEditor.MouseCursor.Link); if (GUILayout.Button(EditorUtils.GetTempContent("△", null, "Read (Out)"), Styles.centerLabel, GUILayout.Width(12))) { tmp = -1; } if (tmp != 0) { UndoUtility.RecordObject(assignable.graph, "Override Variable"); bbParam = new BBMappingParameter(variable); bbParam.canWrite = tmp == 1; bbParam.canRead = tmp == -1; bbParam.useBlackboard = tmp == -1; bbParam.value = variable.value; bbParam.bb = assignable.graph.blackboard; assignable.variablesMap.Add(bbParam); UndoUtility.SetDirty(assignable.graph); } UnityEditor.EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), UnityEditor.MouseCursor.Link); GUILayout.EndHorizontal(); continue; } if (bbParam.varType != variable.varType && (bbParam.canRead || bbParam.canWrite)) { bbParam.SetType(variable.varType); } GUILayout.BeginHorizontal(); GUI.enabled = bbParam.canRead || bbParam.canWrite; NodeCanvas.Editor.BBParameterEditor.ParameterField(variable.name, bbParam); if (bbParam.canRead && !bbParam.useBlackboard) { EditorUtils.MarkLastFieldWarning("The parameter is set to Read Out, but is not linked to any Variable."); } GUI.enabled = true; if (GUILayout.Button(EditorUtils.GetTempContent(bbParam.canWrite ? "▼" : "▽", null, "Write (In)"), Styles.centerLabel, GUILayout.Width(12))) { UndoUtility.RecordObject(assignable.graph, "Set Write In"); bbParam.canWrite = !bbParam.canWrite; UndoUtility.SetDirty(assignable.graph); } UnityEditor.EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), UnityEditor.MouseCursor.Link); if (GUILayout.Button(EditorUtils.GetTempContent(bbParam.canRead ? "▲" : "△", null, "Read (Out)"), Styles.centerLabel, GUILayout.Width(12))) { UndoUtility.RecordObject(assignable.graph, "Set Read Out"); bbParam.canRead = !bbParam.canRead; UndoUtility.SetDirty(assignable.graph); } UnityEditor.EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), UnityEditor.MouseCursor.Link); if (!bbParam.canRead && !bbParam.canWrite) { UndoUtility.RecordObject(assignable.graph, "Remove Override"); assignable.variablesMap.Remove(bbParam); UndoUtility.SetDirty(assignable.graph); } GUILayout.EndHorizontal(); } if (assignable.variablesMap != null) { for (var i = assignable.variablesMap.Count; i-- > 0;) { var bbParam = assignable.variablesMap[i]; var variable = assignable.subGraph.blackboard.GetVariableByID(bbParam.targetSubGraphVariableID); if (variable == null || !variable.isExposedPublic || variable.isPropertyBound) { assignable.variablesMap.RemoveAt(i); UndoUtility.SetDirty(assignable.graph); } } } }
public override void OnConnectionInspectorGUI(int i) { priorities[i] = (BBParameter <float>)EditorUtils.BBParameterField("Priority Weight", priorities[i]); }