Beispiel #1
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            EditorGUILayout.HelpBox("After finished editing, Use 'File > Save Project' to reimport all LDtk projects that use this tile", MessageType.None);

            LDtkEditorGUIUtility.DrawDivider();

            SerializedProperty colliderTypeProp = DrawProp(LDtkIntGridTile.PROP_COLLIDER_TYPE, _colliderLabel);

            if (colliderTypeProp.enumValueIndex == (int)Tile.ColliderType.Sprite)
            {
                SerializedProperty physicsSpriteProp = DrawProp(LDtkIntGridTile.PROP_CUSTOM_PHYSICS_SPRITE, _spriteLabel);
                if (physicsSpriteProp.objectReferenceValue != null)
                {
                    DrawCollisionShape((Sprite)physicsSpriteProp.objectReferenceValue);
                }
            }

            LDtkEditorGUIUtility.DrawDivider();

            SerializedProperty gameObjectProp = DrawProp(LDtkIntGridTile.PROP_GAME_OBJECT, _gameObjectLabel);

            if (gameObjectProp.objectReferenceValue != null)
            {
                DrawGameObjectPreview((GameObject)gameObjectProp.objectReferenceValue);
            }

            serializedObject.ApplyModifiedProperties();
        }
        private void ShowGUI()
        {
            EditorGUIUtility.SetIconSize(Vector2.one * 16);

            if (!AssignJsonField() || _data == null)
            {
                return;
            }

            Definitions defs = _data.Defs;

            DrawField(PixelsPerUnit, LDtkProjectImporter.PIXELS_PER_UNIT);

            //draw the sprite atlas only if we have tiles to pack essentially
            if (!_data.Defs.Tilesets.IsNullOrEmpty())
            {
                DrawField(Atlas, LDtkProjectImporter.ATLAS);
            }

            DrawField(DeparentInRuntime, LDtkProjectImporter.DEPARENT_IN_RUNTIME);
            DrawField(LogBuildTimes, LDtkProjectImporter.LOG_BUILD_TIMES);

            if (!_data.Defs.IntGridLayers.IsNullOrEmpty())
            {
                DrawField(IntGridVisible, LDtkProjectImporter.INTGRID_VISIBLE);
            }

            _sectionIntGrids.Draw(defs.IntGridLayers);
            _sectionEntities.Draw(defs.Entities);
            _sectionEnums.Draw(defs.Enums);

            LDtkEditorGUIUtility.DrawDivider();
        }
Beispiel #3
0
        private Rect GetFrame(int size)
        {
            Rect fieldArea = EditorGUILayout.GetControlRect(false, size);

            fieldArea.width = size;
            fieldArea.x    += LDtkEditorGUIUtility.LabelWidth(fieldArea.width) + 2;
            return(fieldArea);
        }
Beispiel #4
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            using (new EditorGUILayout.HorizontalScope())
            {
                EditorGUILayout.HelpBox("After finished editing, Save Project to reimport all LDtk projects that use this tile", MessageType.None);

                GUIContent saveButtonLabel = new GUIContent
                {
                    tooltip = "Save Project",
                    image   = LDtkIconUtility.GetUnityIcon("SaveAs", "")
                };
                if (GUILayout.Button(saveButtonLabel, GUILayout.Width(30), GUILayout.ExpandHeight(true)))
                {
                    AssetDatabase.SaveAssets();
                }
            }

            LDtkEditorGUIUtility.DrawDivider();

            serializedObject.DrawField(LDtkIntGridTile.PROPERTY_TAG, _tagLabel);
            serializedObject.DrawField(LDtkIntGridTile.PROPERTY_LAYERMASK, _layerMaskLabel);
            serializedObject.DrawField(LDtkIntGridTile.PROPERTY_PHYSICS_MATERIAL, _physicsMaterialLabel);

            LDtkEditorGUIUtility.DrawDivider();

            SerializedProperty colliderTypeProp = serializedObject.DrawField(LDtkIntGridTile.PROPERTY_COLLIDER_TYPE, _colliderLabel);

            if (colliderTypeProp.enumValueIndex == (int)Tile.ColliderType.Sprite || serializedObject.isEditingMultipleObjects)
            {
                SerializedProperty physicsSpriteProp = serializedObject.DrawField(LDtkIntGridTile.PROPERTY_CUSTOM_PHYSICS_SPRITE, _spriteLabel);
                if (physicsSpriteProp.objectReferenceValue != null && !serializedObject.isEditingMultipleObjects)
                {
                    DrawCollisionShape((Sprite)physicsSpriteProp.objectReferenceValue);
                }
            }

            LDtkEditorGUIUtility.DrawDivider();

            SerializedProperty gameObjectProp = serializedObject.DrawField(LDtkIntGridTile.PROPERTY_GAME_OBJECT, _gameObjectLabel);

            LDtkSectionDrawer.DenyPotentialResursiveGameObjects(gameObjectProp);

            if (gameObjectProp.objectReferenceValue != null && !serializedObject.isEditingMultipleObjects)
            {
                DrawGameObjectPreview((GameObject)gameObjectProp.objectReferenceValue);
            }

            serializedObject.ApplyModifiedProperties();
        }
Beispiel #5
0
        public void DrawInternal(T[] datas)
        {
            HasResizedArrayPropThisUpdate = false;
            int arraySize = GetSizeOfArray(datas);

            //don't draw if there is no data for this project relating to this
            if (arraySize == 0 && Selection.objects.Length == 1)
            {
                return;
            }

            LDtkEditorGUIUtility.DrawDivider();
            Rect controlRect = EditorGUILayout.GetControlRect();

            DrawFoldoutArea(controlRect);

            //don't process any data or resize arrays when we have multi-selections; references will break because of how dynamic the arrays can be.
            if (Selection.objects.Length > 1 && !SupportsMultipleSelection)
            {
                EditorGUILayout.HelpBox($"Multi-object editing not supported for {GuiText}.", MessageType.None);
                return;
            }

            if (arraySize > 0)
            {
                if (ArrayProp != null)
                {
                    if (ArrayProp.arraySize != arraySize)
                    {
                        ArrayProp.arraySize           = arraySize;
                        HasResizedArrayPropThisUpdate = true;
                    }
                }
            }

            List <LDtkContentDrawer <T> > drawers = new List <LDtkContentDrawer <T> >();

            GetDrawers(datas, drawers);
            Drawers = drawers.ToArray();

            if (_dropdown)
            {
                DrawDropdownContent(datas);
            }
            else if (HasProblem)
            {
                DrawSectionProblem(controlRect);
            }
        }
        public override void OnInspectorGUI()
        {
            SerializedProperty spritesProp = serializedObject.FindProperty(LDtkArtifactAssets.PROP_SPRITE_LIST);
            SerializedProperty tilesProp   = serializedObject.FindProperty(LDtkArtifactAssets.PROP_TILE_LIST);

            if (spritesProp == null || tilesProp == null)
            {
                Debug.LogError("Drawing error");
                return;
            }

            DrawSection(spritesProp, "Sprite");
            LDtkEditorGUIUtility.DrawDivider();
            DrawSection(tilesProp, "Tile");
        }
Beispiel #7
0
        private static void DrawIconInternal(Vector2 pos, string iconName, string tooltipText, TextAnchor anchor)
        {
            const float dimension = 16;
            Vector2     size      = new Vector2(dimension, dimension);
            Rect        rect      = new Rect(pos, size);

            rect = LDtkEditorGUIUtility.ChangePositionBasedOnAnchor(rect, anchor);

            Texture2D tex = (Texture2D)EditorGUIUtility.IconContent(iconName).image;

            GUIContent content = new GUIContent("", null, tooltipText);

            GUI.Label(rect, content);
            GUI.DrawTexture(rect, tex);
        }
Beispiel #8
0
        public override void OnInspectorGUI()
        {
            TryCacheJson();

            if (JsonData == null)
            {
                Assert.AreNotEqual(JsonData, default);
                return;
            }

            using (new LDtkGUIEnabledScope(true))
            {
                DrawBox();
                LDtkEditorGUIUtility.DrawDivider();
                DrawInspectorGUI();
                LDtkEditorGUIUtility.DrawDivider();
                Tree?.OnGUI();
            }
        }
        public override void OnInspectorGUI()
        {
            SerializedProperty spritesProp     = serializedObject.FindProperty(LDtkArtifactAssets.PROPERTY_SPRITE_LIST);
            SerializedProperty tilesProp       = serializedObject.FindProperty(LDtkArtifactAssets.PROPERTY_TILE_LIST);
            SerializedProperty backgroundsProp = serializedObject.FindProperty(LDtkArtifactAssets.PROPERTY_BACKGROUND_LIST);

            if (spritesProp == null || tilesProp == null || backgroundsProp == null)
            {
                Debug.LogError("Drawing error");
                return;
            }

            using (new LDtkGUIEnabledScope(true))
            {
                DrawSection(spritesProp, "Sprite", "IntGrid Sprite");
                LDtkEditorGUIUtility.DrawDivider();
                DrawSection(backgroundsProp, "Image", "Background Sprite");
                LDtkEditorGUIUtility.DrawDivider();
                DrawSection(tilesProp, "Tile", "Art Tile");
            }
        }
        private void DrawExportButton()
        {
            GUIContent content = new GUIContent()
            {
                text    = "Export",
                tooltip = "Export Native Prefab"
            };

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            bool button = GUILayout.Button(content, GUILayout.Width(45));

            GUILayout.EndHorizontal();

            if (button)
            {
                GameObject gameObject = (GameObject)assetTarget;
                LDtkNativeExportWindow.CreateWindowWithContext(gameObject);
            }

            LDtkEditorGUIUtility.DrawDivider();
        }
        private void ShowGUI()
        {
            EditorGUIUtility.SetIconSize(Vector2.one * 16);

            LdtkJson data = GetJson();

            if (data == null)
            {
                DrawBreakingError();
                return;
            }

            DrawExportButton();
            _sectionMain.SetJson(data);

            Definitions defs = data.Defs;

            _sectionMain.Draw();
            _sectionIntGrids.Draw(defs.IntGridLayers);
            _sectionEntities.Draw(defs.Entities);
            _sectionEnums.Draw(defs.Enums);

            LDtkEditorGUIUtility.DrawDivider();
        }
Beispiel #12
0
        protected bool DrawButtonToLeftOfField(Rect controlRect, GUIContent content, int indentLevel = 0)
        {
            float labelWidth = LDtkEditorGUIUtility.LabelWidth(controlRect.width);

            Rect buttonRect = new Rect(controlRect)
            {
                x = controlRect.x + labelWidth - controlRect.height * (indentLevel + 1),

                width  = controlRect.height,
                height = controlRect.height,
            };
            bool isPressed = GUI.Button(buttonRect, GUIContent.none);

            if (content == null || content.image == null)
            {
                return(isPressed);
            }

            Rect imageArea = new Rect(buttonRect)
            {
                width  = buttonRect.width - 2,
                height = buttonRect.height - 2,
                center = buttonRect.center
            };

            GUIContent tooltipContent = new GUIContent()
            {
                tooltip = content.tooltip
            };


            GUI.Label(imageArea, tooltipContent);
            GUI.DrawTexture(imageArea, content.image);

            return(isPressed);
        }
Beispiel #13
0
        public static Vector2 GetFieldIconPosition(Rect controlRect)
        {
            float labelWidth = LDtkEditorGUIUtility.LabelWidth(controlRect.width);

            return(new Vector2(controlRect.xMin + labelWidth, controlRect.yMin + controlRect.height / 2));
        }