private WordAbstractBehaviour AssociateWordBehaviour(WordResult wordResult) { List <WordAbstractBehaviour> list; string key = wordResult.Word.StringValue.ToLowerInvariant(); if (this.mWordBehaviours.ContainsKey(key)) { list = this.mWordBehaviours[key]; } else if (this.mWordBehaviours.ContainsKey("Template_ID")) { list = this.mWordBehaviours["Template_ID"]; } else { Debug.Log("No prefab available for string value " + key); return(null); } foreach (WordAbstractBehaviour behaviour in list) { if (behaviour.Trackable == null) { return(this.AssociateWordBehaviour(wordResult, behaviour)); } } if (list.Count < this.mMaxInstances) { WordAbstractBehaviour item = InstantiateWordBehaviour(list.First <WordAbstractBehaviour>()); list.Add(item); return(this.AssociateWordBehaviour(wordResult, item)); } return(null); }
public void OnEnable() { WordAbstractBehaviour arg_22_0 = (WordAbstractBehaviour)base.target; this.mSerializedObject = new SerializedWord(base.serializedObject); WordEditor.EditorConfigureTarget(arg_22_0, this.mSerializedObject); }
internal static bool CheckForDuplicates() { bool result = false; WordAbstractBehaviour[] array = (WordAbstractBehaviour[])UnityEngine.Object.FindObjectsOfType(typeof(WordAbstractBehaviour)); for (int i = 0; i < array.Length; i++) { WordAbstractBehaviour wordAbstractBehaviour = array[i]; for (int j = i + 1; j < array.Length; j++) { WordAbstractBehaviour wordAbstractBehaviour2 = array[j]; if (wordAbstractBehaviour.IsTemplateMode && wordAbstractBehaviour2.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."); result = true; } else if (!wordAbstractBehaviour.IsTemplateMode && !wordAbstractBehaviour2.IsTemplateMode && wordAbstractBehaviour.SpecificWord == wordAbstractBehaviour2.SpecificWord) { Debug.LogWarning("Duplicate word target \"" + wordAbstractBehaviour.SpecificWord + "\"found. Only one of the Trackables and its respective Augmentation will be selected for use at runtime - that selection is indeterminate her."); result = true; } } } return(result); }
public static void EditorConfigureTarget(WordAbstractBehaviour wb, SerializedWord serializedObject) { if (wb == null) { Debug.LogError("WordAbstractBehaviour parameter is null !"); return; } if (VuforiaUtilities.GetPrefabType(wb) == PrefabType.Prefab) { return; } if (!SceneManager.Instance.SceneInitialized) { SceneManager.Instance.InitScene(); } using (serializedObject.Edit()) { if (!serializedObject.InitializedInEditor && !EditorApplication.isPlaying) { serializedObject.Mode = WordTemplateMode.Template; serializedObject.SpecificWord = "Word"; WordEditor.UpdateMesh(wb); serializedObject.InitializedInEditor = true; } } }
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(); } }
private static WordAbstractBehaviour CreateWordBehaviour() { GameObject gameObject = new GameObject("Word-AutoTemplate"); WordAbstractBehaviour behaviour = BehaviourComponentFactory.Instance.AddWordBehaviour(gameObject); Debug.Log("Creating Word Behaviour"); return(behaviour); }
private void UnregisterLostWords() { foreach (Word word in this.mLostWords) { if (this.mActiveWordBehaviours.ContainsKey(word.ID)) { WordAbstractBehaviour behaviour = this.mActiveWordBehaviours[word.ID]; behaviour.OnTrackerUpdate(TrackableBehaviour.Status.NOT_FOUND); ((IEditorTrackableBehaviour)behaviour).UnregisterTrackable(); this.mActiveWordBehaviours.Remove(word.ID); } } }
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); }
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(); }
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(); } } } }
private static void UpdateMesh(WordAbstractBehaviour behaviour) { GameObject gameObject = behaviour.gameObject; Transform transform = gameObject.transform.FindChild("Text"); GameObject gameObject2; if (!transform) { gameObject2 = new GameObject("Text"); gameObject2.transform.parent = gameObject.transform; } else { gameObject2 = transform.gameObject; } gameObject2.transform.localScale = Vector3.one; gameObject2.transform.localRotation = Quaternion.AngleAxis(90f, Vector3.right); gameObject2.transform.localPosition = Vector3.zero; TextMesh textMesh = gameObject2.GetComponent <TextMesh>(); if (!textMesh) { textMesh = gameObject2.AddComponent <TextMesh>(); } Font font = (Font)AssetDatabase.LoadAssetAtPath("Assets/Vuforia/Fonts/" + "SourceSansPro.ttf", typeof(Font)); if (font != null) { textMesh.fontSize = 0; textMesh.font = font; } else { Debug.LogWarning("Standard font for Word-prefabs were not found. You might not be able to use it during runtime."); textMesh.font = Resources.Load("Arial", typeof(Font)) as Font; textMesh.fontSize = 36; } MeshRenderer meshRenderer = gameObject2.GetComponent <MeshRenderer>(); if (!meshRenderer) { meshRenderer = gameObject2.AddComponent <MeshRenderer>(); } Material material = meshRenderer.sharedMaterial; if (material == null || material == textMesh.font.material) { material = new Material(textMesh.font.material); } material.color = Color.black; material.shader = Shader.Find("Custom/Text3D"); meshRenderer.sharedMaterial = material; textMesh.text = behaviour.IsTemplateMode ? "\"AnyWord\"" : behaviour.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 = WordEditor.GetBoundsForAxisAlignedTextMesh(textMesh); WordEditor.UpdateRectangleMesh(gameObject, boundsForAxisAlignedTextMesh); WordEditor.UpdateRectangleMaterial(gameObject); gameObject.transform.localRotation = localRotation; gameObject.transform.localScale = localScale; gameObject.transform.localPosition = localPosition; }
public override bool TryGetWordBehaviour(Word word, out WordAbstractBehaviour behaviour) { return(this.mActiveWordBehaviours.TryGetValue(word.ID, out behaviour)); }
private static WordAbstractBehaviour InstantiateWordBehaviour(WordAbstractBehaviour input) { GameObject obj2 = UnityEngine.Object.Instantiate(input.gameObject) as GameObject; return(obj2.GetComponent <WordAbstractBehaviour>()); }
public abstract void DestroyWordBehaviour(WordAbstractBehaviour behaviour, [Optional, DefaultParameterValue(true)] bool destroyGameObject);
public abstract bool TryGetWordBehaviour(Word word, out WordAbstractBehaviour behaviour);
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; }