void OnEnable() { lastT = EditorApplication.timeSinceStartup; UnityEditor.Undo.postprocessModifications += OnPropMod; UnityEditor.Undo.undoRedoPerformed += OnUndoRedo; window = this; string[] search = AssetDatabase.FindAssets("t:asmdef uPixel"); if (search.Length > 0) { m_PackagePath = Regex.Match(AssetDatabase.GUIDToAssetPath(search[0]), ".*\\/").ToString(); } m_Tool = null; // Each editor window contains a root VisualElement object m_Root = rootVisualElement; m_Root.Clear(); // Import UXML var visualTree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(m_PackagePath + "Editor/uPixel.uxml"); VisualElement labelFromUXML = visualTree.CloneTree(); // A stylesheet can be added to a VisualElement. // var styleSheet = AssetDatabase.LoadAssetAtPath<StyleSheet>(m_PackagePath + "Editor/uPixel.uss"); var styleSheet = AssetDatabase.LoadAssetAtPath <StyleSheet>("Assets/uPixel.uss"); // The style will be applied to the VisualElement and all of its children. m_Root.styleSheets.Add(styleSheet); m_Root.Add(labelFromUXML); m_Root.Q <VisualElement>(className: "canvas").StretchToParentSize(); m_Root.Q <VisualElement>(className: "canvas").style.height = this.position.height; m_Root.Q <Image>().style.backgroundImage = AssetDatabase.LoadAssetAtPath <Texture2D>(m_PackagePath + "T_Canvas.png"); m_Root.Query <Toggle>().ForEach(o => { o.RegisterCallback <MouseUpEvent>(SwitchTool); o.Q <Image>().style.backgroundImage = AssetDatabase.LoadAssetAtPath <Texture2D>("Assets/Icons/Icon_" + o.name + ".png"); m_ToolButtons.Add(o); }); m_Root.focusable = true; m_Root.RegisterCallback <KeyDownEvent>(OnKeyDown); m_Root.RegisterCallback <KeyUpEvent>(OnKeyUp); m_Root.RegisterCallback <GeometryChangedEvent>(OnGeometryChanged); m_Image = m_Root.Q <Image>(); var canvas = m_Root.Q <VisualElement>(className: "canvas"); var history = m_Root.Q <VisualElement>(name: "History"); // history.style.width = this.position.width; // history.style.top = this.position.height - history.style.height.value.value; VisualElement HistoryDrawParent = history.Q <VisualElement>(name: "HistoryDraw"); HistoryDrawParent.Add(new IMGUIContainer(HistoryDrawOnGUI)); InitImage(); DrawPalette(); m_Preview = m_Root.Q <Image>(name: "preview"); m_HistoryValue = pixelAsset.GetHistoryLength(); }
public ToolBase() { activators.Add(new ManipulatorActivationFilter() { button = MouseButton.LeftMouse }); activators.Add(new ManipulatorActivationFilter() { button = MouseButton.LeftMouse, modifiers = EventModifiers.Control }); m_Active = false; uPixel = EditorWindow.GetWindow <uPixel>(); }