/// <summary> /// Functions that defines additional UI elements for the Scene View. /// Use Handle class instead of GUI classes for creating the UI /// </summary> public void OnSceneGUI() { /* * Updating UI Values */ // Update this position according to the current position and rotation camLookAt = camera.transform.position + camera.transform.forward * (camera.transform.position - camLookAt).magnitude; /* * Drawing UI */ // Define the colour of the UI Handles.color = Color.yellow; // Draw a line in the look at direction Handles.DrawLine(camera.transform.position, camLookAt); // Draws a sphere to show where the camera is looking at Handles.SphereCap(0, camLookAt, Quaternion.identity, 0.2f); // Tell Unity that we are going to change something so start checking if we've changed anything EditorGUI.BeginChangeCheck(); // Create a handle for users to adjust the look at position and store it camLookAt = Handles.PositionHandle(camLookAt, Quaternion.identity); // Check if there was anything changed if (EditorGUI.EndChangeCheck()) { // We will be changing the object based on the new camLookAt so ask Unity to record the change Undo.RegisterCompleteObjectUndo(camera.transform, Lang.GetString(Key.TranslatedLookAt)); // Update the Look At with the position that the user has changed camera.transform.LookAt(camLookAt); } }
[MenuItem("Gameplay/Spec Overview")] // Tells Unity to show this option in the menu bar public static void ShowWindow() { // Get a reference to the Window var window = GetWindow(typeof(SpecOverviewWindow)); // Set Title window.titleContent.text = Lang.GetString(Key.SpecOverviewTitle); }
/// <summary> /// Function that defines how the inspector should be drawn /// </summary> public override void OnInspectorGUI() { // Use this function to draw the default fields DrawDefaultInspector(); // Add additional fields here EditorGUILayout.Space(); EditorGUILayout.LabelField(Lang.GetString(Key.Others), header); camLookAt = EditorGUILayout.Vector3Field(Lang.GetString(Key.LookAt), camLookAt); }
public Language(IEnumerable <LanguageName> names, LanguageModifier modifier) { Modifier = modifier; if (names == null) { this.names = null; return; } this.names = names.Distinct().ToArray(); }
/// <summary> /// Function to draw the UI for a single property /// </summary> /// <param name="position">The position where Unity will start drawing this property</param> /// <param name="property">The property that Unity is modifying</param> /// <param name="label">The label of this property. Could be a variable name in a component that serializes this property.</param> public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { // Get the reference to the Properties which we will be changing var damageProp = property.FindPropertyRelative("damage"); var speedProp = property.FindPropertyRelative("speed"); // Indicate that we are starting to draw the UI for a single property // -- We must do this as Unity will treat every field as one property if we do not do this. // -- If Unity does that, every single value will be marked as changed when this property is part of a prefab EditorGUI.BeginProperty(position, label, property); // Draw label position = EditorGUI.PrefixLabel(position, label); position.width *= 0.5f; // Unity auto-indents. But we don't want to indent the following as it is a single property. So we save it first and set it to 0 manually. int indent = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; /* * Draw fields based on the BulletSpec's fields */ // Create the field for the speed property string propLabel = position.width > FULL_LABEL_CUTOFF?Lang.GetString(Key.Speed) : Lang.GetString(Key.SpeedShortForm); // -- Set the label width according to the length of the label EditorGUIUtility.labelWidth = propLabel.Length * WIDTH_PER_LABEL_LETTER; // -- Use PropertyField to generate a field automatically EditorGUI.PropertyField(position, speedProp, new GUIContent(propLabel)); // -- Increment the position so that we know where to draw the next field position.x += position.width; // Create the field for the damage property propLabel = " " + (position.width > FULL_LABEL_CUTOFF ? Lang.GetString(Key.Damage) : Lang.GetString(Key.DamageShortForm)); // -- Set the label width according to the length of the label EditorGUIUtility.labelWidth = propLabel.Length * WIDTH_PER_LABEL_LETTER; // -- Damage cannot be negative, so we must handle this manually using IntField to give us more control of the output // -- IntField() gives us a value set by the user which we can assign the property manually // -- PropertyField() does not and sets the value automatically var userSetDamage = EditorGUI.IntField(position, propLabel, damageProp.intValue); // -- Clamp the value to 0 and Max and set it damageProp.intValue = Mathf.Clamp(userSetDamage, 0, Int32.MaxValue); // Set indent back to what it was so that Unity can continue it's auto-indents normally on other properties. EditorGUI.indentLevel = indent; // Indicate that we have finished drawing the UI for this property EditorGUI.EndProperty(); }
public static string ToFriendlyNameString(this LanguageModifier that) { switch (that) { case LanguageModifier.Translated: return(LocalizedStrings.Language.Modifiers.Translated); case LanguageModifier.Rewrite: return(LocalizedStrings.Language.Modifiers.Rewrite); default: return(""); } }
/// <summary> /// Defines the code for drawing the inspector /// </summary> public override void OnInspectorGUI() { // Update the serializedProperty - always do this in the beginning of OnInspectorGUI. serializedObject.Update(); // Make Read Only GUI.enabled = false; // Show the Current Total attributes EditorGUILayout.IntField(Lang.GetString(Key.Total), spec.GetTotal()); // Unset Read Only GUI.enabled = true; /* * Min and Max Buttons */ // Begin a horizontal group, the controls within it will move horizontally EditorGUILayout.BeginHorizontal(); if (GUILayout.Button(Lang.GetString(Key.Min))) { setAllValues(0); } if (GUILayout.Button(Lang.GetString(Key.Average))) { setAllValues(PlayerSpec.MAX_SINGLE_VALUE >> 1); } if (GUILayout.Button(Lang.GetString(Key.Max))) { setAllValues(PlayerSpec.MAX_SINGLE_VALUE); } // End a horizontal group, the controls after it will resume normal vertical layouting EditorGUILayout.EndHorizontal(); /* * Slider for every spec */ for (int i = 0; i < specProperties.Length; ++i) { specProperties[i].intValue = EditorGUILayout.IntSlider(Lang.GetString(Key.Strength + i), specProperties[i].intValue, 0, PlayerSpec.MAX_SINGLE_VALUE); } // Apply changes to the serializedProperty - always do this in the end of OnInspectorGUI if modifying values via serializedObject. serializedObject.ApplyModifiedProperties(); }
/// <summary> /// Defines all the UI Drawing here /// </summary> void OnGUI() { // Set Window Min Size minSize = new Vector2(300.0f, 200.0f); // Label (Language-Based) GUILayout.Label(Lang.GetString(Key.SpecPrefabFolder)); // Get the resource folder path resourceFolderPath = GUILayout.TextField(resourceFolderPath); // Label GUILayout.Label("Specs"); if (GUILayout.Button(Lang.GetString(Key.Refresh))) { // Clear the list specs.Clear(); // Find all the specs in the prefabs folder string[] guids = AssetDatabase.FindAssets("t:GameObject", new string[] { resourceFolderPath }); // Go through each one we found for (int i = 0; i < guids.Length; ++i) { // Load it GameObject prefab = (GameObject)AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(guids[i]), typeof(GameObject)); // Check if it is a Player Spec var spec = prefab.GetComponent <PlayerSpec>(); // Add it to the list if (spec != null) { specs.Add(spec); } // Show & Update Progress Bar EditorUtility.DisplayProgressBar(Lang.GetString(Key.Loading), (i + 1) + "/" + guids.Length + Lang.GetString(Key.Loaded), ((float)i) / guids.Length - 1); System.Threading.Thread.Sleep(100); // For demoing } // We are done. Clear the Progress Bar from the screen EditorUtility.ClearProgressBar(); } // List all the Specs // -- Calculate widths and more const float NAME_LABEL_LENGTH = 100.0f; const float HEIGHT = 18.0f; const float VERTICAL_SPACING = HEIGHT + 2.0f; const float PADDING = 5.0f; const float START_HEIGHT = 5 * HEIGHT; float width = (position.width - NAME_LABEL_LENGTH * 0.1f * 10.0f - PADDING) * 0.245f; float horizontalSpacing = (position.width - NAME_LABEL_LENGTH * 0.1f * 10.0f - PADDING) * 0.25f; // -- Draw UI for each Spec for (int i = 0; i < specs.Count; ++i) { var spec = specs[i]; // Draw Name GUI.Label(new Rect(5, START_HEIGHT + VERTICAL_SPACING * i, NAME_LABEL_LENGTH, HEIGHT), spec.name); // Draw Progress Bars showing stats EditorGUI.ProgressBar(new Rect(NAME_LABEL_LENGTH + horizontalSpacing * 0.0f, START_HEIGHT + VERTICAL_SPACING * i, width, HEIGHT), (float)spec.Strength / PlayerSpec.MAX_SINGLE_VALUE, Lang.GetString(Key.Strength)); EditorGUI.ProgressBar(new Rect(NAME_LABEL_LENGTH + horizontalSpacing * 1.0f, START_HEIGHT + VERTICAL_SPACING * i, width, HEIGHT), (float)spec.Agility / PlayerSpec.MAX_SINGLE_VALUE, Lang.GetString(Key.Agility)); EditorGUI.ProgressBar(new Rect(NAME_LABEL_LENGTH + horizontalSpacing * 2.0f, START_HEIGHT + VERTICAL_SPACING * i, width, HEIGHT), (float)spec.Accuracy / PlayerSpec.MAX_SINGLE_VALUE, Lang.GetString(Key.Accuracy)); // Draw Button to show the object in inspector if (GUI.Button(new Rect(NAME_LABEL_LENGTH + horizontalSpacing * 3.0f, START_HEIGHT + VERTICAL_SPACING * i, width, HEIGHT), Lang.GetString(Key.Open))) { Selection.activeGameObject = spec.gameObject; } } }