public override void OnActivate(string searchContext, VisualElement rootElement) { base.OnActivate(searchContext, rootElement); m_ST2USettings = ST2USettings.GetOrCreateST2USettings(); m_S2TUSettingsObject = new SerializedObject(m_ST2USettings); // Prepare our list of material matchings var matchings = m_S2TUSettingsObject.FindProperty("m_MaterialMatchings"); m_MaterialMatchingsList = new ReorderableList(m_S2TUSettingsObject, matchings, true, false, true, true) { headerHeight = 0, drawElementCallback = OnDrawMaterialMatchingElement, }; // Prepare our list of prefab replacements var replacements = m_S2TUSettingsObject.FindProperty("m_PrefabReplacements"); m_PrefabReplacementList = new ReorderableList(m_S2TUSettingsObject, replacements, true, false, true, true) { headerHeight = 0, drawElementCallback = OnDrawPrefabReplacementElement, }; }
private void DoCustomPropertySettings() { var xmlProperty = m_S2TUSettingsObject.FindProperty("m_ObjectTypesXml"); EditorGUILayout.LabelField("Custom Property Settings", EditorStyles.boldLabel); EditorGUILayout.PropertyField(xmlProperty, SettingsContent.m_ObjectTypesXmlContent); if (!string.IsNullOrEmpty(m_ST2USettings.ParseXmlError)) { EditorGUILayout.HelpBox(m_ST2USettings.ParseXmlError, MessageType.Error); } EditorGUILayout.Space(); using (new GUILayout.HorizontalScope()) { GUILayout.FlexibleSpace(); if (GUILayout.Button("Refresh")) { ST2USettings.GetOrCreateST2USettings().RefreshCustomObjectTypes(); } if (GUILayout.Button("View Custom Properties")) { CustomPropertiesWindow.ShowCustomPropertiesWindow(); } } }
private static void DrawHandles(SuperColliderComponent component, GizmoType gizmoType) { // Only draw gizmos for the SuperObject if we have it in our set // This way users can disable gizmos for the SuperObject through the Gizmos menu if (!SuperColliderComponent.GizmoDrawCommands.Contains(component)) { return; } else { SuperColliderComponent.GizmoDrawCommands.Remove(component); } if (m_Settings == null) { m_Settings = ST2USettings.GetOrCreateST2USettings(); if (m_Settings == null) { // If something goes wrong use some dummy settings m_Settings = CreateInstance <ST2USettings>(); } } if (m_Settings != null) { ColliderGizmos.DrawColliders(component.gameObject, m_Settings); } }
private static void DrawAsConvexPolygonFill(GameObject go, Vector3[] points, ST2USettings settings) { var color = GetColorFromObject(go, settings); color.a *= FillOpcacity; Handles.color = color; Handles.DrawAAConvexPolygon(points); }
private static void OutlineShape(GameObject go, Vector2[] points, ST2USettings settings) { CheckHelpers(); var transformed = points.Select(pt => go.transform.TransformPoint(pt)).ToArray(); DrawAsConvexPolygonOutline(go, transformed, settings); }
// This is only invoked by a deployment batch file private static void DeploySuperTiled2Unity() { var settings = ST2USettings.LoadSettings(); var path = string.Format("{0}/../../deploy/SuperTiled2Unity.{1}.unitypackage", Application.dataPath, settings.Version); Directory.CreateDirectory(Path.GetDirectoryName(path)); AssetDatabase.ExportPackage("Assets/SuperTiled2Unity", path, ExportPackageOptions.Recurse); }
public void ApplyDefaultSettings() { var settings = ST2USettings.GetOrCreateST2USettings(); m_PixelsPerUnit = settings.PixelsPerUnit; m_EdgesPerEllipse = settings.EdgesPerEllipse; EditorUtility.SetDirty(this); }
private static void DrawLines(EdgeCollider2D edge, ST2USettings settings) { Vector3 offset = edge.transform.TransformVector(edge.offset); var points = edge.points.Select(pt => edge.transform.TransformPoint(pt) + offset).ToArray(); Handles.color = GetColorFromObject(edge.gameObject, settings); Handles.DrawAAPolyLine(LineTexture, LineThickness, points); }
private static void DrawPolygon(PolygonCollider2D polygon, ST2USettings settings) { CheckHelpers(); Vector3 offset = polygon.transform.TransformVector(polygon.offset); var points = polygon.GetPath(0).Select(pt => polygon.transform.TransformPoint(pt) + offset).ToArray(); DrawAsConvexPolygon(polygon.gameObject, points, settings); }
private static void DrawPolygon(PolygonCollider2D polygon, ST2USettings settings) { CheckHelpers(); // Note: we are assuming the PolygonCollider2D is convex when using this function Vector3 offset = polygon.transform.TransformVector(polygon.offset); var points = polygon.GetPath(0).Select(pt => polygon.transform.TransformPoint(pt) + offset).ToArray(); DrawAsConvexPolygon(polygon.gameObject, points, settings); }
public static SettingsProvider CreateCustomSettingsProvider() { if (ST2USettings.GetOrCreateST2USettings()) { var provider = new ST2USettingsProvider(); provider.keywords = GetSearchKeywordsFromGUIContentProperties <SettingsContent>(); return(provider); } // Settings Asset doesn't exist yet; no need to display anything in the Settings window. return(null); }
public static void DrawColliderShapes(SuperColliderComponent collider, ST2USettings settings) { foreach (var shape in collider.m_PolygonShapes) { FillShape(collider.gameObject, shape.m_Points, settings); } foreach (var shape in collider.m_OutlineShapes) { OutlineShape(collider.gameObject, shape.m_Points, settings); } }
private static void DrawAsConvexPolygon(GameObject go, Vector3[] points, ST2USettings settings) { var color = GetColorFromObject(go, settings); Handles.color = color; Handles.DrawAAPolyLine(LineTexture, LineThickness, points); Handles.DrawAAPolyLine(LineTexture, LineThickness, points[0], points[points.Length - 1]); color.a *= FillOpcacity; Handles.color = color; Handles.DrawAAConvexPolygon(points); }
private void OnGUICustomProperties() { EditorGUILayout.LabelField(m_TitleContent, EditorStyles.boldLabel); var settings = ST2USettings.GetOrCreateST2USettings(); foreach (var obj in settings.CustomObjectTypes) { EditorGUILayout.Space(); OnGUICustomObjectType(obj); EditorGUILayout.Space(); } }
protected override void InternalOnInspectorGUI() { m_ST2USettings = GetAssetTarget <ST2USettings>(); if (m_ST2USettings != null) { DoGuiHeader(); DoGuiSettings(); DoGuiLayerColors(); ApplyRevertGUI(); DoGuiReimportAssets(); } }
private static void DrawBox(BoxCollider2D box, ST2USettings settings) { CheckHelpers(); Vector3 offset = box.offset; var corners = new Vector2[] { new Vector2(box.offset.x - box.size.x * 0.5f, box.offset.y + box.size.y * 0.5f), new Vector2(box.offset.x + box.size.x * 0.5f, box.offset.y + box.size.y * 0.5f), new Vector2(box.offset.x + box.size.x * 0.5f, box.offset.y - box.size.y * 0.5f), new Vector2(box.offset.x - box.size.x * 0.5f, box.offset.y - box.size.y * 0.5f), }; var points = corners.Select(pt => box.transform.TransformPoint(pt)).ToArray(); DrawAsConvexPolygon(box.gameObject, points, settings); }
private static void DrawCircle(CircleCollider2D circle, ST2USettings settings) { CheckHelpers(); const int count = 50; float theta = ((float)Math.PI * 2.0f) / count; var radius = circle.radius; var offset = (Vector3)circle.offset; Vector3[] points = new Vector3[count]; for (int i = 0; i < count; i++) { points[i].x = offset.x + radius * (float)Math.Cos(theta * i); points[i].y = offset.y + radius * (float)Math.Sin(theta * i); } points = points.Select(pt => circle.transform.TransformPoint(pt)).ToArray(); DrawAsConvexPolygon(circle.gameObject, points, settings); }
private void OnGUIButtons() { EditorGUILayout.Space(); using (new GUILayout.HorizontalScope()) { GUILayout.FlexibleSpace(); if (GUILayout.Button("Refresh Properties")) { ST2USettings.GetOrCreateST2USettings().RefreshCustomObjectTypes(); } if (GUILayout.Button("Close Custom Properties Viewer")) { Close(); return; } } }
private void WrapImportContext(AssetImportContext ctx) { var settings = ST2USettings.LoadSettings(); if (settings == null) { settings = ScriptableObject.CreateInstance <ST2USettings>(); } var icons = ST2USettings.LoadIcons(); if (icons == null) { icons = ScriptableObject.CreateInstance <SuperIcons>(); } // Create a copy of our settings that we can override based on importer settings settings = GameObject.Instantiate <ST2USettings>(settings); OverrideSettings(settings); SuperImportContext = new SuperImportContext(ctx, settings, icons); }
public static void DrawColliders(GameObject go, ST2USettings settings) { foreach (var polygon in go.GetComponentsInChildren <PolygonCollider2D>()) { DrawPolygon(polygon, settings); } foreach (var box in go.GetComponentsInChildren <BoxCollider2D>()) { DrawBox(box, settings); } foreach (var circle in go.GetComponentsInChildren <CircleCollider2D>()) { DrawCircle(circle, settings); } foreach (var edge in go.GetComponentsInChildren <EdgeCollider2D>()) { DrawLines(edge, settings); } }
public override void OnGUI(string searchContext) { EditorGUIUtility.labelWidth = 200; m_S2TUSettingsObject.Update(); using (new GuiScopedIndent()) { DoGuiVersion(); EditorGUILayout.Space(); EditorGUILayout.Space(); DoGuiSettings(); EditorGUILayout.Space(); EditorGUILayout.Space(); DoGuiPrefabReplacements(); EditorGUILayout.Space(); EditorGUILayout.Space(); DoGuiColliders(); EditorGUILayout.Space(); EditorGUILayout.Space(); DoCustomPropertySettings(); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); DoGuiReimportAssets(); } if (m_S2TUSettingsObject.ApplyModifiedProperties()) { ST2USettings.GetOrCreateST2USettings().RefreshCustomObjectTypes(); } }
private static Color GetColorFromObject(GameObject go, ST2USettings settings) { // Tile layers go first var tileLayer = go.GetComponentInParent <SuperTileLayer>(); if (tileLayer != null) { // Use the color of our object in the layer var color = settings.LayerColors.ElementAtOrDefault(go.layer); color.a = tileLayer.CalculateOpacity(); return(color); } // Then comes tile objects var objectLayer = go.GetComponentInParent <SuperObjectLayer>(); if (objectLayer != null) { var color = objectLayer.m_Color; // Type takes precedence for super objects var superObject = go.GetComponent <SuperObject>(); if (superObject != null) { CustomObjectType objectType; if (settings.CustomObjectTypes.TryGetCustomObjectType(superObject.m_Type, out objectType)) { color = objectType.m_Color; } } color.a = objectLayer.CalculateOpacity(); return(color); } return(NamedColors.Gray); }
private void WrapImportContext(AssetImportContext ctx) { var settings = ST2USettings.GetOrCreateST2USettings(); settings.RefreshCustomObjectTypes(); // Create a copy of our settings that we can override based on importer settings settings = Instantiate(settings); if (m_PixelsPerUnit == 0) { m_PixelsPerUnit = settings.PixelsPerUnit; } if (m_EdgesPerEllipse == 0) { m_EdgesPerEllipse = settings.EdgesPerEllipse; } settings.PixelsPerUnit = m_PixelsPerUnit; settings.EdgesPerEllipse = m_EdgesPerEllipse; SuperImportContext = new SuperImportContext(ctx, settings); }
public SuperImportContext(UnityEditor.AssetImporters.AssetImportContext context, ST2USettings settings) { m_Context = context; Settings = settings; }
public SuperImportContext(AssetImportContext context, ST2USettings settings) { m_Context = context; Settings = settings; }
private void OverrideSettings(ST2USettings settings) { settings.DefaultOrOverride_PixelsPerUnit(ref m_PixelsPerUnit); settings.DefaultOrOverride_EdgesPerEllipse(ref m_EdgesPerEllipse); }
public static void ShowCustomPropertiesWindow() { ST2USettings.GetOrCreateST2USettings().RefreshCustomObjectTypes(); GetWindow <CustomPropertiesWindow>("SuperTiled2Unity Custom Properties Viewer"); }
public SuperImportContext(AssetImportContext context, ST2USettings settings, SuperIcons icons) { m_Context = context; Settings = settings; Icons = icons; }