/// <summary> /// The Unhighlight method returns the object back to it's original colour. /// </summary> /// <param name="color">Not used.</param> /// <param name="duration">Not used.</param> public override void Unhighlight(Color?color = null, float duration = 0f) { if (objectToAffect == null) { return; } if (faderRoutines != null) { foreach (KeyValuePair <string, Coroutine> fadeRoutine in faderRoutines) { StopCoroutine(fadeRoutine.Value); } faderRoutines.Clear(); } Renderer[] renderers = objectToAffect.GetComponentsInChildren <Renderer>(true); for (int i = 0; i < renderers.Length; i++) { Renderer renderer = renderers[i]; string objectReference = renderer.gameObject.GetInstanceID().ToString(); MaterialPropertyBlock storedPropertyBlock = VRTK_SharedMethods.GetDictionaryValue(originalMaterialPropertyBlocks, objectReference); if (storedPropertyBlock == null) { continue; } renderer.SetPropertyBlock(storedPropertyBlock); } }
protected virtual void ChangeToHighlightColor(Color color, float duration = 0f) { Renderer[] renderers = objectToAffect.GetComponentsInChildren <Renderer>(true); for (int j = 0; j < renderers.Length; j++) { Renderer renderer = renderers[j]; Material[] swapCustomMaterials = new Material[renderer.materials.Length]; for (int i = 0; i < renderer.materials.Length; i++) { Material material = renderer.materials[i]; if (customMaterial != null) { material = customMaterial; swapCustomMaterials[i] = material; } string faderRoutineID = material.GetInstanceID().ToString(); Coroutine existingFaderRoutine = VRTK_SharedMethods.GetDictionaryValue(faderRoutines, faderRoutineID); if (existingFaderRoutine != null) { StopCoroutine(existingFaderRoutine); faderRoutines.Remove(faderRoutineID); } material.EnableKeyword("_EMISSION"); if (resetMainTexture && material.HasProperty("_MainTex")) { renderer.material.SetTexture("_MainTex", new Texture2D(64, 64)); } if (material.HasProperty("_Color")) { if (duration > 0f) { VRTK_SharedMethods.AddDictionaryValue(faderRoutines, faderRoutineID, StartCoroutine(CycleColor(material, material.color, color, duration)), true); } else { material.color = color; if (material.HasProperty("_EmissionColor")) { material.SetColor("_EmissionColor", VRTK_SharedMethods.ColorDarken(color, emissionDarken)); } } } } if (customMaterial != null) { renderer.materials = swapCustomMaterials; } } }
protected virtual void StoreOriginalMaterials() { originalSharedRendererMaterials.Clear(); originalRendererMaterials.Clear(); Renderer[] renderers = objectToAffect.GetComponentsInChildren <Renderer>(true); for (int i = 0; i < renderers.Length; i++) { Renderer renderer = renderers[i]; string objectReference = renderer.gameObject.GetInstanceID().ToString(); VRTK_SharedMethods.AddDictionaryValue(originalSharedRendererMaterials, objectReference, renderer.sharedMaterials, true); VRTK_SharedMethods.AddDictionaryValue(originalRendererMaterials, objectReference, renderer.materials, true); renderer.sharedMaterials = VRTK_SharedMethods.GetDictionaryValue(originalSharedRendererMaterials, objectReference); } }
protected override void ChangeToHighlightColor(Color color, float duration = 0f) { Renderer[] renderers = objectToAffect.GetComponentsInChildren <Renderer>(true); for (int i = 0; i < renderers.Length; i++) { Renderer renderer = renderers[i]; string faderRoutineID = renderer.gameObject.GetInstanceID().ToString(); if (VRTK_SharedMethods.GetDictionaryValue(originalMaterialPropertyBlocks, faderRoutineID) == null) { continue; } Coroutine existingFaderRoutine = VRTK_SharedMethods.GetDictionaryValue(faderRoutines, faderRoutineID); if (existingFaderRoutine != null) { StopCoroutine(existingFaderRoutine); faderRoutines.Remove(faderRoutineID); } MaterialPropertyBlock highlightMaterialPropertyBlock = highlightMaterialPropertyBlocks[faderRoutineID]; renderer.GetPropertyBlock(highlightMaterialPropertyBlock); if (resetMainTexture) { highlightMaterialPropertyBlock.SetTexture("_MainTex", Texture2D.whiteTexture); } if (duration > 0f) { VRTK_SharedMethods.AddDictionaryValue(faderRoutines, faderRoutineID, StartCoroutine(CycleColor(renderer, highlightMaterialPropertyBlock, color, duration)), true); } else { highlightMaterialPropertyBlock.SetColor("_Color", color); highlightMaterialPropertyBlock.SetColor("_EmissionColor", VRTK_SharedMethods.ColorDarken(color, emissionDarken)); renderer.SetPropertyBlock(highlightMaterialPropertyBlock); } } }
/// <summary> /// The GetOption method is used to return a value from the options array if the given key exists. /// </summary> /// <typeparam name="T">The system type that is expected to be returned.</typeparam> /// <param name="options">The dictionary of options to check in.</param> /// <param name="key">The identifier key to look for.</param> /// <returns>The value in the options at the given key returned in the provided system type.</returns> public virtual T GetOption <T>(Dictionary <string, object> options, string key) { return((T)VRTK_SharedMethods.GetDictionaryValue(options, key, default(T))); }