示例#1
0
    public override void OnInspectorGUI()
    {
        if (GUILayout.Button("Open Editor"))
        {
            PatternRecipeEditorWindow.Open((PatternRecipe)target);
        }

        var amount = (serializedObject.FindProperty("gridSize").vector2IntValue.y * 2) + 1;
        SerializedProperty pattern  = serializedObject.FindProperty("pattern");
        Vector2Int         gridSize = serializedObject.FindProperty("gridSize").vector2IntValue;

        GUIContent content = new GUIContent();

        EditorGUILayout.BeginVertical("box");

        for (int i = 0; i < gridSize.y; i++)
        {
            EditorGUILayout.BeginHorizontal();
            for (int j = 0; j < gridSize.x; j++)
            {
                //(pattern.GetArrayElementAtIndex(i * gridSize.y + j).objectReferenceValue as Item).sprite.texture
                var item = pattern.GetArrayElementAtIndex(i * gridSize.x + j).objectReferenceValue as Item;
                if (item == null)
                {
                    content.text  = "null";
                    content.image = null;
                }
                else
                {
                    content.text  = "";
                    content.image = item.sprite.texture;
                }

                EditorGUILayout.LabelField(content, GUILayout.Width(36), GUILayout.Height(36));
            }
            EditorGUILayout.EndHorizontal();
        }


        SerializedProperty products = serializedObject.FindProperty("products");

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("=", GUILayout.Width(10), GUILayout.Height(36));

        for (int i = 0; i < products.arraySize; i++)
        {
            var productItem = products.GetArrayElementAtIndex(i).objectReferenceValue as Item;
            if (productItem == null)
            {
                content.text  = "null";
                content.image = null;
            }
            else
            {
                content.text  = "";
                content.image = productItem.sprite.texture;
            }
            EditorGUILayout.LabelField(content, GUILayout.Width(36), GUILayout.Height(36));
        }
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.SelectableLabel($"id: {serializedObject.FindProperty("id").intValue}, key: {serializedObject.FindProperty("key").stringValue}");
        EditorGUILayout.EndVertical();
    }
示例#2
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        EditorGUIUtility.wideMode = true;

        position.height /= amount;

        EditorGUI.PropertyField(position, property);

        var buttonRect = new Rect(position.x, position.y, 165, position.height);

        if (property.objectReferenceValue != null)
        {
            if (GUI.Button(buttonRect, new GUIContent("Open Editor of " + label.text)))
            {
                PatternRecipeEditorWindow.Open(property.objectReferenceValue as PatternRecipe);
            }
            buttonRect.x    += 165;
            buttonRect.width = 85;
            if (GUI.Button(buttonRect, new GUIContent("Show Recipe")))
            {
                showRecipe = !showRecipe;
            }

            SerializedObject serializedObject = null;
            if (property.objectReferenceValue != null)
            {
                serializedObject = new SerializedObject(property.objectReferenceValue);
            }
            if (serializedObject != null)
            {
                if (showRecipe)
                {
                    amount = (serializedObject.FindProperty("gridSize").vector2IntValue.y * 2) + 1;
                    SerializedProperty pattern       = serializedObject.FindProperty("pattern");
                    SerializedProperty patternAmount = serializedObject.FindProperty("amountPattern");
                    Vector2Int         gridSize      = serializedObject.FindProperty("gridSize").vector2IntValue;
                    position.y += position.height;
                    Rect       patternPos = new Rect(position.x, position.y, position.width, position.height + 18);
                    GUIContent content    = new GUIContent();
                    basey = position.y;
                    for (int i = 0; i < gridSize.y; i++)
                    {
                        for (int j = 0; j < gridSize.x; j++)
                        {
                            //(pattern.GetArrayElementAtIndex(i * gridSize.y + j).objectReferenceValue as Item).sprite.texture
                            var item    = pattern.GetArrayElementAtIndex(i * gridSize.x + j).objectReferenceValue as Item;
                            var pAmount = patternAmount.GetArrayElementAtIndex(i * gridSize.x + j).intValue;
                            if (item == null)
                            {
                                content.text  = "null";
                                content.image = null;
                            }
                            else
                            {
                                content.text  = "";
                                content.image = item.sprite.texture;
                            }

                            EditorGUI.LabelField(patternPos, content);
                            GUIContent secondContent = new GUIContent();
                            secondContent.text = pAmount == 0 ? "" : pAmount.ToString();
                            EditorGUI.LabelField(patternPos, secondContent);
                            patternPos.x += 36;
                        }
                        patternPos.y += patternPos.height;
                        patternPos.x -= gridSize.x * 36;
                    }


                    SerializedProperty products       = serializedObject.FindProperty("products");
                    SerializedProperty productsAmount = serializedObject.FindProperty("amountProducts");
                    patternPos.y -= patternPos.height * ((float)gridSize.y / 2f);
                    patternPos.y -= 18;
                    patternPos.x += (gridSize.x * 36) + 18;
                    EditorGUI.LabelField(patternPos, "=");
                    patternPos.x += 18;
                    for (int i = 0; i < products.arraySize; i++)
                    {
                        var productItem = products.GetArrayElementAtIndex(i).objectReferenceValue as Item;
                        var pAmount     = productsAmount.GetArrayElementAtIndex(i).intValue;
                        if (productItem == null)
                        {
                            content.text  = "null";
                            content.image = null;
                        }
                        else
                        {
                            content.text  = "";
                            content.image = productItem.sprite.texture;
                        }
                        EditorGUI.LabelField(patternPos, content);
                        GUIContent secondContent = new GUIContent();
                        secondContent.text = pAmount == 0 ? "" : pAmount.ToString();
                        EditorGUI.LabelField(patternPos, secondContent);
                        patternPos.x += 36;
                    }
                    patternPos.y = basey;
                    EditorGUI.SelectableLabel(patternPos, $"id: {serializedObject.FindProperty("id").intValue}, key: {serializedObject.FindProperty("key").stringValue}");
                }
                else
                {
                    amount = baseAmount;
                }
            }
        }

        //base.OnGUI(position, property, label);
    }
示例#3
0
    public static void Open(PatternRecipe dataObject)
    {
        PatternRecipeEditorWindow window = GetWindow <PatternRecipeEditorWindow>("Item Data Editor");

        window.serializedObject = new SerializedObject(dataObject);
    }