Example #1
0
        private void DrawCellBundle()
        {
            EditorGUI.indentLevel = 0;

            var tempColor = GUI.color;

            this.cellBundleScrollPosition = EditorGUILayout.BeginScrollView(this.cellBundleScrollPosition);

            var width  = GUILayout.Width(this.cellSize);
            var height = GUILayout.Height(this.cellSize);

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Cell", width);

            var tempLabelAlignment = GUI.skin.label.alignment;
            var tempGUIColor       = GUI.color;

            GUI.skin.label.alignment = TextAnchor.MiddleCenter;
            for (var x = this.range.x; x <= this.range.width; x++)
            {
                GUILayout.Label(x.ToString(), width);
            }
            EditorGUILayout.EndHorizontal();
            for (var y = this.range.y; y <= this.range.height; y++)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label(y.ToString(), width, height);
                for (var x = this.range.x; x <= this.range.width; x++)
                {
                    var position  = new Vector2Int(x, y);
                    var cellState = this.GetCellState(position);
                    switch (cellState)
                    {
                    case CellState.Choosable:
                        GUI.color = this.choosableCellColor;
                        break;

                    case CellState.CurrentGroup:
                        GUI.color = EditorPrefsKey.GetCellColor(this.cells[position].Id);
                        break;

                    case CellState.OtherGroup:
                        GUI.color = this.otherGroupCellColor;
                        break;

                    default:
                        Assert.IsTrue(false);
                        break;
                    }
                    if (GUILayout.Button(cellGUIContent, width, height))
                    {
                        this.SetCellData(position, this.registerCellRecordId, this.currentGroup);
                    }
                }
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.EndScrollView();

            GUI.skin.label.alignment = tempLabelAlignment;
            GUI.color = tempGUIColor;
        }
Example #2
0
        private void OnEnable()
        {
            var masterData = AssetDatabase.LoadAssetAtPath <MasterData>("Assets/HK/AutoAnt/DataSources/Database/MasterData/MasterData.asset");

            Assert.IsNotNull(masterData, $"{typeof(MasterData).Name}の読み込みに失敗しました");
            this.target = masterData.CellBundle;
            Assert.IsNotNull(this.target, $"{typeof(MasterDataCellBundle).Name}の読み込みに失敗しました");

            this.range = new RectInt();
            foreach (var r in this.target.Records)
            {
                if (this.range.x > r.Position.x)
                {
                    this.range.x = r.Position.x;
                }
                if (this.range.y > r.Position.y)
                {
                    this.range.y = r.Position.y;
                }
                if (this.range.width < r.Position.x)
                {
                    this.range.width = r.Position.x;
                }
                if (this.range.height < r.Position.y)
                {
                    this.range.height = r.Position.y;
                }
            }

            this.groupsInt = this.target.Records
                             .Select(x => x.Group)
                             .Distinct()
                             .ToList();

            this.groupsString = this.groupsInt
                                .Select(x => x.ToString())
                                .ToList();

            var masterDataCell = masterData.Cell;

            this.registerCellRecordId = masterDataCell.Records[0].Id;
            this.cellRecordIdInt      = masterDataCell.Records
                                        .Select(x => x.Id)
                                        .ToArray();
            this.cellRecordIdString = this.cellRecordIdInt
                                      .Select(x => x.ToString())
                                      .ToArray();

            this.cells.Clear();
            foreach (var r in this.target.Records)
            {
                this.cells.Add(r.Position, new MasterDataCellBundle.Cell(r.CellRecordId, r.Group, r.Position));
            }

            this.currentGroup = this.groupsInt[0];

            if (EditorPrefs.HasKey(EditorPrefsKey.CellSize))
            {
                this.cellSize = EditorPrefs.GetFloat(EditorPrefsKey.CellSize);
            }
            if (EditorPrefs.HasKey(EditorPrefsKey.OtherGroupCellColor))
            {
                var otherGroupCellColor = default(Color);
                if (!ColorUtility.TryParseHtmlString(EditorPrefs.GetString(EditorPrefsKey.OtherGroupCellColor), out otherGroupCellColor))
                {
                    Assert.IsTrue(false);
                }
                this.otherGroupCellColor = otherGroupCellColor;
            }
            if (EditorPrefs.HasKey(EditorPrefsKey.ChoosableCellColor))
            {
                var choosableCellColor = default(Color);
                if (!ColorUtility.TryParseHtmlString(EditorPrefs.GetString(EditorPrefsKey.ChoosableCellColor), out choosableCellColor))
                {
                    Assert.IsTrue(false);
                }
                this.choosableCellColor = choosableCellColor;
            }

            if (EditorPrefs.HasKey(EditorPrefsKey.GetCellColorKey(100000)))
            {
                EditorPrefsKey.SetCellColor(100000, Color.white);
            }
            if (EditorPrefs.HasKey(EditorPrefsKey.GetCellColorKey(100100)))
            {
                EditorPrefsKey.SetCellColor(100100, Color.green);
            }

            this.registerCellColor = EditorPrefsKey.GetCellColor(this.registerCellRecordId);
        }
Example #3
0
        private void DrawSystem()
        {
            EditorGUI.indentLevel = 0;

            GUILayout.Label("System");
            EditorGUI.indentLevel++;
            EditorGUILayout.ObjectField("Target", this.target, typeof(MasterDataCellBundle), false);

            this.currentGroup = EditorGUILayout.IntPopup("Group", this.currentGroup, this.groupsString.ToArray(), this.groupsInt.ToArray());

            EditorGUILayout.BeginHorizontal();
            EditorGUI.BeginChangeCheck();
            this.registerCellRecordId = EditorGUILayout.IntPopup("CellRecordId", this.registerCellRecordId, this.cellRecordIdString, this.cellRecordIdInt);
            if (EditorGUI.EndChangeCheck())
            {
                this.registerCellColor = EditorPrefsKey.GetCellColor(this.registerCellRecordId);
            }
            EditorGUI.BeginChangeCheck();
            var cellColor = EditorGUILayout.ColorField(this.registerCellColor);

            if (EditorGUI.EndChangeCheck())
            {
                this.registerCellColor = cellColor;
                EditorPrefsKey.SetCellColor(this.registerCellRecordId, this.registerCellColor);
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("範囲を広げる");
            if (GUILayout.Button("X"))
            {
                this.range.x--;
            }
            if (GUILayout.Button("Y"))
            {
                this.range.y--;
            }
            if (GUILayout.Button("W"))
            {
                this.range.width++;
            }
            if (GUILayout.Button("H"))
            {
                this.range.height++;
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("範囲を狭める");
            if (GUILayout.Button("X"))
            {
                this.NarrowRange(
                    this.range.y,
                    this.range.height,
                    i => new Vector2Int(this.range.x, i),
                    () => this.range.x++
                    );
            }
            if (GUILayout.Button("Y"))
            {
                this.NarrowRange(
                    this.range.x,
                    this.range.width,
                    i => new Vector2Int(i, this.range.y),
                    () => this.range.y++
                    );
            }
            if (GUILayout.Button("W"))
            {
                this.NarrowRange(
                    this.range.y,
                    this.range.height,
                    i => new Vector2Int(this.range.width, i),
                    () => this.range.width--
                    );
            }
            if (GUILayout.Button("H"))
            {
                this.NarrowRange(
                    this.range.x,
                    this.range.width,
                    i => new Vector2Int(i, this.range.height),
                    () => this.range.height--
                    );
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            this.editingGroup = EditorGUILayout.IntField("グループリスト編集", this.editingGroup);
            if (GUILayout.Button("追加"))
            {
                if (this.groupsInt.Contains(this.editingGroup))
                {
                    EditorUtility.DisplayDialog($"[{this.editingGroup}]は既に存在しています", "他のIDを指定してください", "OK");
                }
                else
                {
                    this.groupsInt.Add(this.editingGroup);
                    this.groupsInt.Sort((l, r) => l - r);
                    this.groupsString.Clear();
                    this.groupsString.AddRange(this.groupsInt.Select(x => x.ToString()));
                }
            }
            if (GUILayout.Button("削除"))
            {
                if (!this.groupsInt.Contains(this.editingGroup))
                {
                    EditorUtility.DisplayDialog($"[{this.editingGroup}]は既に存在していません", "他のIDを指定してください", "OK");
                }
                else if (EditorUtility.DisplayDialog($"[{this.editingGroup}]を削除します", "本当によろしいですか?", "OK", "CANCEL"))
                {
                    var targets = this.cells
                                  .Where(x => x.Value.Group == this.editingGroup)
                                  .Select(x => x.Key)
                                  .ToArray();
                    foreach (var t in targets)
                    {
                        this.cells.Remove(t);
                    }

                    this.groupsInt.Remove(this.editingGroup);
                    this.groupsString.Remove(this.editingGroup.ToString());
                }
            }
            EditorGUILayout.EndHorizontal();
        }