private void DrawPredefinedTargetInsprectorUI(IEditorImageTargetBehaviour itb, bool typeChanged)
 {
     if (typeChanged)
     {
         UpdateMaterial(itb);
     }
     if (ConfigDataManager.Instance.NumConfigDataObjects > 1)
     {
         string[] configDataNames = new string[ConfigDataManager.Instance.NumConfigDataObjects];
         ConfigDataManager.Instance.GetConfigDataNames(configDataNames);
         int indexFromString = QCARUtilities.GetIndexFromString(itb.DataSetName, configDataNames);
         if (indexFromString < 0)
         {
             indexFromString = 0;
         }
         int        index       = EditorGUILayout.Popup("Data Set", indexFromString, configDataNames, new GUILayoutOption[0]);
         string     dataSetName = configDataNames[index];
         ConfigData configData  = ConfigDataManager.Instance.GetConfigData(dataSetName);
         string[]   arrayToFill = new string[configData.NumImageTargets];
         configData.CopyImageTargetNames(arrayToFill, 0);
         int selectedIndex = QCARUtilities.GetIndexFromString(itb.TrackableName, arrayToFill);
         if (selectedIndex < 0)
         {
             selectedIndex = 0;
         }
         if (index != indexFromString)
         {
             selectedIndex = 0;
         }
         int   num5  = EditorGUILayout.Popup("Image Target", selectedIndex, arrayToFill, new GUILayoutOption[0]);
         float width = EditorGUILayout.FloatField("Width", itb.GetSize().x, new GUILayoutOption[0]);
         if (width != itb.GetSize().x)
         {
             itb.SetWidth(width);
         }
         float height = EditorGUILayout.FloatField("Height ", itb.GetSize().y, new GUILayoutOption[0]);
         if (height != itb.GetSize().y)
         {
             itb.SetHeight(height);
         }
         itb.SetExtendedTracking(EditorGUILayout.Toggle("Extended tracking", itb.ExtendedTracking, new GUILayoutOption[0]));
         itb.SetPreserveChildSize(EditorGUILayout.Toggle("Preserve child size", itb.PreserveChildSize, new GUILayoutOption[0]));
         if ((arrayToFill.Length > 0) && (((index != indexFromString) || (num5 != selectedIndex)) || typeChanged))
         {
             ConfigData.ImageTargetData data2;
             itb.SetDataSetPath("QCAR/" + configDataNames[index] + ".xml");
             string name = arrayToFill[num5];
             itb.SetNameForTrackable(name);
             configData.GetImageTarget(itb.TrackableName, out data2);
             UpdateAspectRatio(itb, data2.size);
             UpdateScale(itb, data2.size);
             UpdateMaterial(itb);
         }
     }
     else if (GUILayout.Button("No targets defined. Press here for target creation!", new GUILayoutOption[0]))
     {
         SceneManager.Instance.GoToTargetManagerPage();
     }
 }
    private void DrawPredefinedTargetInsprectorUI(IEditorImageTargetBehaviour itb, bool typeChanged)
    {
        if (typeChanged)
            UpdateMaterial(itb);

        if (ConfigDataManager.Instance.NumConfigDataObjects > 1) //< "> 1" because we ignore the default dataset.
        {
            // Draw list for choosing a data set.
            string[] dataSetList = new string[ConfigDataManager.Instance.NumConfigDataObjects];
            ConfigDataManager.Instance.GetConfigDataNames(dataSetList);
            int currentDataSetIndex = QCARUtilities.GetIndexFromString(itb.DataSetName, dataSetList);

            // If name is not in array we automatically choose default name;
            if (currentDataSetIndex < 0)
                currentDataSetIndex = 0;

            int newDataSetIndex = EditorGUILayout.Popup("Data Set",
                                                        currentDataSetIndex,
                                                        dataSetList);

            string chosenDataSet = dataSetList[newDataSetIndex];

            ConfigData dataSetData = ConfigDataManager.Instance.GetConfigData(chosenDataSet);

            // Draw list for choosing a Trackable
            int targetCount = dataSetData.NumImageTargets;
            string[] namesList = new string[targetCount];
            dataSetData.CopyImageTargetNames(namesList, 0);

            // get the current index
            int currentTrackableIndex = QCARUtilities.GetIndexFromString(itb.TrackableName, namesList);

            // If name is not in array we automatically choose default name;
            if (currentTrackableIndex < 0)
                currentTrackableIndex = 0;

            // Reset name index if a new data set has been chosen.
            if (newDataSetIndex != currentDataSetIndex)
            {
                currentTrackableIndex = 0;
            }

            int newTrackableIndex = EditorGUILayout.Popup("Image Target",
                                                            currentTrackableIndex,
                                                            namesList);

            //Expose editors for setting size
            //these values are not really stored, but instead the scale-factor is updated
            var width = EditorGUILayout.FloatField("Width", itb.GetSize().x);
            if (width != itb.GetSize().x)
                itb.SetWidth(width);

            float height = EditorGUILayout.FloatField("Height ", itb.GetSize().y);
            if (height != itb.GetSize().y)
                itb.SetHeight(height);

            // Draw check box to de-/activate "preserve child size" mode.
            itb.SetPreserveChildSize(EditorGUILayout.Toggle("Preserve child size", itb.PreserveChildSize));

            if (namesList.Length > 0)
            {
                if (newDataSetIndex != currentDataSetIndex || newTrackableIndex != currentTrackableIndex || typeChanged)
                {
                    itb.SetDataSetPath("QCAR/" + dataSetList[newDataSetIndex] + ".xml");

                    string selectedString = namesList[newTrackableIndex];

                    ConfigData.ImageTargetData itConfig;
                    itb.SetNameForTrackable(selectedString);
                    dataSetData.GetImageTarget(itb.TrackableName, out itConfig);

                    // Update the aspect ratio and mesh used for visualisation:
                    UpdateAspectRatio(itb, itConfig.size);

                    // Update the scale as defined in the config file
                    UpdateScale(itb, itConfig.size);

                    // Update the material:
                    UpdateMaterial(itb);
                }
            }
        }
        else
        {
            if (GUILayout.Button("No targets defined. Press here for target " +
                                    "creation!"))
            {
                SceneManager.Instance.GoToTargetManagerPage();
            }
        }
    }
예제 #3
0
    private void DrawPredefinedTargetInsprectorUI(IEditorImageTargetBehaviour itb, bool typeChanged)
    {
        if (typeChanged)
        {
            UpdateMaterial(itb);
        }

        if (ConfigDataManager.Instance.NumConfigDataObjects > 1) //< "> 1" because we ignore the default dataset.
        {
            // Draw list for choosing a data set.
            string[] dataSetList = new string[ConfigDataManager.Instance.NumConfigDataObjects];
            ConfigDataManager.Instance.GetConfigDataNames(dataSetList);
            int currentDataSetIndex = QCARUtilities.GetIndexFromString(itb.DataSetName, dataSetList);

            // If name is not in array we automatically choose default name;
            if (currentDataSetIndex < 0)
            {
                currentDataSetIndex = 0;
            }

            int newDataSetIndex = EditorGUILayout.Popup("Data Set",
                                                        currentDataSetIndex,
                                                        dataSetList);

            string chosenDataSet = dataSetList[newDataSetIndex];

            ConfigData dataSetData = ConfigDataManager.Instance.GetConfigData(chosenDataSet);

            // Draw list for choosing a Trackable
            int      targetCount = dataSetData.NumImageTargets;
            string[] namesList   = new string[targetCount];
            dataSetData.CopyImageTargetNames(namesList, 0);

            // get the current index
            int currentTrackableIndex = QCARUtilities.GetIndexFromString(itb.TrackableName, namesList);

            // If name is not in array we automatically choose default name;
            if (currentTrackableIndex < 0)
            {
                currentTrackableIndex = 0;
            }

            // Reset name index if a new data set has been chosen.
            if (newDataSetIndex != currentDataSetIndex)
            {
                currentTrackableIndex = 0;
            }

            int newTrackableIndex = EditorGUILayout.Popup("Image Target",
                                                          currentTrackableIndex,
                                                          namesList);


            //Expose editors for setting size
            //these values are not really stored, but instead the scale-factor is updated
            var width = EditorGUILayout.FloatField("Width", itb.GetSize().x);
            if (width != itb.GetSize().x)
            {
                itb.SetWidth(width);
            }

            float height = EditorGUILayout.FloatField("Height ", itb.GetSize().y);
            if (height != itb.GetSize().y)
            {
                itb.SetHeight(height);
            }

            // Draw check box to de-/activate "preserve child size" mode.
            itb.SetPreserveChildSize(EditorGUILayout.Toggle("Preserve child size", itb.PreserveChildSize));

            if (namesList.Length > 0)
            {
                if (newDataSetIndex != currentDataSetIndex || newTrackableIndex != currentTrackableIndex || typeChanged)
                {
                    itb.SetDataSetPath("QCAR/" + dataSetList[newDataSetIndex] + ".xml");

                    string selectedString = namesList[newTrackableIndex];

                    ConfigData.ImageTargetData itConfig;
                    itb.SetNameForTrackable(selectedString);
                    dataSetData.GetImageTarget(itb.TrackableName, out itConfig);

                    // Update the aspect ratio and mesh used for visualisation:
                    UpdateAspectRatio(itb, itConfig.size);

                    // Update the scale as defined in the config file
                    UpdateScale(itb, itConfig.size);

                    // Update the material:
                    UpdateMaterial(itb);
                }
            }
        }
        else
        {
            if (GUILayout.Button("No targets defined. Press here for target " +
                                 "creation!"))
            {
                SceneManager.Instance.GoToTargetManagerPage();
            }
        }
    }