using System; using System.Linq; using System.Collections.Generic; using System.Globalization; using UnityEditor.Experimental; using UnityEditor.Experimental.GraphView; using UnityEngine; using UnityEngine.VFX; using UnityEngine.UIElements; using PositionType = UnityEngine.UIElements.Position; namespace UnityEditor.VFX.UI { static class BoardPreferenceHelper { public enum Board { blackboard, componentBoard, profilingBoard, } const string rectPreferenceFormat = "vfx-{0}-rect"; const string visiblePreferenceFormat = "vfx-{0}-visible"; public static bool IsVisible(Board board, bool defaultState) { return EditorPrefs.GetBool(string.Format(visiblePreferenceFormat, board), defaultState); } public static void SetVisible(Board board, bool value) { EditorPrefs.SetBool(string.Format(visiblePreferenceFormat, board), value); } public static Rect LoadPosition(Board board, Rect defaultPosition) { string str = EditorPrefs.GetString(string.Format(rectPreferenceFormat, board)); Rect blackBoardPosition = defaultPosition; if (!string.IsNullOrEmpty(str)) { var rectValues = str.Split(','); if (rectValues.Length == 4) { float x, y, width, height; if (float.TryParse(rectValues[0], NumberStyles.Float, CultureInfo.InvariantCulture, out x) && float.TryParse(rectValues[1], NumberStyles.Float, CultureInfo.InvariantCulture, out y) && float.TryParse(rectValues[2], NumberStyles.Float, CultureInfo.InvariantCulture, out width) && float.TryParse(rectValues[3], NumberStyles.Float, CultureInfo.InvariantCulture, out height)) { blackBoardPosition = new Rect(x, y, width, height); } } } return blackBoardPosition; } public static void SavePosition(Board board, Rect r) { EditorPrefs.SetString(string.Format(rectPreferenceFormat, board), string.Format(CultureInfo.InvariantCulture, "{0},{1},{2},{3}", r.x, r.y, r.width, r.height)); } public static void ValidatePosition(GraphElement element, VFXView view, Rect defaultPosition) { var viewrect = view.contentRect; var rect = element.GetPosition(); var changed = false; if (rect.xMin > viewrect.xMax || rect.xMax > viewrect.xMax) { var width = Math.Max(Math.Min(rect.width, viewrect.width), element.resolvedStyle.minWidth.value); rect.xMax = viewrect.xMax; rect.xMin = Math.Max(0, rect.xMax - width); rect.width = width; changed = true; } if (rect.yMin > viewrect.yMax || rect.yMax > viewrect.yMax) { var height = Math.Max(Math.Min(rect.height, viewrect.height), element.resolvedStyle.minHeight.value); rect.yMax = viewrect.yMax; rect.yMin = Math.Max(0, rect.yMax - height); rect.height = height; changed = true; } if (changed) { element.SetPosition(rect); } } } class VFXComponentBoard : GraphElement, IControlledElement, IVFXMovable, IVFXResizable { VFXViewController m_Controller; Controller IControlledElement.controller { get { return m_Controller; } } public VFXViewController controller { get { return m_Controller; } set { if (m_Controller != value) { if (m_Controller != null) { m_Controller.UnregisterHandler(this); } Clear(); m_Controller = value; if (m_Controller != null) { m_Controller.RegisterHandler(this); } } } } VFXView m_View; VFXUIDebug m_DebugUI; public VFXComponentBoard(VFXView view) { m_View = view; var tpl = VFXView.LoadUXML("VFXComponentBoard"); tpl.CloneTree(contentContainer); contentContainer.AddStyleSheetPath("VFXComponentBoard"); m_RootElement = this.Query("component-container"); m_SubtitleIcon = this.Query("subTitle-icon"); m_Subtitle = this.Query