Пример #1
0
        void OnAttachToPanel(AttachToPanelEvent evt)
        {
            m_EditorElement?.Bind(m_WatchedObject);
            (m_EditorElement as PropertyField)?.RemovePropertyFieldValueLabel();

            // TODO: Not surviving domain reload
            if (Store.GetState().EditorDataModel.ShouldExpandElementUponCreation(this))
            {
                Expand();
            }
        }
Пример #2
0
    void SetSelectedObjectData(Object pObject)
    {
        if (pObject == null)
        {
            return;
        }
        string aAssetExtension = pObject.name;

        switch ((AssetMetaData.AssetType)mTypeOfAsset.value)
        {
        case AssetMetaData.AssetType.None:
            return;

        case AssetMetaData.AssetType.TextureAsset:
            aAssetExtension = "Textures/" + aAssetExtension + Path.GetExtension(AssetDatabase.GetAssetPath(pObject));
            break;

        case AssetMetaData.AssetType.AudioAsset:
            aAssetExtension = "Audios/" + aAssetExtension + Path.GetExtension(AssetDatabase.GetAssetPath(pObject));
            break;

        case AssetMetaData.AssetType.FontAsset:
            aAssetExtension = "Fonts/" + aAssetExtension + Path.GetExtension(AssetDatabase.GetAssetPath(pObject));
            break;

        case AssetMetaData.AssetType.PrefabAsset:
            ((GameScriptable)pObject).mIsPrefab = true;
            EditorUtility.SetDirty(pObject);
            aAssetExtension = "Prefabs/" + aAssetExtension + ".json";
            break;
        }
        string[] aAssetFolder = { "Assets/ScriptableObjects/Asset Meta Data" };
        if (!AssetDatabase.IsValidFolder(aAssetFolder[0]))
        {
            AssetDatabase.CreateFolder("Assets/ScriptableObjects", "Asset Meta Data");
        }
        string[] aAssetGUIDs = AssetDatabase.FindAssets(pObject.name, aAssetFolder);
        if (aAssetGUIDs.Length > 0)
        {
            for (int i = 1; i < aAssetGUIDs.Length; i++)
            {
                AssetDatabase.DeleteAsset(AssetDatabase.GUIDToAssetPath(aAssetGUIDs[i]));
            }
            string aPath = AssetDatabase.GUIDToAssetPath(aAssetGUIDs[0]);
            if (AssetDatabase.GetMainAssetTypeAtPath(aPath) == typeof(AssetMetaData))
            {
                mCurrentAssetData = (AssetMetaData)AssetDatabase.LoadAssetAtPath(aPath, typeof(AssetMetaData));
            }
        }

        if (mCurrentAssetData == null)
        {
            mCurrentAssetData = (AssetMetaData)ScriptableObject.CreateInstance(typeof(AssetMetaData));
            mCurrentAssetData.mAssetFilePath = "../Assets/Resources/" + aAssetExtension;
            mCurrentAssetData.mType          = (AssetMetaData.AssetType)mTypeOfAsset.value;
            mCurrentAssetData.mGUID          = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(pObject));
            AssetDatabase.CreateAsset(mCurrentAssetData, aAssetFolder[0] + "/" + pObject.name + ".asset");
        }
        EditorUtility.SetDirty(mCurrentAssetData);
        mObjectData.Bind(new SerializedObject(mCurrentAssetData));
        mAssetEditorData.Add(mObjectData);
    }
Пример #3
0
        public override VisualElement CreateCommandEditorGUI()
        {
            var root = new VisualElement();

            List <Type> compatibleReferenceTypes = new List <Type>
            {
                typeof(IntVariableReference),
                typeof(BoolVariableReference),
                typeof(FloatVariableReference),
                typeof(StringVariableReference),
                typeof(ColorVariableReference),
                typeof(ObjectVariableReference),
                typeof(LayerMaskVariableReference),
                typeof(Vector2VariableReference),
                typeof(Vector3VariableReference),
                typeof(Vector4VariableReference),
                typeof(RectVariableReference),
                typeof(AnimationCurveVariableReference),
                typeof(BoundsVariableReference),
                typeof(GradientVariableReference),
                typeof(QuaternionVariableReference),
                typeof(Vector2IntVariableReference),
                typeof(Vector3IntVariableReference),
                typeof(RectIntVariableReference),
                typeof(BoundsIntVariableReference),
            };

            List <Type> compatibleTypes = compatibleReferenceTypes.Select(t => t.BaseType.GenericTypeArguments[0]).ToList();

            Func <Type, string> formatter = (type) =>
            {
                if (type.IsGenericType)
                {
                    return(type.GetGenericArguments()[0].Name);
                }
                else
                {
                    return(type.Name);
                }
            };

            var typeSelector = new PopupField <Type>(compatibleTypes, 0, formatter, formatter);

            typeSelector.label = "型の変更";
            typeSelector.RegisterCallback <ChangeEvent <Type> >(evt =>
            {
                var type           = compatibleReferenceTypes[compatibleTypes.IndexOf(evt.newValue)];
                var targetProp     = CommandItem.CommandProperty.GetProperty().FindPropertyRelative("target");
                var valueToSetProp = CommandItem.CommandProperty.GetProperty().FindPropertyRelative("value");

                targetProp.managedReferenceValue     = Activator.CreateInstance(type);
                valueToSetProp.managedReferenceValue = Activator.CreateInstance(type);
                targetProp.serializedObject.ApplyModifiedProperties();

                root.Unbind();
                root.Bind(targetProp.serializedObject);
            });

            var defaultType = typeSelector.value;
            var target      = CommandItem.CommandProperty.GetProperty().FindPropertyRelative("target");
            var valueToSet  = CommandItem.CommandProperty.GetProperty().FindPropertyRelative("value");

            root.Add(typeSelector);


            if (target.hasChildren)
            {
                var typeInfo = target.managedReferenceFullTypename.Split(' ');
                if (typeInfo.Length >= 2)
                {
                    var name    = typeInfo[1];
                    var matched = compatibleTypes.FirstOrDefault(t => t.FullName == name);
                    if (matched != default)
                    {
                        typeSelector.value = matched;
                    }
                }
                else
                {
                }
            }

            var targetField = new PropertyField();

            targetField.bindingPath = target.propertyPath;
            var valueToSetField = new PropertyField();

            valueToSetField.bindingPath = valueToSet.propertyPath;

            root.Add(targetField);
            root.Add(valueToSetField);

            root.Bind(target.serializedObject);
            CommandEditorRootElement = root;
            return(root);
        }
Пример #4
0
        public override VisualElement CreatePropertyGUI(SerializedProperty property)
        {
            var root = new VisualElement();

            var target = property.FindPropertyRelative("variable");

            if (target.FindPropertyRelative("key") == null)
            {
                target.managedReferenceValue = new IntVariableReference();
                target.serializedObject.ApplyModifiedProperties();
            }

            List <Type> compatibleTypes = new List <Type>
            {
                typeof(IntVariableReference),
                typeof(BoolVariableReference),
                typeof(FloatVariableReference),
                typeof(StringVariableReference),
                typeof(ColorVariableReference),
                typeof(ObjectVariableReference),
                typeof(LayerMaskVariableReference),
                typeof(Vector2VariableReference),
                typeof(Vector3VariableReference),
                typeof(Vector4VariableReference),
                typeof(RectVariableReference),
                typeof(AnimationCurveVariableReference),
                typeof(BoundsVariableReference),
                typeof(GradientVariableReference),
                typeof(QuaternionVariableReference),
                typeof(Vector2IntVariableReference),
                typeof(Vector3IntVariableReference),
                typeof(RectIntVariableReference),
                typeof(BoundsIntVariableReference),
            };

            Func <Type, string> formatter = (type) =>
            {
                if (type.IsGenericType)
                {
                    return(type.GetGenericArguments()[0].Name);
                }
                else
                {
                    return(type.Name);
                }
            };

            var typeSelector = new PopupField <Type>(compatibleTypes, 0, formatter, formatter);

            typeSelector.label = "型の変更";
            typeSelector.RegisterCallback <ChangeEvent <Type> >(evt =>
            {
                var type       = evt.newValue;
                var targetProp = property.FindPropertyRelative("variable");

                targetProp.managedReferenceValue = Activator.CreateInstance(type);

                targetProp.serializedObject.ApplyModifiedProperties();

                root.Unbind();
                root.Bind(targetProp.serializedObject);
            });

            var defaultType = typeSelector.value;

            root.Add(typeSelector);

            var variableField = new PropertyField(target);

            root.Bind(target.serializedObject);

            root.Add(variableField);
            return(root);
        }
        public override void OnActivate(string searchContext, VisualElement rootElement)
        {
            // This function is called when the user clicks on the MyCustom element in the Settings window.
            _settings    = PvCustomizerSettings.GetOrCreateSettings();
            _srlSettings = new SerializedObject(_settings);
            keywords     = GetSearchKeywordsFromSerializedObject(_srlSettings);

            var tree = Resource.Load <VisualTreeAsset>("UXML/PvCustomizerSettingsProvider_UXML.uxml");

            tree.CloneTree(rootElement);

            #region images

            rootElement.Q(className: "logo").style.backgroundImage =
                new StyleBackground(Resource.Load <Texture2D>("Icons/logo.png"));

            #endregion

            #region list-view

            _rulesListQ = rootElement.Query <ListView>().Name("rulesList");
            ListView rulesList = _rulesListQ.First();
            rulesList.bindItem = (vi, i) =>
            {
                FolderRuleOptionsPanel optionsPanel = vi.Q <FolderRuleOptionsPanel>();
                if (i >= 0 && _settings.Rules.Count > i)
                {
                    optionsPanel.SetEnabled(true);
                    SerializedRule serializedRule = ScriptableObject.CreateInstance <SerializedRule>();
                    serializedRule.rule = _settings.Rules[i];
                    optionsPanel.SetCurrentBound(serializedRule, null);
                }
                else
                {
                    optionsPanel.SetEnabled(false);
                }
            };

            rulesList.makeItem = () =>
            {
                var child = Resource.Load <VisualTreeAsset>("UXML/FolderRuleOptionsPanel_UXML.uxml").CloneTree();
                child.style.paddingTop        = 5;
                child.style.paddingBottom     = 5;
                child.style.borderBottomWidth = 3;
                child.style.borderBottomColor = Color.black;

                var optionsPanel = child.Q <FolderRuleOptionsPanel>();

                optionsPanel.Q <Button>("btn_Reset")?.RemoveFromHierarchy();
                optionsPanel.Q <Button>("btn_Cancel")?.RemoveFromHierarchy();
                optionsPanel.Q <Button>("btn_Apply")?.RemoveFromHierarchy();
                optionsPanel.Q <Button>("btn_Settings")?.RemoveFromHierarchy();
                optionsPanel.Q("tag-holder").RemoveFromHierarchy();

                optionsPanel.OnDelete = () => DeleteRule(child);

                return(child);
            };
            rulesList.style.flexGrow = 1;
            rulesList.Refresh();

            #endregion

            #region tint example + imgui

            _tintExampleContainer = rootElement.Q <IMGUIContainer>("tintExample");
            _tintExampleContainer.onGUIHandler += DrawTintExample;

            #endregion

            rootElement.Bind(_srlSettings);
        }
Пример #6
0
        public override VisualElement CreateInspectorGUI()
        {
            // Update the serializedObject in case it has been changed outside the Inspector.
            serializedObject.Update();

            const string mainMarkup       = "GltfImporter";
            const string reportItemMarkup = "ReportItem";
            const string dependencyMarkup = "Dependency";
            var          root             = new VisualElement();

            var visualTree = Resources.Load(mainMarkup) as VisualTreeAsset;

            visualTree.CloneTree(root);

            var numDeps = m_AssetDependencies.arraySize;

            var maliciousTextureImporters = new List <TextureImporter>();

            var reportItemCount = m_ReportItems.arraySize;

#if !UNITY_ANIMATION
            var animRoot = root.Query <VisualElement>(name: "Animation").First();
            animRoot.SetEnabled(false);
#endif

            var reportRoot = root.Query <VisualElement>(name: "Report").First();

            if (reportItemCount > 0)
            {
                // var reportList = new List<ReportItem>
                var reportItemTree = Resources.Load(reportItemMarkup) as VisualTreeAsset;
                var reportList     = reportRoot.Query <ListView>().First();
                // reportList.bindingPath = nameof(m_ReportItems);
                reportList.makeItem = () => reportItemTree.CloneTree();
                reportList.bindItem = (element, i) => {
                    if (i >= reportItemCount || i >= m_ReportItems.arraySize)
                    {
                        element.style.display = DisplayStyle.None;
                        return;
                    }
                    var msg = element.Q <Label>("Message");

                    var item = m_ReportItems.GetArrayElementAtIndex(i);

                    var typeProp     = item.FindPropertyRelative("type");
                    var codeProp     = item.FindPropertyRelative("code");
                    var messagesProp = item.FindPropertyRelative("messages");

                    var type = (LogType)typeProp.intValue;
                    var code = (LogCode)codeProp.intValue;

                    var icon = element.Q <VisualElement>("Icon");
                    switch (type)
                    {
                    case LogType.Error:
                    case LogType.Assert:
                    case LogType.Exception:
                        icon.RemoveFromClassList("info");
                        icon.AddToClassList("error");
                        break;

                    case LogType.Warning:
                        icon.RemoveFromClassList("info");
                        icon.AddToClassList("warning");
                        break;
                    }

                    var messages       = GetStringValues(messagesProp);
                    var ritem          = new LogItem(type, code, messages);
                    var reportItemText = ritem.ToString();
                    msg.text        = reportItemText;
                    element.tooltip = reportItemText;
                };
            }
            else
            {
                reportRoot.style.display = DisplayStyle.None;
            }

            for (int i = 0; i < numDeps; i++)
            {
                var x             = m_AssetDependencies.GetArrayElementAtIndex(i);
                var assetPathProp = x.FindPropertyRelative("assetPath");

                var typeProp = x.FindPropertyRelative("type");
                var type     = (GltfAssetDependency.Type)typeProp.enumValueIndex;
                if (type == GltfAssetDependency.Type.Texture)
                {
                    var importer = AssetImporter.GetAtPath(assetPathProp.stringValue) as TextureImporter;
                    if (importer != null)
                    {
                        if (importer.textureShape != TextureImporterShape.Texture2D)
                        {
                            maliciousTextureImporters.Add(importer);
                        }
                    }
                }
            }

            if (maliciousTextureImporters.Count > 0)
            {
                var dependencyTree = Resources.Load(dependencyMarkup) as VisualTreeAsset;

                root.Query <Button>("fixall").First().clickable.clicked += () => {
                    AssetDatabase.StartAssetEditing();
                    foreach (var maliciousTextureImporter in maliciousTextureImporters)
                    {
                        FixTextureImportSettings(maliciousTextureImporter);
                    }
                    AssetDatabase.StopAssetEditing();
                    Repaint();
                };

                var foldout = root.Query <Foldout>().First();
                // var row = root.Query<VisualElement>(className: "fix-texture-row").First();
                foreach (var maliciousTextureImporter in maliciousTextureImporters)
                {
                    var row = dependencyTree.CloneTree();
                    foldout.Add(row);
                    // textureRowTree.CloneTree(foldout);
                    var path = AssetDatabase.GetAssetPath(maliciousTextureImporter);
                    row.Query <Label>().First().text = Path.GetFileName(path);
                    row.Query <Button>().First().clickable.clicked += () => {
                        FixTextureImportSettings(maliciousTextureImporter);
                        row.style.display = DisplayStyle.None;
                    };
                }
            }
            else
            {
                var depRoot = root.Query <VisualElement>("Dependencies").First();
                depRoot.style.display = DisplayStyle.None;
            }

            root.Bind(serializedObject);

            // Apply the changes so Undo/Redo is working
            serializedObject.ApplyModifiedProperties();

            root.Add(new IMGUIContainer(ApplyRevertGUI));

            return(root);
        }
Пример #7
0
    private void UpdateOnObjectSelection(ChangeEvent <UnityEngine.Object> evt)
    {
        ObjectNameTextField.value = null;
        objectEditSelectionContainer.Clear();
        if (ve != null)
        {
            ve.Clear();
        }
        if (objectSelectionField.value != null)
        {
            ScriptableObject selection = (ScriptableObject)objectSelectionField.value;
            var serializedObject       = new SerializedObject(selection);
            if (serializedObject == null)
            {
                return;
            }

            string typeOfObject = selection.GetType().ToString();
            switch (typeOfObject)
            {
            case "SpriteObject":
                #region
                var spriteVisualTree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>("Assets/Editor/ObjectTypeEditors/SpriteDrawer.uxml");
                ve = spriteVisualTree.CloneTree();

                ve.style.height       = 500;
                ve.style.alignContent = Align.Center;
                ve.style.paddingTop   = 50;

                ObjectField SpriteSpriteSelection = ve.Q <ObjectField>("SpriteImageObjectSelectionField");
                SpriteSpriteSelection.objectType = typeof(Sprite);

                objectEditSelectionContainer.Add(ve);
                ve.Bind(serializedObject);
                break;

                #endregion
            case "EnvironmentObject":
                #region
                var environemntVisualTree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>("Assets/Editor/ObjectTypeEditors/EnvironmentDrawer.uxml");
                ve = environemntVisualTree.CloneTree();

                ve.style.height       = 500;
                ve.style.alignContent = Align.Center;
                ve.style.paddingTop   = 50;

                ObjectField EnvironementSpriteSelection = ve.Q <ObjectField>("SpriteImageObjectSelectionField");
                EnvironementSpriteSelection.objectType = typeof(SpriteObject);

                ObjectField ColliderSelection = ve.Q <ObjectField>("SpriteColliderObjectSelectionField");
                ColliderSelection.objectType = typeof(ColliderObject);

                objectEditSelectionContainer.Add(ve);
                ve.Bind(serializedObject);
                break;

                #endregion
            case "StaticObject":
                #region
                var staticObjectVisualTree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>("Assets/Editor/ObjectTypeEditors/StaticObjectDrawer.uxml");
                ve = staticObjectVisualTree.CloneTree();

                ve.style.height       = 500;
                ve.style.alignContent = Align.Center;
                ve.style.paddingTop   = 50;

                ObjectField StaticObjectSpriteSelection = ve.Q <ObjectField>("SpriteImageObjectSelectionField");
                StaticObjectSpriteSelection.objectType = typeof(SpriteObject);

                ObjectField StaticObjectColliderSelection = ve.Q <ObjectField>("SpriteColliderObjectSelectionField");
                StaticObjectColliderSelection.objectType = typeof(ColliderObject);

                objectEditSelectionContainer.Add(ve);
                ve.Bind(serializedObject);
                break;

                #endregion
            case "AnimationObject":
                #region
                var animaitonVisualTree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>("Assets/Editor/ObjectTypeEditors/AnimationObjectDrawer.uxml");
                ve = animaitonVisualTree.CloneTree();

                ve.style.height       = 500;
                ve.style.alignContent = Align.Center;
                ve.style.paddingTop   = 50;

                ListView AnimationSpriteSelection = ve.Q <ListView>("AnimationSpriteObjectSelectionField");
                //AnimationSpriteSelection.objectType = typeof(Sprite);

                objectEditSelectionContainer.Add(ve);
                ve.Bind(serializedObject);
                break;

                #endregion
            case "EnemyObject":
                #region
                var enemyObjectVisualTree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>("Assets/Editor/ObjectTypeEditors/EnemyDrawer.uxml");
                ve = enemyObjectVisualTree.CloneTree();

                ve.style.height       = 500;
                ve.style.alignContent = Align.Center;
                ve.style.paddingTop   = 50;

                ObjectField EnemyObjectSpriteSelection = ve.Q <ObjectField>("EnemySpriteObjectSelectionField");
                EnemyObjectSpriteSelection.objectType = typeof(SpriteObject);

                FloatField EnemyHealthField = ve.Q <FloatField>("EnemyObjectHealthField");
                FloatField EnemyAttackField = ve.Q <FloatField>("EnemyObjectAttackField");

                ObjectField EnemyObjectColliderSelection = ve.Q <ObjectField>("EnemyColliderObjectSelectionField");
                EnemyObjectColliderSelection.objectType = typeof(CircleColliderObject);

                objectEditSelectionContainer.Add(ve);
                ve.Bind(serializedObject);
                break;

                #endregion
            case "EnemySpawnerObject":
                #region
                var enemySpawnerObjectVisualTree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>("Assets/Editor/ObjectTypeEditors/EnemySpawnerDrawer.uxml");
                ve = enemySpawnerObjectVisualTree.CloneTree();

                ve.style.height       = 500;
                ve.style.alignContent = Align.Center;
                ve.style.paddingTop   = 50;

                ObjectField EnemySpawnerObjectSpriteSelection = ve.Q <ObjectField>("EnemySpawnerSpriteObjectSelectionField");
                EnemySpawnerObjectSpriteSelection.objectType = typeof(SpriteObject);

                FloatField EnemySpawnerTimeField = ve.Q <FloatField>("EnemySpawnTimeField");

                ObjectField EnemySpawnerenemySelection = ve.Q <ObjectField>("EnemyObjectSelectionField");
                EnemySpawnerenemySelection.objectType = typeof(EnemyObject);
                ObjectField EnemySpawnerObjectColliderSelection = ve.Q <ObjectField>("SpawnerColliderObjectSelectionField");
                EnemySpawnerObjectColliderSelection.objectType = typeof(CircleColliderObject);

                objectEditSelectionContainer.Add(ve);
                ve.Bind(serializedObject);
                break;

                #endregion
            //case "Player":
            //    break;
            case "PolygonColliderObject":
                #region
                var polyColliderObjectVisualTree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>("Assets/Editor/ObjectTypeEditors/PolygonColliderDrawer.uxml");
                ve = polyColliderObjectVisualTree.CloneTree();

                ve.style.height       = 500;
                ve.style.alignContent = Align.Center;
                ve.style.paddingTop   = 50;

                FloatField PolyColliderHeightField     = ve.Q <FloatField>("PolygonColliderHeightField");
                FloatField PolyColliderWidthField      = ve.Q <FloatField>("PolygonColliderWidthField");
                Toggle     PolyColliderIsTriggerToggle = ve.Q <Toggle>("PolygonColliderSetTrigger");

                objectEditSelectionContainer.Add(ve);
                ve.Bind(serializedObject);
                break;

                #endregion
            case "CircleColliderObject":
                #region
                var cirColliderObjectVisualTree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>("Assets/Editor/ObjectTypeEditors/CircleColliderDrawer.uxml");
                ve = cirColliderObjectVisualTree.CloneTree();

                ve.style.height       = 500;
                ve.style.alignContent = Align.Center;
                ve.style.paddingTop   = 50;

                FloatField CircleColliderHeightField     = ve.Q <FloatField>("CircleColliderRadiusField");
                Toggle     CircleColliderIsTriggerToggle = ve.Q <Toggle>("CircleColliderSetTrigger");

                objectEditSelectionContainer.Add(ve);
                ve.Bind(serializedObject);
                break;

                #endregion
            case "ProjectileObject":
                #region
                var projectileObjectVisualTree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>("Assets/Editor/ObjectTypeEditors/ProjectileObjectDrawer.uxml");
                ve = projectileObjectVisualTree.CloneTree();

                ve.style.height       = 500;
                ve.style.alignContent = Align.Center;
                ve.style.paddingTop   = 50;

                ObjectField ProjectileObjectSpriteSelection = ve.Q <ObjectField>("ProjectileSpriteObjectSelectionField");
                ProjectileObjectSpriteSelection.objectType = typeof(SpriteObject);

                FloatField ProjectileSpeedField = ve.Q <FloatField>("ProjectileSpeedField");

                ObjectField ProjectileObjectColliderSelection = ve.Q <ObjectField>("ProjectileColliderObjectSelectionField");
                ProjectileObjectColliderSelection.objectType = typeof(CircleColliderObject);

                objectEditSelectionContainer.Add(ve);
                ve.Bind(serializedObject);
                break;

                #endregion
            case "PlayerObject":
                #region
                var playerObjectVisualTree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>("Assets/Editor/ObjectTypeEditors/PlayerDrawer.uxml");
                ve = playerObjectVisualTree.CloneTree();

                ve.style.height       = 500;
                ve.style.alignContent = Align.Center;
                ve.style.paddingTop   = 50;

                ObjectField PlayerObjectSpriteSelection = ve.Q <ObjectField>("PlayerSpriteObjectSelectionField");
                PlayerObjectSpriteSelection.objectType = typeof(SpriteObject);

                FloatField PlayerHealthField = ve.Q <FloatField>("PlayerObjectHealthField");
                FloatField PlayerAttackField = ve.Q <FloatField>("PlayerObjectAttackField");
                FloatField PlayerSpeedField  = ve.Q <FloatField>("PlayerObjectSpeedField");

                ObjectField PlayerObjectProjectileSelection = ve.Q <ObjectField>("PlayerProjectileObjectSelectionField");
                PlayerObjectProjectileSelection.objectType = typeof(ProjectileObject);
                ObjectField PlayerObjectColliderSelection = ve.Q <ObjectField>("PlayerColliderObjectSelectionField");
                PlayerObjectColliderSelection.objectType = typeof(CircleColliderObject);

                objectEditSelectionContainer.Add(ve);
                ve.Bind(serializedObject);
                break;
                #endregion
            }
        }
    }
Пример #8
0
        private void BuildCommandEditor(VisualElement root)
        {
            var commandProp = CommandItem.CommandProperty.GetProperty();


            //DialogShowMessageSettings
            var settingsProp = commandProp.FindPropertyRelative("settings");

            var    settingsTypeInfo = settingsProp.managedReferenceFullTypename.Split(' ');
            string settingsTypeName = "";

            if (settingsTypeInfo.Length >= 2)
            {
                settingsTypeName = settingsTypeInfo[1];
            }
            else
            {
                //Settingsが未設定(null)

                object settingsInstance;

                //直前に使用したSettingsを使用する
                if (EditorPrefs.HasKey(EditorPrefsDefaultSettingsTypeNameKey))
                {
                    var defaultSettingsTypeName = EditorPrefs.GetString(EditorPrefsDefaultSettingsTypeNameKey);
                    var settingsType            = Type.GetType(defaultSettingsTypeName);
                    if (settingsType == null)
                    {
                        settingsType = typeof(DialogShowMessageSettings);
                    }

                    settingsInstance = Activator.CreateInstance(settingsType);
                }
                else
                {
                    settingsInstance = new DialogShowMessageSettings();
                }

                settingsProp.managedReferenceValue = settingsInstance;
                settingsProp.serializedObject.ApplyModifiedProperties();

                settingsTypeName = settingsInstance.GetType().FullName;
            }

            var settingsField = new VisualElement();

            var settingsButton = new Button();

            settingsButton.text = settingsTypeName.Split('.').Last();
            settingsButton.clickable.clicked += () => SettingsTypeMenu(settingsButton, settingsField);

            var settingsTypeBox = new VisualElement();

            settingsTypeBox.style.flexDirection = new StyleEnum <FlexDirection>(FlexDirection.Row);
            settingsTypeBox.Add(new Label("Settings Type"));
            settingsTypeBox.Add(settingsButton);

            root.Add(settingsTypeBox);

            UpdateSettingsField(settingsField);

            root.Add(settingsField);

            root.Bind(CommandItem.CommandProperty.SerializedObject);
        }
Пример #9
0
        public NoiseEditorView(NoiseSettings _noiseUpdateTarget_ = null, NoiseSettings _sourceAsset_ = null)
        {
            // create temp noisesettings asset and the IMGUI view for this window
            m_noiseUpdateTarget = _noiseUpdateTarget_ == null?ScriptableObject.CreateInstance <NoiseSettings>() : _noiseUpdateTarget_;

            m_serializedNoiseProfile = new SerializedObject(m_noiseUpdateTarget);
            m_noiseGUI = new NoiseSettingsGUI();
            m_noiseGUI.Init(m_noiseUpdateTarget);

            m_noiseSourceAsset = _sourceAsset_;

            var stylesheet = EditorGUIUtility.isProSkin ?
                             Resources.Load <StyleSheet>("Styles/Noise_Dark") :
                             Resources.Load <StyleSheet>("Styles/Noise_Light");

            var settingsScrollView = new ScrollView()
            {
                name = Styles.settingsScrollViewName
            };

            ///////////////////////////////////////////////////////////////////////////////
            // settings buttons
            ///////////////////////////////////////////////////////////////////////////////

            var noiseGUIContainer = new IMGUIContainer()
            {
                name = Styles.noiseGUIContainerName
            };

            noiseGUIContainer.onGUIHandler = () =>
            {
                EditorGUI.BeginChangeCheck();
                {
                    m_noiseGUI.OnGUI(NoiseSettingsGUIFlags.All & (~NoiseSettingsGUIFlags.Preview));
                }
                bool changed = EditorGUI.EndChangeCheck();

                if (changed)
                {
                    INTERNAL_OnSettingsChanged();
                }
            };
            settingsScrollView.Add(noiseGUIContainer);

            ///////////////////////////////////////////////////////////////////////////////
            // settings buttons
            ///////////////////////////////////////////////////////////////////////////////

            filePanelContainer = new VisualElement()
            {
                name  = Styles.saveButtonsContainer,
                style =
                {
                    flexDirection = FlexDirection.Row
                }
            };
            filePanelContainer.AddToClassList(Styles.filePanelContainer);

            saveAsButton = new Button(SaveAsCallback)
            {
                name    = Styles.saveAsButtonName,
                text    = "Save As",
                tooltip = Styles.saveasTooltip
            };
            saveAsButton.AddToClassList(Styles.filePanelButton);

            revertButton = new Button(ResetRevertCallback)
            {
                name    = Styles.resetButtonName,
                text    = "Reset",
                tooltip = Styles.resetTooltip
            };
            revertButton.AddToClassList(Styles.filePanelButton);

            applyButton = new Button(() => { Undo.RecordObject(m_noiseSourceAsset, "NoiseWindow - Apply Settings"); m_noiseSourceAsset.CopySerialized(m_noiseUpdateTarget); })
            {
                name    = Styles.applyButtonName,
                text    = "Apply",
                tooltip = Styles.applyTooltip
            };
            applyButton.AddToClassList(Styles.filePanelButton);
            applyButton.AddToClassList(Styles.filePanelButton);

            ///////////////////////////////////////////////////////////////////////////////
            // noise settings object field
            ///////////////////////////////////////////////////////////////////////////////

            var objectFieldContainer = new VisualElement()
            {
                name = Styles.objectFieldContainer
            };

            objectFieldContainer.AddToClassList(Styles.objectFieldContainer);

            objectField = new ObjectField()
            {
                name = Styles.noiseAssetFieldName,
                allowSceneObjects = false,
                objectType        = typeof(NoiseSettings),
                label             = Styles.noiseAssetFieldLabel,
                tooltip           = Styles.noiseAssetFieldTooltip //,
                                                                  // viewDataKey = Styles.noiseAssetFieldName
            };
            objectField.AddToClassList(Styles.noiseAssetFieldName);
            objectField.RegisterCallback <ChangeEvent <UnityEngine.Object> >(OnSourceProfileChanged);

            objectFieldContainer.Add(objectField);

            ///////////////////////////////////////////////////////////////////////////////
            // export settings
            ///////////////////////////////////////////////////////////////////////////////

            var flexArea = new VisualElement()
            {
                name = Styles.flexArea
            };

            flexArea.AddToClassList(Styles.flexArea);

            var exportContainer = new VisualElement()
            {
                name = Styles.exportContainer
            };

            exportContainer.AddToClassList(Styles.exportContainer);

            var exportHeader = new Foldout()
            {
                name        = Styles.exportHeader,
                text        = "Export Settings",
                tooltip     = Styles.exportTooltip,
                viewDataKey = Styles.exportHeader
            };

            exportHeader.RegisterCallback <ChangeEvent <bool> >(
                (evt) =>
            {
                if (evt.newValue)
                {
                    m_exportContainer.Add(m_exportSettings);
                    m_exportContainer.Add(m_exportButton);
                }
                else
                {
                    m_exportContainer.Remove(m_exportSettings);
                    m_exportContainer.Remove(m_exportButton);
                }
            }
                );
            exportHeader.AddToClassList(Styles.foldoutContainer);

            var exportSettings = CreateExportSettingsView();

            var exportButton = new Button(
                () =>
            {
                if (m_exportType.value == ExportTextureType.Texture2D)
                {
                    Export2D();
                }
                else if (m_exportType.value == ExportTextureType.Texture3D)
                {
                    Export3D();
                }
            }
                )
            {
                name = Styles.exportButton,
                text = "Export To Texture"
            };

            exportButton.AddToClassList(Styles.exportButton);

            m_exportButton = exportButton;
            exportContainer.Add(exportHeader);
            // exportContainer.Add( exportSettings );
            // exportContainer.Add( exportButton );

            m_exportContainer  = exportContainer;
            exportHeader.value = false;

            // container for the settings panel
            var settingsContainer = new VisualElement()
            {
                name = Styles.settingsContainerName
            };

            settingsContainer.AddToClassList(Styles.settingsContainerName);
            settingsContainer.Add(objectFieldContainer);
            settingsContainer.Add(filePanelContainer);
            settingsContainer.Add(settingsScrollView);
            settingsContainer.Add(flexArea);   // add this so the export stuff stays at the bottom of the settings container
            settingsContainer.Add(exportContainer);
            settingsContainer.Bind(m_serializedNoiseProfile);

            ///////////////////////////////////////////////////////////////////////////////
            // settings buttons
            ///////////////////////////////////////////////////////////////////////////////

            var previewContainer = new VisualElement()
            {
                name = Styles.noisePreviewContainerName
            };

            previewContainer.AddToClassList(Styles.noisePreviewContainerName);

            var previewLabel = new Label()
            {
                name    = Styles.noisePreviewLabelName,
                text    = Styles.previewLabel,
                tooltip = Styles.previewLabelTooltip
            };

            previewLabel.AddToClassList(Styles.noisePreviewLabelName);
            previewContainer.Add(previewLabel);

            m_noiseFieldView = new NoiseFieldView(m_serializedNoiseProfile)
            {
                name = Styles.noisePreviewTextureName
            };
            m_noiseFieldView.onGUIHandler += () =>
            {
                INTERNAL_OnSettingsChanged();
            };
            m_noiseFieldView.AddToClassList(Styles.noisePreviewTextureName);
            previewContainer.Add(m_noiseFieldView);

            ///////////////////////////////////////////////////////////////////////////////
            // wrap it all up
            ///////////////////////////////////////////////////////////////////////////////

            styleSheets.Add(stylesheet);
            AddToClassList(Styles.noiseWindowName);
            Add(settingsContainer);
            Add(previewContainer);

            this.Bind(m_serializedNoiseProfile);

            m_settingsContainer = settingsContainer;

            INTERNAL_OnSourceProfileChanged(_sourceAsset_);

            this.viewDataKey = Styles.noiseWindowName;
        }
Пример #10
0
        public override VisualElement CreatePropertyGUI(SerializedProperty property)
        {
            // Create property container element.
            rootContainer = new VisualElement
            {
                style =
                {
                    paddingTop        =           5,
                    paddingBottom     =           5,
                    paddingLeft       =           5,
                    paddingRight      =           5,
                    marginBottom      =          10,
                    marginTop         =          10,
                    borderBottomWidth =           1,
                    borderLeftWidth   =           1,
                    borderRightWidth  =           1,
                    borderTopWidth    =           1,
#if UNITY_2019_3_OR_NEWER
                    borderBottomColor = Color.black,
                    borderLeftColor   = Color.black,
                    borderRightColor  = Color.black,
                    borderTopColor    = Color.black,
#else
                    borderColor       = Color.black,
#endif
                    backgroundColor   = new Color(0,0, 0, 0.1f)
                }
            };

            rootContainer.Bind(property.serializedObject);

            // Create property fields.
            pDataContext = property.FindPropertyRelative("dataContext");
            pComponent   = property.FindPropertyRelative("component");
            pProperty    = property.FindPropertyRelative("property");

            rootContainer.Add(new Label(property.displayName));

            //Data Context Field is always available
            var dataContextField = new ObjectField("Object")
            {
                objectType  = typeof(Object),
                bindingPath = pDataContext.propertyPath
            };

            dataContextField.SetValueWithoutNotify(pDataContext.objectReferenceValue);

            rootContainer.Add(dataContextField);

            UpdateSelectableComponents(pDataContext.objectReferenceValue);
            UpdateSelectableProperties();

            dataContextField.RegisterCallback <ChangeEvent <Object> >(evt =>
            {
                pDataContext.objectReferenceValue = evt.newValue;

                //Clear component when a new data context is set
                pComponent.objectReferenceValue = null;
                pProperty.stringValue           = string.Empty;
                //Update components and properties
                UpdateSelectableComponents(evt.newValue);
                UpdateSelectableProperties();
            });

            return(rootContainer);
        }
    void CreateConfigIns(EnemyConfig data, bool isNewData = false)
    {
        SerializedObject serializedObject = new SerializedObject(data);

        //Clone to create new VisualElement from VisualTreeAssets
        VisualElement configUI = enemyConfigAsset.CloneTree();

        //Query to get Container Element By Id
        VisualElement container = configUI.Q <VisualElement>("Container");

        //Get property of EnemyCOnfig
        var property = serializedObject.GetIterator().Copy();

        while (property.NextVisible(true))
        {
            if (property.name.Equals("id") ||
                property.displayName.Equals("Script"))
            {
                continue;
            }

            //Create property Field and Bind Propery to property field
            PropertyField propertyField = new PropertyField(property, property.displayName);
            propertyField.focusable = true;

            container.Add(propertyField);
        }

        //Bind visual element to object
        configUI.Bind(serializedObject);

        this.scrollViewContent.Add(configUI);
        configUI.MarkDirtyRepaint();
        dataMap.Add(configUI, data);
        firstChild = configUI;
        hasResize  = false;

        EnemyConfig refData   = data;
        Button      btnDelete = configUI.Q <Button>("btnDelete");

        btnDelete.clicked += () =>
        {
            GameConfig.Instance.enemyConfigs.Remove(refData);
            AssetDatabase.RemoveObjectFromAsset(data);
            AssetDatabase.SaveAssets();
            this.scrollViewContent.Remove(configUI);
            this.AdjustContentSize(configUI.layout.size);
            this.dataMap.Remove(configUI);
        };

        Button btnClone = configUI.Q <Button>("btnClone");

        btnClone.clicked += () =>
        {
            var newClone = refData.Clone();
            GameConfig.Instance.enemyConfigs.Add(newClone);
            CreateConfigIns(newClone, true);
        };

        if (isNewData)
        {
            AssetDatabase.AddObjectToAsset(data, GameConfig.Instance);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
    }
Пример #12
0
        private static void UpdatePropertyGUI(SerializedProperty property, VisualElement root)
        {
            root.Clear();

            List <Type> compatibleTypes = new List <Type>
            {
                typeof(IntVariableReference),
                typeof(BoolVariableReference),
                typeof(FloatVariableReference),
                typeof(StringVariableReference),
                typeof(ColorVariableReference),
                typeof(ObjectVariableReference),
                typeof(LayerMaskVariableReference),
                typeof(Vector2VariableReference),
                typeof(Vector3VariableReference),
                typeof(Vector4VariableReference),
                typeof(RectVariableReference),
                typeof(AnimationCurveVariableReference),
                typeof(BoundsVariableReference),
                typeof(GradientVariableReference),
                typeof(QuaternionVariableReference),
                typeof(Vector2IntVariableReference),
                typeof(Vector3IntVariableReference),
                typeof(RectIntVariableReference),
                typeof(BoundsIntVariableReference),
            };



            Func <Type, string> formatter = (type) =>
            {
                if (type.BaseType.IsGenericType)
                {
                    return(type.BaseType.GetGenericArguments()[0].Name);
                }
                else
                {
                    return(type.Name);
                }
            };

            var typeSelector = new PopupField <Type>(compatibleTypes, 0, formatter, formatter);

            typeSelector.label = "タイプ";

            var typeInfo = property.managedReferenceFullTypename.Split(' ');

            if (typeInfo.Length >= 2)
            {
                var matched = compatibleTypes.FirstOrDefault(t => t.FullName == typeInfo[1]);
                if (matched != default)
                {
                    typeSelector.value = matched;
                }
            }

            root.Add(typeSelector);

            if (string.IsNullOrEmpty(property.managedReferenceFullTypename))
            {
                property.managedReferenceValue = new IntVariableReference();
                property.serializedObject.ApplyModifiedProperties();
            }

            var targetTypeProp = property.FindPropertyRelative("storeType");

            var targetType = targetTypeProp.enumDisplayNames[targetTypeProp.enumValueIndex];

            var typeToggle = new PropertyField(targetTypeProp, "ストア");

            root.Add(typeToggle);

            switch (targetType)
            {
            case "Constant":
                var constantField = new PropertyField(property.FindPropertyRelative("constantValue"), "定数値");
                root.Add(constantField);
                break;

            default:
                var targetKey = property.FindPropertyRelative("key");
                var keyField  = new PropertyField(targetKey, "キー");
                root.Add(keyField);
                break;
            }

            root.Bind(property.serializedObject);

            typeSelector.RegisterCallback <ChangeEvent <Type> >(evt =>
            {
                var type = evt.newValue;

                property.managedReferenceValue = Activator.CreateInstance(type);
                property.serializedObject.ApplyModifiedProperties();
                UpdatePropertyGUI(property, root);
            });
            typeToggle.RegisterCallback <ChangeEvent <string> >(evt => { UpdatePropertyGUI(property, root); });
        }