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();
     }
 }
コード例 #2
0
    // Updates the scale values in the transform component from a given size.
    public static void UpdateScale(IEditorImageTargetBehaviour it, Vector2 size)
    {
        // Update the scale:

        float childScaleFactor = it.GetSize()[0] / size[0];

        if (it.AspectRatio <= 1.0f)
        {
            it.transform.localScale = new Vector3(size[0], size[0], size[0]);
        }
        else
        {
            it.transform.localScale = new Vector3(size[1], size[1], size[1]);
        }

        // Check if 3D content should keep its size or if it should be scaled
        // with the target.
        if (it.PreserveChildSize)
        {
            foreach (Transform child in it.transform)
            {
                child.localPosition =
                    new Vector3(child.localPosition.x * childScaleFactor,
                                child.localPosition.y * childScaleFactor,
                                child.localPosition.z * childScaleFactor);

                child.localScale =
                    new Vector3(child.localScale.x * childScaleFactor,
                                child.localScale.y * childScaleFactor,
                                child.localScale.z * childScaleFactor);
            }
        }
    }
コード例 #3
0
    private ConfigData CreateDataSetFromTrackables(TrackableBehaviour[] trackables)
    {
        if (trackables == null)
        {
            return(null);
        }
        ConfigData data = new ConfigData();

        foreach (TrackableBehaviour behaviour in trackables)
        {
            if (behaviour is DataSetTrackableBehaviour)
            {
                IEditorDataSetTrackableBehaviour behaviour2 = (DataSetTrackableBehaviour)behaviour;
                string dataSetName   = behaviour2.DataSetName;
                string trackableName = behaviour2.TrackableName;
                if (((dataSetName == "--- EMPTY ---") || (dataSetName == "")) || ((trackableName == "--- EMPTY ---") || (trackableName == "")))
                {
                    UnityEngine.Debug.LogWarning("Ignoring default Trackable for export");
                }
                else if (behaviour2 is ImageTargetAbstractBehaviour)
                {
                    ImageTargetAbstractBehaviour behaviour3 = (ImageTargetAbstractBehaviour)behaviour2;
                    IEditorImageTargetBehaviour  behaviour4 = behaviour3;
                    ConfigData.ImageTargetData   item       = new ConfigData.ImageTargetData {
                        size = behaviour4.GetSize()
                    };
                    VirtualButtonAbstractBehaviour[] componentsInChildren = behaviour3.GetComponentsInChildren <VirtualButtonAbstractBehaviour>();
                    item.virtualButtons = new List <ConfigData.VirtualButtonData>(componentsInChildren.Length);
                    foreach (VirtualButtonAbstractBehaviour behaviour5 in componentsInChildren)
                    {
                        Vector2 vector;
                        Vector2 vector2;
                        if (behaviour5.CalculateButtonArea(out vector, out vector2))
                        {
                            ConfigData.VirtualButtonData  data3      = new ConfigData.VirtualButtonData();
                            IEditorVirtualButtonBehaviour behaviour6 = behaviour5;
                            data3.name        = behaviour6.VirtualButtonName;
                            data3.enabled     = behaviour6.enabled;
                            data3.rectangle   = new Vector4(vector.x, vector.y, vector2.x, vector2.y);
                            data3.sensitivity = behaviour6.SensitivitySetting;
                            item.virtualButtons.Add(data3);
                        }
                    }
                    data.SetImageTarget(item, behaviour4.TrackableName);
                }
                else if (behaviour2 is MultiTargetAbstractBehaviour)
                {
                    UnityEngine.Debug.Log("Multi Targets not exported.");
                }
                else if (behaviour2 is CylinderTargetAbstractBehaviour)
                {
                    UnityEngine.Debug.Log("Cylinder Targets not exported.");
                }
            }
        }
        return(data);
    }
    public static void UpdateScale(IEditorImageTargetBehaviour it, Vector2 size)
    {
        float num = it.GetSize()[0] / size[0];

        if (it.AspectRatio <= 1f)
        {
            it.transform.localScale = new Vector3(size[0], size[0], size[0]);
        }
        else
        {
            it.transform.localScale = new Vector3(size[1], size[1], size[1]);
        }
        if (it.PreserveChildSize)
        {
            foreach (Transform transform in it.transform)
            {
                transform.localPosition = new Vector3(transform.localPosition.x * num, transform.localPosition.y * num, transform.localPosition.z * num);
                transform.localScale    = new Vector3(transform.localScale.x * num, transform.localScale.y * num, transform.localScale.z * num);
            }
        }
    }
コード例 #5
0
    // Updates the scale values in the transform component from a given size.
    public static void UpdateScale(IEditorImageTargetBehaviour it, Vector2 size)
    {
        // Update the scale:

        float childScaleFactor = it.GetSize()[0] / size[0];

        if (it.AspectRatio <= 1.0f)
        {
            it.transform.localScale = new Vector3(size[0], size[0], size[0]);
        }
        else
        {
            it.transform.localScale = new Vector3(size[1], size[1], size[1]);
        }

        // Check if 3D content should keep its size or if it should be scaled
        // with the target.
        if (it.PreserveChildSize)
        {
            foreach (Transform child in it.transform)
            {
                child.localPosition =
                    new Vector3(child.localPosition.x * childScaleFactor,
                                child.localPosition.y * childScaleFactor,
                                child.localPosition.z * childScaleFactor);

                child.localScale =
                    new Vector3(child.localScale.x * childScaleFactor,
                                child.localScale.y * childScaleFactor,
                                child.localScale.z * childScaleFactor);
            }
        }
    }
コード例 #6
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;
            }

            IEditorDataSetTrackableBehaviour 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;
                IEditorImageTargetBehaviour editorIt = it;

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

                itConfig.size = editorIt.GetSize();

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

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

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

                    itConfig.virtualButtons.Add(vbConfig);
                }

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

        return(sceneData);
    }
コード例 #7
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();
            }
        }
    }
コード例 #8
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();
            }
        }
    }