예제 #1
0
    // Update Virtual Buttons from configuration data.
    public static void UpdateVirtualButtons(ImageTargetBehaviour it,
                                            ConfigData.VirtualButton[] vbs)
    {
        for (int i = 0; i < vbs.Length; ++i)
        {
            // Developer is responsible for deleting Virtual Buttons that
            // are not specified in newly imported config.xml files.
            VirtualButtonBehaviour[] vbBehaviours =
                it.GetComponentsInChildren <VirtualButtonBehaviour>();

            bool vbInScene = false;
            for (int j = 0; j < vbBehaviours.Length; ++j)
            {
                // If the Virtual Button specified in the config.xml file
                // is already part of the scene we fill it with new values.
                if (vbBehaviours[j].VirtualButtonName == vbs[i].name)
                {
                    vbBehaviours[j].enabled            = vbs[i].enabled;
                    vbBehaviours[j].SensitivitySetting = vbs[i].sensitivity;
                    vbBehaviours[j].SetPosAndScaleFromButtonArea(
                        new Vector2(vbs[i].rectangle[0], vbs[i].rectangle[1]),
                        new Vector2(vbs[i].rectangle[2], vbs[i].rectangle[3]));
                    vbInScene = true;
                }
            }
            if (vbInScene)
            {
                continue;
            }

            // If Virtual Button is not part of the scene we create
            // a new one and add it as a direct child of the ImageTarget.
            ImageTargetEditor.AddVirtualButton(it, vbs[i]);
        }
    }
예제 #2
0
    // This method checks for duplicate virtual buttons in a given image
    // target and prints an error accordingly.
    private static void DetectDuplicates(ImageTargetBehaviour it)
    {
        VirtualButtonBehaviour[] vbs =
            it.GetComponentsInChildren <VirtualButtonBehaviour>();

        for (int i = 0; i < vbs.Length; ++i)
        {
            for (int j = i + 1; j < vbs.Length; ++j)
            {
                if (vbs[i].VirtualButtonName == vbs[j].VirtualButtonName)
                {
                    Debug.LogError("Duplicate virtual buttons with name '" +
                                   vbs[i].VirtualButtonName + "' detected in " +
                                   "Image Target '" + it.TrackableName + "'.");
                }
            }
        }
    }
예제 #3
0
    // Update Virtual Buttons from configuration data.
    public static void UpdateVirtualButtons(ImageTargetBehaviour it,
        ConfigData.VirtualButton[] vbs)
    {
        for (int i = 0; i < vbs.Length; ++i)
        {
            // Developer is responsible for deleting Virtual Buttons that
            // are not specified in newly imported config.xml files.
            VirtualButtonBehaviour[] vbBehaviours =
                it.GetComponentsInChildren<VirtualButtonBehaviour>();

            bool vbInScene = false;
            for (int j = 0; j < vbBehaviours.Length; ++j)
            {
                // If the Virtual Button specified in the config.xml file
                // is already part of the scene we fill it with new values.
                if (vbBehaviours[j].VirtualButtonName == vbs[i].name)
                {
                    vbBehaviours[j].enabled = vbs[i].enabled;
                    vbBehaviours[j].SensitivitySetting = vbs[i].sensitivity;
                    VirtualButtonEditor.SetPosAndScaleFromButtonArea(
                        new Vector2(vbs[i].rectangle[0], vbs[i].rectangle[1]),
                        new Vector2(vbs[i].rectangle[2], vbs[i].rectangle[3]),
                        it,
                        vbBehaviours[j]);
                    vbInScene = true;
                }
            }
            if (vbInScene)
            {
                continue;
            }

            // If Virtual Button is not part of the scene we create
            // a new one and add it as a direct child of the ImageTarget.
            ImageTargetEditor.AddVirtualButton(it, vbs[i]);
        }
    }
예제 #4
0
    // This method creates a single data set from the trackables provided.
    // The method ignores the data set property in TrackableBehaviour and
    // adds all Trackables to a single file.
    // Default Trackables are not added to the data set.
    private ConfigData CreateDataSetFromTrackables(TrackableBehaviour[] trackables)
    {
        // Sanity check.
        if (trackables == null)
        {
            return(null);
        }

        ConfigData sceneData = new ConfigData();

        foreach (TrackableBehaviour tb in trackables)
        {
            // Ignore non-data set trackables.
            if (!(tb is DataSetTrackableBehaviour))
            {
                continue;
            }

            DataSetTrackableBehaviour trackable = (DataSetTrackableBehaviour)tb;

            string dataSetName   = trackable.DataSetName;
            string trackableName = trackable.TrackableName;

            // We ignore default Trackables or undefined Trackables.
            if (dataSetName == QCARUtilities.GlobalVars.DEFAULT_DATA_SET_NAME ||
                dataSetName == "" ||
                trackableName == QCARUtilities.GlobalVars.DEFAULT_TRACKABLE_NAME ||
                trackableName == "")
            {
                Debug.LogWarning("Ignoring default Trackable for export");
                continue;
            }

            if (trackable.GetType() == typeof(ImageTargetBehaviour))
            {
                ImageTargetBehaviour it = (ImageTargetBehaviour)trackable;

                ConfigData.ImageTarget itConfig = new ConfigData.ImageTarget();

                itConfig.size = it.GetSize();

                // Process Virtual Button list.
                VirtualButtonBehaviour[] vbs =
                    it.GetComponentsInChildren <VirtualButtonBehaviour>();
                itConfig.virtualButtons = new List <ConfigData.VirtualButton>(vbs.Length);
                foreach (VirtualButtonBehaviour vb in vbs)
                {
                    Vector2 leftTop;
                    Vector2 rightBottom;
                    if (!vb.CalculateButtonArea(out leftTop,
                                                out rightBottom))
                    {
                        // Invalid Button
                        continue;
                    }

                    ConfigData.VirtualButton vbConfig =
                        new ConfigData.VirtualButton();

                    vbConfig.name      = vb.VirtualButtonName;
                    vbConfig.enabled   = vb.enabled;
                    vbConfig.rectangle = new Vector4(leftTop.x,
                                                     leftTop.y,
                                                     rightBottom.x,
                                                     rightBottom.y);
                    vbConfig.sensitivity = vb.SensitivitySetting;

                    itConfig.virtualButtons.Add(vbConfig);
                }

                sceneData.SetImageTarget(itConfig, it.TrackableName);
            }
            else if (trackable.GetType() == typeof(MultiTargetBehaviour))
            {
                Debug.Log("Multi Targets not exported.");
            }
        }

        return(sceneData);
    }
예제 #5
0
    // This method checks for duplicate virtual buttons in a given image
    // target and prints an error accordingly.
    private static void DetectDuplicates(ImageTargetBehaviour it)
    {
        VirtualButtonBehaviour[] vbs =
                        it.GetComponentsInChildren<VirtualButtonBehaviour>();

        for (int i = 0; i < vbs.Length; ++i)
        {
            for (int j = i + 1; j < vbs.Length; ++j)
            {
                if (vbs[i].VirtualButtonName == vbs[j].VirtualButtonName)
                {
                    Debug.LogError("Duplicate virtual buttons with name '" +
                        vbs[i].VirtualButtonName + "' detected in " +
                        "Image Target '" + it.TrackableName + "'.");
                }
            }
        }
    }