/// <summary> /// 选取一个Anchor的标志物 /// </summary> /// <param name="mark"></param> private void SelectMark(AnchorMark mark) { if (currentAnchorInfo != null) { ChangeAdjustType(SpatialAdjustType.None); //currentAnchorInfo.mark.SetAdjustType(AnchorAdjestType.None); currentAnchorInfo.mark.SetMarkSelected(false); StopAdjust(currentAnchorInfo); } if (mark == null) { currentAnchorInfo = null; return; } for (int i = 0; i < anchorObjectList.Count; i++) { AnchorObjectInfo info = anchorObjectList[i]; if (info.anchorName == mark.anchorName) { currentAnchorInfo = info; currentAnchorInfo.mark.SetMarkSelected(true); StartAdjust(currentAnchorInfo); break; } } }
private void OnTap(int tapCount) { if (currentAnchorInfo == null) { if (inputManager.FocusedObject != null) { AnchorMark mark = inputManager.FocusedObject.GetComponentInParent <AnchorMark>(); if (mark != null) { SelectMark(mark); } } else { FinishAdjust(); } } else { if (isFitting) { StopFit(); } else { if (inputManager.FocusedObject != null) { AnchorAdjestButton button = inputManager.FocusedObject.GetComponent <AnchorAdjestButton>(); if (button != null) { // 点到按钮了 ChangeAdjustType(button.type); //currentAnchorInfo.mark.SetAdjustType(button.type); } else { AnchorMark mark = inputManager.FocusedObject.GetComponentInParent <AnchorMark>(); if (mark != null) { // 点到anchor物体了,切换 if (mark != currentAnchorInfo.mark) { SelectMark(mark); } } } } else { SelectMark(null); } } } }
//////////////////////////////////////////// #region 创建、删除、本地存储Anchor相关内容 //////////////////////////////////////////// /// <summary> /// 将指定的物体设置为Anchor /// </summary> /// <param name="name"></param> /// <param name="obj"></param> public AnchorObjectInfo AddAnchorObject(string name, GameObject obj) { AnchorObjectInfo info = new AnchorObjectInfo(); info.anchorName = name; info.rootTrans = obj.transform; AnchorDefinition define = obj.GetComponent <AnchorDefinition>(); if (define == null) { define = obj.AddComponent <AnchorDefinition>(); define.anchorName = name; } info.definition = define; // 创建mark物体 GameObject markObj = PrefabUtils.CreateGameObjectToParent(anchorMarkRoot, markPrefab); AnchorMark mark = markObj.GetComponent <AnchorMark>(); mark.Init(name, info); mark.rootObjectTransform = obj.transform; // 创建指引箭头 GameObject arrowObj = PrefabUtils.CreateGameObjectToParent(gameObject, arrowPrefab); info.arrowTrans = arrowObj.transform; arrowObj.SetActive(false); // 设置位置 Vector3 originPos = obj.transform.position; markObj.transform.position = originPos; info.mark = mark; AddAnchor(info); //info.mark.followRoot = true; //info.FollowRootObject(); //mark.gameObject.SetActive(false); anchorObjectList.Add(info); Debug.Log("Add anchor [" + name + "] to obj [" + obj.name + "]"); return(info); }
public void Init(AnchorMark m) { mark = m; image = GetComponent <Image>(); }