void ResourceListener(AssetPtr ptr) { if (ptr == null || ptr.Data == null) { return; } if (!ptr.Data.url.Contains(mCurnAnimatorame)) { return; } GameObject cameraanimator = new GameObject(mCurnAnimatorame); CameraPath cPath = cameraanimator.AddComponent <CameraPath>(); CameraPathAnimator animator = cameraanimator.AddComponent <CameraPathAnimator>(); XmlDocument xml = new XmlDocument(); xml.LoadXml(ptr.Data.text); cPath.FromXML(xml); if (Camera.main != null) { animator.animationObject = Camera.main.transform; } BaseScene scene = SceneManager.Instance.GetCurScene(); if (scene != null) { animator.AnimationCustomEvent += scene.GetCameraPathManager().OnCustomEvent; animator.AnimationFinishedEvent += animator_AnimationFinishedEvent; } FollowAnimator = animator; animator.Play(); }
public static void ImportCameraPath() { string filefolder = PlayerPrefs.GetString("camerapath"); if (!Directory.Exists(filefolder)) { return; } string path = EditorUtility.OpenFilePanel("打开摄像机文件", filefolder, "xml"); string filename = Path.GetFileNameWithoutExtension(path); string[] arr = filename.Split(new string[] { "_^_^_" }, StringSplitOptions.None); if (arr.Length != 2) { EditorUtility.DisplayDialog("提示", "打开文件错误", "确定"); return; } GameObject newCameraPath = new GameObject(arr[1]); Undo.RegisterCreatedObjectUndo(newCameraPath, "Import Camera Path"); CameraPath cPath = newCameraPath.AddComponent <CameraPath>(); CameraPathAnimator animator = newCameraPath.AddComponent <CameraPathAnimator>(); cPath.FromXML(path); if (Camera.main != null) { animator.animationObject = Camera.main.transform; } Selection.objects = new Object[] { newCameraPath }; SceneView.lastActiveSceneView.FrameSelected(); EditorUtility.SetDirty(newCameraPath); }
/// <summary> /// 动态初始化 /// </summary> /// <param name="data">英雄阵型序列化数据</param> /// <param name="XmlName">Xml地址</param> /// <param name="type">英雄阵型</param> /// <param name="speed">初始移动速度</param> public void Init(HeroPathDataObj data, HeroFormationType type, string PathXml) { //添加轨迹组件 动画组件 读取轨迹数据 HeroPathdata = data; HeroPath = this.gameObject.AddComponent <CameraPath>(); HeroPathAnim = this.gameObject.AddComponent <CameraPathAnimator>(); HeroPath.FromXML(PathXml); HeroPath.hermiteTension = data.Tension; //初始话战斗中心点和英雄中心点 FightCenter = new GameObject("FightCenter"); FightCenter.transform.parent = this.transform; FightCenter.transform.position = data.InitPos; HerosCenter = new GameObject("HerosCenter"); HerosCenter.transform.parent = this.transform; HerosCenter.transform.position = data.InitPos; //初始化战斗摄像机 整队摄像机 FightFollowCam = new GameObject("FightFollowCam"); FightFollowCam.transform.parent = FightCenter.transform; FightFollowCam.transform.localPosition = data.FightFollowCamPos; FightDefaultCam = new GameObject("FightDefaultCam"); FightDefaultCam.transform.SetParent(FightCenter.transform); FightDefaultCam.transform.localPosition = data.FightDefaultCamPos; LineUpFollowCam = new GameObject("LineUpFollowCam"); LineUpFollowCam.transform.parent = HerosCenter.transform; LineUpFollowCam.transform.localPosition = data.LineUpFollowCamPos; //初始化队伍阵型 GameObject objType = AssetLoader.Inst.GetAssetRes(type.ToString()); FormationCenterObj = Instantiate(objType, data.InitPos, data.InitAngles) as GameObject; HeroFormationtype = type; // FormationCenterObj.transform.parent = this.transform; FormationList = new List <GameObject>(); for (int i = 0; i < FormationCenterObj.transform.childCount; i++) { FormationList.Add(FormationCenterObj.transform.GetChild(i).gameObject); //Debug.Log(FormationCenterObj.transform.GetChild(i).position); } FormationDic = new Dictionary <ObjectCreature, GameObject>(); //初始化轨迹组件信息 HeroPathAnim.animationObject = FormationCenterObj.transform; HeroPathAnim.pathSpeed = 0; Heropathtype = HeroPathMoveType.Null; HeroPathPause(); SetHeroPathIdle(); }