Пример #1
0
    public bool AreaPrint(Settings.Layers layer, Coordinate start, Coordinate end, GameObject aimgo)
    {
        if ((t.InMap(start) && t.InMap(end)) == false)
        {
            return(false);
        }
        int x1, x2, y1, y2;

        x1 = start.x;
        x2 = end.x;
        y1 = start.y;
        y2 = end.y;
        if (x1 < x2)
        {
            int t = x1;
            x1 = x2;
            x2 = t;
        }
        if (y1 < y2)
        {
            int t = y1;
            y1 = y2;
            y2 = t;
        }
        for (int xx = x2; xx <= x1; xx++)
        {
            for (int yy = y2; yy <= y1; yy++)
            {
                t.SetAUnit(layer, xx, yy, aimgo);
            }
        }
        return(true);
    }
Пример #2
0
    public static Vector3 GetRenderPosition(Vector3 originPosition, Settings.Layers layer, int height)
    {
        float z;
        Map   currentmap = GameController.CurrentMap;
        float length     = currentmap.UnitLength;
        float miny       = currentmap.UnitCounts.y * length + currentmap.OriginPoint.y;
        float maxy       = currentmap.OriginPoint.y;
        float rate       = (originPosition.y - height * length - miny) / (maxy - miny);
        float dis        = Settings.FirstLayerZ - Settings.ThirdLayerZ;

        if (layer == Settings.Layers.First)
        {
            z = rate * dis * -1f + Settings.ThirdLayerZ + dis;
            return(new Vector3(originPosition.x, originPosition.y, z));
        }
        else if (layer == Settings.Layers.Second)
        {
            z = rate * dis * -1f + Settings.ThirdLayerZ;
            return(new Vector3(originPosition.x, originPosition.y, z));
        }
        else if (layer == Settings.Layers.Third)
        {
            z = rate * dis * -1f + Settings.ThirdLayerZ - dis;
            return(new Vector3(originPosition.x, originPosition.y, z));
        }
        return(originPosition);
    }
Пример #3
0
 public void init(Map map, Settings.Layers layer, int x, int y)
 {
     parent     = map;
     coordinate = new Coordinate(x, y);
     this.layer = layer;
     gameObject.AddComponent <GamePosition> ().Init(layer, height);
 }
Пример #4
0
 public void ShowUnitsInLayer(Settings.Layers layer)
 {
     //测试版,以后修改map的储存方式再修改
     for (int x = 0; x < t.UnitCounts.x; x++)
     {
         for (int y = 0; y < t.UnitCounts.y; y++)
         {
             CreateAUnit(layer, x, y);
         }
     }
 }
Пример #5
0
    public Coordinate GetMapdataCoordinate(int index)
    {
        int unitsPerLayer = UnitCounts.x * UnitCounts.y;
        int layerInt      = Mathf.FloorToInt((float)index / (float)unitsPerLayer);

        Settings.Layers layer = ((Settings.Layers)Enum.GetValues(typeof(Settings.Layers)).GetValue(layerInt));
        index -= layerInt * unitsPerLayer;
        int        y    = Mathf.FloorToInt((float)index / (float)UnitCounts.x);
        int        x    = index % UnitCounts.x;
        Coordinate coor = new Coordinate(x, y);

        coor.layer = layer;
        return(coor);
    }
Пример #6
0
    public GameObject CreateAUnit(Settings.Layers layer, int x, int y)
    {
        GameObject go = GetAUnit(layer, x, y);

        if (go == null)
        {
            return(null);
        }
        GameObject go2 = GameObject.Instantiate(go, gameObject.transform);
        Coordinate ct  = new Coordinate();

        ct.x = x;
        ct.y = y;
        go2.transform.position = GetWorldPositionCenterOfCoordinate(ct);
        go2.GetComponent <MapUnit> ().init(this, layer, x, y);
        return(go2);
    }
Пример #7
0
    public GameObject CreateAUnit(Settings.Layers layer, int x, int y)
    {
        GameObject go = t.GetAUnit(layer, x, y);

        if (go == null)
        {
            return(null);
        }
        GameObject go2 = GameObject.Instantiate(go, t.gameObject.transform);
        Coordinate ct  = new Coordinate();

        ct.x = x;
        ct.y = y;
        MapUnit mu     = go2.GetComponent <MapUnit> ();
        Vector3 newPos = t.GetWorldPositionCenterOfCoordinate(ct);

        newPos = Settings.GetRenderPosition(newPos, layer, mu.height);
        go2.transform.position = newPos;
        go2.GetComponent <MapUnit> ().init(t, layer, x, y);
        return(go2);
    }
Пример #8
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();
        t = target as Map;
        EditorGUILayout.LabelField("地图网格参数");
        EditorGUI.indentLevel++;
        EditorGUILayout.PropertyField(UnitLength);
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.PropertyField(UnitCountX);
        EditorGUILayout.PropertyField(UnitCountY);
        EditorGUILayout.EndHorizontal();
        EditorGUI.indentLevel--;

        EditorGUILayout.LabelField("地图内容参数");
        EditorGUI.indentLevel++;
        MapContentSet tempGO = (MapContentSet)MapContentSet.objectReferenceValue;

        if (GUILayout.Button("新建") == true)
        {
            t.ContentInMap = t.NewMap(UnitCountX.intValue, UnitCountY.intValue);
            Refresh();
        }
        if (t.ContentInMap == null)
        {
            return;
        }
        //检查变更的地图块组是否具有相应的组件
        EditorGUI.BeginChangeCheck();
        EditorGUILayout.PropertyField(MapContentSet);
        if (EditorGUI.EndChangeCheck())
        {
            /*
             * MapContentSet ms = (MapContentSet)MapContentSet.objectReferenceValue;
             * if (ms==null) {
             *      Debug.LogError ("不合法的地图块组");
             *      MapContentSet.objectReferenceValue = tempGO;
             * }
             */
        }
        serializedObject.ApplyModifiedProperties();
        if (t.MapContentSet == null)
        {
            return;
        }
        EditorGUI.indentLevel--;

        EditorGUILayout.LabelField("层数");
        EditorGUI.indentLevel++;
        EditorGUI.BeginChangeCheck();
        selectedLayer = (Settings.Layers)EditorGUILayout.EnumPopup(selectedLayer);
        if (EditorGUI.EndChangeCheck())
        {
            Refresh();
        }
        EditorGUI.indentLevel--;

        EditorGUI.BeginChangeCheck();
        showMap = GUILayout.Toggle(showMap, "显示地图");
        if (EditorGUI.EndChangeCheck())
        {
            ClearMapUnits();
            if (showMap == false)
            {
                ClearMapUnits();
            }
            else
            {
                if (showAllLayers == false)
                {
                    ShowUnitsInLayer(selectedLayer);
                }
                else
                {
                    for (int i = 0; i < Settings.MaxLayers; i++)
                    {
                        ShowUnitsInLayer((Settings.Layers)Enum.GetValues(typeof(Settings.Layers)).GetValue(i));
                    }
                }
            }
        }
        EditorGUI.BeginChangeCheck();
        showAllLayers = GUILayout.Toggle(showAllLayers, "显示所有层");
        if (EditorGUI.EndChangeCheck())
        {
            ClearMapUnits();
            if (showMap == true)
            {
                if (showAllLayers == true)
                {
                    for (int i = 0; i < Settings.MaxLayers; i++)
                    {
                        ShowUnitsInLayer((Settings.Layers)Enum.GetValues(typeof(Settings.Layers)).GetValue(i));
                    }
                }
                else
                {
                    ShowUnitsInLayer(selectedLayer);
                }
            }
        }

        EditorGUI.indentLevel++;

        EditorGUI.indentLevel--;
        EditorGUILayout.LabelField("按S放置,按D删除,按住X以矩形放置,按住C以矩形删除");
        Texture[] images = ((MapContentSet)(MapContentSet.objectReferenceValue)).GetSetImages();
        this.selectedSet = GUILayout.SelectionGrid(this.selectedSet, images, Settings.EditorUnitShowMaxAmount);
        EditorGUI.indentLevel++;
        if (GUILayout.Button("清空") == true)
        {
            t.Clear();
            Refresh();
        }
        EditorGUI.indentLevel--;
        EditorGUILayout.PropertyField(MapName);
        serializedObject.ApplyModifiedProperties();
        if (GUILayout.Button("保存"))
        {
            SaveMapData(t.MapName);
        }
        serializedObject.ApplyModifiedProperties();
    }
Пример #9
0
    ///按行优先排列(从左到右依次增1,一行结束到邻接的下面一行继续)
    public int GetMapdataIndex(Settings.Layers layer, int x, int y)
    {
        int unitsPerLayer = UnitCounts.x * UnitCounts.y;

        return((int)layer * unitsPerLayer + x + y * UnitCounts.x);
    }
Пример #10
0
 public void SetAUnit(Settings.Layers layer, int x, int y, GameObject go)
 {
     ContentInMap [GetMapdataIndex(layer, x, y)] = go;
 }
Пример #11
0
 public GameObject GetAUnit(Settings.Layers layer, int x, int y)
 {
     return(ContentInMap [GetMapdataIndex(layer, x, y)]);
 }
Пример #12
0
 public void Init(Settings.Layers layer, int height)
 {
     this.layer  = layer;
     this.height = height;
 }