Exemplo n.º 1
0
    public override void OnInspectorGUI()
    {
        EditorGUIUtility.LookLikeInspector();
        base.DrawDefaultInspector();
        WordAbstractBehaviour target     = (WordAbstractBehaviour)base.target;
        IEditorWordBehaviour  behaviour2 = target;

        if (QCARUtilities.GetPrefabType(target) == PrefabType.Prefab)
        {
            GUILayout.Label("You can't choose a target for a prefab.", new GUILayoutOption[0]);
        }
        else if (EditorGUILayout.Toggle("Template", behaviour2.IsTemplateMode, new GUILayoutOption[0]))
        {
            behaviour2.SetMode(WordTemplateMode.Template);
        }
        else
        {
            behaviour2.SetMode(WordTemplateMode.SpecificWord);
            string word = EditorGUILayout.TextField("Specific Word", behaviour2.SpecificWord, new GUILayoutOption[0]);
            if (word != behaviour2.SpecificWord)
            {
                if (word.Length == 0)
                {
                    Debug.LogWarning("Empty string used as word: This trackable and its augmentation will never be selected at runtime.");
                }
                behaviour2.SetSpecificWord(word);
            }
        }
        if (GUI.changed)
        {
            UpdateMesh(target);
            EditorUtility.SetDirty(target);
            SceneManager.Instance.SceneUpdated();
        }
    }
Exemplo n.º 2
0
    public static bool CheckForDuplicates()
    {
        bool flag = false;

        WordAbstractBehaviour[] behaviourArray = (WordAbstractBehaviour[])UnityEngine.Object.FindObjectsOfType(typeof(WordAbstractBehaviour));
        for (int i = 0; i < behaviourArray.Length; i++)
        {
            IEditorWordBehaviour behaviour = behaviourArray[i];
            for (int j = i + 1; j < behaviourArray.Length; j++)
            {
                IEditorWordBehaviour behaviour2 = behaviourArray[j];
                if (behaviour.IsTemplateMode && behaviour2.IsTemplateMode)
                {
                    Debug.LogWarning("Duplicate template word target found. Only one of the Trackables and its respective Augmentation will be selected for use at runtime - that selection is indeterminate her.");
                    flag = true;
                }
                else if ((!behaviour.IsTemplateMode && !behaviour2.IsTemplateMode) && (behaviour.SpecificWord == behaviour2.SpecificWord))
                {
                    Debug.LogWarning("Duplicate word target \"" + behaviour.SpecificWord + "\"found. Only one of the Trackables and its respective Augmentation will be selected for use at runtime - that selection is indeterminate her.");
                    flag = true;
                }
            }
        }
        return(flag);
    }
    /// <summary>
    /// Remove a specific word behaviour from list and optionally destroy game object.
    /// This might also remove a template, i.e. no further trackables will be augmented for a specific word or for a template
    /// </summary>
    public override void DestroyWordBehaviour(WordBehaviour behaviour, bool destroyGameObject = true)
    {
        var keys = mWordBehaviours.Keys.ToArray();

        foreach (var key in keys)
        {
            if (mWordBehaviours[key].Contains(behaviour))
            {
                mWordBehaviours[key].Remove(behaviour);

                // no behaviours left - delete whole list
                if (mWordBehaviours[key].Count == 0)
                {
                    mWordBehaviours.Remove(key);
                }

                if (destroyGameObject)
                {
                    Object.Destroy(behaviour.gameObject);
                    mWordBehavioursMarkedForDeletion.Add(behaviour);
                }
                else
                {
                    IEditorWordBehaviour editorTrackableBehaviour = behaviour;
                    editorTrackableBehaviour.UnregisterTrackable();
                }
            }
        }
    }
Exemplo n.º 4
0
    /// <summary>
    /// Initializes the Word-Behaviour when it is drag-dropped into the scene
    /// </summary>
    public void OnEnable()
    {
        var behaviour = (WordBehaviour)target;

        // We don't want to initialize if this is a prefab.
        if (QCARUtilities.GetPrefabType(behaviour) == PrefabType.Prefab)
        {
            return;
        }

        // Initialize scene manager
        if (!SceneManager.Instance.SceneInitialized)
        {
            SceneManager.Instance.InitScene();
        }

        IEditorWordBehaviour editorBehaviour = behaviour;

        if (!editorBehaviour.InitializedInEditor && !EditorApplication.isPlaying)
        {
            //default values
            editorBehaviour.SetMode(WordTemplateMode.Template);
            editorBehaviour.SetSpecificWord("Word");

            //define appearance
            UpdateMesh(behaviour);

            editorBehaviour.SetInitializedInEditor(true);

            // Inform Unity that the behaviour properties have changed.
            EditorUtility.SetDirty(behaviour);
        }
    }
Exemplo n.º 5
0
    /// <summary>
    /// Test if more than one word-target are set to template mode or if more than one word-target have the same specific word assigned.
    /// If duplicate word-targets are found, a warning will be displayed to the developer.
    /// </summary>
    /// <returns>true if duplicate word-targets have been found</returns>
    public static bool CheckForDuplicates()
    {
        var duplicatesFound = false;
        var wordBehaviours  = (WordBehaviour[])FindObjectsOfType(typeof(WordBehaviour));

        for (int i = 0; i < wordBehaviours.Length; i++)
        {
            IEditorWordBehaviour ewb1 = wordBehaviours[i];
            for (int j = i + 1; j < wordBehaviours.Length; j++)
            {
                IEditorWordBehaviour ewb2 = wordBehaviours[j];
                if (ewb1.IsTemplateMode && ewb2.IsTemplateMode)
                {
                    Debug.LogWarning("Duplicate template word target found. Only one of " +
                                     "the Trackables and its respective Augmentation will be selected for " +
                                     "use at runtime - that selection is indeterminate her.");
                    duplicatesFound = true;
                }
                else if (!ewb1.IsTemplateMode && !ewb2.IsTemplateMode && ewb1.SpecificWord == ewb2.SpecificWord)
                {
                    Debug.LogWarning("Duplicate word target \"" + ewb1.SpecificWord + "\"found. Only one of " +
                                     "the Trackables and its respective Augmentation will be selected for " +
                                     "use at runtime - that selection is indeterminate her.");
                    duplicatesFound = true;
                }
            }
        }
        return(duplicatesFound);
    }
    private WordAbstractBehaviour AssociateWordBehaviour(WordResult wordResult, WordAbstractBehaviour wordBehaviourTemplate)
    {
        if (this.mActiveWordBehaviours.Count >= this.mMaxInstances)
        {
            return(null);
        }
        Word word = wordResult.Word;
        WordAbstractBehaviour behaviour  = wordBehaviourTemplate;
        IEditorWordBehaviour  behaviour2 = behaviour;

        behaviour2.SetNameForTrackable(word.StringValue);
        behaviour2.InitializeWord(word);
        this.mActiveWordBehaviours.Add(word.ID, behaviour);
        return(behaviour);
    }
Exemplo n.º 7
0
 private void UpdateTrackablesEditor()
 {
     TrackableBehaviour[] behaviourArray = (TrackableBehaviour[])UnityEngine.Object.FindObjectsOfType(typeof(TrackableBehaviour));
     foreach (TrackableBehaviour behaviour in behaviourArray)
     {
         if (behaviour.enabled)
         {
             if (behaviour is WordAbstractBehaviour)
             {
                 IEditorWordBehaviour behaviour2 = (IEditorWordBehaviour)behaviour;
                 behaviour2.SetNameForTrackable(behaviour2.IsSpecificWordMode ? behaviour2.SpecificWord : "AnyWord");
                 behaviour2.InitializeWord(new WordImpl(0, behaviour2.TrackableName, new Vector2(500f, 100f)));
             }
             behaviour.OnTrackerUpdate(TrackableBehaviour.Status.TRACKED);
         }
     }
 }
 internal void InitializeWordBehaviourTemplates()
 {
     if (this.mWordPrefabCreationMode == WordPrefabCreationMode.DUPLICATE)
     {
         List <WordAbstractBehaviour> list = this.mWordBehavioursMarkedForDeletion.ToList <WordAbstractBehaviour>();
         if (this.mAutomaticTemplate && this.mWordBehaviours.ContainsKey("Template_ID"))
         {
             foreach (WordAbstractBehaviour behaviour in this.mWordBehaviours["Template_ID"])
             {
                 list.Add(behaviour);
                 UnityEngine.Object.Destroy(behaviour.gameObject);
             }
             this.mWordBehaviours.Remove("Template_ID");
         }
         WordAbstractBehaviour[] behaviourArray = (WordAbstractBehaviour[])UnityEngine.Object.FindObjectsOfType(typeof(WordAbstractBehaviour));
         foreach (WordAbstractBehaviour behaviour2 in behaviourArray)
         {
             if (!list.Contains(behaviour2))
             {
                 IEditorWordBehaviour behaviour3 = behaviour2;
                 string key = behaviour3.IsTemplateMode ? "Template_ID" : behaviour3.SpecificWord.ToLowerInvariant();
                 if (!this.mWordBehaviours.ContainsKey(key))
                 {
                     this.mWordBehaviours[key] = new List <WordAbstractBehaviour> {
                         behaviour2
                     };
                     if (key == "Template_ID")
                     {
                         this.mAutomaticTemplate = false;
                     }
                 }
             }
         }
         if (!this.mWordBehaviours.ContainsKey("Template_ID"))
         {
             WordAbstractBehaviour behaviour4 = CreateWordBehaviour();
             this.mWordBehaviours.Add("Template_ID", new List <WordAbstractBehaviour> {
                 behaviour4
             });
             this.mAutomaticTemplate = true;
         }
     }
     this.mWordBehavioursMarkedForDeletion.Clear();
 }
Exemplo n.º 9
0
    public override void OnInspectorGUI()
    {
        EditorGUIUtility.LookLikeInspector();

        DrawDefaultInspector();

        var behaviour = (WordBehaviour)target;
        IEditorWordBehaviour editorBehaviour = behaviour;

        if (QCARUtilities.GetPrefabType(behaviour) == PrefabType.Prefab)
        {
            GUILayout.Label("You can't choose a target for a prefab.");
        }
        else
        {
            var templateMode = EditorGUILayout.Toggle("Template", editorBehaviour.IsTemplateMode);
            if (templateMode)
            {
                editorBehaviour.SetMode(WordTemplateMode.Template);
            }
            else
            {
                editorBehaviour.SetMode(WordTemplateMode.SpecificWord);

                var newWord = EditorGUILayout.TextField("Specific Word", editorBehaviour.SpecificWord);
                if (newWord != editorBehaviour.SpecificWord)
                {
                    if (newWord.Length == 0)
                    {
                        Debug.LogWarning("Empty string used as word: This trackable and its augmentation will never be selected at runtime.");
                    }
                    editorBehaviour.SetSpecificWord(newWord);
                }
            }
        }

        if (GUI.changed)
        {
            UpdateMesh(behaviour);
            EditorUtility.SetDirty(behaviour);
            SceneManager.Instance.SceneUpdated();
        }
    }
Exemplo n.º 10
0
    public void OnEnable()
    {
        WordAbstractBehaviour target = (WordAbstractBehaviour)base.target;

        if (QCARUtilities.GetPrefabType(target) != PrefabType.Prefab)
        {
            if (!SceneManager.Instance.SceneInitialized)
            {
                SceneManager.Instance.InitScene();
            }
            IEditorWordBehaviour behaviour2 = target;
            if (!behaviour2.InitializedInEditor && !EditorApplication.isPlaying)
            {
                behaviour2.SetMode(WordTemplateMode.Template);
                behaviour2.SetSpecificWord("Word");
                UpdateMesh(target);
                behaviour2.SetInitializedInEditor(true);
                EditorUtility.SetDirty(target);
            }
        }
    }
 public override void DestroyWordBehaviour(WordAbstractBehaviour behaviour, [Optional, DefaultParameterValue(true)] bool destroyGameObject)
 {
     foreach (string str in this.mWordBehaviours.Keys.ToArray <string>())
     {
         if (this.mWordBehaviours[str].Contains(behaviour))
         {
             this.mWordBehaviours[str].Remove(behaviour);
             if (this.mWordBehaviours[str].Count == 0)
             {
                 this.mWordBehaviours.Remove(str);
             }
             if (destroyGameObject)
             {
                 UnityEngine.Object.Destroy(behaviour.gameObject);
                 this.mWordBehavioursMarkedForDeletion.Add(behaviour);
             }
             else
             {
                 IEditorWordBehaviour behaviour2 = behaviour;
                 behaviour2.UnregisterTrackable();
             }
         }
     }
 }
Exemplo n.º 12
0
    private static void UpdateMesh(WordAbstractBehaviour behaviour)
    {
        GameObject           obj3;
        GameObject           gameObject = behaviour.gameObject;
        IEditorWordBehaviour behaviour2 = behaviour;
        Transform            transform  = gameObject.transform.FindChild("Text");

        if (transform == null)
        {
            obj3 = new GameObject("Text")
            {
                transform = { parent = gameObject.transform }
            };
        }
        else
        {
            obj3 = transform.gameObject;
        }
        obj3.transform.localScale    = Vector3.one;
        obj3.transform.localRotation = Quaternion.AngleAxis(90f, Vector3.right);
        obj3.transform.localPosition = Vector3.zero;
        TextMesh component = obj3.GetComponent <TextMesh>();

        if (component == null)
        {
            component = obj3.AddComponent <TextMesh>();
        }
        string str  = "Assets/Qualcomm Augmented Reality/Fonts/";
        Font   font = (Font)AssetDatabase.LoadAssetAtPath(str + "SourceSansPro.ttf", typeof(Font));

        if (font != null)
        {
            component.fontSize = 0;
            component.font     = font;
        }
        else
        {
            Debug.LogWarning("Standard font for Word-prefabs were not found. You might not be able to use it during runtime.");
            component.font     = Resources.Load("Arial", typeof(Font)) as Font;
            component.fontSize = 0x24;
        }
        MeshRenderer renderer = obj3.GetComponent <MeshRenderer>();

        if (renderer == null)
        {
            renderer = obj3.AddComponent <MeshRenderer>();
        }
        Material material = new Material(component.font.material)
        {
            color  = Color.black,
            shader = Shader.Find("Custom/Text3D")
        };

        renderer.sharedMaterial = material;
        component.text          = behaviour2.IsTemplateMode ? "\"AnyWord\"" : behaviour2.SpecificWord;
        Quaternion localRotation = gameObject.transform.localRotation;
        Vector3    localScale    = gameObject.transform.localScale;
        Vector3    localPosition = gameObject.transform.localPosition;

        gameObject.transform.localRotation = Quaternion.identity;
        gameObject.transform.localScale    = Vector3.one;
        gameObject.transform.localPosition = Vector3.zero;
        Bounds boundsForAxisAlignedTextMesh = GetBoundsForAxisAlignedTextMesh(component);

        UpdateRectangleMesh(gameObject, boundsForAxisAlignedTextMesh);
        UpdateRectangleMaterial(gameObject);
        gameObject.transform.localRotation = localRotation;
        gameObject.transform.localScale    = localScale;
        gameObject.transform.localPosition = localPosition;
    }