Esempio n. 1
0
 private void INowTaskStateChanged(INowTaskState iNowTaskState, string targetName)
 {
     //接受任务时调用
     if (string.Equals(targetName, GameState.Instance.GetFieldName <INowTaskState, int>(temp => temp.StartTask)))
     {
         InterludesData       interludesData       = DataCenter.Instance.GetMetaData <InterludesData>();
         InterludesItemStruct interludesItemStruct = interludesData.GetInterludesItemStructByTaskID(iNowTaskState.StartTask);
         if (interludesItemStruct != null)
         {
             StartInterludes(interludesItemStruct);
         }
         else
         {
             Debug.Log("该任务没有过场动画");
         }
     }
     //完成任务时调用
     else if (string.Equals(targetName, GameState.Instance.GetFieldName <INowTaskState, int>(temp => temp.OverTaskID)))
     {
         InterludesData       interludesData       = DataCenter.Instance.GetMetaData <InterludesData>();
         InterludesItemStruct interludesItemStruct = interludesData.GetInterludesItemStructByTaskID(iNowTaskState.OverTaskID, InterludesItemStruct.EnumInterludesShowTime.Over);
         if (interludesItemStruct != null)
         {
             StartInterludes(interludesItemStruct);
         }
         else
         {
             Debug.Log("该任务没有过场动画");
         }
     }
 }
Esempio n. 2
0
 /// <summary>
 /// 开始过场动画
 /// </summary>
 /// <param name="interludesItemStruct"></param>
 private void StartInterludes(InterludesItemStruct interludesItemStruct)
 {
     if (interludesEnumerator == null && interludesItemStruct != null)
     {
         iGameState.PushEnumGameRunType(EnumGameRunType.Interludes);
         interludesEnumerator = RunningInterludes(interludesItemStruct);
     }
 }
    private void OnGUI()
    {
        if (interludesItemStructList == null)
        {
            return;
        }
        if (itemDataTypeToExplanDic == null)
        {
            return;
        }
        EditorGUILayout.BeginHorizontal();
        //显示列表
        EditorGUILayout.BeginVertical(GUILayout.Width(200));
        if (GUILayout.Button("保存"))
        {
            string assetStr = SerializeNow(interludesItemStructList);
            File.WriteAllText(dataInterludesFilePath, assetStr, Encoding.UTF8);
            EditorUtility.DisplayDialog("提示!", "保存成功!", "确定");
        }
        if (GUILayout.Button("添加"))
        {
            int nextID = GetNextID();
            interludesItemStructList.Add(new InterludesItemStruct()
            {
                ID = nextID, TaskID = -1, InterludesShowTime = InterludesItemStruct.EnumInterludesShowTime.Start, InterludesDataInfo = new InterludesDataInfo()
                {
                    Datas = new List <InterludesDataInfo.ItemData>()
                }
            });
        }
        listScroll = EditorGUILayout.BeginScrollView(listScroll);
        InterludesItemStruct[] tempInterludesItemStructArray = interludesItemStructList.ToArray();
        foreach (InterludesItemStruct tempInterludesItemStruct in tempInterludesItemStructArray)
        {
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("删除") && EditorUtility.DisplayDialog("警告!", "请再次确认是否删除?", "确认", "取消 "))
            {
                interludesItemStructList.Remove(tempInterludesItemStruct);
                if (selectInterludesItemStruct == tempInterludesItemStruct)
                {
                    selectInterludesItemStruct = interludesItemStructList.FirstOrDefault();
                }
            }
            if (selectInterludesItemStruct == tempInterludesItemStruct)
            {
                GUILayout.Space(10);
            }
            string buttonShow = "[" + tempInterludesItemStruct.ID + "]任务ID:" + tempInterludesItemStruct.TaskID + "--" + tempInterludesItemStruct.InterludesShowTime;
            if (GUILayout.Button(buttonShow))
            {
                selectInterludesItemStruct = tempInterludesItemStruct;
            }
            if (selectInterludesItemStruct != tempInterludesItemStruct)
            {
                GUILayout.Space(10);
            }
            EditorGUILayout.EndHorizontal();
        }


        EditorGUILayout.EndScrollView();
        EditorGUILayout.EndVertical();
        //显示数据
        EditorGUILayout.BeginVertical();
        valueScroll = EditorGUILayout.BeginScrollView(valueScroll);
        if (selectInterludesItemStruct != null)
        {
            EditorGUILayout.LabelField("ID:" + selectInterludesItemStruct.ID);
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("任务ID(输入-1则表示不适用于任务)");
            selectInterludesItemStruct.TaskID = EditorGUILayout.IntField(selectInterludesItemStruct.TaskID);
            EditorGUILayout.EndHorizontal();
            if (selectInterludesItemStruct.TaskID >= 0)
            {
                EditorGUILayout.BeginHorizontal();
                List <InterludesItemStruct.EnumInterludesShowTime> interludesShowTimeValues = interludesShowTimeExplanList.Select(temp => temp.Key).ToList();
                string[] interludesShowTimeExplans = interludesShowTimeExplanList.Select(temp => temp.Value).ToArray();
                int      tempIndex = interludesShowTimeValues.IndexOf(selectInterludesItemStruct.InterludesShowTime);
                EditorGUILayout.LabelField("触发条件:");
                tempIndex = EditorGUILayout.Popup(tempIndex, interludesShowTimeExplans);
                if (tempIndex > -1)
                {
                    selectInterludesItemStruct.InterludesShowTime = interludesShowTimeValues[tempIndex];
                }
                EditorGUILayout.EndHorizontal();
            }
            if (GUILayout.Button("添加数据"))
            {
                selectInterludesItemStruct.InterludesDataInfo.Datas.Add(new InterludesDataInfo.ItemData());
            }

            List <Type> itemDataValues              = itemDataTypeToExplanDic.Select(temp => temp.Key).ToList();
            string[]    itemDataExplans             = itemDataTypeToExplanDic.Select(temp => temp.Value).ToArray();
            InterludesDataInfo.ItemData[] itemDatas = selectInterludesItemStruct.InterludesDataInfo.Datas.ToArray();
            foreach (InterludesDataInfo.ItemData itemData in itemDatas)
            {
                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button("×", GUILayout.Width(20)) && EditorUtility.DisplayDialog("警告!", "请再次确认是否删除?", "确认", "取消"))
                {
                    selectInterludesItemStruct.InterludesDataInfo.Datas.Remove(itemData);
                }
                int tempIndex = selectInterludesItemStruct.InterludesDataInfo.Datas.IndexOf(itemData);
                if (GUILayout.Button("↑", GUILayout.Width(20)))
                {
                    if (tempIndex > 0)
                    {
                        selectInterludesItemStruct.InterludesDataInfo.Datas.Remove(itemData);
                        selectInterludesItemStruct.InterludesDataInfo.Datas.Insert(tempIndex - 1, itemData);
                    }
                }
                if (GUILayout.Button("↓", GUILayout.Width(20)))
                {
                    if (tempIndex < selectInterludesItemStruct.InterludesDataInfo.Datas.Count - 1)
                    {
                        selectInterludesItemStruct.InterludesDataInfo.Datas.Remove(itemData);
                        selectInterludesItemStruct.InterludesDataInfo.Datas.Insert(tempIndex + 1, itemData);
                    }
                }
                EditorGUILayout.EndHorizontal();
                if (itemData == null)
                {
                    EditorGUILayout.LabelField("该项为空");
                    continue;
                }
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("持续时间:", GUILayout.Width(50));
                itemData.baseKeepTime = EditorGUILayout.FloatField(itemData.baseKeepTime);
                EditorGUILayout.EndHorizontal();
                //切换类型
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("数据类型:", GUILayout.Width(50));
                var varItemDataValues   = Enumerable.Range(0, itemDataValues.Count).Select(temp => new { _index = temp, _type = itemDataValues[temp] });
                var varItemDataValue    = varItemDataValues.FirstOrDefault(temp => string.Equals(itemData.GetType().Name, temp._type.Name));
                int tempTypeIndex       = varItemDataValue._index;
                int changeTempTypeIndex = EditorGUILayout.Popup(tempTypeIndex, itemDataExplans, GUILayout.Width(120));
                if (changeTempTypeIndex > -1 && changeTempTypeIndex != tempTypeIndex)// 切换了类型
                {
                    if (EditorUtility.DisplayDialog("提示!", "是否切换类型?注意切换类型后会丢失原有类型的数据!", "确认", "取消"))
                    {
                        Type itemDataType = itemDataValues[changeTempTypeIndex];
                        int  nowIndex     = selectInterludesItemStruct.InterludesDataInfo.Datas.IndexOf(itemData);
                        if (nowIndex > -1)
                        {
                            selectInterludesItemStruct.InterludesDataInfo.Datas[nowIndex] = Activator.CreateInstance(itemDataType) as InterludesDataInfo.ItemData;
                            if (selectInterludesItemStruct.InterludesDataInfo.Datas[nowIndex] == null)
                            {
                                selectInterludesItemStruct.InterludesDataInfo.Datas[nowIndex] = itemData;
                            }
                            selectInterludesItemStruct.InterludesDataInfo.Datas[nowIndex].baseKeepTime = itemData.baseKeepTime;
                        }
                    }
                }
                //显示不同类型的面板
                switch (itemData.GetType().Name)
                {
                case "ItemData_Talk":
                    InterludesDataInfo.ItemData_Talk itemData_Talk = itemData as InterludesDataInfo.ItemData_Talk;
                    if (itemData_Talk != null)
                    {
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.LabelField("对话的ID:", GUILayout.Width(50));
                        itemData_Talk.TalkID = EditorGUILayout.IntField(itemData_Talk.TalkID);
                        EditorGUILayout.EndHorizontal();
                    }
                    break;

                case "ItemData_CameraPathAnimation":
                    InterludesDataInfo.ItemData_CameraPathAnimation itemData_CameraPathAnimation = itemData as InterludesDataInfo.ItemData_CameraPathAnimation;
                    if (itemData_CameraPathAnimation != null)
                    {
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.LabelField("摄像机动画预设体:", GUILayout.Width(100));
                        EditorGUILayout.ObjectField(itemData_CameraPathAnimation.ObjPrefab, typeof(GameObject), false, GUILayout.Width(150));
                        if (GUILayout.Button("S", GUILayout.Width(20)))
                        {
                            ObjectSelectorWindow.get.Show(itemData_CameraPathAnimation.ObjPrefab, typeof(GameObject), null, resultObj => itemData_CameraPathAnimation.ObjPrefab = (GameObject)resultObj, cameraPathDirectoryShowWindowPath);
                        }
                        if (GUILayout.Button("创建"))
                        {
                            string prefabName = "Interludes_CameraPathAnimation_" + System.DateTime.Now.ToBinary();
                            //创建预设体
                            GameObject obj = new GameObject();
                            obj.transform.position = Vector3.forward;
                            obj.AddComponent <CameraPath>();
                            obj.AddComponent <CameraPathAnimator>();
                            UnityEngine.Object prefab = PrefabUtility.CreateEmptyPrefab(cameraPathDirectoryShowWindowPath + "/" + prefabName + ".prefab");
                            //关联并设置到对象
                            itemData_CameraPathAnimation.ObjPrefab = PrefabUtility.ReplacePrefab(obj, prefab, ReplacePrefabOptions.ConnectToPrefab);
                            //然后删除对象
                            GameObject.DestroyImmediate(obj);
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                    break;
                }
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.Space();
                EditorGUILayout.Space();
            }
        }
        EditorGUILayout.EndScrollView();
        EditorGUILayout.EndVertical();
        EditorGUILayout.EndHorizontal();
    }
Esempio n. 4
0
    /// <summary>
    /// 过场动画运行时携程(只能返回true或false)
    /// </summary>
    /// <returns></returns>
    IEnumerator RunningInterludes(InterludesItemStruct interludesItemStruct)
    {
        float       runTime     = 0;
        CanvasGroup canvasGroup = null;

        if (iGameState.InterludesPanel != null)
        {
            canvasGroup = iGameState.InterludesPanel.GetComponent <CanvasGroup>();
        }
        iGameState.InterludesPanel.enabled = true;
        //开场先显示黑幕
        while (runTime < 1)
        {
            runTime += Time.deltaTime;
            if (canvasGroup)
            {
                canvasGroup.alpha = runTime;
            }
            yield return(false);
        }
        canvasGroup.alpha = 1;
        //执行数据的读取和初始化操作
        iGameState.ActionPanel.enabled  = false;
        iGameState.SettingPanel.enabled = false;
        iGameState.MainPanel.enabled    = false;
        iGameState.InterludesCamera.gameObject.SetActive(true);
        iGameState.InterludesCamera.transform.position    = iPlayerState.PlayerCamera.transform.position;
        iGameState.InterludesCamera.transform.eulerAngles = iPlayerState.PlayerCamera.transform.eulerAngles;
        //将黑幕隐藏同时开始控制播放
        bool interludesIsOver = false;

        runTime = 0;
        List <GameObject> rubbishList = new List <GameObject>(); //用于存放临时生成的垃圾
        int    interludesIndex        = -1;                      //当前的过场项目下标
        Action WaitOverAction         = null;                    //等待持续时间结束委托对象

        while (runTime < 1 || !interludesIsOver || WaitOverAction != null)
        {
            runTime += Time.deltaTime;
            if (canvasGroup)
            {
                float alpha = Mathf.Clamp(1 - runTime, 0, 1);
                canvasGroup.alpha = alpha;
            }
            if (!interludesIsOver)
            {
                //具体的控制逻辑
                interludesIsOver = true;
                interludesIndex++;
                runTaskStruct.StopTask();
                if (interludesIndex < interludesItemStruct.InterludesDataInfo.Datas.Count)//如果还有过场数据则取出来
                {
                    InterludesDataInfo.ItemData itemData = interludesItemStruct.InterludesDataInfo.Datas[interludesIndex];
                    float keepTime = itemData.baseKeepTime;
                    //设置持续时间委托对象的实体
                    WaitOverAction = () =>
                    {
                        keepTime -= Time.deltaTime;
                        if (keepTime < 0)
                        {
                            interludesIsOver = false;
                            WaitOverAction   = null;
                        }
                    };
                    //根据不同的类型将数值传递给指定对象
                    //如果是对话则传递给对话控制
                    if (string.Equals(itemData.GetType().Name, typeof(InterludesDataInfo.ItemData_Talk).Name))
                    {
                        //获取对话
                        InterludesDataInfo.ItemData_Talk itemData_talk = itemData as InterludesDataInfo.ItemData_Talk;
                        DialogueCondition talkCondition = dialogueStructData.SearchDialogueConditionByID(itemData_talk.TalkID);
                        ShowTalk(talkCondition);
                        runTaskStruct.StartTask(0f, CheckTalk, -1, true);
                    }
                    else if (string.Equals(itemData.GetType().Name, typeof(InterludesDataInfo.ItemData_CameraPathAnimation).Name))
                    {
                        //获取镜头动画
                        InterludesDataInfo.ItemData_CameraPathAnimation itemData_CameraPathAnimation = itemData as InterludesDataInfo.ItemData_CameraPathAnimation;
                        if (itemData_CameraPathAnimation.ObjPrefab)
                        {
                            GameObject cameraPathAniamtionObj = GameObject.Instantiate <GameObject>(itemData_CameraPathAnimation.ObjPrefab);
                            rubbishList.Add(cameraPathAniamtionObj);
                            CameraPathAnimator cameraPathAniamtor = cameraPathAniamtionObj.GetComponent <CameraPathAnimator>();
                            cameraPathAniamtor.animationObject = iGameState.InterludesCamera.transform;
                            cameraPathAniamtor.Play();
                        }
                    }
                }
                else
                {
                    WaitOverAction = null;
                }
            }
            if (WaitOverAction != null)
            {
                WaitOverAction();
            }
            yield return(false);
        }
        //闭幕前显示黑幕
        while (runTime < 1)
        {
            runTime += Time.deltaTime;
            if (canvasGroup)
            {
                canvasGroup.alpha = runTime;
            }
            yield return(false);
        }
        canvasGroup.alpha = 1;
        //初始化摄像机等数据
        iGameState.ActionPanel.enabled  = true;
        iGameState.SettingPanel.enabled = true;
        iGameState.MainPanel.enabled    = true;
        iGameState.InterludesCamera.gameObject.SetActive(false);
        foreach (var item in rubbishList)
        {
            GameObject.Destroy(item);
        }
        //将黑幕隐藏
        runTime = 0;
        while (runTime < 1)
        {
            runTime += Time.deltaTime;
            if (canvasGroup)
            {
                canvasGroup.alpha = 1 - runTime;
            }
            yield return(false);
        }
        canvasGroup.alpha = 0;
        iGameState.InterludesPanel.enabled = false;
    }