//确有添加操作则返回true
 public static bool _TryAddHideNpcId(ref CameraCinemaJsonData cameraCinemaJsonData, int npcId)
 {
     if (null != cameraCinemaJsonData)
     {
         int index = Array.IndexOf(cameraCinemaJsonData.hideNpcIds, npcId);
         if (index < 0)//不存在,则加入
         {
             int[] newHideNpcIds = new int[cameraCinemaJsonData.hideNpcIds.Length + 1];
             cameraCinemaJsonData.hideNpcIds.CopyTo(newHideNpcIds, 0);
             newHideNpcIds[cameraCinemaJsonData.hideNpcIds.Length] = npcId;//追加新的npcId
             cameraCinemaJsonData.hideNpcIds = newHideNpcIds;
             return(true);
         }
     }
     return(false);
 }
Пример #2
0
        public static void TestSave()
        {
            //新建数据
            CameraCinemaJsonData cameraCinemaJsonData = new CameraCinemaJsonData();

            cameraCinemaJsonData.playMode = CinemaPlayMode.Default;
            cameraCinemaJsonData.extend   = new CinemaExtendJsonData();
            CinemaExtendJsonData.Material m1 = new CinemaExtendJsonData.Material();
            m1.data            = new CinemaExternDataMaterial();
            m1.data.targetPath = "player/create_login_actor";
            m1.data.colorList  = new List <MatColor>()
            {
                new MatColor("_RimColor", 0.0f, 0.4f, 1.0f, 1.0f)
            };
            m1.data.floatList = new List <MatFloat>()
            {
                new MatFloat("_RimIntensity", 5.0f),
                new MatFloat("_RimPower", 2.7300000190734865f),
            };

            cameraCinemaJsonData.extend.materials             = new CinemaExtendJsonData.Material[] { m1 };
            cameraCinemaJsonData.extend.operations            = new CinemaExtendJsonData.Operation[0];
            cameraCinemaJsonData.extend.postEffectFirstIndexs = new int[] { 85, 86 };
            cameraCinemaJsonData.extend.renderLods            = new int[] { -1, 1, 1, 1, 1 };


            cameraCinemaJsonData.needReplayForDelaying = true;
            cameraCinemaJsonData.allowCinemaGroup      = true;
            cameraCinemaJsonData.groupMode             = CinemaGroupMode.ShunXuBoFang;
            cameraCinemaJsonData.groupCinemas          = new string[] { "aaa", "bbb", "ccc" };
            cameraCinemaJsonData.hideHostPlayer        = true;
            cameraCinemaJsonData.hideOtherPlayer       = true;
            cameraCinemaJsonData.hideNpcIds            = new int[] { 111, 222, 333, 444, 555 };
            cameraCinemaJsonData.handleMainCamera      = true;
            cameraCinemaJsonData.handleUICamera        = true;
            cameraCinemaJsonData.canSkip          = true;
            cameraCinemaJsonData.allowSelectScene = true;
            // 写入
            Persistence.json.Save(path, cameraCinemaJsonData);
        }
        //生成的中间json数据,导出新的动画json数据
        public void Export()
        {
            //1. 读取本地cinemjson数据
            _LoadAndCacheCinemaJsonData();
            //2. 读取中间json数据
            BridgeHideNpcCinemaJsonData bridgeHideNpcCinemaJsonData = Persistence.json.LoadFile <BridgeHideNpcCinemaJsonData>(CinemaDataCommon.BridgeHideNpcCinemaJsonName);
            //3. 修改本地cinemaJson数据并导出成新的json文件
            List <int> _dataChangedCinemaIds = new List <int>();//动画配置数据发生变化了的动画ID

            if (null != bridgeHideNpcCinemaJsonData && (bridgeHideNpcCinemaJsonData.data.Length > 0))
            {
                int count = bridgeHideNpcCinemaJsonData.data.Length;
                for (int i = 0; i < count; i++)
                {
                    BridgeHideNpcCinemaJsonData.JsonData jsonData = bridgeHideNpcCinemaJsonData.data[i];
                    int        npcId                = jsonData.npc_id;
                    CinemaType cinemType            = jsonData.cinema_type;
                    int[]      cinemaIdsTobeChanged = jsonData.cinema_ids;//收集需要修改的动画ID
                    //3 优先处理指定类型的动画,不然处理修改指定的动画ID
                    if (cinemType != CinemaType.None)
                    {
                        List <int> cinemaIdsWithSameType;
                        if (cinemaTypeMapCinemaIds.TryGetValue(cinemType, out cinemaIdsWithSameType))
                        {
                            cinemaIdsTobeChanged = cinemaIdsWithSameType.ToArray();
                        }
                    }


                    foreach (var cinemaIdToBeChanged in cinemaIdsTobeChanged)
                    {
                        //根据动画ID获取对应的cinemaJsonData
                        CinemaJsonData cjd;
                        if (cinemaIdMapCinemaJsonData.TryGetValue(cinemaIdToBeChanged, out cjd))
                        {
                            if (cjd is CameraCinemaJsonData)
                            {
                                CameraCinemaJsonData ccjd = cjd as CameraCinemaJsonData;
                                //目前只有镜头动画才有隐藏npc的功能
                                //尝试追加npcId
                                bool dataChanged = _TryAddHideNpcId(ref ccjd, npcId);
                                if (dataChanged)
                                {
                                    //记录已经修改的动画ID
                                    if (!_dataChangedCinemaIds.Contains(cinemaIdToBeChanged))
                                    {
                                        _dataChangedCinemaIds.Add(cinemaIdToBeChanged);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            //4. 将数据有变化的动画数据导出为json
            foreach (var dataChangedCinemaId in _dataChangedCinemaIds)
            {
                //找到动画名
                string cinemaName = "";
                if (cinemaIdMapCinemaName.TryGetValue(dataChangedCinemaId, out cinemaName))
                {
                    //获取更新后的cinemaJsonData
                    CinemaJsonData cjd;
                    if (cinemaIdMapCinemaJsonData.TryGetValue(dataChangedCinemaId, out cjd))
                    {
                        //导出json文件,目前只修改镜头动画的数据
                        if (null != cjd && cjd is CameraCinemaJsonData)
                        {
                            Persistence.json.Save(CinemaDataCommon.GetCinemaJsonFileFullPath(cinemaName), cjd);
                            Console.WriteLine("modify cinema id:{0},cinema name:{1}", dataChangedCinemaId, cinemaName);
                        }
                    }
                }
            }
        }
Пример #4
0
 public static void TestLoad()
 {
     CameraCinemaJsonData cameraCinemaJsonData = Persistence.json.LoadFile <CameraCinemaJsonData>(path);
 }