Advertisement
Guest User

IdealGf

a guest
May 27th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.07 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor;
  5.  
  6. namespace IdealGf.DialogueEditor
  7. {
  8.     ///======================================================================================
  9.     /// IMPORTANT:::::::
  10.     /// PLZ FOLLOW https://templategfdev.tumblr.com/
  11.     ///======================================================================================
  12.     public class IdealGfDialogueEditorWindow : EditorWindow
  13.     {
  14.         public string dialogueId;
  15.         public string sinopsis;
  16.  
  17.         public GameObject target;
  18.  
  19.         #region GUI_PROPERTIES
  20.         public virtual GUIStyle MenuStyle
  21.         {
  22.             get
  23.             {
  24.                 return EditorStyles.helpBox;
  25.             }
  26.         }
  27.         public virtual GUIStyle TextAreaStyle
  28.         {
  29.             get
  30.             {
  31.                 return EditorStyles.textArea;
  32.             }
  33.         }
  34.  
  35.         public const int barHeight = 20;
  36.         public const int menuWidth = 200;
  37.  
  38.         Rect barRect;
  39.         Rect menuRect;
  40.         Rect nodeRegionRect;
  41.         #endregion
  42.  
  43.         [MenuItem("IdealGf/Dialogue Editor")]
  44.         public static void ShowDialogueEditor()
  45.         {
  46.             // Get existing open window or if none, make a new one:
  47.             IdealGfDialogueEditorWindow window = (IdealGfDialogueEditorWindow)EditorWindow.GetWindow(typeof(IdealGfDialogueEditorWindow));
  48.             window.Show();
  49.             window.name = "Ideal Gf Dialogue Editor";
  50.             window.titleContent = new GUIContent("Dialogue Editor");
  51.         }
  52.  
  53.         public void OnGUI()
  54.         {
  55.             // Areas properties
  56.             barRect = new Rect(0, 0, position.width, barHeight);
  57.             menuRect = new Rect(2, barHeight, menuWidth, position.height - barHeight);
  58.             nodeRegionRect = new Rect(menuRect.width + menuRect.x, barRect.height, position.width - (menuRect.width + menuRect.x), position.height - barHeight);
  59.  
  60.             // Handle events
  61.             HandleEvents();
  62.  
  63.             // Creating bar layout
  64.             GUILayout.BeginArea(barRect, EditorStyles.toolbar);
  65.             RenderBarMenu();
  66.             GUILayout.EndArea();
  67.            
  68.             // Creating menu layout
  69.             GUILayout.BeginArea(menuRect, MenuStyle);
  70.             RenderLateralMenu();
  71.             GUILayout.EndArea();
  72.  
  73.             GUILayout.BeginArea(nodeRegionRect, MenuStyle);
  74.             GUILayout.EndArea();
  75.         }
  76.  
  77.         public virtual void RenderNodes()
  78.         {
  79.  
  80.         }
  81.  
  82.         public virtual void RenderBarMenu()
  83.         {
  84.             EditorGUILayout.BeginHorizontal();
  85.             target = (GameObject)EditorGUILayout.ObjectField("Target: ", target, typeof(GameObject), true);
  86.             EditorGUILayout.EndHorizontal();
  87.         }
  88.  
  89.         public virtual void RenderLateralMenu()
  90.         {
  91.             EditorGUILayout.BeginVertical();
  92.             EditorGUILayout.LabelField("Dialogue data", EditorStyles.boldLabel);
  93.             EditorGUILayout.LabelField("Id name");
  94.             dialogueId = EditorGUILayout.TextField(dialogueId);
  95.             EditorGUILayout.LabelField("Sinopsis");
  96.             sinopsis = EditorGUILayout.TextArea(sinopsis, GUILayout.Height(75));
  97.             EditorGUILayout.Separator();
  98.             EditorGUILayout.EndVertical();
  99.         }
  100.  
  101.         public virtual void HandleEvents()
  102.         {
  103.             Event click = Event.current;
  104.             if (nodeRegionRect.Contains(click.mousePosition) & click.type == EventType.ContextClick)
  105.             {
  106.                 GenericMenu genericMenu = new GenericMenu();
  107.                 genericMenu.AddItem(new GUIContent("Add dialogue"), false, new GenericMenu.MenuFunction(Action));
  108.                 genericMenu.AddItem(new GUIContent("Add character"), false, new GenericMenu.MenuFunction(Action));
  109.                 genericMenu.AddItem(new GUIContent("Add action"), false, new GenericMenu.MenuFunction(Action));
  110.                 genericMenu.ShowAsContext();
  111.             }
  112.         }
  113.  
  114.         public void Action()
  115.         {
  116.             Debug.Log("Click");
  117.         }
  118.     }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement