示例#1
0
        public void AddPrefabIcon(VisualElement _iconContainer, PuppeteerAgent _agent)
        {
            _iconContainer.hierarchy.Clear();

            GameObject prefabObject = PrefabUtility.GetCorrespondingObjectFromSource(_agent.gameObject);
            string     path         = prefabObject != null?AssetDatabase.GetAssetPath(prefabObject) : null;

            IMGUIContainer icon = new IMGUIContainer(() =>
            {
                if (path != null)
                {
                    GameObject asset = AssetDatabase.LoadAssetAtPath <GameObject>(path);

                    Editor editor = GetPreviewEditor(asset);

                    editor.OnPreviewGUI(GUILayoutUtility.GetRect(170, 170), new GUIStyle()
                    {
                        normal = { background = Texture2D.whiteTexture }
                    });
                }
                else
                {
                    GUILayout.Label("Not a Prefab.");
                }
            })
            {
                focusable = false,
                name      = "prefabIcon",
            };

            icon.AddToClassList("prefabIcon");

            _iconContainer.hierarchy.Add(icon);
        }
        protected virtual void DrawModelViewer()
        {
            PageColumn modelViewer = root.Q <PageColumn>("model-viewer");

            DestroyImmediate(modelViewerEditor);
            modelViewer.Clear();
            if (chosenKey != null && modelViewer != null)
            {
                if (collection.ContainsKey(chosenKey) && collection[chosenKey].components.ContainsKey(typeof(Model)))
                {
                    Model modelComponent = (Model)collection[chosenKey].components[typeof(Model)];
                    if (modelComponent.manualKey.Equals(""))
                    {
                        modelViewer.style.display = DisplayStyle.None;
                        return;
                    }
                    previewModel = ProvenceManager.ModelBank.LoadModel(modelComponent.manualKey);
                    if (previewModel == null)
                    {
                        return;
                    }
                    modelViewer.style.display = DisplayStyle.Flex;
                    IMGUIContainer modelViewerWrapper = new IMGUIContainer();
                    modelViewerWrapper.AddToClassList("model-preview-wrapper");
                    modelViewer.Add(modelViewerWrapper);
                    modelViewerWrapper.onGUIHandler = () => {
                        DrawObjectPreview(modelViewerWrapper, ref modelViewerEditor, previewModel);
                    };
                }
                else
                {
                    modelViewer.style.display = DisplayStyle.None;
                }
            }
        }
示例#3
0
        protected override void DrawModelViewer()
        {
            PageColumn modelViewer = root.Q <PageColumn>("model-viewer");

            modelViewer.Clear();
            if (chosenKey == null)
            {
                modelViewer.style.display = DisplayStyle.None;
                return;
            }
            if (modelViewer != null)
            {
                previewModel = ((ModelBank)collection).LoadModel(chosenKey);
                if (previewModel != null)
                {
                    modelViewer.style.display = DisplayStyle.Flex;
                    IMGUIContainer modelViewerWrapper = new IMGUIContainer();
                    modelViewerWrapper.AddToClassList("model-preview-wrapper");
                    modelViewer.Add(modelViewerWrapper);
                    modelViewerWrapper.onGUIHandler = () => {
                        DrawObjectPreview(modelViewerWrapper, ref modelViewerEditor, previewModel);
                    };
                }
                else
                {
                    modelViewer.style.display = DisplayStyle.None;
                }
            }
        }
示例#4
0
 internal void SetupIMGUIForCurrentProviderIfNeeded()
 {
     if (m_SettingsPanel.childCount == 0)
     {
         var imguiContainer = new IMGUIContainer(DrawSettingsPanel);
         imguiContainer.AddToClassList("settings-panel-imgui-container");
         m_SettingsPanel.Add(imguiContainer);
     }
 }
示例#5
0
        private void SetupUI()
        {
            var containers = Resources.FindObjectsOfTypeAll(typeof(ContainerWindow));

            minSize = new Vector2(Styles.window.GetFloat("min-width"), Styles.window.GetFloat("min-height"));
            foreach (ContainerWindow window in containers)
            {
                if (window.showMode == ShowMode.MainWindow)
                {
                    position = new Rect(
                        window.position.center - (minSize / 2),
                        minSize);
                    break;
                }
            }

            var root = rootVisualElement;

            root.AddStyleSheetPath("StyleSheets/SettingsWindowCommon.uss");
            root.AddStyleSheetPath($"StyleSheets/SettingsWindow{(EditorGUIUtility.isProSkin ? "Dark" : "Light")}.uss");

            root.style.flexDirection = FlexDirection.Column;

            var toolbar = new IMGUIContainer(DrawToolbar);

            root.Add(toolbar);

            m_Splitter = new VisualSplitter {
                splitSize = Styles.window.GetInt("-unity-splitter-size")
            };
            m_Splitter.AddToClassList("settings-splitter");
            root.Add(m_Splitter);
            var settingsTree = new IMGUIContainer(DrawTreeView)
            {
                style =
                {
                    flexGrow  = m_SplitterFlex,
                    flexBasis = 0f
                },
                focusOnlyIfHasFocusableControls = false,
            };

            settingsTree.AddToClassList("settings-tree-imgui-container");
            m_Splitter.Add(settingsTree);

            m_SettingsPanel = new VisualElement()
            {
                style =
                {
                    flexGrow  = 1.0f - m_SplitterFlex,
                    flexBasis = 0f
                }
            };
            m_SettingsPanel.AddToClassList("settings-panel");
            m_Splitter.Add(m_SettingsPanel);
        }
示例#6
0
        public override void Enable(bool fromInspector)
        {
            base.Enable(fromInspector);

            if (shaderNode.material != null && !owner.graph.IsObjectInGraph(shaderNode.material))
            {
                // Check if the material we have is ours
                if (owner.graph.IsExternalSubAsset(shaderNode.material))
                {
                    shaderNode.material           = new Material(shaderNode.material);
                    shaderNode.material.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector;
                }
                owner.graph.AddObjectToGraph(shaderNode.material);
            }

            shaderSettings = new VisualElement();
            var shaderField = AddControlField(nameof(ShaderNode.shader)) as ObjectField;

            shaderSettings.Add(shaderField);

            var shaderCreationUI = new VisualElement();

            shaderSettings.Add(shaderCreationUI);
            UpdateShaderCreationUI(shaderCreationUI, shaderField);

            shaderField.RegisterValueChangedCallback((v) => {
                SetShader((Shader)v.newValue, shaderCreationUI, shaderField);
            });

            if (!fromInspector)
            {
                if (shaderNode.shader != null)
                {
                    shaderPath = AssetDatabase.GetAssetPath(shaderNode.shader);
                }
                if (!String.IsNullOrEmpty(shaderPath))
                {
                    lastModified = File.GetLastWriteTime(shaderPath);
                }

                var lastWriteDetector = schedule.Execute(DetectShaderChanges);
                lastWriteDetector.Every(200);
                InitializeDebug();

                onPortDisconnected += ResetMaterialPropertyToDefault;
            }

            var materialIMGUI = new IMGUIContainer(() => MaterialGUI(fromInspector, shaderCreationUI, shaderField));

            shaderSettings.Add(materialIMGUI);
            materialIMGUI.AddToClassList("MaterialInspector");

            controlsContainer.Add(shaderSettings);
            MixtureEditorUtils.ScheduleAutoHide(materialIMGUI, owner);
        }
示例#7
0
        public override void Enable(bool fromInspector)
        {
            base.Enable(fromInspector);

            if (!fromInspector)
            {
                if (fixedShaderNode.material != null && !owner.graph.IsObjectInGraph(fixedShaderNode.material))
                {
                    if (owner.graph.IsExternalSubAsset(fixedShaderNode.material))
                    {
                        fixedShaderNode.material           = new Material(fixedShaderNode.material);
                        fixedShaderNode.material.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector;
                    }
                    if (fixedShaderNode.material.shader.name != ShaderNode.DefaultShaderName)
                    {
                        owner.graph.AddObjectToGraph(fixedShaderNode.material);
                    }
                }

                if (fixedShaderNode.shader != null)
                {
                    lastModified = File.GetLastWriteTime(AssetDatabase.GetAssetPath(fixedShaderNode.shader));
                }
                var lastWriteDetector = schedule.Execute(DetectShaderChanges);
                lastWriteDetector.Every(200);

                InitializeDebug();

                onPortDisconnected += ResetMaterialPropertyToDefault;
            }

            if (fixedShaderNode.displayMaterialInspector)
            {
                Action <bool> safeMaterialGUI = (bool init) => {
                    // Copy fromInspector to avoid having the same value (lambda capture fromInspector pointer)
                    bool f = fromInspector;
                    if (!init)
                    {
                        MaterialGUI(f);
                    }
                };
                safeMaterialGUI(true);
                var materialIMGUI = new IMGUIContainer(() => safeMaterialGUI(false));

                materialIMGUI.AddToClassList("MaterialInspector");

                MixtureEditorUtils.ScheduleAutoHide(materialIMGUI, owner);

                controlsContainer.Add(materialIMGUI);
            }
        }
示例#8
0
        public void OnEnable()
        {
            rootVisualElement.styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>("Assets/Examples/Editor/styles.uss"));
            rootVisualElement.style.flexDirection = FlexDirection.Column;

            AddToolbar();

            rootVisualElement.Add(m_RootContainer = new VisualElement());
            m_RootContainer.style.flexGrow        = 1;
            m_RootContainer.style.flexShrink      = 1;

            m_ScrollView = new ScrollView();
            m_ScrollView.showVertical = true;

            m_RowContainer = new VisualElement()
            {
                name = "RowContainer"
            };
            m_RowContainer.style.flexDirection = FlexDirection.Row;
            m_ScrollView.Add(m_RowContainer);

            m_IMGUIContainer         = new IMGUIContainer(OnGUIForLeftContainer);
            m_VisualElementContainer = new VisualElement();
            m_IMGUIContainer.AddToClassList("inner-container");
            m_VisualElementContainer.AddToClassList("inner-container");

            if (EditorGUIUtility.isProSkin)
            {
                m_IMGUIContainer.style.backgroundColor         = new Color(0.30f, 0.30f, 0.30f);
                m_VisualElementContainer.style.backgroundColor = new Color(0.30f, 0.30f, 0.30f);
            }
            else
            {
                m_IMGUIContainer.style.backgroundColor         = new Color(0.80f, 0.80f, 0.80f);
                m_VisualElementContainer.style.backgroundColor = new Color(0.80f, 0.80f, 0.80f);
            }

            m_LeftContainer  = new VisualElement();
            m_RightContainer = new VisualElement();
            m_LeftContainer.AddToClassList("split-container");
            m_RightContainer.AddToClassList("split-container");

            m_LeftContainer.Add(m_IMGUIContainer);
            m_RightContainer.Add(m_VisualElementContainer);

            CreateUIElements();
            UpdateScrollViewUsage();
        }
    static void SetRoot()
    {
        IMGUIContainer container = new IMGUIContainer();

        root.Add(container);

        container.name = "VoxelToolWindow";

        container.StretchToParentSize();
        container.AddToClassList("unity-imgui-container");

        rect = EditorWindow.focusedWindow.rootVisualElement.layout;

        Action GUIHandler = newGUI;

        container.onGUIHandler = GUIHandler;
    }
示例#10
0
        private void SetupUI()
        {
            minSize = new Vector2(Styles.window.GetFloat("min-width"), Styles.window.GetFloat("min-height"));

            var root = rootVisualElement;

            root.AddStyleSheetPath("StyleSheets/SettingsWindowCommon.uss");
            root.AddStyleSheetPath($"StyleSheets/SettingsWindow{(EditorGUIUtility.isProSkin ? "Dark" : "Light")}.uss");

            root.style.flexDirection = FlexDirection.Column;

            var toolbar = new IMGUIContainer(DrawToolbar);

            root.Add(toolbar);

            m_Splitter = new VisualSplitter {
                splitSize = Styles.window.GetInt("-unity-splitter-size")
            };
            m_Splitter.AddToClassList("settings-splitter");
            root.Add(m_Splitter);
            var settingsTree = new IMGUIContainer(DrawTreeView)
            {
                style =
                {
                    flexGrow  = m_SplitterFlex,
                    flexBasis = 0f
                },
                focusOnlyIfHasFocusableControls = false,
            };

            settingsTree.AddToClassList("settings-tree-imgui-container");
            m_Splitter.Add(settingsTree);

            m_SettingsPanel = new VisualElement()
            {
                style =
                {
                    flexGrow  = 1.0f - m_SplitterFlex,
                    flexBasis = 0f
                }
            };
            m_SettingsPanel.AddToClassList("settings-panel");
            m_Splitter.Add(m_SettingsPanel);
        }
        public override void Enable(bool fromInspector)
        {
            base.Enable(fromInspector);

            if (!fromInspector)
            {
                if (fixedShaderNode.material != null && !owner.graph.IsObjectInGraph(fixedShaderNode.material))
                {
                    if (owner.graph.IsExternalSubAsset(fixedShaderNode.material))
                    {
                        fixedShaderNode.material           = new Material(fixedShaderNode.material);
                        fixedShaderNode.material.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector;
                    }
                    if (fixedShaderNode.material.shader.name != ShaderNode.DefaultShaderName)
                    {
                        owner.graph.AddObjectToGraph(fixedShaderNode.material);
                    }
                }

                InitializeDebug();

                onPortDisconnected += ResetMaterialPropertyToDefault;
            }

            if (fixedShaderNode.displayMaterialInspector)
            {
                Action <bool> safeMaterialGUI = (bool init) => {
                    // Copy fromInspector to avoid having the same value (lambda capture fromInspector pointer)
                    bool f = fromInspector;
                    if (!init)
                    {
                        MaterialGUI(f);
                    }
                };
                safeMaterialGUI(true);
                var materialIMGUI = new IMGUIContainer(() => safeMaterialGUI(false));

                materialIMGUI.AddToClassList("MaterialInspector");

                controlsContainer.Add(materialIMGUI);
            }
        }
示例#12
0
        public override void Enable()
        {
            base.Enable();

            if (fixedShaderNode.material != null && !owner.graph.IsObjectInGraph(fixedShaderNode.material))
            {
                owner.graph.AddObjectToGraph(fixedShaderNode.material);
            }

            InitializeDebug();

            if (fixedShaderNode.displayMaterialInspector)
            {
                var materialIMGUI = new IMGUIContainer(MaterialGUI);
                materialIMGUI.AddToClassList("MaterialInspector");

                controlsContainer.Add(materialIMGUI);
                materialEditor = Editor.CreateEditor(fixedShaderNode.material) as MaterialEditor;
            }

            onPortDisconnected += ResetMaterialPropertyToDefault;
        }
示例#13
0
        private void SetupUI()
        {
            minSize = new Vector2(Styles.window.GetFloat("min-width"), Styles.window.GetFloat("min-height"));

            var root = this.GetRootVisualContainer();

            root.style.flexDirection = FlexDirection.Column;

            var toolbar = new IMGUIContainer(DrawToolbar);

            root.Add(toolbar);

            m_Splitter = new VisualSplitter {
                splitSize = Styles.window.GetInt("-unity-splitter-size")
            };
            m_Splitter.AddToClassList("settings-splitter");
            root.Add(m_Splitter);
            var settingsTree = new IMGUIContainer(DrawTreeView)
            {
                style =
                {
                    flex = new Flex(m_SplitterFlex)
                }
            };

            settingsTree.AddToClassList("settings-tree-imgui-container");
            m_Splitter.Add(settingsTree);

            m_SettingsPanel = new VisualElement()
            {
                style =
                {
                    flex = new Flex(1.0f - m_SplitterFlex)
                }
            };
            m_SettingsPanel.AddToClassList("settings-panel");
            m_Splitter.Add(m_SettingsPanel);
        }
示例#14
0
        private void ProviderChanged(SettingsProvider lastSelectedProvider, SettingsProvider newlySelectedProvider)
        {
            if (m_SettingsPanel == null)
            {
                return;
            }

            lastSelectedProvider?.OnDeactivate();
            m_SettingsPanel.Clear();

            if (newlySelectedProvider != null)
            {
                newlySelectedProvider?.OnActivate(m_SearchText, m_SettingsPanel);
                EditorPrefs.SetString(GetPrefKeyName(titleContent.text + "_current_provider"), newlySelectedProvider.settingsPath);
            }

            if (m_SettingsPanel.childCount == 0)
            {
                var imguiContainer = new IMGUIContainer(DrawSettingsPanel);
                imguiContainer.AddToClassList("settings-panel-imgui-container");
                m_SettingsPanel.Add(imguiContainer);
            }
        }
    //
    //
    //
    #endregion

    #region CreateModuleUI()
    //
    //
    //

    public VisualElement CreateModuleUI(string moduleName)
    {
        m_TurretBuilder.ResetModulePreviewEditor(moduleName);

        var imguiContainer = new IMGUIContainer(() =>
        {
            var editor = m_TurretBuilder.GetPreviewEditor(moduleName);
            if (editor != null)
            {
                editor.OnInteractivePreviewGUI(
                    GUILayoutUtility.GetRect(180, 180), null);
            }
        });

        imguiContainer.AddToClassList("module-viewport");

        var property = serializedObject.FindProperty(moduleName);
        var field    = new PropertyField(property);

        imguiContainer.Add(field);

        return(imguiContainer);
    }
示例#16
0
        private static IMGUIContainer CreateButton(DataConfigEditor editor, System.Collections.Generic.HashSet <System.Type> usedComponents, SerializedProperty source, VisualElement elements, bool noFields)
        {
            var addMenuButton = new IMGUIContainer(() => {
                GUILayoutExt.DrawAddComponentMenu(usedComponents, (type, isUsed) => {
                    if (isUsed == false)
                    {
                        usedComponents.Add(type);

                        source.serializedObject.Update();
                        ++source.arraySize;
                        var elem = source.GetArrayElementAtIndex(source.arraySize - 1);
                        elem.managedReferenceValue = System.Activator.CreateInstance(type);
                        source.serializedObject.ApplyModifiedProperties();

                        if (noFields == true)
                        {
                            editor.OnAddComponentFromRemoveList(type);
                        }
                        else
                        {
                            editor.OnAddComponent(type);
                        }
                    }
                    else
                    {
                        RemoveComponent(editor, usedComponents, source, type, noFields);
                    }

                    editor.Save();
                    BuildInspectorProperties(editor, usedComponents, source, elements, noFields);
                }, showRuntime: noFields);
            });

            addMenuButton.AddToClassList("add-component-menu-button-imgui");

            return(addMenuButton);
        }
示例#17
0
        public RecorderItem(RecorderControllerSettings prefs, RecorderSettings recorderSettings, string iconName)
        {
            settings = recorderSettings;

            if (settings != null)
            {
                editor = Editor.CreateEditor(settings);
            }

            UIElementHelper.SetFlex(this, 1.0f);
            style.flexDirection = FlexDirection.Row;

            m_Toggle = new Toggle();

#if UNITY_2019_1_OR_NEWER
            m_Toggle.RegisterValueChangedCallback(evt =>
#elif UNITY_2018_3_OR_NEWER
            m_Toggle.OnValueChanged(evt =>
#else
            m_Toggle.OnToggle(() =>
#endif
            {
                SetItemEnabled(prefs, UIElementHelper.GetToggleValue(m_Toggle));
            });

            Add(m_Toggle);

            m_RecorderIcon = LoadIcon(iconName);

            if (m_RecorderIcon == null)
            {
                m_RecorderIcon = LoadIcon("customrecorder_16");
            }

            UpdateState(false);

            var iconContainer = new IMGUIContainer(() => // UIElement Image doesn't support tint yet. Use IMGUI instead.
            {
                var r   = EditorGUILayout.GetControlRect();
                r.width = r.height = Mathf.Max(r.width, r.height);

                var c = GUI.color;

                var newColor = Color.white;

                if (m_Disabled)
                {
                    newColor.a = 0.5f;
                }
                else
                {
                    if (!m_Selected)
                    {
                        newColor.a = 0.8f;
                    }
                }

                GUI.color = newColor;

                GUI.DrawTexture(r, m_Icon);

                GUI.color = c;
            });

            iconContainer.AddToClassList("RecorderItemIcon");

            iconContainer.SetEnabled(false);

            Add(iconContainer);

            m_EditableLabel = new EditableLabel {
                text = settings.name
            };
            m_EditableLabel.OnValueChanged(newValue =>
            {
                settings.name = newValue;
                prefs.Save();
            });
            Add(m_EditableLabel);

            var recorderEnabled = settings.enabled;
            UIElementHelper.SetToggleValue(m_Toggle, recorderEnabled);

            SetItemEnabled(prefs, recorderEnabled);
        }
示例#18
0
        protected override void BuildOutputNodeSettings()
        {
            var externalOutputNode = nodeTarget as ExternalOutputNode;
            var nodeSettings       = new IMGUIContainer(() =>
            {
                if (externalOutputNode.asset == null)
                {
                    EditorGUILayout.HelpBox("This output has not been saved yet, please click Save As to save the output texture.", MessageType.Info);
                }
                else
                {
                    EditorGUI.BeginDisabledGroup(true);
                    EditorGUILayout.ObjectField("Asset", externalOutputNode.asset, typeof(Texture2D), false);
                    EditorGUI.EndDisabledGroup();
                }
                EditorGUI.BeginChangeCheck();
                var outputDimension = EditorGUILayout.EnumPopup("Output Dimension", externalOutputNode.externalOutputDimension);
                if (EditorGUI.EndChangeCheck())
                {
                    externalOutputNode.externalOutputDimension = (ExternalOutputNode.ExternalOutputDimension)outputDimension;
                    switch (outputDimension)
                    {
                    case ExternalOutputNode.ExternalOutputDimension.Texture2D:
                        externalOutputNode.rtSettings.dimension = OutputDimension.Texture2D;
                        break;

                    case ExternalOutputNode.ExternalOutputDimension.Texture3D:
                        externalOutputNode.rtSettings.dimension = OutputDimension.Texture3D;
                        break;
                    }
                    externalOutputNode.OnSettingsChanged();
                    MarkDirtyRepaint();
                }

                EditorGUI.BeginChangeCheck();
                var outputType = EditorGUILayout.EnumPopup("Output Type", externalOutputNode.external2DOoutputType);
                if (EditorGUI.EndChangeCheck())
                {
                    externalOutputNode.external2DOoutputType = (ExternalOutputNode.External2DOutputType)outputType;
                    MarkDirtyRepaint();
                }
                GUILayout.Space(8);
            }
                                                        );

            nodeSettings.AddToClassList("MaterialInspector");

            controlsContainer.Add(nodeSettings);

            if (graph.isRealtime)
            {
                controlsContainer.Add(new IMGUIContainer(() =>
                {
                    EditorGUILayout.HelpBox("Using this node in a realtime Mixture Graph is not supported", MessageType.Warning);
                }));
            }
            else
            {
                // Add Buttons
                saveButton = new Button(SaveExternal)
                {
                    text = "Save As..."
                };
                updateButton = new Button(UpdateExternal)
                {
                    text = "Update"
                };

                var horizontal = new VisualElement();
                horizontal.style.flexDirection = FlexDirection.Row;
                horizontal.Add(saveButton);
                horizontal.Add(updateButton);
                controlsContainer.Add(horizontal);
                UpdateButtons();
            }
        }
        public void InitUI()
        {
            ui_FileListContainer    = root.Query <VisualElement>("FileListContainer").First();
            ui_Label_TotalFileCount = root.Query <Label>("Label_TotalFileCount").First();

            ui_Button_Refresh          = root.Query <Button>("Button_Refresh").First();
            ui_Button_Refresh.clicked += () => { m_renamerWindow.UpdateMaterialList(); };

            ui_Button_Checkout          = root.Query <Button>("Button_Checkout").First();
            ui_Button_Checkout.clicked += () =>
            {
                m_renamerWindow.CheckOutAllFiles(true);
            };

            ui_Button_Lock          = root.Query <Button>("Button_Lock").First();
            ui_Button_Lock.clicked += () =>
            {
                m_renamerWindow.LockAllFiles(true);
            };
            if (!(Provider.isActive && Provider.enabled))
            {
                ui_Button_Checkout.SetEnabled(false);
                ui_Button_Lock.SetEnabled(false);
                ui_Button_Checkout.tooltip =
                    "Version Control Disabled. Enable it in the Project Settings and re-open this window.";
                ui_Button_Lock.tooltip =
                    "Version Control Disabled. Enable it in the Project Settings and re-open this window.";
            }

            //CreateListView
            Func <VisualElement> makeItem = () => new VisualElement();
            //ListView item update
            Action <VisualElement, int> bindItem = (e, i) =>
            {
                e.Clear();
                e.userData = i;
                e.AddToClassList("fileListElement");

                if (m_AssetList.Count > i)
                {
                    bool isWarning = (m_AssetList[i].IsState(Asset.States.Conflicted) ||
                                      m_AssetList[i].IsState(Asset.States.LockedRemote) ||
                                      m_AssetList[i].IsState(Asset.States.MovedRemote) ||
                                      m_AssetList[i].IsState(Asset.States.OutOfSync));
                    e.EnableInClassList("warning", isWarning);
                    if (isWarning)
                    {
                        string toolTipString = (m_AssetList[i].IsState(Asset.States.OutOfSync)?"Out Of Sync, ":"")
                                               + (m_AssetList[i].IsState(Asset.States.Conflicted)?"Conflicted, ":"")
                                               + (m_AssetList[i].IsState(Asset.States.LockedRemote)?"Locked remotely, ":"")
                                               + (m_AssetList[i].IsState(Asset.States.MovedRemote)?"Moved remotely, ":"");
                        e.tooltip = toolTipString.Substring(0, toolTipString.Length - 2);
                    }
                }



                //UnityEditorInternal.VersionControl.Overlay.DrawOverlay();
                var icon = new IMGUIContainer(() =>
                {
                    //Debug.Log("i="+i+" - ObjectList Count="+m_ObjectList.Count+" - AssetListCount="+m_AssetList.Count);
                    if (m_ObjectList.Count <= i)
                    {
                        return;
                    }
                    //Debug.Log("i="+i+" - ObjectList Count="+m_ObjectList.Count+" - AssetListCount="+m_AssetList.Count);
                    string assetPath = AssetDatabase.GetAssetPath(m_ObjectList[i]);
                    GUI.DrawTexture(new Rect(7, 0, 16, 16), AssetDatabase.GetCachedIcon(assetPath), ScaleMode.ScaleToFit, true);
                    if (m_AssetList.Count > i)
                    {
                        UnityEditorInternal.VersionControl.Overlay.DrawOverlay(m_AssetList[i], new Rect(0, 0, 16, 16));
                    }
                    //Debug.Log("i="+i+" - ObjectList Count="+m_ObjectList.Count+" - AssetListCount="+m_AssetList.Count+"[END]");
                });
                icon.AddToClassList("fileIcon");
                e.Add(icon);
                e.Add(new Label(m_ObjectList[i].name));
                VisualElement warningIcon = new VisualElement();
                warningIcon.AddToClassList("duplicateWarning");
                e.Add(warningIcon);
            };
            // Provide the list view with an explict height for every row
            // so it can calculate how many items to actually display
            const int itemHeight = 20;


            m_ListView = new ListView(m_ObjectList, itemHeight, makeItem, bindItem);
            m_ListView.selectionType = SelectionType.Multiple;
#if UNITY_2020_1_OR_NEWER
            m_ListView.onItemsChosen     += obj => Selection.activeObject = (Object)obj.First();
            m_ListView.onSelectionChange += objects =>
            {
                List <Object> selectionList = (from obj in objects select obj as Object).ToList();

                Selection.objects = selectionList.ToArray();
            };
#else
            m_ListView.onItemChosen       += obj => Selection.activeObject = (Object)obj;
            m_ListView.onSelectionChanged += objects =>
            {
                List <Object> selectionList = (from obj in objects select obj as Object).ToList();

                Selection.objects = selectionList.ToArray();
            };
#endif

            m_ListView.style.flexGrow = 1.0f;
            ui_FileListContainer.Add(m_ListView);
        }
示例#20
0
    void CreateVisualTree()
    {
        var visualTree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>("Assets/Editor/EditorComponents/LevelEditor.uxml");
        var styleSheet = AssetDatabase.LoadAssetAtPath <StyleSheet>("Assets/Editor/LevelEditorWindow.uss");

        levelEditor = visualTree.CloneTree();

        addLevelContainer  = levelEditor.Q <Box>("addLevelContainer");
        levelListContainer = new IMGUIContainer(DrawAnimationList);
        levelListContainer.onGUIHandler = DrawAnimationList;
        levelList = new ReorderableList(allLevels, typeof(Level));
        levelList.drawElementCallback = DrawList;
        levelList.drawHeaderCallback  = WriteHeader;
        levelList.onReorderCallback   = ChangeListOrder;
        levelList.onSelectCallback    = SelectListItem;
        levelList.onAddCallback       = AddToList;
        levelList.onRemoveCallback    = RemoveFromList;
        addLevelContainer.Add(levelListContainer);

        MapLayer map = new MapLayer();

        map.name      = "Environment";
        map.drawRects = new Dictionary <Vector2Int, Drawable>();
        MapLayer objects = new MapLayer();

        objects.name      = "StaticObjects";
        objects.drawRects = new Dictionary <Vector2Int, Drawable>();
        MapLayer enemies = new MapLayer();

        enemies.name      = "Enemies";
        enemies.drawRects = new Dictionary <Vector2Int, Drawable>();
        MapLayer player = new MapLayer();

        player.name      = "Players";
        player.drawRects = new Dictionary <Vector2Int, Drawable>();

        layersToDraw.Add(map);
        layersToDraw.Add(objects);
        layersToDraw.Add(enemies);
        layersToDraw.Add(player);

        VisualElement stampToolLayout = levelEditor.Q <Box>("levelManagerContainer");

        levelEditor.Add(stampToolLayout);

        VisualElement levelPropertyContainer = levelEditor.Q <Box>("PropertiesBarRow1");

        // Create a new field and assign it its value.
        layersPopupField       = new PopupField <string>("Select Layer to Paint", layers, 0);
        layersPopupField.value = "Environment";
        layersPopupField.AddToClassList("height-width-slider");
        levelPropertyContainer.Add(layersPopupField);

        //Label selectTileMapLabel = new Label("Choose TileMap(64x64)");
        //levelPropertyContainer.Add(selectTileMapLabel);

        //textureObjectField = new ObjectField { objectType = typeof(UnityEngine.Texture) };
        ////textureObjectField.StretchToParentSize();
        //textureObjectField.AddToClassList("height-width-slider");
        //levelPropertyContainer.Add(textureObjectField);
        //// Mirror value of uxml field into the C# field.
        //layersPopupField.RegisterCallback<ChangeEvent<string>>((evt) =>
        //{
        //    styledField.value = evt.newValue;
        //});

        VisualElement levelMapContainer = levelEditor.Q <Box>("LevelMapContainer");

        mapElement = new IMGUIContainer(mapOnGUI);

        mapElement.AddToClassList("level-map-sub-container");
        mapElement.RegisterCallback <MouseMoveEvent>(OnMapMouseMove);
        mapElement.RegisterCallback <MouseDownEvent>(OnMapMouseDown);
        mapElement.RegisterCallback <MouseUpEvent>(OnMapMouseUp);
        mapElement.RegisterCallback <MouseOutEvent>(OnMapMouseExit);

        levelMapContainer.Add(mapElement);

        VisualElement levelTileContainer = levelEditor.Q <Box>("TileMapContainer");

        tileElement = new IMGUIContainer(tileOnGUI);

        tileElement.AddToClassList("tile-map-container");
        tileElement.RegisterCallback <MouseUpEvent>(OnTileMouseup);

        levelTileContainer.Add(tileElement);

        InitializeLists();
    }
示例#21
0
        private static IMGUIContainer CreateTemplatesButton(DataConfigEditor editor,
                                                            System.Collections.Generic.HashSet <ME.ECS.DataConfigs.DataConfigTemplate> usedComponents,
                                                            VisualElement rootElement,
                                                            VisualElement templatesContainer,
                                                            SerializedProperty source,
                                                            SerializedObject so,
                                                            System.Action <SerializedObject, ME.ECS.DataConfigs.DataConfigTemplate> onAddTemplate,
                                                            System.Action <SerializedObject, ME.ECS.DataConfigs.DataConfigTemplate> onRemoveTemplate)
        {
            var container = new IMGUIContainer(() => {
                GUILayoutExt.DrawManageDataConfigTemplateMenu(usedComponents, (template, isUsed) => {
                    var path = AssetDatabase.GetAssetPath(template);
                    var guid = AssetDatabase.AssetPathToGUID(path);
                    if (string.IsNullOrEmpty(guid) == true)
                    {
                        return;
                    }

                    if (isUsed == true)
                    {
                        var copy          = source.Copy();
                        var i             = 0;
                        var enterChildren = true;
                        while (copy.NextVisible(enterChildren) == true)
                        {
                            enterChildren = false;

                            if (copy.propertyType != SerializedPropertyType.String)
                            {
                                continue;
                            }

                            if (copy.stringValue == guid)
                            {
                                usedComponents.Remove(template);
                                source.DeleteArrayElementAtIndex(i);
                                so.ApplyModifiedProperties();
                                onRemoveTemplate.Invoke(so, template);
                                break;
                            }

                            ++i;
                        }
                    }
                    else
                    {
                        usedComponents.Add(template);
                        onAddTemplate.Invoke(so, template);

                        ++source.arraySize;
                        var elem         = source.GetArrayElementAtIndex(source.arraySize - 1);
                        elem.stringValue = guid;
                        so.ApplyModifiedProperties();
                    }

                    editor.Save();
                    BuildContainer(editor, rootElement, so);
                });
            });

            container.AddToClassList("add-template-menu-button-imgui");

            return(container);
        }
        private void RefreshUI()
        {
            rootVisualElement.Clear();

            VisualElement topRowElement = new VisualElement();

            topRowElement.AddToClassList("svbm-row");
            rootVisualElement.Add(topRowElement);

            Button refreshButton = new Button(RefreshUI)
            {
                name = "Refresh", text = "Refresh"
            };

            refreshButton.AddToClassList("svbm-cell");
            topRowElement.Add(refreshButton);

            Button saveButton = new Button(() => Bookmarks.Instance?.SaveToJson(Bookmarks.path))
            {
                name = "Save", text = "Save"
            };

            saveButton.AddToClassList("svbm-cell");
            topRowElement.Add(saveButton);

            IMGUIContainer header = new IMGUIContainer(OnCustomGUI);

            header.AddToClassList("sceneLightingButton");
            rootVisualElement.Add(header);

            if (Bookmarks.Count == 0)
            {
                return;
            }


            for (int i = 0; i < Bookmarks.Count; i++)
            {
                var index = i;

                VisualElement bookmarkElement = new VisualElement();
                bookmarkElement.AddToClassList("svbm-row");

                Button loadButton = new Button(() => Bookmarks.Instance[index].Load(SceneView.lastActiveSceneView))
                {
                    name = "LOAD", text = "LOAD"
                };
                loadButton.AddToClassList("svbm-cell-button");
                bookmarkElement.Add(loadButton);

                Button updateButton = new Button(() => Bookmarks.Instance[index].Save(SceneView.lastActiveSceneView))
                {
                    name = "UPDATE", text = "UPDATE"
                };
                updateButton.AddToClassList("svbm-cell-button");
                bookmarkElement.Add(updateButton);

                Button deleteButton = new Button(() =>
                {
                    Bookmarks.Instance.viewpoints.RemoveAt(index);
                    RefreshUI();
                })
                {
                    name = "DELETE", text = "DELETE"
                };
                deleteButton.AddToClassList("svbm-cell-button");
                bookmarkElement.Add(deleteButton);

                TextField nameField = new TextField("")
                {
                    tooltip = "Set this bookmark's menu path / name.\nUse '/' to create a submenu."
                };
                nameField.value = Bookmarks.Instance[index].name;
                nameField.AddToClassList("svbm-cell-text");
                nameField.RegisterValueChangedCallback((x) => Bookmarks.Instance[index].name = x.newValue);
                bookmarkElement.Add(nameField);

                MaskField overridesMask = new MaskField(Enum.GetNames(typeof(Viewpoint.Overrides)).ToList(), (int)Bookmarks.Instance[index].overrides)
                {
                    tooltip = "Set this bookmark's Overrides."
                };
                overridesMask.AddToClassList("svbm-cell-mask");
                overridesMask.RegisterValueChangedCallback((x) => Bookmarks.Instance[index].overrides = (Viewpoint.Overrides)x.newValue);
                bookmarkElement.Add(overridesMask);

                Toggle orthoToggle = new Toggle("")
                {
                    tooltip = "Enable to set this bookmark's SceneView to Orthographic."
                };
                orthoToggle.value = Bookmarks.Instance[index].settings.ortho;
                orthoToggle.AddToClassList("svbm-cell-checkbox");
                orthoToggle.RegisterValueChangedCallback((x) => Bookmarks.Instance[index].settings.ortho = x.newValue);
                bookmarkElement.Add(orthoToggle);

                Toggle is2dToggle = new Toggle("")
                {
                    tooltip = "Enable to set this bookmark's SceneView to 2D Mode."
                };
                is2dToggle.value = Bookmarks.Instance[index].settings.is2D;
                is2dToggle.AddToClassList("svbm-cell-checkbox");
                is2dToggle.RegisterValueChangedCallback((x) => Bookmarks.Instance[index].settings.is2D = x.newValue);
                bookmarkElement.Add(is2dToggle);

                FloatField fovField = new FloatField()
                {
                    tooltip = "Set this bookmark's Camera Field of View."
                };
                fovField.value = Bookmarks.Instance[index].settings.fov;
                fovField.AddToClassList("svbm-cell-float");
                fovField.RegisterValueChangedCallback((x) => Bookmarks.Instance[index].settings.fov = Mathf.Clamp(x.newValue, 4, 120));
                bookmarkElement.Add(fovField);

                EnumField cameraModeMask = new EnumField("", Bookmarks.Instance[index].settings.mode.drawMode)
                {
                    tooltip = "Set this bookmark's Camera Shading Mode."
                };
                cameraModeMask.AddToClassList("svbm-cell-mask");
                // Catching cases where SceneView.GetBuiltinCameraMode() will fail on some DrawCameraMode such as Normal and User Defined
                cameraModeMask.RegisterValueChangedCallback((x) => {
                    try
                    {
                        Bookmarks.Instance[index].settings.mode = SceneView.GetBuiltinCameraMode((DrawCameraMode)x.newValue);
                    }
                    catch
                    {
                        cameraModeMask.SetValueWithoutNotify(x.previousValue);
                    }
                });
                bookmarkElement.Add(cameraModeMask);

                Toggle lightingToggle = new Toggle("")
                {
                    tooltip = "Enable this bookmark's SceneView Lighting."
                };
                lightingToggle.value = Bookmarks.Instance[index].settings.sceneLighting;
                lightingToggle.AddToClassList("svbm-cell-checkbox");
                lightingToggle.RegisterValueChangedCallback((x) => Bookmarks.Instance[index].settings.sceneLighting = x.newValue);
                bookmarkElement.Add(lightingToggle);

                MaskField viewStatesMask = new MaskField(SceneViewStatesLabels, (int)Bookmarks.Instance[index].settings.sceneViewState.GetFlags())
                {
                    tooltip = "Set this bookmark's SceneView States."
                };
                viewStatesMask.AddToClassList("svbm-cell-mask");
                viewStatesMask.RegisterValueChangedCallback((x) => Bookmarks.Instance[index].settings.sceneViewState.SetFlags((SceneViewExtensions.SceneViewStateFlags)x.newValue));
                bookmarkElement.Add(viewStatesMask);

                Toggle gridToggle = new Toggle("")
                {
                    tooltip = "Enable this bookmark's SceneView Grid."
                };
                gridToggle.value = Bookmarks.Instance[index].settings.showGrid;
                gridToggle.AddToClassList("svbm-cell-checkbox");
                gridToggle.RegisterValueChangedCallback((x) => Bookmarks.Instance[index].settings.showGrid = x.newValue);
                bookmarkElement.Add(gridToggle);

                Toggle gizmosToggle = new Toggle("")
                {
                    tooltip = "Enable this bookmark's SceneView Gizmos."
                };
                gizmosToggle.value = Bookmarks.Instance[index].settings.drawGizmos;
                gizmosToggle.AddToClassList("svbm-cell-checkbox");
                gizmosToggle.RegisterValueChangedCallback((x) => Bookmarks.Instance[index].settings.drawGizmos = x.newValue);
                bookmarkElement.Add(gizmosToggle);

                LayerMaskField visibleLayerMask = new LayerMaskField("", Bookmarks.Instance[index].visibleLayers)
                {
                    tooltip = "Set this bookmark's Visible Layers."
                };
                visibleLayerMask.AddToClassList("svbm-cell-mask");
                visibleLayerMask.RegisterValueChangedCallback((x) => Bookmarks.Instance[index].visibleLayers = x.newValue);
                bookmarkElement.Add(visibleLayerMask);

                LayerMaskField lockedLayerMask = new LayerMaskField("", Bookmarks.Instance[index].lockedLayers)
                {
                    tooltip = "Set this bookmark's Locked Layers."
                };
                lockedLayerMask.AddToClassList("svbm-cell-mask");
                lockedLayerMask.RegisterValueChangedCallback((x) => Bookmarks.Instance[index].lockedLayers = x.newValue);
                bookmarkElement.Add(lockedLayerMask);

                EnumField shortcutMask = new EnumField("", Bookmarks.Instance[index].shortcut)
                {
                    tooltip = "Set this bookmark's shortcut\nBeware this will override any other function the shortcut is associated with."
                };
                shortcutMask.AddToClassList("svbm-cell-mask");
                shortcutMask.RegisterValueChangedCallback((x) => Bookmarks.Instance[index].shortcut = (KeyCode)x.newValue);
                bookmarkElement.Add(shortcutMask);

                Button moveUpButton = new Button(() =>
                {
                    if (index <= 0)
                    {
                        return;
                    }

                    var item = Bookmarks.Instance.viewpoints[index];
                    Bookmarks.Instance.viewpoints.RemoveAt(index);

                    Bookmarks.Instance.viewpoints.Insert(index - 1, item);
                    RefreshUI();
                })
                {
                    name = "Up", text = "Up"
                };
                moveUpButton.AddToClassList("svbm-cell-button");
                bookmarkElement.Add(moveUpButton);

                Button moveDownButton = new Button(() =>
                {
                    if (index >= Bookmarks.Instance.viewpoints.Count - 1)
                    {
                        return;
                    }

                    var item = Bookmarks.Instance.viewpoints[index];
                    Bookmarks.Instance.viewpoints.RemoveAt(index);

                    Bookmarks.Instance.viewpoints.Insert(index + 1, item);
                    RefreshUI();
                })
                {
                    name = "Down", text = "Dn"
                };
                moveDownButton.AddToClassList("svbm-cell-button");
                bookmarkElement.Add(moveDownButton);

                rootVisualElement.Add(bookmarkElement);
            }
        }