using System; using UnityEditor.UIElements; using UnityEditor.Experimental.GraphView; using UnityEngine; using UnityEngine.VFX; using UnityEngine.UIElements; using UnityEditor.VFX; using System.Collections.Generic; using UnityEditor; using System.Linq; using System.Text; using UnityEditor.SceneManagement; using System.Globalization; using PositionType = UnityEngine.UIElements.Position; namespace UnityEditor.VFX.UI { static class BoardPreferenceHelper { public enum Board { blackboard, componentBoard } 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 readonly Vector2 sizeMargin = Vector2.one * 30; public static bool ValidatePosition(GraphElement element, VFXView view, Rect defaultPosition) { Rect viewrect = view.contentRect; Rect rect = element.GetPosition(); bool changed = false; if (!viewrect.Contains(rect.position)) { Vector2 newPosition = defaultPosition.position; if (!viewrect.Contains(defaultPosition.position)) { newPosition = sizeMargin; } rect.position = newPosition; changed = true; } Vector2 maxSizeInView = viewrect.max - rect.position - sizeMargin; float newWidth = Mathf.Max(element.resolvedStyle.minWidth.value, Mathf.Min(rect.width, maxSizeInView.x)); float newHeight = Mathf.Max(element.resolvedStyle.minHeight.value, Mathf.Min(rect.height, maxSizeInView.y)); if (Mathf.Abs(newWidth - rect.width) > 1) { rect.width = newWidth; changed = true; } if (Mathf.Abs(newHeight - rect.height) > 1) { rect.height = newHeight; changed = true; } if (changed) { element.SetPosition(rect); } return false; } } 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_AttachButton = this.Query