コード例 #1
0
    public void virtualObj(SCENEOBJ_TYPE type)
    {
        if (_lastVirtualObj != null)
        {
            DestroyImmediate(_lastVirtualObj);
        }
        var rsc = GameObject.Find("GameStone").GetComponent <ResrouceManager>();

        switch (type)
        {
        case SCENEOBJ_TYPE.BOX:
            _lastVirtualObj = Instantiate(rsc.P_BOX);
            break;

        case SCENEOBJ_TYPE.DICI:
            _lastVirtualObj = Instantiate(rsc.P_DICI);
            break;

        case SCENEOBJ_TYPE.FLAG:
            _lastVirtualObj = Instantiate(rsc.P_FLAG);
            break;

        case SCENEOBJ_TYPE.DOOR:
            _lastVirtualObj = Instantiate(rsc.P_DOOR);
            break;

        case SCENEOBJ_TYPE.ROCK:
            _lastVirtualObj = Instantiate(rsc.P_ROCK);
            break;

        case SCENEOBJ_TYPE.TREE:
            _lastVirtualObj = Instantiate(rsc.P_TREE);
            break;

        default:
            break;
        }
    }
コード例 #2
0
 public void TouchedCellBuild(SCENEOBJ_TYPE type)
 {
     beginPosSelect();
     virtualObj(type);
     to_build_type = type;
 }
コード例 #3
0
ファイル: Output.cs プロジェクト: lozzmki/ZProject
        public static DRoomPreset GetPresetByMap(string filename)
        {
            FileStream   fs = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Read);
            BinaryReader br = new BinaryReader(fs);

            //var map = GameObject.Find("CellContainer").GetComponent<CellManager>();


            int width  = br.ReadInt32();
            int height = br.ReadInt32();

            //map.RegenerateMap_Editor(width, height);
            DRoomPreset rlsPreset = new DRoomPreset(width, height);

            SCENEOBJ_TYPE[,] objmap = new SCENEOBJ_TYPE[width, height];
            int[,] texMap           = new int[width, height];

            Debug.Log(width + " , " + height);
            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    var mat_id = br.ReadInt32();
                    texMap[i, j] = mat_id;
                    Debug.Log(mat_id);
                    //map.getCell(new Vector2(i, j)).GetComponent<Cell>().ChangeFoorMat(mat_id);
                }
            }

            var objLength = br.ReadInt32();

            for (int i = 0; i < objLength; i++)
            {
                var mapx     = br.ReadInt32();
                var mapy     = br.ReadInt32();
                var rotateId = br.ReadInt32();
                var name     = br.ReadString();
                Debug.Log(mapx + " , " + mapy + "ROTATE :" + rotateId + " NAME:" + name);
                objmap[mapx, mapy] = NameToSceneObj(name);
                //map.getCell(new Vector2(mapx, mapy)).GetComponent<Cell>().BuildBox(
                //   GameObject.Find("GameStone").GetComponent<ResrouceManager>().NameToSceneObj(name));
                //map.getCell(new Vector2(mapx, mapy)).GetComponent<Cell>().GetBuilding.GetObjRotate = rotateId;
            }
            for (int w = 0; w < width; w++)
            {
                for (int h = 0; h < height; h++)
                {
                    DCell cell = new DCell(texMap[w, h]);
                    if (objmap[w, h] == SCENEOBJ_TYPE.DOOR0)
                    {
                        cell.d_bIsDoor = true;
                    }
                    if (objmap[w, h] == SCENEOBJ_TYPE.WALL_1 || objmap[w, h] == SCENEOBJ_TYPE.WALL_CORNER_1)
                    {
                        cell.d_bIsWall = true;
                    }
                    rlsPreset.d_Data[h * width + w] = cell;
                }
            }
            fs.Close();
            br.Close();
            return(rlsPreset);
        }
コード例 #4
0
ファイル: Cell.cs プロジェクト: lozzmki/ZProject
    //在该格上建立方块
    public bool BuildBox(SCENEOBJ_TYPE type)
    {
        this.sceneObj_type = type;
        if (type == SCENEOBJ_TYPE.NONE)
        {
            DestroyImmediate(_building);
            GameObject.Find("CellContainer").GetComponent <CellManager>().setCellUnUsed((int)mapPos.x, (int)mapPos.y);
            return(true);
        }
        Debug.Log("BEGIN BUILD: " + type);
        if (GameObject.Find("CellContainer").
            GetComponent <CellManager>().getIfUsed((int)mapPos.x, (int)mapPos.y))
        {
            Debug.LogWarning("this cell already has static object");
            return(false);
        }

        Transform obj = null;

        var rsc = GameObject.Find("CellContainer").GetComponent <ResrouceManager>();

        switch (sceneObj_type)
        {
        case SCENEOBJ_TYPE.ROCK:
            obj = Instantiate(rsc.P_ROCK.transform);
            break;

        case SCENEOBJ_TYPE.FLAG:
            obj = Instantiate(rsc.P_FLAG.transform);
            break;

        case SCENEOBJ_TYPE.TREE:
            obj = Instantiate(rsc.P_TREE.transform);
            break;

        case SCENEOBJ_TYPE.BOX:
            obj = Instantiate(rsc.P_BOX.transform);
            break;

        case SCENEOBJ_TYPE.DOOR:
            obj = Instantiate(rsc.P_DOOR.transform);
            break;

        case SCENEOBJ_TYPE.DICI:
            obj = Instantiate(rsc.P_DICI.transform);
            break;

        case SCENEOBJ_TYPE.WALL_1:
            obj = Instantiate(rsc.P_WALL_1.transform);
            break;

        case SCENEOBJ_TYPE.DOOR0:
            obj = Instantiate(rsc.P_DOOR0.transform);
            break;

        case SCENEOBJ_TYPE.WALL_CORNER_1:
            obj = Instantiate(rsc.P_WALL_CORNET_1.transform);
            break;

        default: return(false);
        }
        if (obj != null)
        {
            _building              = obj.gameObject;
            obj.transform.parent   = GameObject.Find("BuildingContainer").transform;
            obj.transform.position = this.transform.position;
            obj.GetComponent <SceneObj>().m_FatherCell = this;
        }

        GameObject.Find("CellContainer").GetComponent <CellManager>().setCellUsed((int)mapPos.x, (int)mapPos.y);
        return(true);
    }
コード例 #5
0
ファイル: MapWindow.cs プロジェクト: lozzmki/ZProject
    private void OnGUI()
    {
        if (!_cellManager)
        {
            _cellManager = GameObject.Find("CellContainer").GetComponent <CellManager>();
        }
        GUILayout.Label("Map Information", EditorStyles.boldLabel);
        GUILayout.BeginHorizontal();
        GUILayout.Label("width & height:");
        GUILayout.Label(_cellManager.Width + " X " + _cellManager.Height);
        GUILayout.EndHorizontal();


        genMapGroup = EditorGUILayout.BeginToggleGroup("Regenerate Map", genMapGroup);
        {
            GUILayout.BeginVertical();
            width  = EditorGUILayout.IntField("width", width);
            height = EditorGUILayout.IntField("height", height);
            if (GUILayout.Button("ReGenerate"))
            {
                if (width >= 0 && height >= 0)
                {
                    _cellManager.RegenerateMap_Editor(width, height);
                }
            }
            if (GUILayout.Button("Fix Error"))
            {
                _cellManager.ReadMapFromEditor();
            }
            GUILayout.EndVertical();
        }
        EditorGUILayout.EndToggleGroup();

        cellGroup = EditorGUILayout.BeginToggleGroup("Tile", cellGroup);
        {
            GUILayout.BeginVertical();
            GUILayout.BeginHorizontal();
            GUILayout.Label("BuildingType: ");
            selectedType = (SCENEOBJ_TYPE)EditorGUILayout.EnumPopup(selectedType);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Rotation: ");
            if (GUILayout.Button("0"))
            {
                foreach (var obj in Selection.gameObjects)
                {
                    if (obj.GetComponent <Cell>() && obj.GetComponent <Cell>().GetBuilding)
                    {
                        obj.GetComponent <Cell>().GetBuilding.GetComponent <SceneObj>().GetObjRotate = 0;
                    }
                }
            }
            if (GUILayout.Button("90"))
            {
                foreach (var obj in Selection.gameObjects)
                {
                    if (obj.GetComponent <Cell>() && obj.GetComponent <Cell>().GetBuilding)
                    {
                        obj.GetComponent <Cell>().GetBuilding.GetComponent <SceneObj>().GetObjRotate = 1;
                    }
                }
            }
            if (GUILayout.Button("180"))
            {
                foreach (var obj in Selection.gameObjects)
                {
                    if (obj.GetComponent <Cell>() && obj.GetComponent <Cell>().GetBuilding)
                    {
                        obj.GetComponent <Cell>().GetBuilding.GetComponent <SceneObj>().GetObjRotate = 2;
                    }
                }
            }
            if (GUILayout.Button("270"))
            {
                foreach (var obj in Selection.gameObjects)
                {
                    if (obj.GetComponent <Cell>() && obj.GetComponent <Cell>().GetBuilding)
                    {
                        obj.GetComponent <Cell>().GetBuilding.GetComponent <SceneObj>().GetObjRotate = 3;
                    }
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Build"))
            {
                foreach (var obj in Selection.gameObjects)
                {
                    if (obj.GetComponent <Cell>())
                    {
                        obj.GetComponent <Cell>().BuildBox(selectedType);
                    }
                }
            }
            if (GUILayout.Button("UnBuild"))
            {
                List <Cell> cells = new List <Cell>();
                foreach (var obj in Selection.gameObjects)
                {
                    if (obj.GetComponent <Cell>() || obj.GetComponentInParent <SceneObj>())
                    {
                        if (obj.GetComponentInParent <SceneObj>())
                        {
                            cells.Add(obj.GetComponentInParent <SceneObj>().m_FatherCell);
                        }
                        else
                        {
                            cells.Add(obj.GetComponent <Cell>());
                        }
                    }
                }
                foreach (var cell in cells)
                {
                    cell.BuildBox(SCENEOBJ_TYPE.NONE);
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            //GUILayout.Label("Material ID: ");
            materialID = EditorGUILayout.IntField("Material ID: ", materialID);
            if (GUILayout.Button("Use"))
            {
                foreach (var obj in Selection.gameObjects)
                {
                    if (obj.GetComponent <Cell>())
                    {
                        obj.GetComponent <Cell>().ChangeFoorMat(materialID);
                    }
                }
            }
            GUILayout.EndHorizontal();

            ioGroup = EditorGUILayout.BeginToggleGroup("IO", ioGroup);
            {
                GUILayout.BeginHorizontal();
                EditorGUILayout.TextField("map file name:", mapFileName);
                if (GUILayout.Button("..."))
                {
                    mapFileName = EditorUtility.OpenFilePanel("Open Map File", "", "txt");
                }
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Output Map"))
                {
                    mapEditor.Output.OutputBinary(mapFileName);
                }
                if (GUILayout.Button("Read Map"))
                {
                    mapEditor.Output.ReadBinrayMap(mapFileName);
                }
                GUILayout.EndHorizontal();
                GUILayout.EndVertical();
            }
        }
    }