示例#1
0
 public void TryToAddNewCell(GroundCell cell)
 {
     cells[cell.CellNumber] = cell;
     if (cell.Click == null)
     {
         cell.Click += OnCellClick;
     }
 }
 private void MoveCell(GroundCell cell)
 {
     if (isGameStarted)
     {
         if (cell.Value == "")
         {
             return;
         }
         if (cell.Variants.HaveTopAction && cellList[cell.Place - 5].Value == "")
         {
             cellList[cell.Place - 5].Value = cell.Value;
             cell.Value = "";
             UpdateGrid();
             Moves++;
         }
         else if (cell.Variants.HaveLeftAction && cellList[cell.Place - 2].Value == "")
         {
             cellList[cell.Place - 2].Value = cell.Value;
             cell.Value = "";
             UpdateGrid();
             Moves++;
         }
         else if (cell.Variants.HaveRightAction && cellList[cell.Place].Value == "")
         {
             cellList[cell.Place].Value = cell.Value;
             cell.Value = "";
             UpdateGrid();
             Moves++;
         }
         else if (cell.Variants.HaveBottomAction && cellList[cell.Place + 3].Value == "")
         {
             cellList[cell.Place + 3].Value = cell.Value;
             cell.Value = "";
             UpdateGrid();
             Moves++;
         }
     }
 }
示例#3
0
 private void Awake()
 {
     _entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
     _groundCell    = new GroundCell(groundGeneratorData);
     _randomSeed    = new Random();
 }
示例#4
0
    /// <summary>
    /// 导出数据
    /// </summary>
    /// <param name="fileName"></param>
    private void OnExportData(string fileName)
    {
        GameObject root_scene = getSceneRoot();
        GameObject root_map   = getMapRoot();

        GameObject light   = GameObject.Find(light_name);
        GameObject ui_root = GameObject.Find(ui_name);

        if (light == null)
        {
            Debug.LogError("没有添加方向光");
            return;
        }

        if (ui_root == null)
        {
            Debug.LogError("没有添加摄像机");
            return;
        }

        SceneConf conf_scene = new SceneConf()
        {
            //Trans = root_scene.transform,
            Map = new MapConf()
            {
                // Trans = root_map.transform,
                Ground  = new GroundConf(),
                Surface = new SurfaceConf(),
            },
            Light = new PrefabConf()
            {
                PrefabName = light_name
            },
            UI = new PrefabConf()
            {
                PrefabName = ui_name
            }
        };

        conf_scene.SetTransform(root_scene.transform);
        conf_scene.Map.SetTransform(root_map.transform);
        conf_scene.Light.SetTransform(light.transform);
        conf_scene.UI.SetTransform(ui_root.transform.FindChild("Camera"));

        //序列化小怪位置数据
        Transform placeholder_root_trans = getPlaceHolderRoot();

        conf_scene.PlaceHolder = new List <PlaceHolderConfig>();
        for (int i = 0; i < placeholder_root_trans.childCount; i++)
        {
            PlaceHolderConfig v_point = new PlaceHolderConfig();
            v_point.SetTransform(placeholder_root_trans.GetChild(i), false);
            conf_scene.PlaceHolder.Add(v_point);
        }

        //序列化Bounds数据
        Transform bounds_root_trans  = BoundsRoot;
        int       bounds_point_count = bounds_root_trans.childCount;

        conf_scene.Bounds = new List <BoundsConfig>();

        List <Transform> bounds_points_list = new List <Transform>();

        for (int i = 0; i < bounds_point_count; i++)
        {
            Transform bounds_points_trans = bounds_root_trans.GetChild(i);
            bounds_points_list.Add(bounds_points_trans);
        }

        //按照字符串排序
        var bounds_points_sorted =
            from point in bounds_points_list
            orderby point.name ascending
            select point;

        foreach (var item in bounds_points_sorted)
        {
            BoundsConfig v_point = new BoundsConfig();
            v_point.SetTransform(item);
            conf_scene.Bounds.Add(v_point);
        }

        //序列化ground数据
        Transform ground_root_trans = root_map.transform.FindChild(ground_root_name);

        if (ground_root_trans != null)
        {
            List <GroundCell> cells = new List <GroundCell>();

            float w = 1, h = 1;
            int   gournd_cell_count = ground_root_trans.childCount;

            if (gournd_cell_count > 0)
            {
                Mesh mesh = ground_root_trans.GetChild(0).GetComponent <MeshFilter>().sharedMesh;
                w = mesh.bounds.size.x;
                h = mesh.bounds.size.z;
                //Debug.Log(mesh.vertices[0] + "," + mesh.vertices[1] + "," + mesh.vertices[2] + "," + mesh.vertices[3]);
            }

            for (int i = 0; i < gournd_cell_count; i++)
            {
                GroundCell cell = new GroundCell();
                // cell.Trans = ground_root_trans.GetChild(i);
                Transform item_trans = ground_root_trans.GetChild(i);
                cell.SetTransform(item_trans);
                List <string> mats = new List <string>();

                Material[] mat = item_trans.GetComponent <MeshRenderer>().sharedMaterials;
                if (mat != null && mat.Length > 0)
                {
                    for (int j = 0; j < mat.Length; j++)
                    {
                        if (mat[j] != null)
                        {
                            mats.Add(mat[j].name);
                        }
                    }
                }
                cell.Materials = mats;
                cells.Add(cell);
            }
            conf_scene.Map.Ground.SetTransform(ground_root_trans);
            conf_scene.Map.Ground.GroundCells = cells;
            conf_scene.Map.Ground.CellWidth   = w;
            conf_scene.Map.Ground.CellHeight  = h;
        }
        else
        {
            EditorUtility.DisplayDialog("提示", "亲,还没创建地图!", "确认");
            return;
        }

        //序列化surface数据
        Transform surface_root_trans = root_map.transform.FindChild(surface_root_name);

        if (surface_root_trans != null)
        {
            conf_scene.Map.Surface.SetTransform(surface_root_trans);
            List <SurfaceCellCollider>          element_colliders          = new List <SurfaceCellCollider>();
            List <SurfaceCellPlaneWithCollider> element_planeWithColliders = new List <SurfaceCellPlaneWithCollider>();
            List <SurfaceCellPlane>             element_planes             = new List <SurfaceCellPlane>();

            for (int i = 0; i < surface_root_trans.childCount; i++)
            {
                Transform item_trans    = surface_root_trans.GetChild(i);
                string    name_post_fix = item_trans.name.Substring(item_trans.gameObject.name.LastIndexOf('_') + 1);

                if (name_post_fix.Equals("pc"))
                {
                    SurfaceCellPlaneWithCollider cell = new SurfaceCellPlaneWithCollider();
                    cell.SetTransform(item_trans);

                    List <string> mats = new List <string>();
                    Material[]    mat  = item_trans.gameObject.GetComponent <MeshRenderer>().sharedMaterials;
                    if (mat != null && mat.Length > 0)
                    {
                        for (int j = 0; j < mat.Length; j++)
                        {
                            if (mat[j] != null)
                            {
                                mats.Add(mat[j].name);
                            }
                        }
                    }
                    cell.Plane = new SurfaceCellPlane()
                    {
                        Materials = mats
                    };
                    cell.Plane.CellWidth  = item_trans.GetComponent <MeshFilter>().sharedMesh.bounds.size.x;
                    cell.Plane.CellHeight = item_trans.GetComponent <MeshFilter>().sharedMesh.bounds.size.z;

                    List <SurfaceCellCollider> colliders = new List <SurfaceCellCollider>();
                    for (int j = 0; j < item_trans.childCount; j++)
                    {
                        Transform           item_item_trans = item_trans.GetChild(j);
                        SurfaceCellCollider cell_col        = new SurfaceCellCollider();
                        cell_col.SetTransform(item_item_trans);
                        BoxCollider col = item_item_trans.GetComponent <BoxCollider>();

                        cell_col.Center    = cell_col.Vector3ToList(col.center);
                        cell_col.Size      = cell_col.Vector3ToList(col.size);
                        cell_col.IsTrigger = col.isTrigger;
                        colliders.Add(cell_col);
                    }

                    cell.Colliders = colliders;
                    element_planeWithColliders.Add(cell);
                }
                else if (name_post_fix.Equals("p"))
                {
                    SurfaceCellPlane cell = new SurfaceCellPlane();
                    cell.SetTransform(item_trans);

                    List <string> mats = new List <string>();
                    Material[]    mat  = item_trans.gameObject.GetComponent <MeshRenderer>().sharedMaterials;
                    if (mat != null && mat.Length > 0)
                    {
                        for (int j = 0; j < mat.Length; j++)
                        {
                            if (mat[j] != null)
                            {
                                mats.Add(mat[j].name);
                            }
                        }
                    }
                    cell.Materials = mats;
                    Mesh mesh = item_trans.GetComponent <MeshFilter>().sharedMesh;
                    cell.CellWidth  = mesh.bounds.size.x;
                    cell.CellHeight = mesh.bounds.size.z;
                    element_planes.Add(cell);
                }
                else if (name_post_fix.Equals("c"))
                {
                    SurfaceCellCollider cell = new SurfaceCellCollider();
                    cell.SetTransform(item_trans);
                    BoxCollider col = item_trans.GetComponent <BoxCollider>();

                    cell.Center    = cell.Vector3ToList(col.center);
                    cell.Size      = cell.Vector3ToList(col.size);
                    cell.IsTrigger = col.isTrigger;

                    element_colliders.Add(cell);
                }
            }


            conf_scene.Map.Surface.Colliders          = element_colliders;
            conf_scene.Map.Surface.PlaneWithColliders = element_planeWithColliders;
            conf_scene.Map.Surface.Planes             = element_planes;
        }



        string json = JsonMapper.ToJson(conf_scene);

        if (File.Exists(fileName))
        {
            File.Delete(fileName);
        }
        File.WriteAllText(fileName, json);

        SceneConf obj = JsonMapper.ToObject <SceneConf>(File.ReadAllText(fileName));

        bool success = json.Equals(JsonMapper.ToJson(obj));

        if (success)
        {
            Debug.Log(fileName + ",导出成功!");
        }
        else
        {
            Debug.LogError("shit,导出貌似出错了,问问程序猿吧!");
        }
    }