Example #1
0
    /// <summary>
    /// 从数据库储存数据加载building
    /// </summary>
    /// <param name="data"></param>
    /// <returns></returns>
    public static Building Create(BuildingSaveData data)
    {
        Model model = LocalAssetUtil.GetModel(data.ModelDataId);

        if (model == null)
        {
            return(null);
        }
        GameObject obj = CreateGameObjcet(model, data.Name);

        ((TransformGroup)data.TransformGroupSaveData).Inject(obj.transform);
        Building building = AddComponentBuilding(obj.transform, model);

        if (data.MaterialColorSaveData != null)
        {
            Material material = MaterialUtil.Create();
            material.color    = (Color)data.MaterialColorSaveData;
            building.Material = material;
        }
        #region animation
        building.isAnimOn            = data.IsAnimOn;
        building.appearanceAnimDatas = AnimDataUtil.Parse(data.AppearanceAnimDataSaveDatas);
        building.normalAnimDatas     = AnimDataUtil.Parse(data.NormalAnimDataSaveDatas);
        #endregion
        return(building);
    }
Example #2
0
    /// <summary>
    /// 克隆
    /// </summary>
    /// <param name="building"></param>
    /// <returns></returns>
    public static Building Clone(Building building)
    {
        Building cloneBuilding = Create(LocalAssetUtil.GetModel(building.modelDataId), building.gameObject.name + CLONE_SUFFIX);

        cloneBuilding.Build();
        building.transformGroup.Inject(cloneBuilding.transform);
        building.appearanceAnimDatas.ForEach(p => cloneBuilding.appearanceAnimDatas.Add(p.Clone()));
        building.normalAnimDatas.ForEach(p => cloneBuilding.normalAnimDatas.Add(p.Clone()));
        cloneBuilding.isAnimOn = building.isAnimOn;
        return(cloneBuilding);
    }