public static void EditorConfigureTarget(VirtualButtonAbstractBehaviour vb) { if (vb == null) { Debug.LogError("VirtualButtonAbstractBehaviour parameter is null !"); return; } if (VuforiaUtilities.GetPrefabType(vb) == PrefabType.Prefab) { return; } if (!SceneManager.Instance.SceneInitialized) { SceneManager.Instance.InitScene(); } if (!EditorApplication.isPlaying) { if (!vb.HasUpdatedPose) { vb.UpdatePose(); } if (!VirtualButtonEditor.IsVBMeshCreated(vb)) { VirtualButtonEditor.CreateVBMesh(vb.gameObject); } VirtualButtonEditor.Validate(); } }
internal static bool CorrectPoses(VirtualButtonAbstractBehaviour[] vbs) { bool result = false; for (int i = 0; i < vbs.Length; i++) { VirtualButtonAbstractBehaviour virtualButtonAbstractBehaviour = vbs[i]; if (virtualButtonAbstractBehaviour.PreviousTransform != virtualButtonAbstractBehaviour.transform.localToWorldMatrix || (virtualButtonAbstractBehaviour.transform.parent != null && virtualButtonAbstractBehaviour.PreviousParent != virtualButtonAbstractBehaviour.transform.parent.gameObject) || !virtualButtonAbstractBehaviour.HasUpdatedPose) { if (virtualButtonAbstractBehaviour.UpdatePose()) { result = true; } virtualButtonAbstractBehaviour.PreviousTransform = virtualButtonAbstractBehaviour.transform.localToWorldMatrix; virtualButtonAbstractBehaviour.PreviousParent = (virtualButtonAbstractBehaviour.transform.parent ? virtualButtonAbstractBehaviour.transform.parent.gameObject : null); } } return(result); }
void IEditorImageTargetBehaviour.AssociateExistingVirtualButtonBehaviour(VirtualButtonAbstractBehaviour virtualButtonBehaviour) { VirtualButton virtualButtonByName = this.mImageTarget.GetVirtualButtonByName(virtualButtonBehaviour.VirtualButtonName); if (virtualButtonByName == null) { Vector2 vector; Vector2 vector2; virtualButtonBehaviour.CalculateButtonArea(out vector, out vector2); RectangleData area = new RectangleData { leftTopX = vector.x, leftTopY = vector.y, rightBottomX = vector2.x, rightBottomY = vector2.y }; virtualButtonByName = this.mImageTarget.CreateVirtualButton(virtualButtonBehaviour.VirtualButtonName, area); if (virtualButtonByName != null) { Debug.Log("Successfully created virtual button " + virtualButtonBehaviour.VirtualButtonName + " at startup"); virtualButtonBehaviour.UnregisterOnDestroy = true; } else { Debug.LogError("Failed to create virtual button " + virtualButtonBehaviour.VirtualButtonName + " at startup"); } } if ((virtualButtonByName != null) && !this.mVirtualButtonBehaviours.ContainsKey(virtualButtonByName.ID)) { IEditorVirtualButtonBehaviour behaviour = virtualButtonBehaviour; behaviour.InitializeVirtualButton(virtualButtonByName); this.mVirtualButtonBehaviours.Add(virtualButtonByName.ID, virtualButtonBehaviour); Debug.Log(string.Concat(new object[] { "Found VirtualButton named ", virtualButtonBehaviour.VirtualButton.Name, " with id ", virtualButtonBehaviour.VirtualButton.ID })); virtualButtonBehaviour.UpdatePose(); if (!virtualButtonBehaviour.UpdateAreaRectangle() || !virtualButtonBehaviour.UpdateSensitivity()) { Debug.LogError("Failed to update virtual button " + virtualButtonBehaviour.VirtualButton.Name + " at startup"); } else { Debug.Log("Updated virtual button " + virtualButtonBehaviour.VirtualButton.Name + " at startup"); } } }
private static void AddVirtualButton(ImageTargetAbstractBehaviour it, ConfigData.VirtualButtonData vb) { VirtualButtonAbstractBehaviour virtualButtonAbstractBehaviour = it.CreateVirtualButton(vb.name, new Vector2(0f, 0f), new Vector2(1f, 1f)); if (virtualButtonAbstractBehaviour != null) { SerializedObject serializedObject = new SerializedObject(virtualButtonAbstractBehaviour); using (serializedObject.Edit()) { VirtualButtonEditor.GetSensitivityProperty(serializedObject).enumValueIndex = (int)vb.sensitivity; } virtualButtonAbstractBehaviour.SetPosAndScaleFromButtonArea(new Vector2(vb.rectangle[0], vb.rectangle[1]), new Vector2(vb.rectangle[2], vb.rectangle[3])); VirtualButtonEditor.CreateVBMesh(virtualButtonAbstractBehaviour.gameObject); VirtualButtonEditor.CreateMaterial(virtualButtonAbstractBehaviour.gameObject); virtualButtonAbstractBehaviour.enabled = vb.enabled; BehaviourComponentFactory.Instance.AddTurnOffBehaviour(virtualButtonAbstractBehaviour.gameObject); virtualButtonAbstractBehaviour.UpdatePose(); return; } Debug.LogError("VirtualButton could not be added!"); }
public void OnEnable() { if (QCARUtilities.GetPrefabType(base.target) != PrefabType.Prefab) { if (!SceneManager.Instance.SceneInitialized) { SceneManager.Instance.InitScene(); } VirtualButtonAbstractBehaviour target = (VirtualButtonAbstractBehaviour)base.target; if (!EditorApplication.isPlaying) { if (!target.HasUpdatedPose) { target.UpdatePose(); } if (!IsVBMeshCreated(target)) { CreateVBMesh(target); } Validate(); } } }