protected virtual void OnEnable() { if (!_skin) { _skin = E_Helpers.LoadSkin(E_Core.e_guiSkinPath); } _titleColor = E_Colors.e_c_blue_5; _skinHolder = new CBColorHolder(_skin.label); }
public override void OnInspectorGUI() { if (_originalHolder == null) { _originalHolder = new CBColorHolder(EditorStyles.label); } if (_originalFoldout == null) { _originalFoldout = new CBColorHolder(EditorStyles.foldout); } _original = GUI.skin; GUI.skin = _skin; serializedObject.Update(); rect = GUILayoutUtility.GetRect(1, 1); GUILayout.BeginHorizontal(_skin.box, GUILayout.ExpandHeight(false)); GUILayout.BeginVertical(GUILayout.ExpandHeight(false)); CBEditor.SetColorToEditorStyle(_skinHolder, _skinHolder); }
public static void SetColorToEditorStyle(CBColorHolder label, CBColorHolder foldout) { EditorStyles.label.normal.textColor = label.n_c; EditorStyles.label.hover.textColor = label.h_c; EditorStyles.label.active.textColor = label.a_c; EditorStyles.label.focused.textColor = label.f_c; EditorStyles.label.onNormal.textColor = label.on_c; EditorStyles.label.onHover.textColor = label.oh_c; EditorStyles.label.onActive.textColor = label.oa_c; EditorStyles.label.onFocused.textColor = label.of_c; EditorStyles.foldout.normal.textColor = foldout.n_c; EditorStyles.foldout.hover.textColor = foldout.h_c; EditorStyles.foldout.active.textColor = foldout.a_c; EditorStyles.foldout.focused.textColor = foldout.f_c; EditorStyles.foldout.onNormal.textColor = foldout.on_c; EditorStyles.foldout.onHover.textColor = foldout.oh_c; EditorStyles.foldout.onActive.textColor = foldout.oa_c; EditorStyles.foldout.onFocused.textColor = foldout.of_c; }
private void OnGUI() { CBColorHolder _orglabel = new CBColorHolder(EditorStyles.label); CBColorHolder _orgfoldout = new CBColorHolder(EditorStyles.foldout); CBColorHolder _skinHolder = new CBColorHolder(_skin.label); //Apply the gui skin GUI.skin = _skin; //Draw title bar EditorGUI.DrawRect(new Rect(0, 0, position.width, position.height), E_Colors.e_c_blue_5); EditorGUILayout.Space(); EditorGUI.DrawRect(new Rect(5, 5, position.width - 10, 40), E_Colors.e_c_blue_4); EditorGUILayout.LabelField("Convert Scene Objects For Multiplayer Support", _skin.label); EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(_skin.box, GUILayout.ExpandHeight(false)); EditorGUILayout.BeginVertical(GUILayout.ExpandHeight(false)); //Draw Helpful Text EditorGUILayout.LabelField(_help, _skin.textField); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); //Draw Selection Booleans EditorGUILayout.BeginVertical(_skin.box, GUILayout.Width(100)); EditorGUILayout.BeginHorizontal(GUILayout.Width(100)); CBEditor.SetColorToEditorStyle(_skinHolder, _skinHolder); _cRigidbodies = EditorGUILayout.ToggleLeft("Rigidbodies", _cRigidbodies, GUILayout.Width(150)); _cvBreakableObjects = EditorGUILayout.ToggleLeft("vBreakableObjects", _cvBreakableObjects, GUILayout.Width(163)); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(GUILayout.Width(100)); _cvItemCollections = EditorGUILayout.ToggleLeft("vItemCollections", _cvItemCollections, GUILayout.Width(150)); _cvHealthController = EditorGUILayout.ToggleLeft("vHealthControllers", _cvHealthController, GUILayout.Width(163)); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(GUILayout.Width(100)); _cvTriggerGenericAction = EditorGUILayout.ToggleLeft("vTriggerGenericActions", _cvTriggerGenericAction, GUILayout.Width(150)); _cvThrowCollectable = EditorGUILayout.ToggleLeft("vThrowCollectables", _cvThrowCollectable, GUILayout.Width(150)); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(GUILayout.Width(100)); _cUseItemTrigger = EditorGUILayout.ToggleLeft("UseItemEventTriggers", _cUseItemTrigger, GUILayout.Width(150)); CBEditor.SetColorToEditorStyle(_orglabel, _orgfoldout); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); if (_cRigidbodies != _pRigidbodies || _cvItemCollections != _pvItemCollections || _cvBreakableObjects != _pvBreakableObjects || _cvHealthController != _pvHealthController || _cvTriggerGenericAction != _pvTriggerGenericAction || _cvThrowCollectable != _pvThrowCollectable || _cUseItemTrigger != _pUseItemTrigger) { _pRigidbodies = _cRigidbodies; _pvItemCollections = _cvItemCollections; _pvBreakableObjects = _cvBreakableObjects; _pvHealthController = _cvHealthController; _pvThrowCollectable = _cvThrowCollectable; _pvTriggerGenericAction = _cvTriggerGenericAction; _pUseItemTrigger = _cUseItemTrigger; _valueChanged = true; } if (_valueChanged == true) { _valueChanged = false; OnEnable(); } //Draw Selectable List _count = 0; EditorGUILayout.BeginHorizontal(_skin.box, GUILayout.Width(325)); EditorGUILayout.BeginVertical(GUILayout.Height(300)); _scrollPos = GUI.BeginScrollView(new Rect(10, 260, 300, position.height - 290), _scrollPos, new Rect(0, 0, 230, _scrollHeight), false, true); for (int i = 0; i < convertables.Count; i++) { EditorGUILayout.BeginHorizontal(); if (GUI.Button(new Rect(5, _count, 29, 30), "X", _skin.button) && _converting == false) { convertables.RemoveAt(i); } if (GUI.Button(new Rect(40, _count, 230, 30), convertables[i].name, _skin.button) && _converting == false) { PreviewObject(convertables[i]); } EditorGUILayout.EndHorizontal(); _count += 35; } GUI.EndScrollView(); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); //Draw Target Preview if (_target) { _objectPreview.OnInteractivePreviewGUI(new Rect(position.width - 170, 162, 150, 150), "window"); EditorGUI.DrawRect(new Rect(position.width - 170, 315, 150, 214), E_Colors.e_c_blue_3); _previewScrollPos = GUI.BeginScrollView(new Rect(position.width - 168, 312, 167, 210), _previewScrollPos, new Rect(0, 0, 150, _previewScrollHeight), false, true); for (int i = 0; i < _previewConverts.Count; i++) { EditorGUI.LabelField(new Rect(0, (i * 30), 150, 40), _previewConverts[i], _skin.textField); } GUI.EndScrollView(); } //Draw Convert button if (GUI.Button(new Rect(position.width - 170, position.height - 38, 167, 30), "CONVERT ALL", _skin.button) && _converting == false) { if (EditorUtility.DisplayDialog("Start Converting Scene Objects?", "It's important to note that this does not make a copy of these " + "objects but edits them in place. If this is not something that you " + "want to do then stop this operation now by selecting the 'Cancel' " + "button. If you're unsure what this could do simply copy this scene " + "and run this operation on the copied scene.", "Start Conversion", "Cancel")) { this.StartCoroutine(ConvertAll()); } } if (_converting == true) { EditorGUI.DrawRect(new Rect(0, 50, position.width, position.height - 30), _lockColor); EditorGUI.DrawRect(new Rect(0, position.height / 2 - 50, position.width, 100), _convertBar); EditorGUI.LabelField(new Rect(0, position.height / 2 - 50, position.width, 100), "Converting Objects, please wait...", _skin.GetStyle("Label")); EditorGUI.LabelField(new Rect(100, position.height / 2 + 10, position.width, 100), "Important Note: You can refresh this window by clicking into it.", _skin.GetStyle("TextField")); } }
private void OnGUI() { CBColorHolder _org = new CBColorHolder(EditorStyles.label); CBColorHolder _orgFoldout = new CBColorHolder(EditorStyles.foldout); CBColorHolder _skinHolder = new CBColorHolder(_skin.label); //Apply the gui skin GUI.skin = _skin; //Draw title bar EditorGUI.DrawRect(new Rect(0, 0, position.width, position.height), E_Colors.e_c_blue_5); EditorGUI.DrawRect(new Rect(5, 5, position.width - 10, 40), E_Colors.e_c_blue_4); EditorGUILayout.Space(); EditorGUILayout.LabelField("Convert Prefabs To Multiplayer", _skin.label); EditorGUILayout.Space(); //Draw Body EditorGUILayout.BeginHorizontal(_skin.box, GUILayout.ExpandHeight(false)); EditorGUILayout.BeginVertical(GUILayout.ExpandHeight(false)); //Apply Body Title/Description EditorGUILayout.LabelField("This will find all prefabs in your project. " + "Then it will scan each one and give you a list of prefabs that could be converted " + "to support multiplayer. You can click the 'X' button to the left and it will remove the prefab " + "from the convert list. You can also click on the name of each prefab and get a preview of " + "the object and what will be converted on it. Converted items are saved in \"Assets/Resources\"." + "So they can be PhotonInstantiated across the network when needed.\n\n" + "WARNING NOTE: If your project is large this could take considerable time. It is suggested to right " + "click on each prefab you want to convert and selecting the appropriate action from the CB Games menu " + "item.", _skin.textField); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); if (_converted == true) { EditorGUILayout.LabelField(string.Format("Successfully copied and converted all selected CB_prefabs.\nView converted CB_prefabs at \"Assets{0}Resources\".\n\nNOTE: The original CB_prefabs remain unmodified.", Path.DirectorySeparatorChar), _skin.GetStyle("Label")); return; } if (_scanned == false && _scanning == false) { EditorGUILayout.BeginVertical(_skin.box, GUILayout.Width(100)); EditorGUILayout.BeginHorizontal(GUILayout.Width(100)); CBEditor.SetColorToEditorStyle(_skinHolder, _skinHolder); _cvBreakableObjects = EditorGUILayout.ToggleLeft("Show vBreakableObjects", _cvBreakableObjects, GUILayout.Width(150)); _cvShooterWeapons = EditorGUILayout.ToggleLeft("Show vShooterWeapons", _cvShooterWeapons, GUILayout.Width(150)); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(GUILayout.Width(100)); _cItemCollection = EditorGUILayout.ToggleLeft("Show vItemCollections", _cItemCollection, GUILayout.Width(150)); _cvHealthController = EditorGUILayout.ToggleLeft("Show vHealthControllers", _cvHealthController, GUILayout.Width(163)); CBEditor.SetColorToEditorStyle(_org, _orgFoldout); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Scan Project", _skin.button, GUILayout.Height(40), GUILayout.Width(300)) && _scanning == false) { this.StartCoroutine(ScanProject()); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); } if (_scanning == true) { EditorGUI.DrawRect(new Rect(10, 160, position.width - 20, 40), E_Colors.e_c_blue_2); EditorGUI.LabelField(new Rect(100, 160, 300, 50), "Scanning, please wait...\nImportant Note: You can click into this window to refresh it.", _skin.textField); } if (_scanned == true && CB_prefabs.Count > 0) { _scrollPos = GUI.BeginScrollView(new Rect(15, 210, 300, position.height - 260), _scrollPos, new Rect(0, 0, 250, _scrollHeight), false, true); _count = 0; foreach (KeyValuePair <GameObject, string> prefab in CB_prefabs) { if (GUI.Button(new Rect(5, _count * 39, 30, 35), "X", _skin.button)) { CB_prefabs.Remove(prefab.Key); break; } if (GUI.Button(new Rect(40, _count * 39, 220, 35), prefab.Key.name, _skin.button)) { ViewSelectedObject(prefab.Key); SetConvertables(prefab.Key); } _count += 1; } GUI.EndScrollView(); if (GUI.Button(new Rect(10, position.height - 40, 235, 30), "Convert Found Prefabs", _skin.button) && _scanning == false) { ConvertPrefabsToMultiplayer(); } if (GUI.Button(new Rect(255, position.height - 40, 235, 30), "Rescan Project", _skin.button) && _scanning == false) { _scanning = false; _scanned = false; CB_prefabs.Clear(); _target = null; } } if (_target) { _objectPreview.OnInteractivePreviewGUI(new Rect(position.width - 170, 207, 150, 150), "window"); EditorGUI.DrawRect(new Rect(position.width - 170, 350, 150, 150), E_Colors.e_c_blue_4); for (int i = 0; i < CB_previewConverts.Count; i++) { EditorGUI.LabelField(new Rect(position.width - 170, (350 + (i * 30)), 150, 60), CB_previewConverts[i], _skin.textField); } } if (_converting == true) { EditorGUI.DrawRect(new Rect(0, 50, position.width, position.height - 30), E_Colors.e_c_blue_1); EditorGUI.DrawRect(new Rect(0, position.height / 2 - 50, position.width, 100), E_Colors.e_c_blue_3); EditorGUI.LabelField(new Rect(0, position.height / 2 - 50, position.width, 100), "Converting Prefabs, please wait...", _skin.label); EditorGUI.LabelField(new Rect(30, position.height / 2 + 10, position.width, 100), "If this window is just staying here longer than 2 seconds, then an internal error occured.", _skin.GetStyle("TextField")); } }
private void OnGUI() { CBColorHolder _original = new CBColorHolder(EditorStyles.label); CBColorHolder _originalFold = new CBColorHolder(EditorStyles.foldout); CBColorHolder _skinHolder = new CBColorHolder(_skin.label); //Apply the gui skin GUI.skin = _skin; //Draw title bar EditorGUI.DrawRect(new Rect(0, 0, position.width, position.height), E_Colors.e_c_blue_5); EditorGUILayout.Space(); EditorGUILayout.LabelField("Convert Players For Multiplayer Support", _skin.GetStyle("Label")); if (_converting == false) { EditorGUILayout.BeginHorizontal(_skin.box, GUILayout.ExpandHeight(false)); EditorGUILayout.BeginVertical(GUILayout.ExpandHeight(false)); //Apply Body Title/Description EditorGUILayout.LabelField("Converts a player to support multiplayer logic", _skin.GetStyle("Label")); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); //Divider EditorGUILayout.BeginHorizontal(_skin.box, GUILayout.ExpandHeight(false)); EditorGUILayout.BeginVertical(GUILayout.ExpandHeight(false)); EditorGUILayout.LabelField( "This will do all of the following on your selected player object:\n\r" + "* Copies the original player and only does the following modifications on the copied player\r\n" + "* Replace all components that have an equivalent multiplayer version in this package\r\n" + "* Copy the original values to the newly created multiplayer versions\r\n" + "* Attempt to re-create the custom UnityEvents into the new multiplayer versions\r\n" + "* Notify you of any failures that might have occured\r\n" + "\r\n" + "This entire process will only take a few seconds for your selected character.", _skin.GetStyle("TextField")); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); //Help text EditorGUILayout.BeginHorizontal(_skin.box, GUILayout.ExpandHeight(false)); EditorGUILayout.BeginVertical(GUILayout.ExpandHeight(false)); EditorGUILayout.LabelField("First select the player object you want to convert. You can either do this " + "manually or choose automatically from the dropdown list.", _skin.textField); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); //Toggle for adding player name bar or not CB_addNameBar = EditorGUI.ToggleLeft(new Rect(320, 273, 250, 20), "Add Player Name Bar", CB_addNameBar, _skin.textField); CB_addVoiceChat = EditorGUI.ToggleLeft(new Rect(320, 293, 250, 20), "Add Voice Chat Support", CB_addVoiceChat, _skin.textField); //Player Object Selection / Player Preview Window if (GUI.Button(new Rect(5, 275, 250, 30), "Switch Player Selection Method", _skin.button)) { _manualPlayerSelect = !_manualPlayerSelect; } if (_manualPlayerSelect == false && options.Count > 0) { CBEditor.SetColorToEditorStyle(_skinHolder, _skinHolder); _autoSelectNumber = EditorGUI.Popup(new Rect(5, 310, 305, 16), "Available Player Objects:", _autoSelectNumber, options.ToArray()); CBEditor.SetColorToEditorStyle(_original, _originalFold); playerObj = _players[_autoSelectNumber]; } else { CBEditor.SetColorToEditorStyle(_skinHolder, _skinHolder); playerObj = EditorGUI.ObjectField(new Rect(5, 310, 310, 16), "Player Object:", playerObj, typeof(GameObject), true) as GameObject; CBEditor.SetColorToEditorStyle(_original, _originalFold); } if (playerObj != null) { if ((_previousplayerObj == null && playerObj != null) || (_previousplayerObj.GetInstanceID() != playerObj.GetInstanceID())) { _playerChanged = true; _previousplayerObj = playerObj; } Selection.activeObject = playerObj; EditorGUI.DrawRect(new Rect(322, 312, 160, 160), E_Colors.e_c_blue_1); if (_prefabPreview == null || _playerChanged == true) { _prefabPreview = null; _prefabPreview = Editor.CreateEditor(playerObj); } if (_prefabPreview != null) { _prefabPreview.OnInteractivePreviewGUI(new Rect(327, 317, 150, 150), "window"); } } else { _prefabPreview = null; } for (int i = 0; i < 9; i++) { EditorGUILayout.Space(); } EditorGUILayout.BeginHorizontal(_skin.box, GUILayout.ExpandHeight(false), GUILayout.Height(120), GUILayout.Width(305)); EditorGUILayout.BeginVertical(GUILayout.ExpandHeight(false)); //Draw Toggles Based on Player Components EditorGUILayout.LabelField("List of found components that will attempt to be converted:", _skin.textField); if (foundComps.Count == 0 && _prefabPreview != null || _playerChanged == true) { _playerChanged = false; foundComps.Clear(); foundComps = GetConvertableComps(); } EditorGUILayout.BeginHorizontal(_skin.box, GUILayout.ExpandHeight(false)); EditorGUILayout.BeginVertical(GUILayout.ExpandHeight(false)); _scrollPos = EditorGUILayout.BeginScrollView(_scrollPos, GUILayout.Height(100)); foreach (KeyValuePair <string, Component> item in foundComps) { EditorGUILayout.LabelField(item.Key, _skin.textField); } EditorGUILayout.EndScrollView(); EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); //Draw Convert Now Button if (playerObj != null) { if (GUI.Button(new Rect(30, 477, 430, 30), "Convert Now!", _skin.GetStyle("Button"))) { try { this.StartCoroutine(ConvertPlayer(playerObj)); } catch (Exception ex) { _errorsOccured = true; if (convertLog != null) { convertLog.Add("\n"); } if (convertLog != null) { convertLog.Add("ERRORS OCCURED!"); } if (convertLog != null) { convertLog.Add("Please review the log window for the full error."); } if (convertLog != null) { convertLog.Add("\n"); } if (convertLog != null) { convertLog.Add("--------------------------------------"); } if (convertLog != null) { convertLog.Add("ERROR: " + ex.Message); } if (convertLog != null) { convertLog.Add("--------------------------------------"); } Debug.LogError(ex); } finally { _running = false; _done = true; } } } } //Currently converting a player window else { //Apply Body Title/Description if (_done == false) { EditorGUI.LabelField(new Rect(10, 40, 480, 50), "Converting, please wait...", _skin.label); } else { EditorGUI.LabelField(new Rect(10, 40, 480, 50), "Completed! You can close this window anytime.", _skin.label); } EditorGUI.DrawRect(new Rect(10, 80, position.width - 20, position.height - 160), E_Colors.e_c_blue_4); _prefabPreview.OnInteractivePreviewGUI(new Rect(position.width - 170, 90, 150, 150), "window"); if (_done == false) { EditorGUI.DrawRect(new Rect(position.width - 170, 215, 150, 25), _convertColor); EditorGUI.LabelField(new Rect(position.width - 125, 215, 150, 25), "Converting...", _skin.textField); } else { if (_errorsOccured == false) { EditorGUI.DrawRect(new Rect(position.width - 170, 215, 150, 25), _convertSuccessColor); EditorGUI.LabelField(new Rect(position.width - 115, 215, 150, 25), "Success!", _skin.textField); } else { EditorGUI.DrawRect(new Rect(position.width - 170, 215, 150, 25), _convertErrorColor); EditorGUI.LabelField(new Rect(position.width - 130, 215, 150, 25), "Error Occured!", _skin.textField); } } if (_running == false && _done == false) { _running = true; ConvertPlayer(playerObj); } else { EditorGUI.LabelField(new Rect(330, 250, 160, 90), "IMPORTANT NOTE: You need to click into this window to refresh it manually.", _skin.GetStyle("TextField")); _scrollHeight = convertLog.Count * 10.5f; _logScrollPos = GUI.BeginScrollView(new Rect(10, 80, 310, position.height - 210), _logScrollPos, new Rect(0, 0, 430, _scrollHeight), false, true); for (int i = 0; i < convertLog.Count; i++) { EditorGUI.LabelField(new Rect(10, i * 10, 490, 90), convertLog[i], _skin.GetStyle("TextField")); } GUI.EndScrollView(); //GUI.EndGroup(); if (_done == true) { EditorGUI.LabelField(new Rect(10, 390, 490, 90), "Completed! Review this log to make sure there is nothing manually that you need to do or errors that need to be addressed. If you would like to convert another player press the respective button below.", _skin.GetStyle("TextField")); if (GUI.Button(new Rect(50, 460, 370, 30), "Convert Another Player", _skin.GetStyle("Button"))) { _converting = false; _done = false; _running = false; OnEnable(); } } } } }