private void Start()
    {
        sw = FileManager.GetStreamWriter((FileManager.GetFilePath("Input.rec")));

        if (sw == null)
        {
            return;
        }

        Debug.Log("luckyhigh Input Record start");

#if UNITY_EDITOR
        // 获得gameView窗口
        System.Type T = System.Type.GetType("UnityEditor.GameView,UnityEditor");
        gameView = UnityEditor.EditorWindow.GetWindow(T, true, "Game") as UnityEditor.EditorWindow;

        // 获得gameView中渲染窗口的分辨率
        var prop       = gameView.GetType().GetProperty("currentGameViewSize", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
        var gvsize     = prop.GetValue(gameView, new object[0] {
        });
        var gvSizeType = gvsize.GetType();

        height = (int)gvSizeType.GetProperty("height", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance).GetValue(gvsize, new object[0] {
        });
        width  = (int)gvSizeType.GetProperty("width", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance).GetValue(gvsize, new object[0] {
        });
#elif UNITY_ANDROID
        height = Screen.currentResolution.height;
        width  = Screen.currentResolution.width;
#endif

        StreamWriter ssww = FileManager.GetStreamWriter((FileManager.GetFilePath("Resolution.rec")));
        ssww.WriteLine(height + " x " + width);
        ssww.Close();
    }
        public static UnityEditor.EditorWindow ViewInInspectorInstance(UnityEngine.Object viewTarget, UnityEditor.EditorWindow inspectorInstance = null)
        {
            var inspectorType = typeof(UnityEditor.Editor).Assembly.GetType("UnityEditor.InspectorWindow");

            if (inspectorInstance == null)
            {
                inspectorInstance = ScriptableObject.CreateInstance(inspectorType) as UnityEditor.EditorWindow;
            }

            if (inspectorInstance.GetType() != inspectorType)
            {
                throw new System.NotImplementedException();
            }

            inspectorInstance.Show();

            System.Reflection.BindingFlags bindingFlags       = System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public;
            System.Reflection.MethodInfo   isLockedMethodInfo = inspectorType.GetProperty("isLocked", bindingFlags).GetSetMethod();
            isLockedMethodInfo.Invoke(inspectorInstance, new object[] { false });       //解除InspectorLock
            var prevSelection = UnityEditor.Selection.objects;                          //記錄前一個選擇的物件

            UnityEditor.Selection.objects = new UnityEngine.Object[] { viewTarget };    //選擇viewTarget讓Inspector刷新
            isLockedMethodInfo.Invoke(inspectorInstance, new object[] { true });        //Inspector Lock
            UnityEditor.Selection.objects = prevSelection;                              //重新選擇前一個物件,當作什麼都沒發生

            return(inspectorInstance);
        }
Exemple #3
0
        internal void Reload(object userData)
        {
            EditorWindow editorWindow = userData as EditorWindow;

            if (!(editorWindow == null))
            {
                Type     type     = editorWindow.GetType();
                string   json     = EditorJsonUtility.ToJson(editorWindow);
                DockArea dockArea = editorWindow.m_Parent as DockArea;
                if (dockArea != null)
                {
                    int idx = dockArea.m_Panes.IndexOf(editorWindow);
                    dockArea.RemoveTab(editorWindow, false);
                    UnityEngine.Object.DestroyImmediate(editorWindow, true);
                    editorWindow = (ScriptableObject.CreateInstance(type) as EditorWindow);
                    dockArea.AddTab(idx, editorWindow);
                }
                else
                {
                    editorWindow.Close();
                    editorWindow = (ScriptableObject.CreateInstance(type) as EditorWindow);
                    if (editorWindow != null)
                    {
                        editorWindow.Show();
                    }
                }
                EditorJsonUtility.FromJsonOverwrite(json, editorWindow);
            }
        }
        internal static EditorWindow ShowAppropriateViewOnEnterExitPlaymode(bool entering)
        {
            if (WindowFocusState.instance.m_CurrentlyInPlayMode == entering)
            {
                return(null);
            }
            WindowFocusState.instance.m_CurrentlyInPlayMode = entering;
            EditorWindow maximizedWindow = WindowLayout.GetMaximizedWindow();

            if (entering)
            {
                WindowFocusState.instance.m_WasMaximizedBeforePlay = (maximizedWindow != null);
                if (maximizedWindow != null)
                {
                    return(maximizedWindow);
                }
            }
            else
            {
                if (WindowFocusState.instance.m_WasMaximizedBeforePlay)
                {
                    return(maximizedWindow);
                }
            }
            if (maximizedWindow)
            {
                WindowLayout.Unmaximize(maximizedWindow);
            }
            EditorWindow editorWindow = WindowLayout.TryFocusAppropriateWindow(entering);

            if (editorWindow)
            {
                return(editorWindow);
            }
            if (entering)
            {
                EditorWindow editorWindow2 = WindowLayout.FindEditorWindowOfType(typeof(SceneView));
                GameView     gameView;
                if (editorWindow2 && editorWindow2.m_Parent is DockArea)
                {
                    DockArea dockArea = editorWindow2.m_Parent as DockArea;
                    if (dockArea)
                    {
                        WindowFocusState.instance.m_LastWindowTypeInSameDock = editorWindow2.GetType().ToString();
                        gameView = ScriptableObject.CreateInstance <GameView>();
                        dockArea.AddTab(gameView);
                        return(gameView);
                    }
                }
                gameView = ScriptableObject.CreateInstance <GameView>();
                gameView.Show(true);
                gameView.Focus();
                return(gameView);
            }
            return(editorWindow);
        }
Exemple #5
0
        protected void RegisterSelectedPane(bool sendEvents)
        {
            if (!m_ActualView)
            {
                return;
            }

            m_ActualView.m_Parent = this;

            visualTree.Add(EditorModes.GetRootElement(m_ActualView));
            panel.getViewDataDictionary  = m_ActualView.GetViewDataDictionary;
            panel.savePersistentViewData = m_ActualView.SavePersistentViewData;
            panel.name = m_ActualView.GetType().Name;

            if (GetPaneMethod("Update") != null)
            {
                EditorApplication.update += SendUpdate;
            }

            EditorApplication.update += SendUpdateToOverride;

            if (GetPaneMethod("ModifierKeysChanged") != null)
            {
                EditorApplication.modifierKeysChanged += SendModKeysChanged;
            }

            EditorApplication.update += SendModKeysChangedToOverride;

            m_ActualView.MakeParentsSettingsMatchMe();

            if (m_ActualView.m_FadeoutTime != 0)
            {
                EditorApplication.update += m_ActualView.CheckForWindowRepaint;
            }

            if (sendEvents)
            {
                try
                {
                    Invoke("OnBecameVisible");
                    EditorModes.OnBecameVisible(m_ActualView);
                    Invoke("OnFocus");
                    EditorModes.OnFocus(m_ActualView);
                }
                catch (TargetInvocationException ex)
                {
                    // We need to catch these so the window initialization doesn't get screwed
                    if (ex.InnerException != null)
                    {
                        Debug.LogError(ex.InnerException.GetType().Name + ":" + ex.InnerException.Message);
                    }
                }
            }

            UpdateViewMargins(m_ActualView);
        }
 internal static void SaveCurrentFocusedWindowInSameDock(EditorWindow windowToBeFocused)
 {
     if (windowToBeFocused.m_Parent != null && windowToBeFocused.m_Parent is DockArea)
     {
         DockArea     dockArea   = windowToBeFocused.m_Parent as DockArea;
         EditorWindow actualView = dockArea.actualView;
         if (actualView)
         {
             WindowFocusState.instance.m_LastWindowTypeInSameDock = actualView.GetType().ToString();
         }
     }
 }
 internal static EditorWindow ShowAppropriateViewOnEnterExitPlaymode(bool entering)
 {
     GameView view;
     if (WindowFocusState.instance.m_CurrentlyInPlayMode == entering)
     {
         return null;
     }
     WindowFocusState.instance.m_CurrentlyInPlayMode = entering;
     EditorWindow window2 = null;
     EditorWindow maximizedWindow = GetMaximizedWindow();
     if (entering)
     {
         WindowFocusState.instance.m_WasMaximizedBeforePlay = maximizedWindow != null;
         if (maximizedWindow != null)
         {
             return maximizedWindow;
         }
     }
     else if (WindowFocusState.instance.m_WasMaximizedBeforePlay)
     {
         return maximizedWindow;
     }
     if (maximizedWindow != null)
     {
         Unmaximize(maximizedWindow);
     }
     window2 = TryFocusAppropriateWindow(entering);
     if (window2 != null)
     {
         return window2;
     }
     if (!entering)
     {
         return window2;
     }
     EditorWindow window4 = FindEditorWindowOfType(typeof(SceneView));
     if ((window4 != null) && (window4.m_Parent is DockArea))
     {
         DockArea parent = window4.m_Parent as DockArea;
         if (parent != null)
         {
             WindowFocusState.instance.m_LastWindowTypeInSameDock = window4.GetType().ToString();
             view = ScriptableObject.CreateInstance<GameView>();
             parent.AddTab(view);
             return view;
         }
     }
     view = ScriptableObject.CreateInstance<GameView>();
     view.Show(true);
     view.Focus();
     return view;
 }
 internal static void CheckWindowConsistency()
 {
     UnityEngine.Object[] array  = Resources.FindObjectsOfTypeAll(typeof(EditorWindow));
     UnityEngine.Object[] array2 = array;
     for (int i = 0; i < array2.Length; i++)
     {
         EditorWindow editorWindow = (EditorWindow)array2[i];
         if (editorWindow.m_Parent == null)
         {
             UnityEngine.Debug.LogError("Invalid editor window " + editorWindow.GetType());
         }
     }
 }
Exemple #9
0
        internal static EditorWindow ShowAppropriateViewOnEnterExitPlaymode(bool entering)
        {
            if (WindowFocusState.instance.m_CurrentlyInPlayMode == entering)
            {
                return((EditorWindow)null);
            }
            WindowFocusState.instance.m_CurrentlyInPlayMode = entering;
            EditorWindow maximizedWindow = WindowLayout.GetMaximizedWindow();

            if (entering)
            {
                WindowFocusState.instance.m_WasMaximizedBeforePlay = (UnityEngine.Object)maximizedWindow != (UnityEngine.Object)null;
                if ((UnityEngine.Object)maximizedWindow != (UnityEngine.Object)null)
                {
                    return(maximizedWindow);
                }
            }
            else if (WindowFocusState.instance.m_WasMaximizedBeforePlay)
            {
                return(maximizedWindow);
            }
            if ((bool)((UnityEngine.Object)maximizedWindow))
            {
                WindowLayout.Unmaximize(maximizedWindow);
            }
            EditorWindow editorWindow = WindowLayout.TryFocusAppropriateWindow(entering);

            if ((bool)((UnityEngine.Object)editorWindow) || !entering)
            {
                return(editorWindow);
            }
            EditorWindow editorWindowOfType = WindowLayout.FindEditorWindowOfType(typeof(SceneView));

            if ((bool)((UnityEngine.Object)editorWindowOfType) && editorWindowOfType.m_Parent is DockArea)
            {
                DockArea parent = editorWindowOfType.m_Parent as DockArea;
                if ((bool)((UnityEngine.Object)parent))
                {
                    WindowFocusState.instance.m_LastWindowTypeInSameDock = editorWindowOfType.GetType().ToString();
                    GameView instance = ScriptableObject.CreateInstance <GameView>();
                    parent.AddTab((EditorWindow)instance);
                    return((EditorWindow)instance);
                }
            }
            GameView instance1 = ScriptableObject.CreateInstance <GameView>();

            instance1.Show(true);
            instance1.Focus();
            return((EditorWindow)instance1);
        }
Exemple #10
0
        internal static void SaveCurrentFocusedWindowInSameDock(EditorWindow windowToBeFocused)
        {
            if (!((UnityEngine.Object)windowToBeFocused.m_Parent != (UnityEngine.Object)null) || !(windowToBeFocused.m_Parent is DockArea))
            {
                return;
            }
            EditorWindow actualView = (windowToBeFocused.m_Parent as DockArea).actualView;

            if (!(bool)((UnityEngine.Object)actualView))
            {
                return;
            }
            WindowFocusState.instance.m_LastWindowTypeInSameDock = actualView.GetType().ToString();
        }
 public static void CloseWindows()
 {
     try
     {
         TooltipView.Close();
     }
     catch (Exception)
     {
     }
     UnityEngine.Object[] array  = Resources.FindObjectsOfTypeAll(typeof(ContainerWindow));
     UnityEngine.Object[] array2 = array;
     for (int i = 0; i < array2.Length; i++)
     {
         ContainerWindow containerWindow = (ContainerWindow)array2[i];
         try
         {
             containerWindow.Close();
         }
         catch (Exception)
         {
         }
     }
     UnityEngine.Object[] array3 = Resources.FindObjectsOfTypeAll(typeof(EditorWindow));
     if (array3.Length != 0)
     {
         string text = "";
         UnityEngine.Object[] array4 = array3;
         for (int j = 0; j < array4.Length; j++)
         {
             EditorWindow editorWindow = (EditorWindow)array4[j];
             text = text + "\n" + editorWindow.GetType().Name;
             UnityEngine.Object.DestroyImmediate(editorWindow, true);
         }
         UnityEngine.Debug.LogError("Failed to destroy editor windows: #" + array3.Length + text);
     }
     UnityEngine.Object[] array5 = Resources.FindObjectsOfTypeAll(typeof(View));
     if (array5.Length != 0)
     {
         string text2 = "";
         UnityEngine.Object[] array6 = array5;
         for (int k = 0; k < array6.Length; k++)
         {
             View view = (View)array6[k];
             text2 = text2 + "\n" + view.GetType().Name;
             UnityEngine.Object.DestroyImmediate(view, true);
         }
         UnityEngine.Debug.LogError("Failed to destroy views: #" + array5.Length + text2);
     }
 }
Exemple #12
0
        public void InvokeOnGUI(Rect onGUIPosition, Rect viewRect)
        {
            DoWindowDecorationStart();

            BeginOffsetArea(viewRect, GUIContent.none, "TabWindowBackground");

            EditorGUIUtility.ResetGUIState();

            bool isExitGUIException = false;

            try
            {
                var viewName = actualView != null?actualView.GetType().Name : GetType().Name;

                using (new EditorPerformanceTracker(viewName + ".OnGUI." + Event.current.type))
                {
                    Invoke("OnGUI");
                }
            }
            catch (TargetInvocationException e)
            {
                if (e.InnerException is ExitGUIException)
                {
                    isExitGUIException = true;
                }
                throw;
            }
            finally
            {
                // We can't reset gui state after ExitGUI we just want to bail completely
                if (!isExitGUIException)
                {
                    CheckNotificationStatus();

                    EndOffsetArea();

                    EditorGUIUtility.ResetGUIState();

                    DoWindowDecorationEnd();

                    if (Event.current != null && Event.current.type == EventType.Repaint)
                    {
                        HostViewStyles.overlay.Draw(onGUIPosition, GUIContent.none, 0);
                    }
                }
            }
        }
Exemple #13
0
        internal void Reload(object userData)
        {
            EditorWindow window = userData as EditorWindow;

            if (window == null)
            {
                return;
            }

            // Get some info on the existing window.
            Type windowType = window.GetType();

            // Save what we can of the window.
            string windowJson = EditorJsonUtility.ToJson(window);

            DockArea dockArea = window.m_Parent as DockArea;

            if (dockArea != null)
            {
                int windowIndex = dockArea.m_Panes.IndexOf(window);

                // Destroy window.
                dockArea.RemoveTab(window, false); // Don't kill dock if empty.
                DestroyImmediate(window, true);

                // Create window.
                window = EditorWindow.CreateInstance(windowType) as EditorWindow;
                dockArea.AddTab(windowIndex, window);
            }
            else
            {
                // Close the existing window.
                window.Close();

                // Recreate window.
                window = EditorWindow.CreateInstance(windowType) as EditorWindow;
                if (window != null)
                {
                    window.Show();
                }
            }

            // Restore what we can of the window.
            EditorJsonUtility.FromJsonOverwrite(windowJson, window);
        }
Exemple #14
0
    /// <summary>
    /// Gets an accessor to the parent panel's bounds accessor.
    /// </summary>
    /// <param name="gameView">The game view.</param>
    /// <returns>An accessor to the parent panel's bounds accessor</returns>
    protected virtual Func <Rect> GetWindowParentBoundsAccessor(UnityEditor.EditorWindow gameView)
    {
        System.Diagnostics.Debug.Assert(gameView != null);
        var parentHostField = gameView.GetType().GetField("m_Parent", BindingFlags.NonPublic | BindingFlags.Instance);

        if (parentHostField != null)
        {
            var parentHost = parentHostField.GetValue(gameView);
            if (parentHost != null)
            {
                var windowPositionProperty = parentHost.GetType().GetProperty("windowPosition", BindingFlags.Public | BindingFlags.Instance);
                if (windowPositionProperty != null)
                {
                    // Create a delegate to get the parent host bounds.
                    return((Func <Rect>)
                           Delegate.CreateDelegate(typeof(Func <Rect>), parentHost,
                                                   windowPositionProperty.GetGetMethod()));
                }
            }
        }
        throw new InvalidOperationException("Could not resolve window parent position accessor.");
    }
    private void Start()
    {
        // 文件读写
        sr = FileManager.GetStreamReader((FileManager.GetFilePath("Input.rec")));
        Debug.Log("lucky start play input");
        if (sr == null)
        {
            return;
        }

        cursor = DebugControl.instance.cursor;

        // 获得gameView窗口
        System.Type T = System.Type.GetType("UnityEditor.GameView,UnityEditor");
        gameView = UnityEditor.EditorWindow.GetWindow(T, true, "Game") as UnityEditor.EditorWindow;

        // 获得gameView中渲染窗口的分辨率
        var prop       = gameView.GetType().GetProperty("currentGameViewSize", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
        var gvsize     = prop.GetValue(gameView, new object[0] {
        });
        var gvSizeType = gvsize.GetType();

        resh = (int)gvSizeType.GetProperty("height", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance).GetValue(gvsize, new object[0] {
        });
        resw = (int)gvSizeType.GetProperty("width", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance).GetValue(gvsize, new object[0] {
        });

        if ((line = sr.ReadLine()) != null)
        {
            string[] ss = line.Split(' ');
            time = Convert.ToSingle(ss[0]);
            type = (MouseType)Convert.ToInt32(ss[1]);
            xpre = Convert.ToSingle(ss[2]);
            ypre = Convert.ToSingle(ss[3]);
        }
    }
        static internal EditorWindow ShowAppropriateViewOnEnterExitPlaymode(bool entering)
        {
            // Prevent trying to go into the same state as we're already in, as it wil break things
            if (WindowFocusState.instance.m_CurrentlyInPlayMode == entering)
            {
                return(null);
            }

            WindowFocusState.instance.m_CurrentlyInPlayMode = entering;

            EditorWindow window = null;

            EditorWindow maximized = GetMaximizedWindow();

            if (entering)
            {
                WindowFocusState.instance.m_WasMaximizedBeforePlay = (maximized != null);
                // If a view is already maximized before entering play mode,
                // just keep that maximized view, no matter if it's the game view or some other.
                // Trust that user has a good reason (desire by Ethan etc.)
                if (maximized != null)
                {
                    return(maximized);
                }
            }
            else
            {
                // If a view was already maximized before entering play mode,
                // then it was kept when switching to play mode, and can simply still be kept when exiting
                if (WindowFocusState.instance.m_WasMaximizedBeforePlay)
                {
                    return(maximized);
                }
            }

            // Unmaximize if maximized
            if (maximized)
            {
                Unmaximize(maximized);
            }

            // Try finding and focusing appropriate window/tab
            window = TryFocusAppropriateWindow(entering);
            if (window)
            {
                return(window);
            }

            // If we are entering Play more and no Game View was found, create one
            if (entering)
            {
                // Try to create and focus a Game View tab docked together with the Scene View tab
                EditorWindow sceneView = FindEditorWindowOfType(typeof(SceneView));
                GameView     gameView;
                if (sceneView && sceneView.m_Parent is DockArea)
                {
                    DockArea dock = sceneView.m_Parent as DockArea;
                    if (dock)
                    {
                        WindowFocusState.instance.m_LastWindowTypeInSameDock = sceneView.GetType().ToString();
                        gameView = ScriptableObject.CreateInstance <GameView>();
                        dock.AddTab(gameView);
                        return(gameView);
                    }
                }

                // If no Scene View was found at all, just create a floating Game View
                gameView = ScriptableObject.CreateInstance <GameView>();
                gameView.Show(true);
                gameView.Focus();

                return(gameView);
            }

            return(window);
        }