Example #1
0
    void Start()
    {
        this.m_UpWall = this.transform.FindChild(ClientStringConstants.BUILDING_ANCHOR_OBJECT_NAME).GetChild(0)
                        .FindChild(UP_WALL_OBJECT_NAME).gameObject;
        this.m_RightWall = this.transform.FindChild(ClientStringConstants.BUILDING_ANCHOR_OBJECT_NAME).GetChild(0)
                           .FindChild(RIGHT_WALL_OBJECT_NAME).gameObject;

        this.m_UpWall.SetActive(false);
        this.m_RightWall.SetActive(false);
        this.m_BuildingBehavior = this.GetComponent <EditorBuildingBehavior>();
    }
Example #2
0
    private void SelectColumn()
    {
        this.m_Selections.Clear();

        //int initialColumn = this.Position.Column;
        int initialRow    = this.Position.Row;
        int currentColumn = this.Position.Column;
        int currentRow    = this.Position.Row;

        while (currentRow >= 0 && EditorFactory.Instance.MapData[currentRow, currentColumn] != null)
        {
            EditorBuildingBehavior b = EditorFactory.Instance.MapData[currentRow, currentColumn].
                                       GetComponent <EditorBuildingBehavior>();
            if (b == null)
            {
                break;
            }
            if (!this.m_Selections.Contains(b))
            {
                this.m_Selections.Add(b);
            }
            currentRow--;
        }
        currentRow = initialRow;
        while (currentRow < ClientSystemConstants.BUILDING_TILE_MAP_SIZE.height && EditorFactory.Instance.MapData[currentRow, currentColumn] != null)
        {
            EditorBuildingBehavior b = EditorFactory.Instance.MapData[currentRow, currentColumn].
                                       GetComponent <EditorBuildingBehavior>();
            if (b == null)
            {
                break;
            }
            if (!this.m_Selections.Contains(b))
            {
                this.m_Selections.Add(b);
            }
            currentRow++;
        }

        foreach (EditorBuildingBehavior b in this.m_Selections)
        {
            b.Select(b.Position - this.Position);
        }
    }
Example #3
0
    public void ConstructBuilding(BuildingType type, int level, TilePosition position)
    {
        BuildingConfigData configData = ConfigInterface.Instance.BuildingConfigHelper.GetBuildingData(type, level);

        string prefabName = string.Format("{0}{1}{2}", ClientStringConstants.BATTLE_SCENE_RESOURCE_PREFAB_PREFIX_NAME,
                                          ClientStringConstants.BUILDING_OBJECT_PREFAB_PREFIX_NAME, configData.BuildingPrefabName);
        GameObject buildingPrefab = Resources.Load(prefabName) as GameObject;
        GameObject newBuilding    = GameObject.Instantiate(buildingPrefab) as GameObject;

        GameObject.DestroyImmediate(newBuilding.GetComponent <BuildingAI>());
        GameObject.DestroyImmediate(newBuilding.GetComponent <BuildingHPBehavior>());

        ResourceStoreBehavior storeBehavior = newBuilding.GetComponent <ResourceStoreBehavior>();

        if (storeBehavior != null)
        {
            GameObject.DestroyImmediate(storeBehavior);
        }
        WallUtility wall = newBuilding.GetComponent <WallUtility>();

        if (wall != null)
        {
            GameObject.DestroyImmediate(wall);
            newBuilding.AddComponent <EditorWallUtility>();
        }

        EditorBuildingBehavior buildingBehavior = newBuilding.AddComponent <EditorBuildingBehavior>();

        buildingBehavior.Position     = position;
        buildingBehavior.BuildingType = type;
        buildingBehavior.Level        = level;

        newBuilding.transform.position = PositionConvertor.GetWorldPositionByBuildingTileIndex(position);
        newBuilding.transform.parent   = this.m_SceneParent;
        this.PopulateMapData(position, configData.BuildingObstacleList, newBuilding);
    }
Example #4
0
    public void SaveMap()
    {
        var buildings            = GameObject.FindObjectsOfType(typeof(EditorBuildingBehavior));
        var objects              = GameObject.FindObjectsOfType(typeof(EditorRemovableObjectBehavior));
        var achievementBuildings = GameObject.FindObjectsOfType(typeof(EditorAchievementBuildingBehavior));
        var defenseObjects       = GameObject.FindObjectsOfType(typeof(EditorDefenseObjectBehavior));
        BuildingNoGenerator buildingGenerator = new BuildingNoGenerator();
        Hashtable           map          = new Hashtable();
        ArrayList           buildingList = new ArrayList();

        foreach (var b in buildings)
        {
            EditorBuildingBehavior building = (EditorBuildingBehavior)b;
            Hashtable property = new Hashtable();
            property.Add(EditorConfigInterface.Instance.MapBuildingTypeKey, (int)building.BuildingType);
            property.Add(EditorConfigInterface.Instance.MapBuildingNoKey, buildingGenerator.GetBuildingNO(building.BuildingType));
            property.Add(EditorConfigInterface.Instance.MapBuildingLevelKey, building.Level);
            property.Add(EditorConfigInterface.Instance.MapBuildingRowKey, building.Position.Row);
            property.Add(EditorConfigInterface.Instance.MapBuildingColumnKey, building.Position.Column);

            buildingList.Add(property);
        }
        map.Add(EditorConfigInterface.Instance.MapBuildingKey, buildingList);
        ArrayList objectList = new ArrayList();

        foreach (var o in objects)
        {
            EditorRemovableObjectBehavior removableObject = (EditorRemovableObjectBehavior)o;
            Hashtable property = new Hashtable();
            property.Add(EditorConfigInterface.Instance.MapRemovableObjectTypeKey, (int)removableObject.RemovableObjectType);
            property.Add(EditorConfigInterface.Instance.MapRemovableObjectRowKey, removableObject.Position.Row);
            property.Add(EditorConfigInterface.Instance.MapRemovableObjectColumnKey, removableObject.Position.Column);

            objectList.Add(property);
        }
        map.Add(EditorConfigInterface.Instance.MapRemovableObjectKey, objectList);
        ArrayList achievementBuildingList = new ArrayList();

        foreach (var a in achievementBuildings)
        {
            EditorAchievementBuildingBehavior achievementBuilding = (EditorAchievementBuildingBehavior)a;
            Hashtable property = new Hashtable();
            property.Add(EditorConfigInterface.Instance.MapAchievementBuildingTypeKey, (int)achievementBuilding.AchievementBuildingType);
            property.Add(EditorConfigInterface.Instance.MapAchievementBuildingRowKey, achievementBuilding.Position.Row);
            property.Add(EditorConfigInterface.Instance.MapAchievementBuildingColumnKey, achievementBuilding.Position.Column);

            achievementBuildingList.Add(property);
        }
        map.Add(EditorConfigInterface.Instance.MapAchievementBuildingKey, achievementBuildingList);
        ArrayList defenseObjectList = new ArrayList();

        foreach (var d in defenseObjects)
        {
            EditorDefenseObjectBehavior defenseObject = (EditorDefenseObjectBehavior)d;
            Hashtable property = new Hashtable();
            property.Add(EditorConfigInterface.Instance.MapDefenseObjectTypeKey, (int)defenseObject.PropsType);
            property.Add(EditorConfigInterface.Instance.MapDefenseObjectRowKey, defenseObject.Position.Row);
            property.Add(EditorConfigInterface.Instance.MapDefenseObjectColumnKey, defenseObject.Position.Column);

            defenseObjectList.Add(property);
        }
        map.Add(EditorConfigInterface.Instance.MapDefenseObjectKey, defenseObjectList);

        FileStream fs = Application.platform == RuntimePlatform.OSXEditor ?
                        new FileStream(this.m_MapName + "." + EditorConfigInterface.Instance.MapSuffix, FileMode.Create) :
                        new FileStream(EditorConfigInterface.Instance.MapStorePath + "/" +
                                       this.m_MapName + "." + EditorConfigInterface.Instance.MapSuffix, FileMode.Create);
        StreamWriter sw = new StreamWriter(fs);

        sw.Write(JSONHelper.jsonEncode(map));
        sw.Close();

        Debug.Log("write finish!");
    }