#if (UNITY_EDITOR) using UnityEngine; using UnityEditor; namespace ECE { [System.Serializable] public class EasyColliderPreferences : ScriptableObject { #if (!UNITY_EDITOR_LINUX) /// /// Currently set vhacd parameters. /// private VHACDParameters _VHACDParameters; [SerializeField] public VHACDParameters VHACDParameters { get { if (_VHACDParameters == null) { _VHACDParameters = new VHACDParameters(); } return _VHACDParameters; } set { _VHACDParameters = value; } } /// /// Float to convert to vhacd parameters resolution using 2^Value for UI Slider when advanced parameters is expanded /// [SerializeField] public float VHACDResFloat = 12.97f; /// /// Resets vhacd parameters to default. /// public void VHACDSetDefaultParameters() { VHACDParameters = new VHACDParameters(); } #endif /// /// Auto include child skinned meshes /// [SerializeField] public bool AutoIncludeChildSkinnedMeshes; /// /// Key to hold before box selection to only add vertices in the box. /// [SerializeField] public KeyCode BoxSelectPlusKey; /// /// Key to hold before box selection to only remove vertices in the box. /// [SerializeField] public KeyCode BoxSelectMinusKey; /// /// Capsule collider generation method to use when creating a capsule collider. /// [SerializeField] public CAPSULE_COLLIDER_METHOD CapsuleColliderMethod; /// /// A helpful common multiplier for all scales when using any scaling method. /// [SerializeField] public float CommonScalingMultiplier = 1.0f; /// /// Created colliders automatically get disabled to make vertex selection easier. /// [SerializeField] public bool CreatedColliderDisabled; /// /// key to press to create from the current preview. /// [SerializeField] public KeyCode CreateFromPreviewKey; /// /// number of sides when creating a cylinder collider. /// [SerializeField] public int CylinderNumberOfSides = 16; /// /// Should tips be displayed? /// [SerializeField] public bool DisplayTips; /// /// Display vertices colour /// [SerializeField] public Color DisplayVerticesColour; /// /// Display vertices scaling size /// [SerializeField] public float DisplayVerticesScaling; /// /// Should the scene be focused during selection? /// [SerializeField] public bool ForceFocusScene; /// /// Type of gizmos to use when drawing gizmos for vertices /// public GIZMO_TYPE GizmoType; /// /// Hover vertices scaling colour /// [SerializeField] public Color HoverVertColour; /// /// Hover vertices scaling size /// [SerializeField] public float HoverVertScaling; // [SerializeField] public CREATE_COLLIDER_TYPE MergeCollidersTo; /// /// Number of points to generate around a rounded portion of a collider like sphere or capsules /// [SerializeField] public int MergeCollidersRoundnessAccuracy = 10; /// /// Method to use when generating mesh colliders /// [SerializeField] public MESH_COLLIDER_METHOD MeshColliderMethod; /// /// Overlapped vertice scaling colour /// [SerializeField] public Color OverlapSelectedVertColour; /// /// Overlapped selected vertex scale /// [SerializeField] public float OverlapSelectedVertScale; /// /// Key used to select points (any point on a mesh that isn't a vertex) /// [SerializeField] public KeyCode PointSelectKeyCode; /// /// Collider type we want to preview /// [SerializeField] public CREATE_COLLIDER_TYPE PreviewColliderType; /// /// Color of lines to draw previewed colliders with. /// [SerializeField] public Color PreviewDrawColor; /// /// Raycast delay time, ie only check / select at increments of this time. /// [SerializeField] public float RaycastDelayTime; /// /// Render point method /// [SerializeField] public RENDER_POINT_TYPE RenderPointType; [SerializeField] public bool RemoveMergedColliders; /// /// If true, puts rotated colliders on the same layer as the selected gameobject. /// [SerializeField] public bool RotatedOnSelectedLayer; /// /// When true, meshes created from creating convex hulls are saved as assets. /// [SerializeField] public bool SaveConvexHullAsAsset; /// /// Saves convex hull's mesh at the same path as the selected gameobject if true /// [SerializeField] public bool SaveConvexHullMeshAtSelected; /// /// if SaveConvexHullMeshAtSelected is false, saves at the path specified. /// [SerializeField] public string SaveConvexHullPath; /// /// Suffix with which to save convex hulls. /// [SerializeField] public string SaveConvexHullSuffix; /// /// Selected vertice scaling colour /// [SerializeField] public Color SelectedVertColour; /// /// Selected vertice scaling size /// [SerializeField] public float SelectedVertScaling; /// /// Type of collider to use when auto generating skinned mesh colliders along a bone chain. /// [SerializeField] public SKINNED_MESH_COLLIDER_TYPE SkinnedMeshColliderType; /// /// Sphere method to use when creating a sphere collider. /// public SPHERE_COLLIDER_METHOD SphereColliderMethod; /// /// Should gizmos and shaders used to draw vertices be scaled by density of vertices on the selected meshes? /// [SerializeField] public bool UseDensityScale; /// /// Should HandleUtility.GetHandleSize be used when using gizmos to draw to keep gizmo size constant regardless of distance to camera? /// [SerializeField] public bool UseFixedGizmoScale; /// /// Enables using left click to select vertices, and right click to select points. /// [SerializeField] public bool UseMouseClickSelection; /// /// Method used when raycasting for closest vertices, add (only snap to unselected verts), remove (only snap to selected verts), both (default) /// [SerializeField] public VERTEX_SNAP_METHOD VertexSnapMethod; /// /// Key used to select vertices. /// [SerializeField] public KeyCode VertSelectKeyCode; /// /// Should we update the VHACD calculation and preview as parameters change? /// [SerializeField] public bool VHACDPreview; /// /// Sets all values to default values. /// public void SetDefaultValues() { #if (!UNITY_EDITOR_LINUX) VHACDParameters = new VHACDParameters(); VHACDPreview = true; #endif AutoIncludeChildSkinnedMeshes = true; // shifts do not work. BoxSelectMinusKey = KeyCode.S; BoxSelectPlusKey = KeyCode.A; CapsuleColliderMethod = CAPSULE_COLLIDER_METHOD.MinMax; CommonScalingMultiplier = 1.0f; CreatedColliderDisabled = true; CylinderNumberOfSides = 16; DisplayTips = true; DisplayVerticesColour = Color.blue; DisplayVerticesScaling = 0.05f; CreateFromPreviewKey = KeyCode.BackQuote; GizmoType = GIZMO_TYPE.SPHERE; ForceFocusScene = false; HoverVertColour = Color.cyan; HoverVertScaling = 0.1F; // MergeCollidersTo = CREATE_COLLIDER_TYPE.Box; MeshColliderMethod = MESH_COLLIDER_METHOD.QuickHull; OverlapSelectedVertColour = Color.red; OverlapSelectedVertScale = 0.1f; PointSelectKeyCode = KeyCode.B; PreviewDrawColor = Color.cyan; RaycastDelayTime = 0.1f; RemoveMergedColliders = true; if (SystemInfo.graphicsShaderLevel < 45) { RenderPointType = RENDER_POINT_TYPE.GIZMOS; } else { RenderPointType = RENDER_POINT_TYPE.SHADER; } RotatedOnSelectedLayer = true; SaveConvexHullMeshAtSelected = true; SaveConvexHullPath = AssetDatabase.GetAssetPath(MonoScript.FromScriptableObject(this)); SaveConvexHullPath = SaveConvexHullPath.Remove(SaveConvexHullPath.LastIndexOf("/")) + "/"; SaveConvexHullAsAsset = true; SaveConvexHullSuffix = "_ConvexHull_"; SelectedVertColour = Color.green; SelectedVertScaling = 0.1f; SkinnedMeshColliderType = SKINNED_MESH_COLLIDER_TYPE.Capsule; SphereColliderMethod = SPHERE_COLLIDER_METHOD.MinMax; UseFixedGizmoScale = true; UseMouseClickSelection = false; UseDensityScale = true; VertSelectKeyCode = KeyCode.V; } private static EasyColliderPreferences _Prefereneces; public static EasyColliderPreferences Preferences { get { if (_Prefereneces == null) { _Prefereneces = FindOrCreatePreferences(); } return _Prefereneces; } } private static EasyColliderPreferences FindOrCreatePreferences() { EasyColliderPreferences preferences; string[] ecp = AssetDatabase.FindAssets("EasyColliderPreferences t:ScriptableObject"); string assetPath = ""; if (ecp.Length > 0) { assetPath = AssetDatabase.GUIDToAssetPath(ecp[0]); if (ecp.Length > 1) { Debug.LogWarning("Easy Collider Editor has found multiple preferences files. Using the one located at " + assetPath); } preferences = AssetDatabase.LoadAssetAtPath(assetPath, typeof(EasyColliderPreferences)) as EasyColliderPreferences; } else { ecp = AssetDatabase.FindAssets("EasyColliderWindow t:script"); if (ecp.Length > 0) { assetPath = AssetDatabase.GUIDToAssetPath(ecp[0]); if (ecp.Length > 1) { Debug.LogWarning("Easy Collider Editor has found multiple preferences files. Using the one located at " + assetPath); } } // preferences = AssetDatabase.LoadAssetAtPath(assetPath, typeof(EasyColliderPreferences)) as EasyColliderPreferences; // Create a new preferences file. string prefPath = assetPath.Remove(assetPath.Length - 21) + "EasyColliderPreferences.asset"; preferences = CreateInstance(); preferences.SetDefaultValues(); AssetDatabase.CreateAsset(preferences, prefPath); AssetDatabase.SaveAssets(); Debug.LogWarning("Easy Collider Editor did not find a preferences file, new preferences file created at " + prefPath); } return preferences; } } } #endif