コード例 #1
0
 private void DeleteNode(MapCellSTWithTexture node)
 {
     node.block  = "";
     node.param  = "";
     node.sprite = null;
     this.SaveNode(node);
 }
コード例 #2
0
    private void InitMapCellData(List <SecenLayoutData> list)
    {
        int count = m_row * m_col;

        this.m_cellDataList = new List <MapCellSTWithTexture>(count);
        var wrapMap = this.WrapMST(list);

        for (int i = 0, index = -1; i < m_col; i++)
        {
            for (int j = 0; j < m_row; j++)
            {
                index++;
                //兼容旧数据
                string key = j + "_" + i;
                if (wrapMap.ContainsKey(key))
                {
                    var cell = wrapMap[key];
                    MapCellSTWithTexture temp = new MapCellSTWithTexture();
                    temp.index    = index;
                    temp.x        = cell.x;
                    temp.y        = cell.y;
                    temp.rotation = cell.rotation;
                    temp.block    = cell.block;
                    temp.param    = cell.param;

                    var tex = LoadSprite(temp.block);
                    temp.sprite       = tex.Item1;
                    temp.occupyWidth  = tex.Item2;
                    temp.occupyHeight = tex.Item3;
                    temp.scale        = tex.Item4 * this.m_editorCellXScale;
                    temp.pos          = tex.Item5;
                    this.m_cellDataList.Add(temp);
                }
                else
                {
                    MapCellSTWithTexture temp = new MapCellSTWithTexture();
                    temp.index        = index;
                    temp.x            = j;
                    temp.y            = i;
                    temp.occupyWidth  = 1;
                    temp.occupyHeight = 1;
                    this.m_cellDataList.Add(temp);
                }
            }
        }
    }
コード例 #3
0
    private void PasteNodes()
    {
        if (this.m_copyNodesCache.Count == 0 || this.m_curSelectNodes.Count == 0)
        {
            return;
        }
        MapCellSTWithTexture firstSelectNode = default(MapCellSTWithTexture);

        foreach (var item in this.m_curSelectNodes)
        {
            firstSelectNode = item.Value;
            break;
        }

        int offsetX = firstSelectNode.x - this.m_copyNodesCache[0].x;
        int offsetY = firstSelectNode.y - this.m_copyNodesCache[0].y;

        for (int j = 0; j < this.m_copyNodesCache.Count; j++)
        {
            var item = this.m_copyNodesCache[j];
        }
        foreach (var item in this.m_copyNodesCache)
        {
            for (int i = 0; i < this.m_cellDataList.Count; i++)
            {
                var data = this.m_cellDataList[i];
                if (data.x == item.x + offsetX && data.y == item.y + offsetY)
                {
                    var copy = item;
                    copy.x                 = data.x;
                    copy.y                 = data.y;
                    copy.index             = data.index;
                    this.m_cellDataList[i] = copy;
                    this.DeleteNode(item);
                    break;
                }
            }
        }
        this.m_copyNodesCache.Clear();
    }
コード例 #4
0
 private MapCellSTWithTexture?RefreshSingleTexture(MapCellSTWithTexture item)
 {
     if (item.sprite != null)
     {
         Resources.UnloadAsset(item.sprite);
         item.sprite = null;
         this.m_cellDataList[item.index] = item;
     }
     if (!string.IsNullOrEmpty(item.block))
     {
         var tex = this.LoadSprite(item.block);
         if (null != tex.Item1)
         {
             item.sprite       = tex.Item1;
             item.occupyWidth  = tex.Item2;
             item.occupyHeight = tex.Item3;
             item.scale        = tex.Item4 * this.m_editorCellXScale;
             item.pos          = tex.Item5;
             this.m_cellDataList[item.index] = item;
             return(item);
         }
     }
     return(item);
 }
コード例 #5
0
 private void SaveNode(MapCellSTWithTexture node)
 {
     this.m_cellDataList[node.index] = node;
 }
コード例 #6
0
    private void DrawCellDetail()
    {
        GUILayout.BeginArea(detailContentArea);
        this.m_editorPixelScale = EditorGUILayout.FloatField("格子像素缩放值", this.m_editorPixelScale);
        this.m_editorCellXScale = EditorGUILayout.FloatField("格子宽度缩放值", this.m_editorCellXScale);
        this.unitW = s_cellWPixel * this.m_editorPixelScale;
        this.unitH = s_cellHPixel * this.m_editorPixelScale;
        var firstSelect = this.GetFirstSelectCell();

        if (firstSelect != null)
        {
            MapCellSTWithTexture data = (MapCellSTWithTexture)firstSelect;
            EditorGUILayout.LabelField($"格子行列:({data.x},{data.y})", GUILayout.Width(180), GUILayout.Height(20));
            EditorGUILayout.LabelField($"格子坐标:({data.x * unitW},{data.y * unitH})", GUILayout.Width(180), GUILayout.Height(20));
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.LabelField("障碍物:");
            data.block = GUILayout.TextField(data.block, GUILayout.Width(200));
            EditorGUILayout.LabelField("旋转:");
            data.rotation = EditorGUILayout.FloatField(data.rotation, GUILayout.Width(200), GUILayout.Height(20));
            EditorGUILayout.LabelField("参数:");
            data.param = GUILayout.TextArea(data.param, GUILayout.Width(200), GUILayout.Height(100));
            if (EditorGUI.EndChangeCheck())
            {
                this.m_curSelectNodes[data.index] = data;
                this.SaveNode(data);
                RefreshSingleTexture(data);
            }
        }

        GUILayout.Space(20);
        if (GUILayout.Button("Save"))
        {
            if (EditorUtility.DisplayDialog("提示", "是否保存数据??", "确定", "取消"))
            {
                this.m_pkg.Data = this.ParseMapCellST();
                EditorUtility.SetDirty(this.m_pkg);
                EditorPrefs.SetFloat(map_editor_cell_x_scale_key, this.m_editorCellXScale);
                EditorPrefs.SetString(map_editor_cell_filter_key, this.m_cellSourceNameFilter);
                Debug.Log("保存MapCell数据成功");
            }
        }
        if (GUILayout.Button("Show All Texture"))
        {
            RefreshTexture();
        }
        GUILayout.Space(10);
        if (GUILayout.Button("Clear All Texture"))
        {
            if (EditorUtility.DisplayDialog("警 告", "是否拭除所有图片??", "确定", "取消"))
            {
                for (int i = 0; i < this.m_cellDataList.Count; i++)
                {
                    var data = this.m_cellDataList[i];
                    data.block             = null;
                    this.m_cellDataList[i] = data;
                }
                RefreshTexture();
            }
        }
        GUILayout.EndArea();
    }