/// <summary> /// Associates existing virtual button behaviour with virtualbuttons and creates new VirtualButtons if necessary /// </summary> void IEditorImageTargetBehaviour.AssociateExistingVirtualButtonBehaviour(VirtualButtonBehaviour virtualButtonBehaviour) { VirtualButton virtualButton = mImageTarget.GetVirtualButtonByName(virtualButtonBehaviour.VirtualButtonName); if (virtualButton == null) { Vector2 leftTop, rightBottom; virtualButtonBehaviour.CalculateButtonArea(out leftTop, out rightBottom); var area = new RectangleData { leftTopX = leftTop.x, leftTopY = leftTop.y, rightBottomX = rightBottom.x, rightBottomY = rightBottom.y }; virtualButton = mImageTarget.CreateVirtualButton(virtualButtonBehaviour.VirtualButtonName, area); // Create the virtual button if (virtualButton != 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 (virtualButton != null) { // Duplicate check: if (!mVirtualButtonBehaviours.ContainsKey(virtualButton.ID)) { // OK: IEditorVirtualButtonBehaviour editorVirtualButtonBehaviour = virtualButtonBehaviour; editorVirtualButtonBehaviour.InitializeVirtualButton(virtualButton); mVirtualButtonBehaviours.Add(virtualButton.ID, virtualButtonBehaviour); Debug.Log("Found VirtualButton named " + virtualButtonBehaviour.VirtualButton.Name + " with id " + virtualButtonBehaviour.VirtualButton.ID); // Handle any changes to the virtual button in the scene // that are not reflected in the config file 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"); } } } }