public static Vector2 DrawAOTList <AOTListType> (string p_labelString, AOTListType p_list, Delegates.FunctionPointer <AOTListType, int> p_onDrawElementFunction, Delegates.FunctionPointer <AOTListType> p_onAddElementFunctions, Vector2 p_scrollView, Vector2 p_initialOffset, bool p_useScroll = true) where AOTListType : IAOTList { Vector2 v_scrollView = p_scrollView; if (p_list != null) { InspectorUtils.BeginContainer(p_initialOffset.x, p_initialOffset.y); p_list.FoldOut = EditorGUILayout.Foldout(p_list.FoldOut, p_labelString); int v_indexToRemove = -1; if (p_list.FoldOut) { EditorGUILayout.BeginHorizontal(); GUILayout.Space(10); EditorGUILayout.BeginVertical(); EditorGUILayout.BeginHorizontal(); GUI.enabled = false; GUILayout.Label("Length", GUILayout.Width(50)); EditorGUILayout.IntField(p_list.Count, GUILayout.Width(80)); GUI.enabled = true; //Add Functions Caller if (InspectorUtils.DrawButton("Add", Color.cyan, GUILayout.Width(50))) { if (p_onAddElementFunctions != null) { p_onAddElementFunctions(p_list); } } EditorGUILayout.EndHorizontal(); //Draw Opener InspectorUtils.DrawTitleText("{", new Color(0.5f, 0.5f, 0.5f)); if (p_useScroll) { v_scrollView = GUILayout.BeginScrollView(p_scrollView); } for (int i = 0; i < p_list.Count; i++) { EditorGUILayout.BeginHorizontal(); GUILayout.Space(10); EditorGUILayout.BeginVertical(); if (p_onDrawElementFunction != null) { p_onDrawElementFunction(p_list, i); } EditorGUILayout.EndVertical(); if (InspectorUtils.DrawButton("X", Color.red, GUILayout.MaxWidth(24), GUILayout.MaxHeight(15))) { v_indexToRemove = i; } EditorGUILayout.EndHorizontal(); } if (p_useScroll) { GUILayout.EndScrollView(); } //Draw Closer InspectorUtils.DrawTitleText("}", new Color(0.5f, 0.5f, 0.5f)); EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); } //Remove Clicked if (v_indexToRemove >= 0 && v_indexToRemove <= p_list.Count) { p_list.RemoveAt(v_indexToRemove); v_indexToRemove = -1; } InspectorUtils.EndContainer(); } return(v_scrollView); }
protected override void OnGUI() { _panelScroll = EditorGUILayout.BeginScrollView(_panelScroll); if (m_windowInformation == null) { m_windowInformation = new TackRopeCreatorWindowInformation(); } bool v_refreshClicked = InspectorUtils.DrawButton("Refresh Informations", Color.cyan); if (v_refreshClicked) { Refresh(); } if (_needFillSelected) { FillSelectedObjects(); } if (_needRecreateList) { RecreateList(true); } if (m_windowInformation.Ropes != null) { m_windowInformation.RopeParent = (Transform)EditorGUILayout.ObjectField("Rope Parent", m_windowInformation.RopeParent, typeof(Transform), true); m_windowInformation.SelectedRopeIndex = EditorGUILayout.Popup("Ropes", m_windowInformation.SelectedRopeIndex, m_windowInformation.Ropes.GetStringList().ToArray()); Rope2D v_rope = m_windowInformation.Ropes != null && m_windowInformation.SelectedRopeIndex >= 0 && m_windowInformation.Ropes.Count > m_windowInformation.SelectedRopeIndex? m_windowInformation.Ropes[m_windowInformation.SelectedRopeIndex] : null; if (m_windowInformation.Rope != v_rope) { m_windowInformation.Rope = v_rope as TackRope; if (v_rope != null) { m_windowInformation.RopeDepth = v_rope.RopeDepth; m_windowInformation.RopeSortingLayerName = v_rope.RopeSortingLayerName; m_windowInformation.CustomPrefabNode = v_rope.CustomNodePrefab; } } bool v_pickSelected = EditorGUILayout.Toggle("Use Selected Objects in Scene", m_windowInformation.PickSelectedObjects); if (m_selectedObjects.Count > 2) { m_windowInformation.PlugLastWithFirst = EditorGUILayout.Toggle("Plug Last With First", m_windowInformation.PlugLastWithFirst); } if (m_windowInformation.PickSelectedObjects != v_pickSelected) { m_windowInformation.PickSelectedObjects = v_pickSelected; FillSelectedObjects(); RecreateList(true); } DrawList(); InspectorUtils.DrawTitleText("Rope Properties", new Color(1, 0.1f, 0.7f)); //Sorting Layer string[] v_sortingLayers = GetSortingLayerNames(); int v_sortingIndex = EditorGUILayout.Popup("Rope Sorting Layer", GetObjectIndexInArrayOrStrings(v_sortingLayers, m_windowInformation.RopeSortingLayerName), v_sortingLayers); m_windowInformation.RopeSortingLayerName = v_sortingLayers.Length > v_sortingIndex && v_sortingIndex >= 0? v_sortingLayers[v_sortingIndex] : "Default"; m_windowInformation.RopeDepth = EditorGUILayout.IntField("Rope Z Order", m_windowInformation.RopeDepth); m_windowInformation.CustomPrefabNode = EditorGUILayout.ObjectField("Custom Node Prefab", m_windowInformation.CustomPrefabNode, typeof(GameObject), false) as GameObject; m_windowInformation.AutomaticCalculateNodes = EditorGUILayout.Toggle("Automatic Calculate Amount of Nodes", m_windowInformation.AutomaticCalculateNodes); if (!m_windowInformation.AutomaticCalculateNodes) { m_windowInformation.AmountOfNodes = EditorGUILayout.IntField("Amount of Nodes", m_windowInformation.AmountOfNodes); } m_windowInformation.UsePrefabRopeScale = EditorGUILayout.Toggle("Use Prefab Rope Scale", m_windowInformation.UsePrefabRopeScale); InspectorUtils.DrawTitleText("", new Color(1, 0.1f, 0.7f)); GUILayout.Space(10); if (m_selectedObjects.Count >= 2) { //Final Buttons bool v_recreateClicked = false; bool v_deletePreviousClicked = false; if (m_currentCreatedRopes.Count > 0) { EditorGUILayout.BeginHorizontal(); v_recreateClicked = InspectorUtils.DrawButton("Recreate Previus Ropes", new Color(0.4f, 0.7f, 1f)); v_deletePreviousClicked = InspectorUtils.DrawButton("Delete Previus Ropes", new Color(1f, 0.7f, 0.1f)); EditorGUILayout.EndHorizontal(); } bool v_buttonClicked = InspectorUtils.DrawButton("Create New Rope", Color.green); if (v_recreateClicked) { RecreateRopeClicked(); } if (v_deletePreviousClicked) { DeleteRopeClicked(); } else if (v_buttonClicked) { CreateRopeClicked(); } } } EditorGUILayout.EndScrollView(); if (GUI.changed) { EditorUtility.SetDirty(this); } }
protected virtual void DrawTitleText(string p_text, Color v_color) { InspectorUtils.DrawTitleText(p_text, v_color); }