123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079 |
- /*
- Copyright (c) 2020 Omar Duarte
- Unauthorized copying of this file, via any medium is strictly prohibited.
- Writen by Omar Duarte, 2020.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- */
- using System.Linq;
- using UnityEngine;
- namespace PluginMaster
- {
- public class ToolProperties : UnityEditor.EditorWindow
- {
- #region COMMON
- private const string UNDO_MSG = "Tool properties";
- private Vector2 _mainScrollPosition = Vector2.zero;
- private GUIContent _updateButtonContent = null;
- private GUISkin _skin = null;
- private GUIStyle _reloadBtnStyle = null;
- private static ToolProperties _instance = null;
- [UnityEditor.MenuItem("Tools/Plugin Master/Prefab World Builder/Tool Properties...", false, 1130)]
- public static void ShowWindow() => _instance = GetWindow<ToolProperties>("Tool Properties");
- public static void RepainWindow()
- {
- if (_instance != null) _instance.Repaint();
- }
- public static void CloseWindow()
- {
- if (_instance != null) _instance.Close();
- }
- private void OnEnable()
- {
- if (BrushManager.settings.paintOnMeshesWithoutCollider) PWBCore.UpdateTempColliders();
- _updateButtonContent
- = new GUIContent(Resources.Load<Texture2D>("Sprites/Update"), "Update Temp Colliders");
- _skin = Resources.Load<GUISkin>("PWBSkin");
- _reloadBtnStyle = _skin.GetStyle("EyeButton");
- UnityEditor.Undo.undoRedoPerformed += Repaint;
- }
- private void OnDisable()
- {
- PWBCore.DestroyTempColliders();
- UnityEditor.Undo.undoRedoPerformed -= Repaint;
- }
- private void OnGUI()
- {
- if (_instance == null) _instance = this;
- using (var scrollView = new UnityEditor.EditorGUILayout.ScrollViewScope(_mainScrollPosition,
- false, false, GUI.skin.horizontalScrollbar, GUI.skin.verticalScrollbar, GUIStyle.none))
- {
- _mainScrollPosition = scrollView.scrollPosition;
- #if UNITY_2021_2_OR_NEWER
- #else
- if (PWBToolbar.instance == null) PWBToolbar.ShowWindow();
- #endif
- if (ToolManager.tool == ToolManager.PaintTool.PIN) PinGroup();
- else if (ToolManager.tool == ToolManager.PaintTool.BRUSH) BrushGroup();
- else if (ToolManager.tool == ToolManager.PaintTool.ERASER) EraserGroup();
- else if (ToolManager.tool == ToolManager.PaintTool.GRAVITY) GravityGroup();
- else if (ToolManager.tool == ToolManager.PaintTool.EXTRUDE) ExtrudeGroup();
- else if (ToolManager.tool == ToolManager.PaintTool.LINE) LineGroup();
- else if (ToolManager.tool == ToolManager.PaintTool.SHAPE) ShapeGroup();
- else if (ToolManager.tool == ToolManager.PaintTool.TILING) TilingGroup();
- else if (ToolManager.tool == ToolManager.PaintTool.SELECTION) SelectionGroup();
- else if (ToolManager.tool == ToolManager.PaintTool.CIRCLE_SELECT) CircleSelectGroup();
- else if (ToolManager.tool == ToolManager.PaintTool.MIRROR) MirrorGroup();
- else if (ToolManager.tool == ToolManager.PaintTool.REPLACER) ReplacerGroup();
- else if (ToolManager.tool == ToolManager.PaintTool.FLOOR) FloorGroup();
- else if (ToolManager.tool == ToolManager.PaintTool.WALL) WallGroup();
- }
- if (Event.current.type == EventType.MouseDown && Event.current.button == 0)
- {
- GUI.FocusControl(null);
- Repaint();
- }
- }
- public static void ClearUndo()
- {
- if (_instance == null) return;
- UnityEditor.Undo.ClearUndo(_instance);
- }
- #endregion
- #region UNDO
- [SerializeField] private LineData _lineData = LineData.instance;
- [SerializeField] private TilingData _tilingData = TilingData.instance;
- [SerializeField] private MirrorSettings _mirrorSettings = MirrorManager.settings;
- [SerializeField] private ShapeData _shapeData = ShapeData.instance;
- [SerializeField] private TilingManager _tilingManager = TilingManager.instance as TilingManager;
- [SerializeField] private ShapeManager _shapeManager = ShapeManager.instance as ShapeManager;
- [SerializeField] private LineManager _lineManager = LineManager.instance as LineManager;
- public static void RegisterUndo(string commandName)
- {
- if (_instance != null) UnityEditor.Undo.RegisterCompleteObjectUndo(_instance, commandName);
- }
- #endregion
- #region TOOL PROFILE
- public class ProfileData
- {
- public readonly IToolManager toolManager = null;
- public readonly string profileName = string.Empty;
- public ProfileData(IToolManager toolManager, string profileName)
- => (this.toolManager, this.profileName) = (toolManager, profileName);
- }
- private void ToolProfileGUI(IToolManager toolManager)
- {
- using (new GUILayout.HorizontalScope(UnityEditor.EditorStyles.helpBox))
- {
- GUILayout.FlexibleSpace();
- GUILayout.Label("Tool Profile:");
- if (GUILayout.Button(toolManager.selectedProfileName,
- UnityEditor.EditorStyles.popup, GUILayout.MinWidth(100)))
- {
- GUI.FocusControl(null);
- var menu = new UnityEditor.GenericMenu();
- foreach (var profileName in toolManager.profileNames)
- menu.AddItem(new GUIContent(profileName), profileName == toolManager.selectedProfileName,
- SelectProfileItem, new ProfileData(toolManager, profileName));
- menu.AddSeparator(string.Empty);
- if (toolManager.selectedProfileName != ToolProfile.DEFAULT) menu.AddItem(new GUIContent("Save"),
- false, SaveProfile, toolManager);
- menu.AddItem(new GUIContent("Save As..."), false, SaveProfileAs,
- new ProfileData(toolManager, toolManager.selectedProfileName));
- if (toolManager.selectedProfileName != ToolProfile.DEFAULT)
- menu.AddItem(new GUIContent("Delete Selected Profile"), false, DeleteProfile,
- new ProfileData(toolManager, toolManager.selectedProfileName));
- menu.AddItem(new GUIContent("Revert Selected Profile"), false, RevertProfile, toolManager);
- menu.AddItem(new GUIContent("Factory Reset Selected Profile"), false,
- FactoryResetProfile, toolManager);
- menu.ShowAsContext();
- }
- }
- }
- private void SelectProfile(ProfileData profileData)
- {
- GUI.FocusControl(null);
- profileData.toolManager.selectedProfileName = profileData.profileName;
- Repaint();
- if (ToolManager.tool == ToolManager.PaintTool.MIRROR)
- UnityEditor.SceneView.lastActiveSceneView.LookAt(MirrorManager.settings.mirrorPosition);
- else if (ToolManager.tool == ToolManager.PaintTool.LINE)
- LineManager.settings.OnDataChanged();
- UnityEditor.SceneView.RepaintAll();
- }
- private void SelectProfileItem(object value) => SelectProfile(value as ProfileData);
- private void SaveProfile(object value)
- {
- var manager = value as IToolManager;
- manager.SaveProfile();
- }
- private void SaveProfileAs(object value)
- {
- var profiledata = value as ProfileData;
- SaveProfileWindow.ShowWindow(profiledata, OnSaveProfileDone);
- }
- private void OnSaveProfileDone(IToolManager toolManager, string profileName)
- {
- toolManager.SaveProfileAs(profileName);
- Repaint();
- }
- private class SaveProfileWindow : UnityEditor.EditorWindow
- {
- private IToolManager _toolManager = null;
- private string _profileName = string.Empty;
- private System.Action<IToolManager, string> OnDone;
- public static void ShowWindow(ProfileData data, System.Action<IToolManager, string> OnDone)
- {
- var window = GetWindow<SaveProfileWindow>(true, "Save Profile");
- window._toolManager = data.toolManager;
- window._profileName = data.profileName;
- window.OnDone = OnDone;
- window.minSize = window.maxSize = new Vector2(160, 50);
- UnityEditor.EditorGUIUtility.labelWidth = 70;
- UnityEditor.EditorGUIUtility.fieldWidth = 70;
- }
- private void OnGUI()
- {
- const string textFieldName = "NewProfileName";
- GUI.SetNextControlName(textFieldName);
- _profileName = UnityEditor.EditorGUILayout.TextField(_profileName).Trim();
- GUI.FocusControl(textFieldName);
- using (new UnityEditor.EditorGUI.DisabledGroupScope(_profileName == string.Empty))
- {
- if (GUILayout.Button("Save"))
- {
- OnDone(_toolManager, _profileName);
- Close();
- }
- }
- }
- }
- private void DeleteProfile(object value)
- {
- var profiledata = value as ProfileData;
- profiledata.toolManager.DeleteProfile();
- if (ToolManager.tool == ToolManager.PaintTool.MIRROR)
- UnityEditor.SceneView.lastActiveSceneView.LookAt(MirrorManager.settings.mirrorPosition);
- }
- private void RevertProfile(object value)
- {
- var manager = value as IToolManager;
- manager.Revert();
- if (ToolManager.tool == ToolManager.PaintTool.MIRROR)
- UnityEditor.SceneView.lastActiveSceneView.LookAt(MirrorManager.settings.mirrorPosition);
- }
- private void FactoryResetProfile(object value)
- {
- var manager = value as IToolManager;
- manager.FactoryReset();
- if (ToolManager.tool == ToolManager.PaintTool.MIRROR)
- UnityEditor.SceneView.lastActiveSceneView.LookAt(MirrorManager.settings.mirrorPosition);
- }
- #endregion
- #region COMMON PAINT SETTINGS
- private static float _maxRadius = 50f;
- private static Vector3[] _dir =
- {
- Vector3.right, Vector3.left,
- Vector3.up, Vector3.down,
- Vector3.forward, Vector3.back
- };
- private static string[] _dirNames = new string[] { "+X", "-X", "+Y", "-Y", "+Z", "-Z" };
- private static readonly string[] _brushShapeOptions = { "Point", "Circle", "Square" };
- private static readonly string[] _spacingOptions = { "Auto", "Custom" };
- private void PaintSettingsGUI(IPaintOnSurfaceToolSettings paintOnSurfaceSettings,
- IPaintToolSettings paintSettings)
- {
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- void UpdateTempColliders()
- {
- if (paintOnSurfaceSettings.paintOnMeshesWithoutCollider) PWBCore.UpdateTempColliders();
- else PWBCore.DestroyTempColliders();
- }
- using (new UnityEditor.EditorGUI.DisabledGroupScope
- (PWBCore.staticData.tempCollidersAction == PWBData.TempCollidersAction.NEVER_CREATE))
- {
- using (new GUILayout.HorizontalScope())
- {
- UnityEditor.EditorGUIUtility.labelWidth = 150;
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var paintOnMeshesWithoutCollider
- = UnityEditor.EditorGUILayout.ToggleLeft("Paint on meshes without collider",
- paintOnSurfaceSettings.paintOnMeshesWithoutCollider);
- if (check.changed)
- {
- paintOnSurfaceSettings.paintOnMeshesWithoutCollider = paintOnMeshesWithoutCollider;
- UpdateTempColliders();
- UnityEditor.SceneView.RepaintAll();
- }
- }
- using (new UnityEditor.EditorGUI.DisabledGroupScope
- (!paintOnSurfaceSettings.paintOnMeshesWithoutCollider))
- if (GUILayout.Button(_updateButtonContent, _reloadBtnStyle))
- PWBCore.UpdateTempColliders();
- }
- }
- UnityEditor.EditorGUIUtility.labelWidth = 110;
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var paintOnPalettePrefabs = UnityEditor.EditorGUILayout.ToggleLeft("Paint on palette prefabs",
- paintOnSurfaceSettings.paintOnPalettePrefabs);
- var paintOnSelectedOnly = UnityEditor.EditorGUILayout.ToggleLeft("Paint on selected only",
- paintOnSurfaceSettings.paintOnSelectedOnly);
- if (check.changed)
- {
- paintOnSurfaceSettings.paintOnPalettePrefabs = paintOnPalettePrefabs;
- paintOnSurfaceSettings.paintOnSelectedOnly = paintOnSelectedOnly;
- UpdateTempColliders();
- UnityEditor.SceneView.RepaintAll();
- }
- }
- }
- PaintToolSettingsGUI(paintSettings);
- }
- private void ParentSettingsGUI(IPaintToolSettings paintSettings)
- {
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var autoCreateParent
- = UnityEditor.EditorGUILayout.ToggleLeft("Create parent", paintSettings.autoCreateParent);
- if (check.changed)
- {
- paintSettings.autoCreateParent = autoCreateParent;
- }
- }
- if (!paintSettings.autoCreateParent)
- {
- paintSettings.setSurfaceAsParent = UnityEditor.EditorGUILayout.ToggleLeft("Set surface as parent",
- paintSettings.setSurfaceAsParent);
- if (!paintSettings.setSurfaceAsParent)
- {
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var parent = (Transform)UnityEditor.EditorGUILayout.ObjectField("Parent Transform:",
- paintSettings.parent, typeof(Transform), true);
- if (check.changed)
- {
- paintSettings.parent = parent;
- }
- }
- }
- }
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var createSubparent = UnityEditor.EditorGUILayout.ToggleLeft("Create sub-parents per palette",
- paintSettings.createSubparentPerPalette);
- if (check.changed)
- {
- paintSettings.createSubparentPerPalette = createSubparent;
- }
- }
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var createSubparent = UnityEditor.EditorGUILayout.ToggleLeft("Create sub-parents per tool",
- paintSettings.createSubparentPerTool);
- if (check.changed)
- {
- paintSettings.createSubparentPerTool = createSubparent;
- }
- }
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var createSubparent = UnityEditor.EditorGUILayout.ToggleLeft("Create sub-parents per brush",
- paintSettings.createSubparentPerBrush);
- if (check.changed)
- {
- paintSettings.createSubparentPerBrush = createSubparent;
- }
- }
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var createSubparent = UnityEditor.EditorGUILayout.ToggleLeft("Create sub-parents per prefab",
- paintSettings.createSubparentPerPrefab);
- if (check.changed)
- {
- paintSettings.createSubparentPerPrefab = createSubparent;
- }
- }
- }
- }
- private void OverwriteLayerGUI(IPaintToolSettings paintSettings)
- {
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var overwritePrefabLayer = UnityEditor.EditorGUILayout.ToggleLeft("Overwrite prefab layer",
- paintSettings.overwritePrefabLayer);
- int layer = paintSettings.layer;
- if (paintSettings.overwritePrefabLayer) layer = UnityEditor.EditorGUILayout.LayerField("Layer:",
- paintSettings.layer);
- if (check.changed)
- {
- paintSettings.overwritePrefabLayer = overwritePrefabLayer;
- paintSettings.layer = layer;
- UnityEditor.SceneView.RepaintAll();
- }
- }
- }
- }
- private void PaintToolSettingsGUI(IPaintToolSettings paintSettings)
- {
- ParentSettingsGUI(paintSettings);
- OverwriteLayerGUI(paintSettings);
- }
- private void RadiusSlider(CircleToolBase settings)
- {
- using (new GUILayout.HorizontalScope())
- {
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- if (settings.radius > _maxRadius)
- _maxRadius = Mathf.Max(Mathf.Floor(settings.radius / 10) * 20f, 10f);
- UnityEditor.EditorGUIUtility.labelWidth = 60;
- var radius = UnityEditor.EditorGUILayout.Slider("Radius:", settings.radius, 0.05f, _maxRadius);
- if (check.changed)
- {
- settings.radius = radius;
- UnityEditor.SceneView.RepaintAll();
- }
- }
- if (GUILayout.Button("|>", GUILayout.Width(20))) _maxRadius *= 2f;
- if (GUILayout.Button("|<", GUILayout.Width(20)))
- _maxRadius = Mathf.Min(Mathf.Floor(settings.radius / 10f) * 10f + 10f, _maxRadius);
- }
- }
- private void BrushToolBaseSettingsGUI(BrushToolBase settings)
- {
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- UnityEditor.EditorGUIUtility.labelWidth = 60;
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var brushShape = (BrushToolSettings.BrushShape)UnityEditor.EditorGUILayout.Popup("Shape:",
- (int)settings.brushShape, _brushShapeOptions);
- if (check.changed)
- {
- settings.brushShape = brushShape;
- UnityEditor.SceneView.RepaintAll();
- }
- }
- if (settings.brushShape != BrushToolBase.BrushShape.POINT)
- {
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var randomize
- = UnityEditor.EditorGUILayout.ToggleLeft("Randomize positions", settings.randomizePositions);
- if (check.changed)
- {
- settings.randomizePositions = randomize;
- UnityEditor.SceneView.RepaintAll();
- }
- }
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- UnityEditor.EditorGUIUtility.labelWidth = 80;
- var randomness = UnityEditor.EditorGUILayout.Slider("Randomness:", settings.randomness, 0f, 1f);
- if (check.changed)
- {
- settings.randomness = randomness;
- UnityEditor.SceneView.RepaintAll();
- }
- UnityEditor.EditorGUIUtility.labelWidth = 60;
- }
- }
- RadiusSlider(settings);
- }
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var density = UnityEditor.EditorGUILayout.IntSlider("Density:", settings.density, 0, 100);
- if (check.changed)
- {
- settings.density = density;
- UnityEditor.SceneView.RepaintAll();
- }
- }
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- UnityEditor.EditorGUIUtility.labelWidth = 90;
- var spacingType = (BrushToolBase.SpacingType)UnityEditor.EditorGUILayout.Popup("Min Spacing:",
- (int)settings.spacingType, _spacingOptions);
- var spacing = settings.minSpacing;
- using (new UnityEditor.EditorGUI.DisabledGroupScope(spacingType != BrushToolBase.SpacingType.CUSTOM))
- {
- spacing = UnityEditor.EditorGUILayout.FloatField("Value:", settings.minSpacing);
- }
- if (check.changed)
- {
- settings.spacingType = spacingType;
- settings.minSpacing = spacing;
- UnityEditor.SceneView.RepaintAll();
- }
- }
- }
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var orientAlongBrushstroke = UnityEditor.EditorGUILayout.ToggleLeft("Orient Along the Brushstroke",
- settings.orientAlongBrushstroke);
- var additionalAngle = settings.additionalOrientationAngle;
- if (orientAlongBrushstroke)
- additionalAngle = UnityEditor.EditorGUILayout.Vector3Field("Additonal angle:", additionalAngle);
- if (check.changed)
- {
- settings.orientAlongBrushstroke = orientAlongBrushstroke;
- settings.additionalOrientationAngle = additionalAngle;
- UnityEditor.SceneView.RepaintAll();
- }
- }
- }
- }
- }
- private void EmbedInSurfaceSettingsGUI(SelectionToolBaseBasic settings)
- {
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- using (new UnityEditor.EditorGUI.DisabledGroupScope
- (PWBCore.staticData.tempCollidersAction == PWBData.TempCollidersAction.NEVER_CREATE))
- {
- using (new GUILayout.HorizontalScope())
- {
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var createTempColliders = UnityEditor.EditorGUILayout.ToggleLeft("Create Temp Colliders",
- settings.createTempColliders);
- if (check.changed)
- {
- settings.createTempColliders = createTempColliders;
- PWBCore.UpdateTempColliders();
- UnityEditor.SceneView.RepaintAll();
- }
- }
- using (new UnityEditor.EditorGUI.DisabledGroupScope(!settings.createTempColliders))
- if (GUILayout.Button(_updateButtonContent, _reloadBtnStyle))
- PWBCore.UpdateTempColliders();
- }
- }
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- UnityEditor.EditorGUIUtility.labelWidth = 60;
- var embedInSurface = UnityEditor.EditorGUILayout.ToggleLeft("Embed On the Surface",
- settings.embedInSurface);
- if (check.changed)
- {
- settings.embedInSurface = embedInSurface;
- if (embedInSurface && settings is SelectionToolSettings) PWBIO.EmbedSelectionInSurface();
- UnityEditor.SceneView.RepaintAll();
- }
- }
- if (settings.embedInSurface)
- {
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var embedAtPivotHeight = UnityEditor.EditorGUILayout.ToggleLeft("Embed At Pivot Height",
- settings.embedAtPivotHeight);
- if (check.changed)
- {
- settings.embedAtPivotHeight = embedAtPivotHeight;
- if (settings.embedInSurface && settings is SelectionToolSettings) PWBIO.EmbedSelectionInSurface();
- UnityEditor.SceneView.RepaintAll();
- }
- }
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- UnityEditor.EditorGUIUtility.labelWidth = 110;
- var surfaceDistance = UnityEditor.EditorGUILayout.FloatField("Surface Distance:",
- settings.surfaceDistance);
- if (check.changed)
- {
- settings.surfaceDistance = surfaceDistance;
- if (settings is SelectionToolSettings) PWBIO.EmbedSelectionInSurface();
- UnityEditor.SceneView.RepaintAll();
- }
- }
- if (settings is SelectionToolBase)
- {
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var selectionSettings = settings as SelectionToolBase;
- var rotateToTheSurface = UnityEditor.EditorGUILayout.ToggleLeft("Rotate To the Surface",
- selectionSettings.rotateToTheSurface);
- if (check.changed)
- {
- selectionSettings.rotateToTheSurface = rotateToTheSurface;
- if (settings.embedInSurface && settings is SelectionToolSettings)
- PWBIO.EmbedSelectionInSurface();
- UnityEditor.SceneView.RepaintAll();
- }
- }
- }
- }
- }
- }
- private struct BrushPropertiesGroupState
- {
- public bool brushPosGroupOpen;
- public bool brushRotGroupOpen;
- public bool brushScaleGroupOpen;
- public bool brushFlipGroupOpen;
- }
- private void OverwriteBrushPropertiesGUI(IPaintToolSettings settings,
- ref BrushPropertiesGroupState state)
- {
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var overwriteBrushProperties = UnityEditor.EditorGUILayout.ToggleLeft("Overwrite Brush Properties",
- settings.overwriteBrushProperties);
- if (check.changed)
- {
- settings.overwriteBrushProperties = overwriteBrushProperties;
- UnityEditor.SceneView.RepaintAll();
- }
- }
- if (PaletteManager.selectedBrush != null)
- settings.brushSettings.isAsset2D = PaletteManager.selectedBrush.isAsset2D;
- else settings.brushSettings.isAsset2D = false;
- if (settings.overwriteBrushProperties)
- BrushProperties.BrushFields(settings.brushSettings,
- ref state.brushPosGroupOpen, ref state.brushRotGroupOpen,
- ref state.brushScaleGroupOpen, ref state.brushFlipGroupOpen);
- }
- }
- private static readonly string[] _editModeTypeOptions = { "Line nodes", "Line position and rotation" };
- private void EditModeToggle(IPersistentToolManager persistentToolManager)
- {
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- using (new GUILayout.HorizontalScope())
- {
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var editMode = UnityEditor.EditorGUILayout.ToggleLeft("Edit Mode", ToolManager.editMode);
- if (check.changed)
- {
- ToolManager.editMode = editMode;
- PWBIO.ResetLineRotation();
- PWBIO.repaint = true;
- UnityEditor.SceneView.RepaintAll();
- PWBItemsWindow.RepainWindow();
- }
- }
- if (persistentToolManager == LineManager.instance && ToolManager.editMode)
- {
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var editModeType = (LineManager.EditModeType)UnityEditor.EditorGUILayout
- .Popup((int)LineManager.editModeType, _editModeTypeOptions);
- if (check.changed)
- {
- LineManager.editModeType = editModeType;
- PWBIO.ResetLineRotation();
- PWBIO.repaint = true;
- UnityEditor.SceneView.RepaintAll();
- }
- }
- }
- }
- if (ToolManager.editMode)
- {
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var applyBrushToexisting = UnityEditor.EditorGUILayout.ToggleLeft(
- "Apply brush setings to Pre-existing objects", persistentToolManager.applyBrushToExisting);
- if (check.changed)
- {
- persistentToolManager.applyBrushToExisting = applyBrushToexisting;
- if (ToolManager.tool == ToolManager.PaintTool.LINE) PWBIO.PreviewSelectedPersistentLines();
- else if (ToolManager.tool == ToolManager.PaintTool.SHAPE) PWBIO.PreviewSelectedPersistentShapes();
- else if (ToolManager.tool == ToolManager.PaintTool.TILING)
- PWBIO.PreviewSelectedPersistentTilings();
- PWBIO.repaint = true;
- UnityEditor.SceneView.RepaintAll();
- }
- }
- }
- if (ToolManager.editMode)
- {
- if (GUILayout.Button("Open items window")) PWBItemsWindow.ShowWindow();
- }
- }
- }
- private void HandlePosition()
- {
- if (PWBIO.selectedPointIdx < 0) return;
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- PWBIO.handlePosition = UnityEditor.EditorGUILayout.Vector3Field("Handle position:", PWBIO.handlePosition);
- if (check.changed) PWBIO.UpdateHandlePosition();
- }
- }
- }
- private void HandleRotation()
- {
- if (PWBIO.selectedPointIdx < 0) return;
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var eulerAngles = PWBIO.handleRotation.eulerAngles;
- eulerAngles = UnityEditor.EditorGUILayout.Vector3Field("Handle rotation:", eulerAngles);
- if (check.changed)
- {
- var newRotation = Quaternion.Euler(eulerAngles);
- PWBIO.handleRotation = newRotation;
- PWBIO.UpdateHandleRotation();
- }
- }
- }
- }
- #endregion
- #region SELECTION BRUSH AND MODIFIER SETTINGS
- private static readonly string[] _modifierCommandOptions = { "All", "Palette Prefabs", "Brush Prefabs" };
- private void SelectionBrushGroup(ISelectionBrushTool settings, string actionLabel)
- {
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- UnityEditor.EditorGUIUtility.labelWidth = 60;
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var command = (ModifierToolSettings.Command)UnityEditor.EditorGUILayout.Popup(actionLabel + ":",
- (int)settings.command, _modifierCommandOptions);
- if (check.changed)
- {
- settings.command = command;
- PWBIO.UpdateOctree();
- }
- }
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var onlyTheClosest = UnityEditor.EditorGUILayout.ToggleLeft(actionLabel + " only the closest",
- settings.onlyTheClosest);
- if (check.changed)
- {
- settings.onlyTheClosest = onlyTheClosest;
- }
- }
- }
- }
- private void ModifierGroup(IModifierTool settings, string actionLabel)
- {
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- UnityEditor.EditorGUIUtility.labelWidth = 60;
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var allButSelected = UnityEditor.EditorGUILayout.ToggleLeft(actionLabel + " all but selected",
- settings.modifyAllButSelected);
- if (check.changed)
- {
- settings.modifyAllButSelected = allButSelected;
- PWBIO.UpdateOctree();
- }
- }
- }
- }
- #endregion
- #region PIN
- private static readonly string[] _pinModeNames = { "Auto", "Paint on surface", "Paint on grid" };
- private static BrushPropertiesGroupState _pinOverwriteGroupState;
- private void PinGroup()
- {
- ToolProfileGUI(PinManager.instance);
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var mode = (PinSettings.PaintMode)UnityEditor.EditorGUILayout.Popup("Paint mode:",
- (int)PinManager.settings.mode, _pinModeNames);
- if (check.changed)
- {
- PinManager.settings.mode = mode;
- UnityEditor.SceneView.RepaintAll();
- }
- }
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var repeat = UnityEditor.EditorGUILayout.ToggleLeft("Repeat multi-brush item", PinManager.settings.repeat);
- if (check.changed)
- {
- PinManager.settings.repeat = repeat;
- UnityEditor.SceneView.RepaintAll();
- }
- }
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var avoidOverlapping = UnityEditor.EditorGUILayout.ToggleLeft("Avoid overlapping",
- PinManager.settings.avoidOverlapping);
- if (check.changed)
- {
- PinManager.settings.avoidOverlapping = avoidOverlapping;
- UnityEditor.SceneView.RepaintAll();
- }
- }
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var snapRotationToGrid = UnityEditor.EditorGUILayout.ToggleLeft("Snap rotation to grid",
- PinManager.settings.snapRotationToGrid);
- if (check.changed)
- {
- PinManager.settings.snapRotationToGrid = snapRotationToGrid;
- UnityEditor.SceneView.RepaintAll();
- }
- }
- }
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- UnityEditor.EditorGUIUtility.labelWidth = 60;
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var flattenTerrain
- = UnityEditor.EditorGUILayout.ToggleLeft("Flatten the terrain", PinManager.settings.flattenTerrain);
- if (check.changed)
- {
- PinManager.settings.flattenTerrain = flattenTerrain;
- }
- }
- using (new UnityEditor.EditorGUI.DisabledGroupScope(!PinManager.settings.flattenTerrain))
- {
- var flatteningSettings = PinManager.settings.flatteningSettings;
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var hardness = UnityEditor.EditorGUILayout.Slider("Hardness:", flatteningSettings.hardness, 0, 1);
- if (check.changed)
- {
- flatteningSettings.hardness = hardness;
- }
- }
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var padding = UnityEditor.EditorGUILayout.FloatField("Padding:", flatteningSettings.padding);
- if (check.changed)
- {
- flatteningSettings.padding = padding;
- }
- }
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var clearTrees = UnityEditor.EditorGUILayout.ToggleLeft("Clear trees", flatteningSettings.clearTrees);
- if (check.changed)
- {
- flatteningSettings.clearTrees = clearTrees;
- }
- }
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var clearDetails
- = UnityEditor.EditorGUILayout.ToggleLeft("Clear details", flatteningSettings.clearDetails);
- if (check.changed)
- {
- flatteningSettings.clearDetails = clearDetails;
- }
- }
- }
- }
- PaintSettingsGUI(PinManager.settings, PinManager.settings);
- OverwriteBrushPropertiesGUI(PinManager.settings, ref _pinOverwriteGroupState);
- }
- #endregion
- #region BRUSH
- private static readonly string[] _heightTypeNames = { "Custom", "Radius" };
- private static readonly string[] _avoidOverlappingTypeNames = { "Disabled", "With Palette Prefabs",
- "With Brush Prefabs", "With Same Prefabs", "With All Objects" };
- private static BrushPropertiesGroupState _brushOverwriteGroupState;
- private void BrushGroup()
- {
- ToolProfileGUI(BrushManager.instance);
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- BrushManager.settings.showPreview = UnityEditor.EditorGUILayout.ToggleLeft("Show Brushstroke Preview",
- BrushManager.settings.showPreview);
- if (BrushManager.settings.showPreview)
- UnityEditor.EditorGUILayout.HelpBox("The brushstroke preview can cause slowdown issues.",
- UnityEditor.MessageType.Info);
- UnityEditor.EditorGUILayout.LabelField("Brushstroke object count:", BrushstrokeManager.itemCount.ToString());
- }
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- BrushToolBaseSettingsGUI(BrushManager.settings);
- UnityEditor.EditorGUIUtility.labelWidth = 150;
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var avoidOverlapping = (BrushToolSettings.AvoidOverlappingType)
- UnityEditor.EditorGUILayout.Popup("Avoid Overlapping:",
- (int)BrushManager.settings.avoidOverlapping, _avoidOverlappingTypeNames);
- if (check.changed)
- {
- BrushManager.settings.avoidOverlapping = avoidOverlapping;
- }
- }
- if (BrushManager.settings.brushShape != BrushToolBase.BrushShape.POINT)
- {
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var heightType = (BrushToolSettings.HeightType)
- UnityEditor.EditorGUILayout.Popup("Max Height From center:",
- (int)BrushManager.settings.heightType, _heightTypeNames);
- if (check.changed)
- {
- BrushManager.settings.heightType = heightType;
- if (heightType == BrushToolSettings.HeightType.RADIUS)
- BrushManager.settings.maxHeightFromCenter = BrushManager.settings.radius;
- UnityEditor.SceneView.RepaintAll();
- }
- }
- using (new UnityEditor.EditorGUI.DisabledGroupScope(
- BrushManager.settings.heightType == BrushToolSettings.HeightType.RADIUS))
- {
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var maxHeightFromCenter = Mathf.Abs(UnityEditor.EditorGUILayout.FloatField("Value:",
- BrushManager.settings.maxHeightFromCenter));
- if (check.changed)
- {
- BrushManager.settings.maxHeightFromCenter = maxHeightFromCenter;
- UnityEditor.SceneView.RepaintAll();
- }
- }
- }
- }
- }
- }
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- GUILayout.Label("Surface Filters", UnityEditor.EditorStyles.boldLabel);
- UnityEditor.EditorGUIUtility.labelWidth = 110;
- using (new GUILayout.HorizontalScope())
- {
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var minSlope = BrushManager.settings.slopeFilter.min;
- var maxSlope = BrushManager.settings.slopeFilter.max;
- UnityEditor.EditorGUILayout.MinMaxSlider("Slope Angle:", ref minSlope, ref maxSlope, 0, 90);
- minSlope = Mathf.Round(minSlope);
- maxSlope = Mathf.Round(maxSlope);
- GUILayout.Label("[" + minSlope.ToString("00") + "°," + maxSlope.ToString("00") + "°]");
- if (check.changed)
- {
- BrushManager.settings.slopeFilter.v1 = minSlope;
- BrushManager.settings.slopeFilter.v2 = maxSlope;
- UnityEditor.SceneView.RepaintAll();
- }
- }
- }
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var mask = UnityEditor.EditorGUILayout.MaskField("Layers:",
- EditorGUIUtils.LayerMaskToField(BrushManager.settings.layerFilter),
- UnityEditorInternal.InternalEditorUtility.layers);
- if (check.changed)
- {
- BrushManager.settings.layerFilter = EditorGUIUtils.FieldToLayerMask(mask);
- UnityEditor.SceneView.RepaintAll();
- }
- }
- UnityEditor.EditorGUIUtility.labelWidth = 108;
- var field = EditorGUIUtils.MultiTagField.Instantiate("Tags:", BrushManager.settings.tagFilter, null);
- field.OnChange += OnBrushTagFilterChanged;
- bool terrainFilterChanged = false;
- var terrainFilter = EditorGUIUtils.ObjectArrayFieldWithButtons("Terrain Layers:",
- BrushManager.settings.terrainLayerFilter, ref _terrainLayerFilterFoldout, out terrainFilterChanged);
- if (terrainFilterChanged)
- {
- BrushManager.settings.terrainLayerFilter = terrainFilter.ToArray();
- UnityEditor.SceneView.RepaintAll();
- }
- }
- PaintSettingsGUI(BrushManager.settings, BrushManager.settings);
- OverwriteBrushPropertiesGUI(BrushManager.settings, ref _brushOverwriteGroupState);
- }
- private bool _terrainLayerFilterFoldout = false;
- private void OnBrushTagFilterChanged(System.Collections.Generic.List<string> prevFilter,
- System.Collections.Generic.List<string> newFilter, string key)
- {
- BrushManager.settings.tagFilter = newFilter;
- }
- #endregion
- #region ERASER
- private void EraserGroup()
- {
- UnityEditor.EditorGUIUtility.labelWidth = 60;
- var settings = EraserManager.settings;
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox)) RadiusSlider(settings);
- var actionLabel = "Erase";
- SelectionBrushGroup(settings, actionLabel);
- ModifierGroup(settings, actionLabel);
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var outermostFilter = UnityEditor.EditorGUILayout.ToggleLeft("Outermost prefab filter",
- settings.outermostPrefabFilter);
- if (check.changed)
- {
- settings.outermostPrefabFilter = outermostFilter;
- }
- }
- if (!settings.outermostPrefabFilter)
- GUILayout.Label("When you delete a child of a prefab, the prefab will be unpacked.",
- UnityEditor.EditorStyles.helpBox);
- }
- }
- #endregion
- #region GRAVITY
- private static BrushPropertiesGroupState _gravityOverwriteGroupState;
- private void GravityGroup()
- {
- ToolProfileGUI(GravityToolManager.instance);
- BrushToolBaseSettingsGUI(GravityToolManager.settings);
- UnityEditor.EditorGUIUtility.labelWidth = 120;
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- var settings = GravityToolManager.settings.Clone();
- var data = settings.simData;
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- settings.height = UnityEditor.EditorGUILayout.FloatField("Height:", settings.height);
- data.maxIterations = UnityEditor.EditorGUILayout.IntField("Max Iterations:", data.maxIterations);
- data.maxSpeed = UnityEditor.EditorGUILayout.FloatField("Max Speed:", data.maxSpeed);
- data.maxAngularSpeed = UnityEditor.EditorGUILayout.FloatField("Max Angular Speed:", data.maxAngularSpeed);
- data.mass = UnityEditor.EditorGUILayout.FloatField("Mass:", data.mass);
- data.drag = UnityEditor.EditorGUILayout.FloatField("Drag:", data.drag);
- data.angularDrag = UnityEditor.EditorGUILayout.FloatField("Angular Drag:", data.angularDrag);
- if (check.changed)
- {
- GravityToolManager.settings.Copy(settings);
- UnityEditor.SceneView.RepaintAll();
- }
- }
- using (new UnityEditor.EditorGUI.DisabledGroupScope
- (PWBCore.staticData.tempCollidersAction == PWBData.TempCollidersAction.NEVER_CREATE))
- {
- using (new GUILayout.HorizontalScope())
- {
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var createTempColliders = UnityEditor.EditorGUILayout.ToggleLeft("Create Temp Colliders",
- GravityToolManager.settings.createTempColliders);
- if (check.changed)
- {
- GravityToolManager.settings.createTempColliders = createTempColliders;
- PWBCore.UpdateTempColliders();
- UnityEditor.SceneView.RepaintAll();
- }
- }
- using (new UnityEditor.EditorGUI.DisabledGroupScope(!GravityToolManager.settings.createTempColliders))
- if (GUILayout.Button(_updateButtonContent, _reloadBtnStyle))
- PWBCore.UpdateTempColliders();
- }
- }
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- data.ignoreSceneColliders = UnityEditor.EditorGUILayout.ToggleLeft("Ignore Scene Colliders",
- data.ignoreSceneColliders);
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- data.changeLayer
- = UnityEditor.EditorGUILayout.ToggleLeft("Change Layer Temporarily", data.changeLayer);
- if (data.changeLayer)
- data.tempLayer = UnityEditor.EditorGUILayout.LayerField("Temp layer:", data.tempLayer);
- }
- if (check.changed)
- {
- GravityToolManager.settings.Copy(settings);
- UnityEditor.SceneView.RepaintAll();
- }
- }
- }
- PaintToolSettingsGUI(GravityToolManager.settings);
- OverwriteBrushPropertiesGUI(GravityToolManager.settings, ref _gravityOverwriteGroupState);
- }
- #endregion
- #region LINE
- private static readonly string[] _lineModeNames = { "Auto", "Paint on surface", "Paint on the line" };
- private static readonly string[] _lineSpacingNames = { "Bounds", "Constant" };
- private static readonly string[] _lineAxesAlongTheLineNames = { "X", "Z" };
- private static string[] _shapeProjDirNames = new string[] { "+X", "-X", "+Y", "-Y", "+Z", "-Z", "Plane Axis" };
- private static int _lineProjDirIdx = 6;
- private static BrushPropertiesGroupState _lineOverwriteGroupState;
- private void LineBaseGUI<SETTINGS>(SETTINGS lineSettings) where SETTINGS : LineSettings
- {
- void OnValueChanged()
- {
- PWBIO.UpdateStroke();
- PWBIO.repaint = true;
- }
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var mode = (PaintOnSurfaceToolSettingsBase.PaintMode)
- UnityEditor.EditorGUILayout.Popup("Paint Mode:", (int)lineSettings.mode, _lineModeNames);
- if (check.changed)
- {
- lineSettings.mode = mode;
- OnValueChanged();
- }
- }
- if (lineSettings is ShapeSettings)
- {
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var parallelToTheSurface = UnityEditor.EditorGUILayout.ToggleLeft(
- lineSettings.mode == PaintOnSurfaceToolSettingsBase.PaintMode.ON_SHAPE
- ? "Place objects perpendicular to the plane"
- : "Place objects perpendicular to the surface",
- lineSettings.perpendicularToTheSurface);
- if (check.changed)
- {
- lineSettings.perpendicularToTheSurface = parallelToTheSurface;
- OnValueChanged();
- }
- }
- }
- else
- {
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var parallelToTheSurface
- = UnityEditor.EditorGUILayout.ToggleLeft("Place objects perpendicular to the " +
- (lineSettings.mode == PaintOnSurfaceToolSettingsBase.PaintMode.ON_SHAPE ? "line" : "surface"),
- lineSettings.perpendicularToTheSurface);
- if (check.changed)
- {
- lineSettings.perpendicularToTheSurface = parallelToTheSurface;
- OnValueChanged();
- }
- }
- }
- var dirNames = lineSettings is ShapeSettings ? _shapeProjDirNames : _dirNames;
- var shapeSettings = lineSettings as ShapeSettings;
- if (shapeSettings != null)
- {
- _lineProjDirIdx = shapeSettings.projectInNormalDir ? _lineProjDirIdx = 6
- : System.Array.IndexOf(_dir, lineSettings.projectionDirection);
- }
- else _lineProjDirIdx = System.Array.IndexOf(_dir, lineSettings.projectionDirection);
- if (_lineProjDirIdx == -1) _lineProjDirIdx = 3;
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- _lineProjDirIdx = UnityEditor.EditorGUILayout.Popup("Projection Direction:", _lineProjDirIdx, dirNames);
- if (check.changed)
- {
- if (shapeSettings != null) shapeSettings.projectInNormalDir = _lineProjDirIdx == 6;
- lineSettings.projectionDirection = _lineProjDirIdx == 6
- ? PWBIO.GetShapePlaneNormal() : _dir[_lineProjDirIdx];
- OnValueChanged();
- }
- }
- }
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var objectsOrientedAlongTheLine
- = UnityEditor.EditorGUILayout.ToggleLeft("Orient Along the Line",
- lineSettings.objectsOrientedAlongTheLine);
- if (check.changed)
- {
- lineSettings.objectsOrientedAlongTheLine = objectsOrientedAlongTheLine;
- OnValueChanged();
- }
- }
- if (lineSettings.objectsOrientedAlongTheLine)
- {
- UnityEditor.EditorGUIUtility.labelWidth = 170;
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var axisOrientedAlongTheLine = UnityEditor.EditorGUILayout.Popup("Axis Oriented Along the Line:",
- lineSettings.axisOrientedAlongTheLine == AxesUtils.Axis.X ? 0 : 1,
- _lineAxesAlongTheLineNames) == 0 ? AxesUtils.Axis.X : AxesUtils.Axis.Z;
- if (check.changed)
- {
- lineSettings.axisOrientedAlongTheLine = axisOrientedAlongTheLine;
- OnValueChanged();
- }
- }
- }
- }
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- UnityEditor.EditorGUIUtility.labelWidth = 120;
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var spacingType = (LineSettings.SpacingType)
- UnityEditor.EditorGUILayout.Popup("Spacing:", (int)lineSettings.spacingType, _lineSpacingNames);
- if (check.changed)
- {
- lineSettings.spacingType = spacingType;
- OnValueChanged();
- }
- }
- if (lineSettings.spacingType == LineSettings.SpacingType.CONSTANT)
- {
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var spacing = UnityEditor.EditorGUILayout.FloatField("Value:", lineSettings.spacing);
- if (check.changed)
- {
- lineSettings.spacing = spacing;
- OnValueChanged();
- }
- }
- }
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var gapSize = UnityEditor.EditorGUILayout.FloatField("Gap Size:", lineSettings.gapSize);
- if (check.changed)
- {
- if (PaletteManager.selectedBrushIdx >= 0 && PaletteManager.selectedBrush != null)
- {
- var spacing = lineSettings.spacingType == LineSettings.SpacingType.CONSTANT
- ? lineSettings.spacing : PaletteManager.selectedBrush.minBrushMagnitude;
- var min = Mathf.Min(0, 0.05f - spacing);
- gapSize = Mathf.Max(min, gapSize);
- }
- lineSettings.gapSize = gapSize;
- OnValueChanged();
- }
- }
- }
- }
- private void LineGroup()
- {
- ToolProfileGUI(LineManager.instance);
- EditModeToggle(LineManager.instance);
- HandlePosition();
- UnityEditor.EditorGUIUtility.labelWidth = 120;
- LineBaseGUI(LineManager.settings);
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var closed = UnityEditor.EditorGUILayout.ToggleLeft("Colsed Path", PWBIO.lineData.closed);
- if (check.changed)
- {
- PWBIO.lineData.closed = closed;
- PWBIO.UpdateStroke();
- UnityEditor.SceneView.RepaintAll();
- PWBIO.repaint = true;
- }
- }
- }
- PaintSettingsGUI(LineManager.settings, LineManager.settings);
- OverwriteBrushPropertiesGUI(LineManager.settings, ref _lineOverwriteGroupState);
- }
- #endregion
- #region SHAPE
- private static readonly string[] _shapeTypeNames = { "Circle", "Polygon" };
- private static BrushPropertiesGroupState _shapeOverwriteGroupState;
- private static string[] _shapeDirNames = new string[] { "+X", "-X", "+Y", "-Y", "+Z", "-Z", "Normal to surface" };
- private void ShapeGroup()
- {
- UnityEditor.EditorGUIUtility.labelWidth = 100;
- ToolProfileGUI(ShapeManager.instance);
- EditModeToggle(ShapeManager.instance);
- HandlePosition();
- HandleRotation();
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var shapeType = (ShapeSettings.ShapeType)UnityEditor.EditorGUILayout.Popup("Shape:",
- (int)ShapeManager.settings.shapeType, _shapeTypeNames);
- if (check.changed)
- {
- ShapeManager.settings.shapeType = shapeType;
- if (shapeType == ShapeSettings.ShapeType.CIRCLE)
- {
- ShapeData.instance.UpdateCircleSideCount();
- }
- ShapeData.instance.Update(true);
- PWBIO.UpdateStroke();
- PWBIO.repaint = true;
- }
- }
- if (ShapeManager.settings.shapeType == ShapeSettings.ShapeType.POLYGON)
- {
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var sideCount = UnityEditor.EditorGUILayout.IntSlider("Number of sides:",
- ShapeManager.settings.sidesCount, 3, 12);
- if (check.changed)
- {
- ShapeManager.settings.sidesCount = sideCount;
- ShapeData.instance.UpdateIntersections();
- PWBIO.UpdateStroke();
- PWBIO.repaint = true;
- }
- }
- }
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var normalDirIdx = ShapeManager.settings.axisNormalToSurface
- ? 6 : System.Array.IndexOf(_dir, ShapeManager.settings.normal);
- UnityEditor.EditorGUIUtility.labelWidth = 120;
- normalDirIdx = UnityEditor.EditorGUILayout.Popup("Initial axis direction:", normalDirIdx, _shapeDirNames);
- var axisNormalToSurface = normalDirIdx == 6;
- if (check.changed)
- {
- ShapeManager.settings.axisNormalToSurface = axisNormalToSurface;
- ShapeManager.settings.normal = normalDirIdx == 6 ? Vector3.up : _dir[normalDirIdx];
- PWBIO.UpdateStroke();
- PWBIO.repaint = true;
- }
- }
- }
- UnityEditor.EditorGUIUtility.labelWidth = 120;
- LineBaseGUI(ShapeManager.settings);
- PaintSettingsGUI(ShapeManager.settings, ShapeManager.settings);
- OverwriteBrushPropertiesGUI(ShapeManager.settings, ref _shapeOverwriteGroupState);
- }
- #endregion
- #region TILING
- private static readonly string[] _tilingModeNames = { "Auto", "Paint on surface", "Paint on the plane" };
- private static readonly string[] _cellTypeNames = { "Smallest object", "Biggest object", "Custom" };
- private static BrushPropertiesGroupState _tilingOverwriteGroupState;
- private void TilingGroup()
- {
- ToolProfileGUI(TilingManager.instance);
- EditModeToggle(TilingManager.instance);
- HandlePosition();
- if (!ToolManager.editMode)
- {
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- TilingManager.settings.showPreview = UnityEditor.EditorGUILayout.ToggleLeft("Show Preview",
- TilingManager.settings.showPreview);
- if (TilingManager.settings.showPreview)
- UnityEditor.EditorGUILayout.HelpBox("If you experience slowdown issues, disable preview.",
- UnityEditor.MessageType.Info);
- UnityEditor.EditorGUILayout.LabelField("Object count:", BrushstrokeManager.itemCount.ToString());
- }
- }
- UnityEditor.EditorGUIUtility.labelWidth = 180;
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var settings = TilingManager.settings;
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- settings.mode = (TilingSettings.PaintMode)UnityEditor.EditorGUILayout.Popup("Paint mode:",
- (int)settings.mode, _tilingModeNames);
- using (var angleCheck = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var eulerAngles = settings.rotation.eulerAngles;
- eulerAngles = UnityEditor.EditorGUILayout.Vector3Field("Plane Rotation:", eulerAngles);
- if (angleCheck.changed)
- {
- var newRotation = Quaternion.Euler(eulerAngles);
- PWBIO.UpdateTilingRotation(newRotation);
- settings.rotation = newRotation;
- }
- }
- var axisIdx = UnityEditor.EditorGUILayout.Popup("Axis aligned with plane normal: ",
- settings.axisAlignedWithNormal, _dirNames);
- settings.axisAlignedWithNormal = axisIdx;
- }
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- UnityEditor.EditorGUIUtility.labelWidth = 76;
- settings.cellSizeType = (TilesUtils.SizeType)
- UnityEditor.EditorGUILayout.Popup("Cell size:", (int)settings.cellSizeType, _cellTypeNames);
- using (new UnityEditor.EditorGUI.DisabledGroupScope(
- settings.cellSizeType != TilesUtils.SizeType.CUSTOM))
- {
- settings.cellSize = UnityEditor.EditorGUILayout.Vector2Field("", settings.cellSize);
- }
- }
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- settings.spacing = UnityEditor.EditorGUILayout.Vector2Field("Spacing", settings.spacing);
- }
- if (check.changed)
- {
- PWBIO.UpdateStroke();
- UnityEditor.SceneView.RepaintAll();
- }
- }
- PaintSettingsGUI(TilingManager.settings, TilingManager.settings);
- OverwriteBrushPropertiesGUI(TilingManager.settings, ref _tilingOverwriteGroupState);
- }
- #endregion
- #region EXTRUDE
- private static readonly string[] _spaceOptions = { "Global", "Local" };
- private static readonly string[] _rotationOptions = { "First Object Selected", "Last Object Selected" };
- private static readonly string[] _extrudeSpacingOptions = { "Box Size", "Custom" };
- private static readonly string[] _addRotationOptions = { "Constant", "Random" };
- private void ExtrudeGroup()
- {
- ToolProfileGUI(ExtrudeManager.instance);
- UnityEditor.EditorGUIUtility.labelWidth = 60;
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var extrudeSettings = ExtrudeManager.settings.Clone();
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- extrudeSettings.space = (Space)(UnityEditor.EditorGUILayout.Popup("Space:",
- (int)extrudeSettings.space, _spaceOptions));
- if (extrudeSettings.space == Space.Self)
- {
- UnityEditor.EditorGUIUtility.labelWidth = 150;
- extrudeSettings.rotationAccordingTo = (ExtrudeSettings.RotationAccordingTo)UnityEditor
- .EditorGUILayout.Popup("Set rotation according to:",
- (int)extrudeSettings.rotationAccordingTo, _rotationOptions);
- }
- }
- UnityEditor.EditorGUIUtility.labelWidth = 60;
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- extrudeSettings.spacingType = (ExtrudeSettings.SpacingType)UnityEditor.EditorGUILayout.Popup("Spacing:",
- (int)extrudeSettings.spacingType, _extrudeSpacingOptions);
- if (extrudeSettings.spacingType == ExtrudeSettings.SpacingType.BOX_SIZE)
- extrudeSettings.multiplier
- = UnityEditor.EditorGUILayout.Vector3Field("Multiplier:", extrudeSettings.multiplier);
- else extrudeSettings.spacing
- = UnityEditor.EditorGUILayout.Vector3Field("Value:", extrudeSettings.spacing);
- }
- if (extrudeSettings.space == Space.World)
- {
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- UnityEditor.EditorGUIUtility.labelWidth = 80;
- extrudeSettings.addRandomRotation = UnityEditor.EditorGUILayout.Popup("Add Rotation:",
- extrudeSettings.addRandomRotation ? 1 : 0, _addRotationOptions) == 1;
- if (extrudeSettings.addRandomRotation)
- {
- extrudeSettings.randomEulerOffset = EditorGUIUtils.Range3Field(string.Empty,
- extrudeSettings.randomEulerOffset);
- using (new GUILayout.HorizontalScope())
- {
- extrudeSettings.rotateInMultiples = UnityEditor.EditorGUILayout.ToggleLeft
- ("Only in multiples of:", extrudeSettings.rotateInMultiples);
- using (new UnityEditor.EditorGUI.DisabledGroupScope(!extrudeSettings.rotateInMultiples))
- extrudeSettings.rotationFactor
- = UnityEditor.EditorGUILayout.FloatField(extrudeSettings.rotationFactor);
- }
- }
- else extrudeSettings.eulerOffset = UnityEditor.EditorGUILayout.Vector3Field(string.Empty,
- extrudeSettings.eulerOffset);
- }
- }
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- extrudeSettings.sameParentAsSource
- = UnityEditor.EditorGUILayout.ToggleLeft("Same parent as source", extrudeSettings.sameParentAsSource);
- if (!extrudeSettings.sameParentAsSource)
- {
- extrudeSettings.autoCreateParent
- = UnityEditor.EditorGUILayout.ToggleLeft("Create parent", extrudeSettings.autoCreateParent);
- if (extrudeSettings.autoCreateParent) extrudeSettings.createSubparentPerPrefab
- = UnityEditor.EditorGUILayout.ToggleLeft("Create sub-parent per prefab",
- extrudeSettings.createSubparentPerPrefab);
- else extrudeSettings.parent = (Transform)UnityEditor.EditorGUILayout.ObjectField("Parent Transform:",
- extrudeSettings.parent, typeof(Transform), true);
- }
- }
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- extrudeSettings.overwritePrefabLayer
- = UnityEditor.EditorGUILayout.ToggleLeft("Overwrite prefab layer",
- extrudeSettings.overwritePrefabLayer);
- if (extrudeSettings.overwritePrefabLayer)
- extrudeSettings.layer = UnityEditor.EditorGUILayout.LayerField("Layer:", extrudeSettings.layer);
- }
- if (check.changed)
- {
- ExtrudeManager.settings.Copy(extrudeSettings);
- UnityEditor.SceneView.RepaintAll();
- PWBIO.ClearExtrudeAngles();
- }
- }
- EmbedInSurfaceSettingsGUI(ExtrudeManager.settings);
- }
- #endregion
- #region SELECTION TOOL
- private void SelectionGroup()
- {
- ToolProfileGUI(SelectionToolManager.instance);
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- UnityEditor.EditorGUIUtility.labelWidth = 90;
- var handleSpace = (Space)(UnityEditor.EditorGUILayout.Popup("Handle Space:",
- (int)SelectionToolManager.settings.handleSpace, _spaceOptions));
- if (SelectionManager.topLevelSelection.Length > 1) SelectionToolManager.settings.boxSpace = Space.World;
- var boxSpace = SelectionToolManager.settings.boxSpace;
- using (new UnityEditor.EditorGUI.DisabledGroupScope(SelectionManager.topLevelSelection.Length > 1))
- {
- boxSpace = (Space)(UnityEditor.EditorGUILayout.Popup("Box Space:",
- (int)SelectionToolManager.settings.boxSpace, _spaceOptions));
- }
- if (check.changed)
- {
- SelectionToolManager.settings.handleSpace = handleSpace;
- SelectionToolManager.settings.boxSpace = boxSpace;
- PWBIO.ResetSelectionRotation();
- UnityEditor.SceneView.RepaintAll();
- }
- }
- }
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- GUILayout.Label("Selection Filters", UnityEditor.EditorStyles.boldLabel);
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- UnityEditor.EditorGUIUtility.labelWidth = 90;
- var paletteFilter = UnityEditor.EditorGUILayout.ToggleLeft("Prefabs from selected palette only",
- SelectionToolManager.settings.paletteFilter);
- var brushFilter = UnityEditor.EditorGUILayout.ToggleLeft("Prefabs from selected brush only",
- SelectionToolManager.settings.brushFilter);
- var layerMask = UnityEditor.EditorGUILayout.MaskField("Layers:",
- EditorGUIUtils.LayerMaskToField(SelectionToolManager.settings.layerFilter),
- UnityEditorInternal.InternalEditorUtility.layers);
- var tagField = EditorGUIUtils.MultiTagField.Instantiate("Tags:",
- SelectionToolManager.settings.tagFilter, null);
- tagField.OnChange += OnSelectionTagFilterChanged;
- if (check.changed)
- {
- SelectionToolManager.settings.paletteFilter = paletteFilter;
- SelectionToolManager.settings.brushFilter = brushFilter;
- SelectionToolManager.settings.layerFilter = EditorGUIUtils.FieldToLayerMask(layerMask);
- PWBIO.ApplySelectionFilters();
- UnityEditor.SceneView.RepaintAll();
- }
- }
- }
- EmbedInSurfaceSettingsGUI(SelectionToolManager.settings);
- }
- private void OnSelectionTagFilterChanged(System.Collections.Generic.List<string> prevFilter,
- System.Collections.Generic.List<string> newFilter, string key)
- {
- SelectionToolManager.settings.tagFilter = newFilter;
- PWBIO.ApplySelectionFilters();
- UnityEditor.SceneView.RepaintAll();
- }
- #endregion
- #region CIRCLE SELECT
- private void CircleSelectGroup()
- {
- UnityEditor.EditorGUIUtility.labelWidth = 60;
- var settings = CircleSelectManager.settings;
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox)) RadiusSlider(settings);
- SelectionBrushGroup(settings, actionLabel: "Select");
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var outermostFilter = UnityEditor.EditorGUILayout.ToggleLeft("Outermost prefab filter",
- settings.outermostPrefabFilter);
- if (check.changed)
- {
- settings.outermostPrefabFilter = outermostFilter;
- }
- }
- }
- }
- #endregion
- #region MIRROR
- private static readonly string[] _mirrorActionNames = { "Transform", "Create" };
- private void MirrorGroup()
- {
- ToolProfileGUI(MirrorManager.instance);
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var mirrorSettings = new MirrorSettings();
- mirrorSettings.Copy(MirrorManager.settings);
- using (var mirrorCheck = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- UnityEditor.EditorGUIUtility.labelWidth = 80;
- mirrorSettings.mirrorPosition = UnityEditor.EditorGUILayout.Vector3Field("Position:",
- mirrorSettings.mirrorPosition);
- mirrorSettings.mirrorRotation = Quaternion.Euler(UnityEditor.EditorGUILayout.Vector3Field("Rotation:",
- mirrorSettings.mirrorRotation.eulerAngles));
- }
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- UnityEditor.EditorGUIUtility.labelWidth = 110;
- mirrorSettings.invertScale
- = UnityEditor.EditorGUILayout.ToggleLeft("Invert scale", mirrorSettings.invertScale);
- mirrorSettings.reflectRotation
- = UnityEditor.EditorGUILayout.ToggleLeft("Reflect rotation", mirrorSettings.reflectRotation);
- mirrorSettings.action = (MirrorSettings.MirrorAction)UnityEditor.EditorGUILayout.Popup("Action:",
- (int)mirrorSettings.action, _mirrorActionNames);
- }
- if (mirrorCheck.changed) UnityEditor.SceneView.RepaintAll();
- }
- if (mirrorSettings.action == MirrorSettings.MirrorAction.CREATE)
- {
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- mirrorSettings.sameParentAsSource = UnityEditor.EditorGUILayout.ToggleLeft("Same parent as source",
- mirrorSettings.sameParentAsSource);
- if (!mirrorSettings.sameParentAsSource)
- {
- mirrorSettings.autoCreateParent
- = UnityEditor.EditorGUILayout.ToggleLeft("Create parent", mirrorSettings.autoCreateParent);
- if (mirrorSettings.autoCreateParent)
- mirrorSettings.createSubparentPerPrefab
- = UnityEditor.EditorGUILayout.ToggleLeft("Create sub-parent per prefab",
- mirrorSettings.createSubparentPerPrefab);
- else mirrorSettings.parent
- = (Transform)UnityEditor.EditorGUILayout.ObjectField("Parent Transform:",
- mirrorSettings.parent, typeof(Transform), true);
- }
- }
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- mirrorSettings.overwritePrefabLayer = UnityEditor.EditorGUILayout.ToggleLeft("Overwrite prefab layer",
- mirrorSettings.overwritePrefabLayer);
- if (mirrorSettings.overwritePrefabLayer)
- mirrorSettings.layer = UnityEditor.EditorGUILayout.LayerField("Layer:", mirrorSettings.layer);
- }
- }
- if (check.changed)
- {
- MirrorManager.settings.Copy(mirrorSettings);
- UnityEditor.SceneView.RepaintAll();
- }
- }
- EmbedInSurfaceSettingsGUI(MirrorManager.settings);
- }
- #endregion
- #region REPLACER
- private static BrushPropertiesGroupState _replacerOverwriteGroupState;
- private static readonly string[] _replacerModeOptions = { "Target Center", "Target Pivot", "On Surface" };
- private void ReplacerGroup()
- {
- UnityEditor.EditorGUIUtility.labelWidth = 60;
- var settings = ReplacerManager.settings;
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox)) RadiusSlider(settings);
- var actionLabel = "Replace";
- SelectionBrushGroup(settings, actionLabel);
- ModifierGroup(settings, actionLabel);
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var positionMode = (ReplacerSettings.PositionMode)UnityEditor.EditorGUILayout.Popup("Position:",
- (int)settings.positionMode, _replacerModeOptions);
- if (check.changed)
- {
- settings.positionMode = positionMode;
- }
- }
- var keepTargetSize = settings.keepTargetSize;
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- keepTargetSize = UnityEditor.EditorGUILayout.ToggleLeft("Keep target size", settings.keepTargetSize);
- if (check.changed)
- {
- settings.keepTargetSize = keepTargetSize;
- }
- }
- if (keepTargetSize)
- {
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var maintainProportions = UnityEditor.EditorGUILayout.ToggleLeft("Maintain proportions",
- settings.maintainProportions);
- if (check.changed)
- {
- settings.maintainProportions = maintainProportions;
- }
- }
- }
- }
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var outermostFilter = UnityEditor.EditorGUILayout.ToggleLeft("Outermost prefab filter",
- settings.outermostPrefabFilter);
- if (check.changed) settings.outermostPrefabFilter = outermostFilter;
- }
- if (!settings.outermostPrefabFilter)
- GUILayout.Label("When you replace a child of a prefab, the prefab will be unpacked.",
- UnityEditor.EditorStyles.helpBox);
- }
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- settings.sameParentAsTarget = UnityEditor.EditorGUILayout.ToggleLeft("Same Parent as the target",
- settings.sameParentAsTarget);
- if (!settings.sameParentAsTarget) ParentSettingsGUI(ReplacerManager.settings);
- }
- OverwriteLayerGUI(ReplacerManager.settings);
- OverwriteBrushPropertiesGUI(ReplacerManager.settings, ref _replacerOverwriteGroupState);
- using (new GUILayout.HorizontalScope(UnityEditor.EditorStyles.helpBox))
- {
- GUILayout.FlexibleSpace();
- if (GUILayout.Button("Replace all selected"))
- {
- PWBIO.ReplaceAllSelected();
- UnityEditor.SceneView.RepaintAll();
- }
- GUILayout.FlexibleSpace();
- }
- }
- #endregion
- #region FLOOR
- private static BrushPropertiesGroupState _floorOverwriteGroupState;
- private void FloorGroup()
- {
- ToolProfileGUI(FloorManager.instance);
- var settings = FloorManager.settings;
- UnityEditor.EditorGUIUtility.labelWidth = 80;
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var axisIdx = UnityEditor.EditorGUILayout.Popup("Upward axis:",
- settings.upwardAxis, _dirNames);
- if (check.changed)
- {
- settings.upwardAxis = axisIdx;
- }
- }
- }
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- UnityEditor.EditorGUIUtility.labelWidth = 90;
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var moduleSizeType = (TilesUtils.SizeType)
- UnityEditor.EditorGUILayout.Popup("Cell size type:", (int)settings.moduleSizeType, _cellTypeNames);
- if (check.changed)
- {
- settings.moduleSizeType = moduleSizeType;
- if(settings.moduleSizeType == TilesUtils.SizeType.CUSTOM) FloorManager.settings.ResetSize();
- }
- }
- using (new GUILayout.HorizontalScope())
- {
- GUILayout.FlexibleSpace();
- UnityEditor.EditorGUIUtility.labelWidth = 20;
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- using (new UnityEditor.EditorGUI.DisabledGroupScope(
- settings.moduleSizeType != TilesUtils.SizeType.CUSTOM))
- {
- var x = UnityEditor.EditorGUILayout.FloatField("X:", settings.moduleSize.x);
- var z = UnityEditor.EditorGUILayout.FloatField("Z:", settings.moduleSize.z);
- if (check.changed)
- {
- settings.moduleSize = new Vector3(x, 1, z);
- }
- }
- }
- if (GUILayout.Button("Swap"))
- {
- settings.SwapXZ();
- RepainWindow();
- }
- }
- if (settings.moduleSizeType == TilesUtils.SizeType.CUSTOM)
- {
- int sizeIndex = 0;
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- UnityEditor.EditorGUIUtility.labelWidth = 70;
- sizeIndex = UnityEditor.EditorGUILayout.Popup("Cell Size:", settings.GetIndexOfSelectedSize(),
- settings.GetSizesNames());
- if (check.changed)
- {
- settings.SelectSize(sizeIndex);
- }
- }
- using (new GUILayout.HorizontalScope())
- {
- GUILayout.FlexibleSpace();
- if (GUILayout.Button("Reset")) FloorManager.settings.ResetSize();
- if (GUILayout.Button("Save..."))
- {
- RenameWindow.ShowWindow(position.position + Event.current.mousePosition,
- FloorManager.settings.SaveSize, "Save Size", settings.selectedSizeName);
- }
- using (new UnityEditor.EditorGUI.DisabledGroupScope(sizeIndex == 0))
- {
- if (GUILayout.Button("Delete"))
- {
- FloorManager.settings.DeleteSelectedSize();
- }
- }
- }
- }
- }
- UnityEditor.EditorGUIUtility.labelWidth = 70;
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var spacing = UnityEditor.EditorGUILayout.Vector3Field("Spacing", settings.spacing);
- if (check.changed)
- {
- settings.spacing = spacing;
- PWBIO.UpdateStroke();
- UnityEditor.SceneView.RepaintAll();
- }
- }
- }
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- int originIndex = 0;
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- originIndex = UnityEditor.EditorGUILayout.Popup("Grid origin:",
- SnapManager.settings.GetIndexOfSelectedOrigin(), SnapManager.settings.GetOriginNames());
- if (check.changed)
- {
- SnapManager.settings.SelectOrigin(originIndex);
- UnityEditor.SceneView.RepaintAll();
- }
- }
- using (new GUILayout.HorizontalScope())
- {
- GUILayout.Label("Position");
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var origin = UnityEditor.EditorGUILayout.Vector3Field(string.Empty,
- SnapManager.settings.origin);
- if (check.changed)
- {
- SnapManager.settings.origin = origin;
- UnityEditor.SceneView.RepaintAll();
- }
- }
- }
- using (new GUILayout.HorizontalScope())
- {
- GUILayout.Label("Rotation");
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var angle = UnityEditor.EditorGUILayout.Vector3Field(string.Empty,
- SnapManager.settings.rotation.eulerAngles);
- if (check.changed)
- {
- SnapManager.settings.rotation = Quaternion.Euler(angle);
- UnityEditor.SceneView.RepaintAll();
- }
- }
- }
- using (new GUILayout.HorizontalScope())
- {
- GUILayout.FlexibleSpace();
- if(GUILayout.Button("Reset"))
- {
- SnapManager.settings.ResetOrigin();
- }
- if (GUILayout.Button("Save..."))
- {
- RenameWindow.ShowWindow(position.position + Event.current.mousePosition,
- SnapManager.settings.SaveGridOrigin, "Save Origin", SnapManager.settings.selectedOrigin);
- }
- using (new UnityEditor.EditorGUI.DisabledGroupScope(originIndex == 0))
- {
- if (GUILayout.Button("Delete"))
- {
- SnapManager.settings.DeleteSelectedOrigin();
- }
- }
- }
- }
- PaintToolSettingsGUI(FloorManager.settings);
- OverwriteBrushPropertiesGUI(FloorManager.settings, ref _floorOverwriteGroupState);
- }
- #endregion
- #region WALL
- private static BrushPropertiesGroupState _wallOverwriteGroupState;
- private void WallGroup()
- {
- ToolProfileGUI(WallManager.instance);
- var settings = WallManager.settings;
- UnityEditor.EditorGUIUtility.labelWidth = 80;
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- settings.autoCalculateAxes = UnityEditor.EditorGUILayout.ToggleLeft("Auto calculate axes",
- settings.autoCalculateAxes);
- using (new UnityEditor.EditorGUI.DisabledGroupScope(settings.autoCalculateAxes))
- {
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var upAxisIdx = UnityEditor.EditorGUILayout.Popup("Upward axis:",
- settings.upwardAxis, _dirNames);
- if (check.changed) settings.upwardAxis = upAxisIdx;
- }
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var forwardAxisIdx = UnityEditor.EditorGUILayout.Popup("Forward axis:",
- settings.forwardAxis, _dirNames);
- if (check.changed) settings.forwardAxis = forwardAxisIdx;
- }
- }
- }
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- UnityEditor.EditorGUIUtility.labelWidth = 90;
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var moduleSizeType = (TilesUtils.SizeType)
- UnityEditor.EditorGUILayout.Popup("Cell size type:", (int)settings.moduleSizeType, _cellTypeNames);
- if (check.changed)
- {
- settings.moduleSizeType = moduleSizeType;
- if (settings.moduleSizeType == TilesUtils.SizeType.CUSTOM) WallManager.settings.ResetSize();
- }
- }
- using (new UnityEditor.EditorGUI.DisabledGroupScope(
- settings.moduleSizeType != TilesUtils.SizeType.CUSTOM))
- {
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var size = UnityEditor.EditorGUILayout.FloatField("Size:", settings.moduleSize.x);
- if (check.changed) settings.SetSize(size);
- }
- }
- if (settings.moduleSizeType == TilesUtils.SizeType.CUSTOM)
- {
- int sizeIndex = 0;
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- UnityEditor.EditorGUIUtility.labelWidth = 70;
- sizeIndex = UnityEditor.EditorGUILayout.Popup("Cell Size:", settings.GetIndexOfSelectedSize(),
- settings.GetSizesNames());
- if (check.changed)
- {
- settings.SelectSize(sizeIndex);
- }
- }
- using (new GUILayout.HorizontalScope())
- {
- GUILayout.FlexibleSpace();
- if (GUILayout.Button("Reset")) WallManager.settings.ResetSize();
- if (GUILayout.Button("Save..."))
- {
- RenameWindow.ShowWindow(position.position + Event.current.mousePosition,
- WallManager.settings.SaveSize, "Save Size", settings.selectedSizeName);
- }
- using (new UnityEditor.EditorGUI.DisabledGroupScope(sizeIndex == 0))
- {
- if (GUILayout.Button("Delete"))
- {
- WallManager.settings.DeleteSelectedSize();
- }
- }
- }
- }
- }
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- settings.spacing = UnityEditor.EditorGUILayout.Vector3Field("Spacing", settings.spacing);
- }
- using (new GUILayout.VerticalScope(UnityEditor.EditorStyles.helpBox))
- {
- int originIndex = 0;
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- originIndex = UnityEditor.EditorGUILayout.Popup("Grid origin:",
- SnapManager.settings.GetIndexOfSelectedOrigin(), SnapManager.settings.GetOriginNames());
- if (check.changed)
- {
- SnapManager.settings.SelectOrigin(originIndex);
- UnityEditor.SceneView.RepaintAll();
- }
- }
- using (new GUILayout.HorizontalScope())
- {
- GUILayout.Label("Position");
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var origin = UnityEditor.EditorGUILayout.Vector3Field(string.Empty,
- SnapManager.settings.origin);
- if (check.changed)
- {
- SnapManager.settings.origin = origin;
- UnityEditor.SceneView.RepaintAll();
- }
- }
- }
- using (new GUILayout.HorizontalScope())
- {
- GUILayout.Label("Rotation");
- using (var check = new UnityEditor.EditorGUI.ChangeCheckScope())
- {
- var angles = UnityEditor.EditorGUILayout.Vector3Field(string.Empty,
- SnapManager.settings.rotation.eulerAngles);
- if (check.changed)
- {
- SnapManager.settings.rotation = Quaternion.Euler(angles);
- UnityEditor.SceneView.RepaintAll();
- }
- }
- }
- using (new GUILayout.HorizontalScope())
- {
- GUILayout.FlexibleSpace();
- if (GUILayout.Button("Reset"))
- {
- SnapManager.settings.ResetOrigin();
- }
- if (GUILayout.Button("Save..."))
- {
- RenameWindow.ShowWindow(position.position + Event.current.mousePosition,
- SnapManager.settings.SaveGridOrigin, "Save Origin", SnapManager.settings.selectedOrigin);
- }
- using (new UnityEditor.EditorGUI.DisabledGroupScope(originIndex == 0))
- {
- if (GUILayout.Button("Delete"))
- {
- SnapManager.settings.DeleteSelectedOrigin();
- }
- }
- }
- }
- PaintToolSettingsGUI(FloorManager.settings);
- OverwriteBrushPropertiesGUI(FloorManager.settings, ref _floorOverwriteGroupState);
- }
- #endregion
- }
- }
|