Пример #1
0
        private void Draw(Rect rect)
        {
            if (this.m_SceneView == null || this.m_SceneView.m_SceneViewState == null)
            {
                return;
            }
            Rect rect2 = new Rect(1f, 1f, rect.width - 2f, 16f);

            SceneView.SceneViewState state = this.m_SceneView.m_SceneViewState;
            this.DrawListElement(rect2, "Skybox", state.showSkybox, delegate(bool value)
            {
                state.showSkybox = value;
            });
            rect2.y += 16f;
            this.DrawListElement(rect2, "Fog", state.showFog, delegate(bool value)
            {
                state.showFog = value;
            });
            rect2.y += 16f;
            this.DrawListElement(rect2, "Flares", state.showFlares, delegate(bool value)
            {
                state.showFlares = value;
            });
            rect2.y += 16f;
            this.DrawListElement(rect2, "Animated Materials", state.showMaterialUpdate, delegate(bool value)
            {
                state.showMaterialUpdate = value;
            });
            rect2.y += 16f;
        }
Пример #2
0
        static void CSG4Split()
        {
            string layoutsPath = Path.Combine(InternalEditorUtility.unityPreferencesFolder, "Layouts");
            string filePath    = Path.Combine(layoutsPath, "4 Split.wlt");

            EditorUtility.LoadWindowLayout(filePath);

            for (int i = 0; i < 4; i++)
            {
                SceneView sceneView = ((SceneView)SceneView.sceneViews[i]);
                if (EditorHelper.GetSceneViewCamera(sceneView) == EditorHelper.SceneViewCamera.Other)
                {
                    sceneView.orthographic    = false;
                    sceneView.m_SceneLighting = true;
                }
                else
                {
                    sceneView.orthographic    = true;
                    sceneView.m_SceneLighting = false;
                    SceneView.SceneViewState state = GetSceneViewState(sceneView);
                    state.Toggle(false);
                }
            }
            SceneView.RepaintAll();
        }
 public static void SetFlags(this SceneView.SceneViewState state, SceneViewStateFlags flags)
 {
     state.showSkybox          = (flags & SceneViewStateFlags.ShowSkybox) == SceneViewStateFlags.ShowSkybox;
     state.showFog             = (flags & SceneViewStateFlags.ShowFog) == SceneViewStateFlags.ShowFog;
     state.showFlares          = (flags & SceneViewStateFlags.ShowFlares) == SceneViewStateFlags.ShowFlares;
     state.showMaterialUpdate  = (flags & SceneViewStateFlags.ShowMaterialUpdate) == SceneViewStateFlags.ShowMaterialUpdate;
     state.showImageEffects    = (flags & SceneViewStateFlags.ShowImageEffects) == SceneViewStateFlags.ShowImageEffects;
     state.showParticleSystems = (flags & SceneViewStateFlags.ShowParticleSystems) == SceneViewStateFlags.ShowParticleSystems;
 }
 public static void Copy(this SceneView.SceneViewState state, SceneView.SceneViewState source)
 {
     state.showSkybox          = source.showSkybox;
     state.showFog             = source.showFog;
     state.showFlares          = source.showFlares;
     state.showMaterialUpdate  = source.showMaterialUpdate;
     state.showImageEffects    = source.showImageEffects;
     state.showParticleSystems = source.showParticleSystems;
 }
 public void SaveStateFromSceneView(SceneView view)
 {
     cameraMode     = view.cameraMode;
     sceneLighting  = view.sceneLighting;
     audioPlay      = view.audioPlay;
     sceneViewState = new SceneView.SceneViewState(view.sceneViewState);
     in2DMode       = view.in2DMode;
     pivot          = view.pivot;
     rotation       = view.rotation;
     size           = view.size;
     orthographic   = view.orthographic;
 }
        public static SceneViewStateFlags GetFlags(this SceneView.SceneViewState state)
        {
            SceneViewStateFlags flags = 0;

            flags |= state.showSkybox ? SceneViewStateFlags.ShowSkybox : 0;
            flags |= state.showFog ? SceneViewStateFlags.ShowFog : 0;
            flags |= state.showFlares ? SceneViewStateFlags.ShowFlares : 0;
            flags |= state.showMaterialUpdate ? SceneViewStateFlags.ShowMaterialUpdate : 0;
            flags |= state.showImageEffects ? SceneViewStateFlags.ShowImageEffects : 0;
            flags |= state.showParticleSystems ? SceneViewStateFlags.ShowParticleSystems : 0;

            return(flags);
        }
Пример #7
0
    static bool UpdateSceneViewSkybox ()
    {
        SceneView sceneView = SceneView.lastActiveSceneView;

        if (sceneView == null)
            return false;
        
        SceneView.SceneViewState state = sceneView.sceneViewState;
        state.SetAllEnabled(false);
        sceneView.sceneViewState = state;

        return true;
    }
 public ViewSettings(Vector3 pivot, Quaternion rotation, float size, bool ortho, float fieldOfView, bool is2D, SceneView.CameraMode cameraMode, bool drawGizmos, bool sceneLighting, SceneView.SceneViewState sceneViewState, bool showGrid)
 {
     this.pivot          = pivot;
     this.rotation       = rotation;
     this.size           = size;
     this.ortho          = ortho;
     this.fov            = fieldOfView;
     this.is2D           = is2D;
     this.mode           = cameraMode;
     this.drawGizmos     = drawGizmos;
     this.sceneLighting  = sceneLighting;
     this.sceneViewState = new SceneView.SceneViewState(sceneViewState);
     this.showGrid       = showGrid;
 }
 public ViewSettings(SceneView sceneView)
 {
     this.pivot          = sceneView.pivot;
     this.rotation       = sceneView.rotation;
     this.size           = sceneView.size;
     this.ortho          = sceneView.orthographic;
     this.fov            = sceneView.cameraSettings.fieldOfView;
     this.is2D           = sceneView.in2DMode;
     this.mode           = sceneView.cameraMode;
     this.drawGizmos     = sceneView.drawGizmos;
     this.sceneLighting  = sceneView.sceneLighting;
     this.sceneViewState = new SceneView.SceneViewState(sceneView.sceneViewState);
     this.showGrid       = sceneView.showGrid;
 }
Пример #10
0
        private void DrawHandlesAtCursor(RaycastHit hit)
        {
#if UNITY_EDITOR
            if (brushHandle == null)
            {
                UpdateHandle();
            }
            Material mat   = MaterialUtilities.IntersectionHighlight;
            Color    color =
                GuiEventUtilities.IsCtrl ? ColorLibrary.RedSemiTransparent :
                GuiEventUtilities.IsShift ? ColorLibrary.YellowSemiTransparent :
                ColorLibrary.CyanSemiTransparent;
            mat.SetColor("_Color", color);
            Color intersectColor =
                GuiEventUtilities.IsCtrl ? ColorLibrary.Red :
                GuiEventUtilities.IsShift ? ColorLibrary.Yellow :
                ColorLibrary.Cyan;
            mat.SetColor("_IntersectColor", intersectColor);
            brushHandle.transform.position = hit.point;

            if (Settings.brushMode == BrushMode.Cylindrical)
            {
                brushHandle.transform.up         = Vector3.up;
                brushHandle.transform.localScale = new Vector3(Settings.brushRadius * 2, Mathf.Abs(hit.point.y), Settings.brushRadius * 2);
            }
            else if (Settings.brushMode == BrushMode.Spherical)
            {
                brushHandle.transform.up         = hit.normal;
                brushHandle.transform.localScale = Vector3.one * Settings.brushRadius * 2;
            }
            brushHandle.gameObject.SetActive(true);

            //brush handle will not update correctly if AnimatedMaterial option is disable in Scene view
            //in such case, we update the Scene view manually
            foreach (SceneView sv in SceneView.sceneViews)
            {
                //the sceneViewState property is not exposed in 5.6.1 yet
                FieldInfo field = sv.GetType().GetField("m_SceneViewState", BindingFlags.NonPublic | BindingFlags.Instance);
                if (field != null)
                {
                    SceneView.SceneViewState state = field.GetValue(sv) as SceneView.SceneViewState;
                    if (!state.showMaterialUpdate)
                    {
                        sv.Repaint();
                    }
                }
            }
#endif
        }
Пример #11
0
        static Bookmarks()
        {
            instance = new Bookmarks();
            instance.builtin_viewpoints = new List <Viewpoint>();

            var allDisabled = new SceneView.SceneViewState();

            allDisabled.SetAllEnabled(false);

            var perspective_settings = new ViewSettings(Vector3.zero, Quaternion.Euler(30f, -50f, 0), 100f, false, 60f, false, SceneView.GetBuiltinCameraMode(DrawCameraMode.Textured), true, true, new SceneView.SceneViewState(), true);
            var perspective_view     = new Viewpoint("Perspective (Shaded)", perspective_settings, -1 ^ (1 << 5), 0, (Viewpoint.Overrides)(-1) ^ Viewpoint.Overrides.Position);

            instance.builtin_viewpoints.Add(perspective_view);

            var top_settings = new ViewSettings(Vector3.zero, Quaternion.LookRotation(Vector3.down, Vector3.forward), 100f, true, 60f, false, SceneView.GetBuiltinCameraMode(DrawCameraMode.Wireframe), true, false, allDisabled, true);
            var top_view     = new Viewpoint("Top (Wireframe, UI Hidden)", top_settings, -1 ^ (1 << 5), 0, (Viewpoint.Overrides)(-1) ^ Viewpoint.Overrides.Position);

            instance.builtin_viewpoints.Add(top_view);

            var front_settings = new ViewSettings(Vector3.zero, Quaternion.LookRotation(Vector3.forward, Vector3.up), 100f, true, 60f, false, SceneView.GetBuiltinCameraMode(DrawCameraMode.Wireframe), true, false, allDisabled, true);
            var front_view     = new Viewpoint("Front (Wireframe, UI Hidden)", front_settings, -1 ^ (1 << 5), 0, (Viewpoint.Overrides)(-1) ^ Viewpoint.Overrides.Position);

            instance.builtin_viewpoints.Add(front_view);

            var ui_settings = new ViewSettings(Vector3.zero, Quaternion.identity, 100f, true, 60f, true, SceneView.GetBuiltinCameraMode(DrawCameraMode.Textured), true, true, allDisabled, true);
            var ui_view     = new Viewpoint("2D (UI Only)", ui_settings, 0 ^ (1 << 5), 0, () =>
            {
                SceneView.lastActiveSceneView.FrameLayers(Tools.visibleLayers);
            });

            instance.builtin_viewpoints.Add(ui_view);

            instance.viewpoints = new List <Viewpoint>();
            instance.LoadFromJson(path);
            SceneView.duringSceneGui   += SceneView_duringSceneGui;
            EditorApplication.quitting += EditorApplication_quitting;
            EditorSceneManager.activeSceneChangedInEditMode += EditorSceneManager_activeSceneChangedInEditMode;

#if DISCOVERY_MENU
            HotBoxMenuItem hotBoxMenuItem = new HotBoxMenuItem("Views");
            hotBoxMenuItem.Refresh = () => { hotBoxMenuItem.menu = QuickAccessMenu(SceneView.lastActiveSceneView); };
            SceneViewHotBox.menuItems.Add("Views", hotBoxMenuItem);
#endif
        }
Пример #12
0
    static bool UpdateSceneViewSkybox()
    {
        if (StageUtility.GetCurrentStageHandle() != StageUtility.GetMainStageHandle())
        {
            return(false);
        }

        SceneView sceneView = SceneView.lastActiveSceneView;

        if (sceneView == null)
        {
            return(false);
        }

        SceneView.SceneViewState state = sceneView.sceneViewState;
        state.showSkybox         = false;
        sceneView.sceneViewState = state;

        return(true);
    }
        private void DrawHandlesAtCursor(RaycastHit hit)
        {
#if UNITY_EDITOR
            if (sphereHandle == null)
            {
                UpdateHandle();
            }
            Material mat   = MaterialUtilities.IntersectionHighlight;
            Color    color = GuiEventUtilities.IsCtrl ? ColorLibrary.RedSemiTransparent : ColorLibrary.CyanSemiTransparent;
            mat.SetColor("_Color", color);
            Color intersectColor = GuiEventUtilities.IsCtrl ? ColorLibrary.Red : ColorLibrary.Cyan;
            mat.SetColor("_IntersectColor", intersectColor);
            sphereHandle.transform.position   = hit.point;
            sphereHandle.transform.localScale = 2 * Settings.brushRadius * Vector3.one;
            sphereHandle.transform.up         = hit.normal;
            sphereHandle.gameObject.SetActive(true);

            if (GuiEventUtilities.IsShift && !GuiEventUtilities.IsCtrl && Settings.mode == Mode.Spawning)
            {
                Handles.color = ColorLibrary.Cyan;
                Quaternion rotation = Quaternion.LookRotation(hit.normal);
                Handles.ArrowHandleCap(0, hit.point, rotation, Settings.brushRadius, Event.current.type);
            }

            //brush handle will not update correctly if AnimatedMaterial option is disabled in Scene view
            //in such case, we update the Scene view manually
            foreach (SceneView sv in SceneView.sceneViews)
            {
                //the sceneViewState property is not exposed yet in 5.6.1
                FieldInfo field = sv.GetType().GetField("m_SceneViewState", BindingFlags.NonPublic | BindingFlags.Instance);
                if (field != null)
                {
                    SceneView.SceneViewState state = field.GetValue(sv) as SceneView.SceneViewState;
                    if (!state.showMaterialUpdate)
                    {
                        sv.Repaint();
                    }
                }
            }
#endif
        }
Пример #14
0
 private void Draw(Rect rect)
 {
     if (!(this.m_SceneView == null) && this.m_SceneView.sceneViewState != null)
     {
         Rect rect2 = new Rect(1f, 1f, rect.width - 2f, 16f);
         SceneView.SceneViewState state = this.m_SceneView.sceneViewState;
         this.DrawListElement(rect2, "Skybox", state.showSkybox, delegate(bool value)
         {
             state.showSkybox = value;
         });
         rect2.y += 16f;
         this.DrawListElement(rect2, "Fog", state.showFog, delegate(bool value)
         {
             state.showFog = value;
         });
         rect2.y += 16f;
         this.DrawListElement(rect2, "Flares", state.showFlares, delegate(bool value)
         {
             state.showFlares = value;
         });
         rect2.y += 16f;
         this.DrawListElement(rect2, "Animated Materials", state.showMaterialUpdate, delegate(bool value)
         {
             state.showMaterialUpdate = value;
         });
         rect2.y += 16f;
         this.DrawListElement(rect2, "Image Effects", state.showImageEffects, delegate(bool value)
         {
             state.showImageEffects = value;
         });
         rect2.y += 16f;
         this.DrawListElement(rect2, "Particle Systems", state.showParticleSystems, delegate(bool value)
         {
             state.showParticleSystems = value;
         });
         rect2.y += 16f;
     }
 }
Пример #15
0
        public void HideHandle()
        {
#if UNITY_EDITOR
            if (brushHandle != null)
            {
                brushHandle.gameObject.SetActive(false);
            }
            //brush handle will not update correctly if AnimatedMaterial option is disable in Scene view
            //in such case, we update the Scene view manually
            foreach (SceneView sv in SceneView.sceneViews)
            {
                //the sceneViewState property is not exposed in 5.6.1 yet
                FieldInfo field = sv.GetType().GetField("m_SceneViewState", BindingFlags.NonPublic | BindingFlags.Instance);
                if (field != null)
                {
                    SceneView.SceneViewState state = field.GetValue(sv) as SceneView.SceneViewState;
                    if (!state.showMaterialUpdate)
                    {
                        sv.Repaint();
                    }
                }
            }
#endif
        }
Пример #16
0
        public void OnGUI()
        {
            if (EditorApplication.isCompiling)
            {
                ShowNotification(new GUIContent("Compiling\n...Please wait..."));
                return;
            }

            GUI.skin.label.richText         = true;
            GUI.skin.label.alignment        = TextAnchor.UpperLeft;
            EditorStyles.label.richText     = true;
            EditorStyles.textField.wordWrap = true;
            EditorStyles.foldout.richText   = true;


            GUI.backgroundColor = new Color(1f, 1f, 1f, 0.5f);
            GUI.color           = Color.white;
            GUILayout.BeginHorizontal(EditorStyles.toolbar);


            if (GUILayout.Button("File", EditorStyles.toolbarButton, GUILayout.Width(60)))
            {
                scenesGenericMenu.ShowAsContext();
            }

            if (GUILayout.Button("Edit2D", EditorStyles.toolbarButton, GUILayout.Width(60)))
            {
                SceneView sceneView = SceneView.lastActiveSceneView;
                if (is2DState == false)
                {
                    lastSceneViewRotation = sceneView.rotation;
                    lastSceneViewOrtho    = sceneView.orthographic;
                }
                is2DState = true;
                sceneView.LookAt(sceneView.pivot, Quaternion.Euler(90, 0, 0), sceneView.size, true);
                sceneView.isRotationLocked = true;
                FieldInfo fieldInfo = sceneView.GetType()
                                      .GetField("m_SceneViewState", BindingFlags.NonPublic | BindingFlags.Instance);

                SceneView.SceneViewState scneViewState = (SceneView.SceneViewState)fieldInfo.GetValue(sceneView);
                scneViewState.showFog = false;
                fieldInfo.SetValue(sceneView, scneViewState);

                sceneView.Repaint();
            }

            if (GUILayout.Button("Edit3D", EditorStyles.toolbarButton, GUILayout.Width(60)))
            {
                is2DState = false;
                SceneView sceneView = SceneView.lastActiveSceneView;
                sceneView.isRotationLocked = false;
                sceneView.LookAt(sceneView.pivot, lastSceneViewRotation, sceneView.size, lastSceneViewOrtho);
                sceneView.Repaint();
            }

            if (sceneCFG)
            {
                if (GUILayout.Button("Save", EditorStyles.toolbarButton, GUILayout.Width(60)))
                {
                    GameObject root      = sceneCFG.gameObject;
                    var        prefabSrc = PrefabUtility.GetCorrespondingObjectFromSource(root);
                    var        path      = AssetDatabase.GetAssetPath(prefabSrc);
                    PrefabUtility.SaveAsPrefabAssetAndConnect(root, path,
                                                              InteractionMode.AutomatedAction);

                    Scene scene = root.scene;
                    if (scene != null)
                    {
                        EditorSceneManager.MarkSceneDirty(scene);
                    }
                }
            }
            else
            {
                if (GUILayout.Button("Check", EditorStyles.toolbarButton, GUILayout.Width(60)))
                {
                    CheckSceneInfo(false);
                }
            }

            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            GUI.backgroundColor = Color.white;

            if (sceneCFG == null)
            {
                string  label     = string.Format("<size=30><b>{0}</b></size>", "Welcome to SceneEditor!");
                Vector2 size      = new GUIStyle("label").CalcSize(new GUIContent(label));
                Rect    titleRect = new Rect(0, 0, size.x, size.y);
                titleRect.center = new Vector2(Screen.width / 2, (Screen.height / 2) - size.y);
                GUI.Label(titleRect, label);

                titleRect.y      = titleRect.y + titleRect.height;
                titleRect.height = 20;
                //空场景没有存在时才能创建;
                string path = getSceneAssetPrefix() + "/sceneInfo.prefab";
                if (File.Exists(path) == false)
                {
                    if (GUI.Button(titleRect, "create"))
                    {
                        CreateSceneInfo();
                    }
                }
                return;
            }

            EditorGUILayout.Space();
            this.ModeToggle();
            EditorGUILayout.Space();

            this.scrollPos = EditorGUILayout.BeginScrollView(this.scrollPos, new GUILayoutOption[0]);

            switch (this._selectedSceneCfgMode)
            {
            case SceneCFGMode.SceneSettings:
                this.SceneInfo();
                break;

            case SceneCFGMode.RegionSettings:
                this.RegionSettings();
                break;

            case SceneCFGMode.PathsSettings:
                this.PathsSettings();
                break;

            case SceneCFGMode.SpawersSettings:
                this.SpawersSettings();
                break;

            case SceneCFGMode.NPCSettings:
                this.NPCSettings();
                break;

            case SceneCFGMode.CutSettings:
                this.CutSettings();
                break;

            case SceneCFGMode.COPYSettings:
                this.CopySetting();
                break;
            }
            EditorGUILayout.EndScrollView();
        }