static IEnumerator CheckSupport(Action <bool> checkCall) { yield return(ARSession.CheckAvailability()); if (ARSession.state == ARSessionState.NeedsInstall) { yield return(ARSession.Install()); } if (ARSession.state == ARSessionState.Ready) { checkCall(true); } else { switch (ARSession.state) { case ARSessionState.Unsupported: AFLogger.d("Your device does not support AR."); checkCall(false); break; case ARSessionState.NeedsInstall: AFLogger.d("软件更新失败,或者您拒绝了更新。变为本地放置模型"); checkCall(false); break; } } }
public static void PopulateAvailableScriptingDefineSymbolPredicateInfos() { List <ScriptingDefineSymbolPredicateInfo> predicateInfos = new List <ScriptingDefineSymbolPredicateInfo>(); foreach (Type type in ARSDK_SharedMethod.GetTypesOfType(typeof(AF_SDKManager))) { MethodInfo[] methodInfos = type.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static); for (int index = 0; index < methodInfos.Length; index++) { AFSDK_ScriptingDefineSymbolAttribute[] predicateAttributes = (AFSDK_ScriptingDefineSymbolAttribute[])methodInfos[index].GetCustomAttributes(typeof(AFSDK_ScriptingDefineSymbolAttribute), false); if (predicateAttributes.Length == 0) { continue; } if (methodInfos[index].ReturnType != typeof(bool) || methodInfos[index].GetParameters().Length != 0) { AFLogger.d((methodInfos[index].ReturnType != typeof(bool)) + " " + (methodInfos[index].GetParameters().Length != 0)); AFLogger.e(string.Format("The method '{0}' on '{1}' has '{2}' specified but its signature is wrong. The method must take no arguments and return bool.", methodInfos[index].Name, type, typeof(AFSDK_ScriptingDefineSymbolAttribute))); return; } predicateInfos.AddRange(predicateAttributes.Select(predicateAttribute => new ScriptingDefineSymbolPredicateInfo(predicateAttribute, methodInfos[index]))); } } predicateInfos.Sort((x, y) => string.Compare(x.attribute.SDKSymbol, y.attribute.SDKSymbol, StringComparison.Ordinal)); AvailableScriptingDefineSymbolPredicateInfos = predicateInfos.AsReadOnly(); }
public void ExcelToTxt() { string[,] ExcelInfo = ExcelHelper.GetFirstSheetInfo(excelPath); for (int j = 1; j < ExcelInfo.GetLength(1); j++) { string oneLanuage = ""; for (int i = 1; i < ExcelInfo.GetLength(0); i++) { if (i != 1) { oneLanuage += "\n"; } oneLanuage += ExcelInfo[i, 0] + "=" + ExcelInfo[i, j].Replace("=", "#"); } oneLanuage = oneLanuage.Replace("\n\n", "\n"); if (!LanuageNameToPath.ContainsKey(ExcelInfo[0, j])) { AFLogger.EditorErrorLog("请注意Excel表格与LanuageNameToPath的对应!"); return; } FileHelper.CreatFile(LanuageNameToPath[ExcelInfo[0, j]], System.Text.Encoding.UTF8.GetBytes(oneLanuage), true); } AFLogger.d("Excel表格转TXT文件转换完成!"); }
public void LoadPrefab() { //加载Resource路径下的Prefabs Res.Add(Instantiate( resLoader.LoadSync <GameObject>(ResFromType.ResourcesRes, "ExampleRes/Models/OxygenTank", DestroyCache: true))); AFLogger.d("从Resources加载并实例化了" + Res.Count + "个"); }
private void ABStart(APPVersionStatus versionStatus) { resLoader = ResLoader.Allocate(); if (versionStatus != APPVersionStatus.Abandon) { //这里为了保证PersistentDataPathAB时云端资源下载完成 switch (ABDataHolder.Instance.GetABResLoadFrom()) { case ABResLoadFrom.EditorRes: isABFinish = true; ABStatus.text = "AB包准备完成"; break; case ABResLoadFrom.PersistentDataPathAB: ABHotUpdate.Instance.ABMD5Request("Main", ABProcessevent, ABMD5Callback); break; case ABResLoadFrom.StreamingAssetAB: isABFinish = true; ABStatus.text = "AB包准备完成"; break; } } else { AFLogger.d("版本检测显示是废弃APP,请检查设置"); } }
private static void AddFolderBuild(PBXProject pbx, string targetGUID, string xcodePath, string root) { //获得源文件下所有目录文件 string currDir = Path.Combine(xcodePath, root); if (root.EndsWith(".framework", System.StringComparison.Ordinal) || root.EndsWith(".bundle", System.StringComparison.Ordinal)) { #if UNITY_2019_2_OR_NEWER string target = pbx.TargetGuidByName(pbx.GetUnityMainTargetGuid()); #else string target = pbx.TargetGuidByName(PBXProject.GetUnityTargetName()); #endif Debug.LogFormat("add framework or bundle to build:{0}->{1}", currDir, root); pbx.AddFileToBuild(target, pbx.AddFile(currDir, root, PBXSourceTree.Source)); return; } List <string> folders = new List <string>(Directory.GetDirectories(currDir)); foreach (string folder in folders) { string name = Path.GetFileName(folder); string t_path = Path.Combine(currDir, name); string t_projPath = Path.Combine(root, name); if (folder.EndsWith(".framework", System.StringComparison.Ordinal) || folder.EndsWith(".bundle", System.StringComparison.Ordinal)) { #if UNITY_2019_2_OR_NEWER string target = pbx.TargetGuidByName(pbx.GetUnityMainTargetGuid()); #else string target = pbx.TargetGuidByName(PBXProject.GetUnityTargetName()); #endif Debug.LogFormat("add framework or bundle to build:{0}->{1}", t_path, t_projPath); pbx.AddFileToBuild(target, pbx.AddFile(t_path, t_projPath, PBXSourceTree.Source)); AutoAddSearchPath(pbx, targetGUID, xcodePath, t_path); } else { AddFolderBuild(pbx, targetGUID, xcodePath, t_projPath); } } List <string> files = new List <string>(Directory.GetFiles(currDir)); foreach (string file in files) { if (NeedCopy(file)) { string name = Path.GetFileName(file); string t_path = Path.Combine(currDir, name); string t_projPath = Path.Combine(root, name); #if UNITY_2019_2_OR_NEWER string target = pbx.TargetGuidByName(pbx.GetUnityMainTargetGuid()); #else string target = pbx.TargetGuidByName(PBXProject.GetUnityTargetName()); #endif pbx.AddFileToBuild(target, pbx.AddFile(t_path, t_projPath, PBXSourceTree.Source)); AutoAddSearchPath(pbx, targetGUID, xcodePath, t_path); AFLogger.d("add file to build:" + Path.Combine(root, file)); } } }
public void ReleaseResLoader(List <string> resI) { AFLogger.d("ReleaseRes:" + resI.Count); for (int i = resI.Count - 1; i >= 0; i--) { //减少引用计数,当引用计数为0时才能释放ResInfo ReleaseResouce(resI[i]); } }
public void ChangeLanuageSuffix(string newLanuageSuffix) { if (!LanuageSuffix.Equals(newLanuageSuffix)) { AFLogger.d("更改语言"); LanuageSuffix = newLanuageSuffix; UIManager.Instance.UpdateIntClassData(); } }
public void TxtToExcel() { List <string> LanuageDes = new List <string>(); List <string> LanuageName = new List <string>(LanuageNameToPath.Keys); Dictionary <string, Dictionary <string, string> > LanuageNameToCon = new Dictionary <string, Dictionary <string, string> >(); Dictionary <Vector2, string> excelCon = new Dictionary <Vector2, string>(); excelCon.Add(new Vector2(1, 1), "Description"); for (int i = 0; i < LanuageName.Count; i++) { Dictionary <string, string> txtCon = new Dictionary <string, string>(); TextAsset ta = AssetDatabase.LoadAssetAtPath <TextAsset>(LanuageNameToPath[LanuageName[i]]); string text = ta.text; string[] lines = text.Split('\n'); foreach (string line in lines) { if (line == null) { continue; } string[] keyAndValue = line.Split('='); if (keyAndValue.Length < 2) { AFLogger.EditorErrorLog(LanuageName + "语言文件路径为:" + LanuageNameToPath[LanuageName[i]] + "不符合格式要求,请检查:" + line); continue; } if (i == 0) { LanuageDes.Add(keyAndValue[0]); } if (txtCon.ContainsKey(keyAndValue[0])) { AFLogger.EditorErrorLog("相同的描述:" + keyAndValue[0]); return; } txtCon.Add(keyAndValue[0], keyAndValue[1]); } LanuageNameToCon.Add(LanuageName[i], txtCon); excelCon.Add(new Vector2(1, i + 2), LanuageName[i]); } for (int j = 0; j < LanuageDes.Count; j++) { excelCon.Add(new Vector2(j + 2, 1), LanuageDes[j]); for (int k = 0; k < LanuageName.Count; k++) { excelCon.Add(new Vector2(j + 2, k + 2), LanuageNameToCon[LanuageName[k]][LanuageDes[j]]); } } ExcelHelper.WriteExcel(excelPath, excelCon); EditorUtility.RevealInFinder(excelPath); AFLogger.d("TXT文件转Excel表格转化完成"); }
/// <summary> /// 下载Assetbundleconfig文件回调 /// </summary> /// <param name="data"></param> /// <param name="downResult"></param> /// <param name="downError"></param> public void ABInit(byte[] data, DownStatus downResult = DownStatus.Sucess, string downError = "") { if (downResult != DownStatus.Sucess) { AFLogger.d("下载ABConfig文件失败:" + downError); return; } ABConfigInit(); IsABCheckFinish = true; //开始注册事件 ABCheckInitFinish.InvokeGracefully(versionStatus); }
/// <summary> /// 创建实例 /// </summary> /// <param name="tag"></param> /// <param name="args"></param> /// <typeparam name="T2"></typeparam> /// <returns></returns> public T2 CreateInstance <T2>(string tag, params object[] args) where T2 : class { var cd = GetClassData(tag); if (cd == null) { AFLogger.d("没有找到:" + tag + " -" + typeof(T2).Name); return(null); } return(CreateInstance <T2>(cd, args)); }
public void LoadResPrefab(bool result, ResInfo resInfo) { if (result) { Res.Add(Instantiate(resInfo.ResObject as GameObject)); AFLogger.d("从Resources加载并实例化了" + Res.Count + "个"); } else { AFLogger.e("加载" + resInfo.ResPath + "失败!"); } }
/// <summary> /// 获取xml文件中的识别对象,比如全部的识别图名称,或者模型名称 /// </summary> /// <param name="xmlPath"></param> /// <returns></returns> public static List <string> GetDataSetTarget(string xmlPath) { if (xmlPath == "") { AFLogger.d("未找到DataSet对应的xml文件,请检查设置!"); return(null); } if (!FileHelper.JudgeFilePathExit(xmlPath)) { AFLogger.d("DataSet对应的xml路径不存在:" + xmlPath); return(null); } string xmlContent = FileHelper.ReadTxtToStr(xmlPath); if (xmlContent.Contains("ImageTarget")) { FileInfo fileInfo = new FileInfo(xmlPath); using (FileStream fs = fileInfo.OpenRead()) { var knownTypes = new Type[] { typeof(VuforiaImage.ImageTargetList) }; XmlSerializer xmlserializer = new XmlSerializer(typeof(VuforiaImage.QCARConfig), knownTypes); VuforiaImage.QCARConfig data = xmlserializer.Deserialize(fs) as VuforiaImage.QCARConfig; List <string> imageTargets = new List <string>(); foreach (var OneImageTarget in data.Tracking.ImageTarget) { imageTargets.Add(OneImageTarget.name); } return(imageTargets); } } else if (xmlContent.Contains("ModelTarget") && xmlContent.Contains("Assembly")) { FileInfo fileInfo = new FileInfo(xmlPath); using (FileStream fs = fileInfo.OpenRead()) { var knownTypes = new Type[] { typeof(VuforiaModel.ModelTargetInfo), typeof(VuforiaModel.ModelTargetNameInfo), typeof(VuforiaModel.Assembly), typeof(VuforiaModel.Part) }; XmlSerializer xmlserializer = new XmlSerializer(typeof(VuforiaModel.QCARConfig), knownTypes); VuforiaModel.QCARConfig data = xmlserializer.Deserialize(fs) as VuforiaModel.QCARConfig; List <string> imageTargets = new List <string>(); imageTargets.Add(data.Assembly.Part.name); return(imageTargets); } } return(null); }
protected override void InitUI(UIDataParent UIDataParent = null) { base.InitUI(UIDataParent); AFLogger.d("UIChild InitUI"); if (UIDataParent == null) { return; } UIChildData uIChildData = UIDataParent as UIChildData; AFLogger.log(transform); indexText.text = "子物体:" + uIChildData.index.ToString(); }
public void ReleaseObjPrefab() { if (Obj.Count > 0) { AFLogger.d("释放从AB包加载的资源"); //满足释放的条件 : 1.maxCacheCount为0 2.destoryObj为true 3.引用计数为0 resLoader.ReleaseObj(Obj[Obj.Count - 1], 0, true); Obj.RemoveAt(Obj.Count - 1); } else { AFLogger.d("请先加载资源再释放"); } }
//拷贝文件 public static void CopyFiles(PBXProject pbx, string targetGUID, List <XcodeSettingDic> CopyFileDic, string xcodePath) { foreach (var entry in CopyFileDic) { if (NeedCopy(entry.Key)) { string des = xcodePath + "/" + entry.Value; FileHelper.CopyFile(entry.Key, des); pbx.AddFileToBuild(targetGUID, pbx.AddFile(des, entry.Value, PBXSourceTree.Absolute)); AutoAddSearchPath(pbx, targetGUID, xcodePath, des); AFLogger.d("copy file " + entry.Key + " -> " + des); } } }
public void UpdateFileHead() { byte[] curTexts = System.Text.Encoding.UTF8.GetBytes(FileHeadStr); using (FileStream fs = new FileStream(NewBehaviourScriptPath, FileMode.OpenOrCreate, FileAccess.Write)) { if (fs != null) { fs.SetLength(0); //清空文件 fs.Write(curTexts, 0, curTexts.Length); fs.Flush(); fs.Dispose(); AFLogger.d("Update File: 81-C# Script-NewBehaviourScript.cs.txt, Success"); } } }
public void ReleaseResPrefab() { if (Res.Count > 0) { AFLogger.d("释放从Resources加载的资源"); DestroyImmediate(Res[Res.Count - 1]); Res.RemoveAt(Res.Count - 1); //满足释放的条件 : 1.释放资源时destoryObj为true,默认为false 2.此资源的引用计数为0 //也就是说你加载此资源实例化了多少次,就需要释放多少次,并且最后一次释放调用destoryObj = true resLoader.ReleaseRes("ExampleRes/Models/OxygenTank", true); } else { AFLogger.d("请先加载资源再释放"); } }
public void ReleaseObjLoader(List <int> resI) { AFLogger.d("ReleaseRes:" + resI.Count); for (int i = resI.Count - 1; i >= 0; i--) { //确定是ObjectLoader创建的 if (mResouceObjDic.ContainsKey(resI[i])) { ReleaseObj(resI[i], 0, destoryCache: mResouceObjDic[resI[i]].mClear); } else { AFLogger.e("对象不是ObjectLoader创建的!"); } } }
protected override void InitUI(UIDataParent UIDataParent = null) { base.InitUI(UIDataParent); AFLogger.d("UIABLoadTestPre InitUI"); UIChildData uIChildData = new UIChildData(); //初始化子物体 for (int i = 0; i < 3; i++) { //TODO : transformPath完成替换 uIChildData.index = i; CreateSubPanel <UIChild>((int)testChildUIEnum.UIChild, transform.GetChild(1).GetChild(0).GetChild(0), UIDataParent: uIChildData, this); } }
void TransformBind() { //解析AFTransformPathAttribute属性 var flag = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; FieldInfo[] fieldInfos = this.GetType().GetFields(flag); foreach (var fi in fieldInfos) { var attrs = fi.GetCustomAttributes(typeof(AFTransformPathAttribute), false); if (attrs != null && attrs.Length > 0) { if (attrs.Length > 1) { Debug.LogWarning("自动注入只能标记一次,重复的会取最后一次"); } var attr = attrs[attrs.Length - 1] as AFTransformPathAttribute; Transform trans = transform.Find(attr.TransPath); if (!trans) { AFLogger.d("节点不存在:" + attr.TransPath); continue; } else { if (fi.FieldType == typeof(GameObject)) { fi.SetValue(this, trans.gameObject); continue; } else if (fi.FieldType == typeof(Transform)) { fi.SetValue(this, trans); continue; } else if (typeof(Component).IsAssignableFrom(fi.FieldType)) { fi.SetValue(this, trans.GetComponent(fi.FieldType)); continue; } } } else { continue; } } }
IEnumerator SendRequstFromList() { while (true) { if (!isDowning && URLToHttpBase.Count > 0) { List <string> urls = new List <string>(URLToHttpBase.Keys); AFLogger.d("请求URL为:" + urls[0]); CurRequesting = URLToHttpBase[urls[0]]; CurRequesting.StartWebRequest(); isDowning = true; } else { yield return(null); } } }
public bool Register(int key, MsgEvent fun) { var kv = key; EventInfo wrap; if (!EventIDToAction.TryGetValue(kv, out wrap)) { wrap = new EventInfo(); EventIDToAction.Add(kv, wrap); } if (wrap.Add(fun)) { return(true); } AFLogger.d("Already Register Same Event:" + key); return(false); }
static void BunildAssetBundle(AF_ABConfig abConfig) { string[] allBundles = AssetDatabase.GetAllAssetBundleNames(); //key : 为全路径 value :为名字 Dictionary <string, string> resPathDic = new Dictionary <string, string>(); for (int i = 0; i < allBundles.Length; i++) { string[] allBundlePath = AssetDatabase.GetAssetPathsFromAssetBundle(allBundles[i]); for (int j = 0; j < allBundlePath.Length; j++) { //判断有没有包含脚本文件 if (allBundlePath[j].EndsWith(".cs")) { continue; } //Debug.Log("此AB包:" + allBundles[i] + "下面包含的资源文件路径:" + allBundlePath[j]); if (ValidPath(allBundlePath[j])) { resPathDic.Add(allBundlePath[j], allBundles[i]); } } } //现在已经设置好了在这一次要打包的AB包,因此要清除无用的AB包,比如之前存在的AB包 DeleteAB(); //生成自己的配置表 WriteData(resPathDic, abConfig.configWritingMode, abConfig.packageABType); AssetBundleManifest manifest = BuildPipeline.BuildAssetBundles(m_BundleTargetPath, BuildAssetBundleOptions.ChunkBasedCompression, buildTarget); if (manifest == null) { AFLogger.EditorErrorLog("AssetBundle" + buildTarget.ToString() + "打包失败,请检查设置!"); } else { AFLogger.d("AssetBundle" + buildTarget.ToString() + "打包完毕"); } }
/// <summary> /// 从外部路径加载dataset /// </summary> /// <param name="absolutePath"></param> public static void LoadDataSetFromPath(string absolutePath) { ObjectTracker objectTracker = TrackerManager.Instance.GetTracker <ObjectTracker>(); if (!DataSet.Exists(absolutePath, VuforiaUnity.StorageType.STORAGE_ABSOLUTE)) { AFLogger.d("load dataset Exists null:" + absolutePath); return; } else { objectTracker.Stop(); DataSet dataSet = objectTracker.CreateDataSet(); if (dataSet.Load(absolutePath, VuforiaUnity.StorageType.STORAGE_ABSOLUTE)) { //这里必须要停止跟踪才能激活DataSet objectTracker.ActivateDataSet(dataSet); } objectTracker.Start(); } }
/// <summary> /// 主循环 /// </summary> void Update() { //停止所有协程 if (isStopAllCroutine) { AFLogger.d("停止所有协程"); StopAllCoroutines(); isStopAllCroutine = false; } //优先停止协程 while (stopIEIdQueue.Count > 0) { var id = stopIEIdQueue.Dequeue(); Coroutine coroutine = null; if (coroutineDictionary.TryGetValue(id, out coroutine)) { base.StopCoroutine(coroutine); coroutineDictionary.Remove(id); } else { AFLogger.e(string.Format("此id协程不存在,无法停止:{0}", id)); } } //协程循环 while (IEnumeratorQueue.Count > 0) { var id = IEnumeratorQueue.Dequeue(); //取出协程 var ie = iEnumeratorDictionary[id]; iEnumeratorDictionary.Remove(id); //执行协程 var coroutine = base.StartCoroutine(ie); //存入coroutine coroutineDictionary[id] = coroutine; } }
public void AutoAddTarget() { if (TargetDataSetName.IsNullOrEmpty()) { AFLogger.EditorErrorLog("DataSet名称为空!"); return; } AF_ABConfig ABConfig = AssetDatabasex.LoadAssetOfType <AF_ABConfig>("AF_ABConfig"); char[] t = ABConfig.defaultDataSetPath.ToCharArray(); string xmlPath = ABConfig.defaultDataSetPath; if (t[t.Length - 1] == '/') { xmlPath += TargetDataSetName + ".xml"; } else { xmlPath += "/" + TargetDataSetName + ".xml"; } if (xmlPath == "") { AFLogger.d("未找到DataSet对应的xml文件,请检查m_AllFileAB中是否有配置CategoryOfOwnership为" + ABClassType + "且isHasDataset为true"); return; } if (mImagetTargetInfo == null) { mImagetTargetInfo = new List <OneTargetInfo>(); } List <string> allRecogTarget = AFSDK_DataSetHandle.GetDataSetTarget(xmlPath); if (allRecogTarget == null) { AFLogger.EditorErrorLog("解析xml失败!"); return; } for (int j = mImagetTargetInfo.Count - 1; j >= 0; j--) { bool isNeedRemove = true; for (int i = allRecogTarget.Count - 1; i >= 0; i--) { if (mImagetTargetInfo[j].ImageTargetName.Equals(allRecogTarget[i])) { isNeedRemove = false; allRecogTarget.RemoveAt(i); break; } } if (isNeedRemove) { mImagetTargetInfo.RemoveAt(j); } } foreach (string recogName in allRecogTarget) { OneTargetInfo oneTargetInfo = new OneTargetInfo(); oneTargetInfo.ImageTargetName = recogName; oneTargetInfo.oneResInfo.ResScale = new Vector3(1, 1, 1); mImagetTargetInfo.Add(oneTargetInfo); } }
protected override void InitUIAll(UIDataParent UIDataParent = null) { base.InitUIAll(UIDataParent); AFLogger.d("UIABLoadTestPre InitUIAll"); }
protected override void RegisterUIEvent() { base.RegisterUIEvent(); AFLogger.d("UIABLoadTestPre RegisterUIEvent"); }
public override void RefreshUIByData(UIDataParent UIDataParent = null) { base.RefreshUIByData(UIDataParent); AFLogger.d("UIABLoadTestPre RefreshUIByData"); }