// Lets the user choose a Cylinder Target from a drop down list. Cylinder Target
    // must be defined in the "config.xml" file.
    public override void OnInspectorGUI()
    {
        EditorGUIUtility.LookLikeInspector();

        DrawDefaultInspector();

        CylinderTargetBehaviour        ctb       = (CylinderTargetBehaviour)target;
        IEditorCylinderTargetBehaviour editorCtb = ctb;

        if (QCARUtilities.GetPrefabType(ctb) ==
            PrefabType.Prefab)
        {
            GUILayout.Label("You can't choose a target for a prefab.");
        }
        else if (ConfigDataManager.Instance.NumConfigDataObjects > 1)
        {
            // Draw list for choosing a data set.
            string[] dataSetList = new string[ConfigDataManager.Instance.NumConfigDataObjects];
            ConfigDataManager.Instance.GetConfigDataNames(dataSetList);
            int currentDataSetIndex =
                QCARUtilities.GetIndexFromString(editorCtb.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.
            string[] namesList = new string[dataSetData.NumCylinderTargets];
            dataSetData.CopyCylinderTargetNames(namesList, 0);
            int currentTrackableIndex =
                QCARUtilities.GetIndexFromString(editorCtb.TrackableName, namesList);

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

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

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

                    editorCtb.SetNameForTrackable(namesList[newTrackableIndex]);


                    ConfigData.CylinderTargetData ctConfig;
                    dataSetData.GetCylinderTarget(ctb.TrackableName, out ctConfig);

                    //geometry has to be updated when a new target has been selected
                    UpdateAspectRatio(editorCtb, ctConfig);
                    UpdateScale(editorCtb, ctConfig.sideLength);
                }
            }

            //Expose editors for setting sideLength and diameterss
            //these values are not really stored, but instead the scale-factor is updated
            var sideLength = EditorGUILayout.FloatField("Side Length", ctb.SideLength);
            if (sideLength != ctb.SideLength)
            {
                ctb.SetSideLength(sideLength);
            }

            float topDiameter = EditorGUILayout.FloatField("Top Diameter ", ctb.TopDiameter);
            if (topDiameter != ctb.TopDiameter)
            {
                ctb.SetTopDiameter(topDiameter);
            }

            float bottomDiameter = EditorGUILayout.FloatField("Bottom Diameter", ctb.BottomDiameter);
            if (bottomDiameter != ctb.BottomDiameter)
            {
                ctb.SetBottomDiameter(bottomDiameter);
            }

            // Draw check box to de-/activate "preserve child size" mode.
            editorCtb.SetPreserveChildSize(EditorGUILayout.Toggle("Preserve child size", editorCtb.PreserveChildSize));
        }
        else
        {
            if (GUILayout.Button("No targets defined. Press here for target " +
                                 "creation!"))
            {
                SceneManager.Instance.GoToTargetManagerPage();
            }
        }

        if (GUI.changed)
        {
            EditorUtility.SetDirty(ctb);
            SceneManager.Instance.SceneUpdated();
        }
    }
Example #2
0
    public override void OnInspectorGUI()
    {
        EditorGUIUtility.LookLikeInspector();
        base.DrawDefaultInspector();
        CylinderTargetAbstractBehaviour target = (CylinderTargetAbstractBehaviour)base.target;
        IEditorCylinderTargetBehaviour  ct     = target;

        if (QCARUtilities.GetPrefabType(target) == PrefabType.Prefab)
        {
            GUILayout.Label("You can't choose a target for a prefab.", new GUILayoutOption[0]);
        }
        else if (ConfigDataManager.Instance.NumConfigDataObjects > 1)
        {
            string[] configDataNames = new string[ConfigDataManager.Instance.NumConfigDataObjects];
            ConfigDataManager.Instance.GetConfigDataNames(configDataNames);
            int indexFromString = QCARUtilities.GetIndexFromString(ct.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.NumCylinderTargets];
            configData.CopyCylinderTargetNames(arrayToFill, 0);
            int selectedIndex = QCARUtilities.GetIndexFromString(ct.TrackableName, arrayToFill);
            if (selectedIndex < 0)
            {
                selectedIndex = 0;
            }
            int num4 = EditorGUILayout.Popup("Cylinder Target", selectedIndex, arrayToFill, new GUILayoutOption[0]);
            if ((arrayToFill.Length > 0) && ((index != indexFromString) || (num4 != selectedIndex)))
            {
                ConfigData.CylinderTargetData data2;
                ct.SetDataSetPath("QCAR/" + configDataNames[index] + ".xml");
                ct.SetNameForTrackable(arrayToFill[num4]);
                configData.GetCylinderTarget(target.TrackableName, out data2);
                UpdateAspectRatio(ct, data2);
                UpdateScale(ct, data2.sideLength);
            }
            float num5 = EditorGUILayout.FloatField("Side Length", target.SideLength, new GUILayoutOption[0]);
            if (num5 != target.SideLength)
            {
                target.SetSideLength(num5);
            }
            float num6 = EditorGUILayout.FloatField("Top Diameter ", target.TopDiameter, new GUILayoutOption[0]);
            if (num6 != target.TopDiameter)
            {
                target.SetTopDiameter(num6);
            }
            float num7 = EditorGUILayout.FloatField("Bottom Diameter", target.BottomDiameter, new GUILayoutOption[0]);
            if (num7 != target.BottomDiameter)
            {
                target.SetBottomDiameter(num7);
            }
            ct.SetExtendedTracking(EditorGUILayout.Toggle("Extended tracking", ct.ExtendedTracking, new GUILayoutOption[0]));
            ct.SetPreserveChildSize(EditorGUILayout.Toggle("Preserve child size", ct.PreserveChildSize, new GUILayoutOption[0]));
        }
        else if (GUILayout.Button("No targets defined. Press here for target creation!", new GUILayoutOption[0]))
        {
            SceneManager.Instance.GoToTargetManagerPage();
        }
        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
            SceneManager.Instance.SceneUpdated();
        }
    }