Exemplo n.º 1
0
    private void GeneratePropertyFields()
    {
        EquipmentLayout equip = (EquipmentLayout)target;

        EditorUtils.Header("Type");
        EditorGUI.indentLevel++;
        equip.type = (EquipmentType)EditorGUILayout.EnumPopup("Equipment Type", equip.type, _typeEnumDropdownOptions);
        EditorGUI.indentLevel--;

        EditorUtils.Header("Size");
        EditorGUI.indentLevel++;

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.PrefixLabel(new GUIContent("Rows"));
        equip.Rows = EditorGUILayout.IntSlider(equip.Rows, 1, 10, _intSliderOptions);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Space();

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.PrefixLabel(new GUIContent("Cols"));
        equip.Cols = EditorGUILayout.IntSlider(equip.Cols, 1, 10, _intSliderOptions);
        EditorGUILayout.EndHorizontal();
        EditorGUI.indentLevel--;
    }
Exemplo n.º 2
0
 private void OnEquipmentSelected(EquipmentLayout equip)
 {
     _currentEquipment.gameObject.SetActive(true);
     _currentEquipment.Layout   = equip;
     _currentEquipment.dragging = true;
     isDraggingEquipment        = true;
 }
Exemplo n.º 3
0
 public void AddEquipment(EquipmentLayout equip)
 {
     if (!_equipments.Contains(equip))
     {
         _equipments.Add(equip);
         EquipmentButton newButton = Instantiate(_templateButton, Vector3.zero, Quaternion.identity, transform);
         newButton.Equipment = equip;
     }
 }
Exemplo n.º 4
0
        public async Task <ActionResult> Save(EquipmentLayoutViewModel model)
        {
            MethodReturnResult rst = new MethodReturnResult();

            if (model.BackgroundImage != null &&
                !model.BackgroundImage.ContentType.Contains("image"))
            {
                rst.Code    = 1000;
                rst.Message = string.Format(StringResource.ValidateImageFileFormat, FMMResources.StringResource.EquipmentLayoutViewModel_BackgroundImage);
                return(Json(rst));
            }
            try
            {
                using (EquipmentLayoutServiceClient client = new EquipmentLayoutServiceClient())
                {
                    EquipmentLayout obj = new EquipmentLayout()
                    {
                        Key         = model.Name,
                        Height      = model.Height,
                        Width       = model.Width,
                        Status      = model.Status,
                        Description = model.Description,
                        Editor      = User.Identity.Name,
                        EditTime    = DateTime.Now,
                        CreateTime  = DateTime.Now,
                        Creator     = User.Identity.Name
                    };
                    if (model.BackgroundImage != null &&
                        model.BackgroundImage.ContentLength > 10)
                    {
                        int length = (int)model.BackgroundImage.InputStream.Length;
                        obj.BackgroundImage = new byte[length];
                        model.BackgroundImage.InputStream.Read(obj.BackgroundImage, 0, length);
                    }
                    rst = await client.AddAsync(obj);

                    if (rst.Code == 0)
                    {
                        rst.Message = string.Format(FMMResources.StringResource.EquipmentLayout_Save_Success
                                                    , model.Name);
                    }
                }
            }
            catch (Exception ex)
            {
                rst.Code    = 1000;
                rst.Message = ex.Message;
                rst.Detail  = ex.ToString();
            }
            return(Json(rst));
        }
Exemplo n.º 5
0
    private void GenerateCellsMatrix()
    {
        EquipmentLayout equip = (EquipmentLayout)target;
        int             cols  = equip.Cols;
        int             rows  = equip.Rows;

        EditorUtils.Header("Grid");
        GUILayoutOption[] options = new GUILayoutOption[]
        {
            GUILayout.Width(30),
            GUILayout.Height(30)
        };
        if (!equip.CheckLayout())
        {
            EquipmentNotCompleteAlert();
        }

        for (int j = 0; j < rows; j++)
        {
            EditorGUILayout.BeginHorizontal();
            for (int i = 0; i < cols; i++)
            {
                CellState state          = equip.GetState(i, j);
                string    buttonName     = EquipmentEditorUtils.GetCellButtonText(state);
                bool      isSelectedCell = _selectedCellPos.x == i && _selectedCellPos.y == j;
                if (isSelectedCell)
                {
                    GUI.backgroundColor = _selectedCellColor;
                }
                if (GUILayout.Button(buttonName, options))
                {
                    if (!isSelectedCell)
                    {
                        _selectedCellPos = new Vector2Int(i, j);
                    }
                    else
                    {
                        _selectedCellPos = _noSelectedCellPos;
                    }
                }
                if (isSelectedCell)
                {
                    GUI.backgroundColor = Color.white;
                }
            }
            EditorGUILayout.EndHorizontal();
        }
        EditorUtility.SetDirty(equip);
    }
Exemplo n.º 6
0
    public override void OnInspectorGUI()
    {
        // We have to put the style creation here
        // Else we have some NullPointerException
        // More info: https://answers.unity.com/questions/1130714/editorstyles-was-overridden-can-i-revert-back.html
        _alertLabelStyle = new GUIStyle(EditorStyles.label);
        _alertLabelStyle.normal.textColor = Color.red;

        EquipmentLayout equip = (EquipmentLayout)target;

        GeneratePropertyFields();
        EditorGUILayout.Space();
        GenerateSelectedCellInfo();
        EditorGUILayout.Space();
        GenerateCellsMatrix();
    }
Exemplo n.º 7
0
    private void GenerateSelectedCellInfo()
    {
        EquipmentLayout equip = (EquipmentLayout)target;
        int             x     = _selectedCellPos.x;
        int             y     = _selectedCellPos.y;

        if (_selectedCellPos.x != -1)
        {
            EditorUtils.Header("Cell Info");
            EditorGUI.indentLevel++;
            CellState tmpState = (CellState)EditorGUILayout.EnumPopup("State", equip.GetState(x, y), _typeEnumDropdownOptions);
            equip.SetState(x, y, tmpState);
            Cell cell    = equip.GetCell(x, y);
            Cell tmpCell = (Cell)EditorGUILayout.ObjectField("Cell", cell, typeof(Cell), false, _gameObjectOptions);
            equip.SetCell(x, y, tmpCell);
            Sprite sprite    = equip.GetSprite(x, y);
            Sprite tmpSprite = (Sprite)EditorGUILayout.ObjectField("Sprite", sprite, typeof(Sprite), false, _gameObjectOptions);
            equip.SetSprite(x, y, tmpSprite);

            EditorGUI.indentLevel--;
        }
    }