Example #1
0
        /// <summary>
        ///     Initializes <see cref="ImagePlane" />.
        /// </summary>
        protected virtual void InitializeImagePlane()
        {
            // Loads the prefab
            if (ImagePlanePrefab == null)
            {
                ImagePlanePrefab = Resources.Load("ArucoObjectDisplayerImagePlane") as GameObject;
            }

            // Creates the image plane if null
            if (ImagePlane == null)
            {
                // Finds or creates the image plane gameObject
                var imagePlaneTransform = transform.Find(ImagePlanePrefab.name);
                if (imagePlaneTransform != null)
                {
                    ImagePlane = imagePlaneTransform.gameObject;
                }
                else
                {
                    ImagePlane      = Instantiate(ImagePlanePrefab, transform);
                    ImagePlane.name = ImagePlanePrefab.name;
                }

                // Updates the image plane material
#if UNITY_EDITOR
                if (!EditorApplication.isPlayingOrWillChangePlaymode)
#else
                if (Application.isEditor)
#endif
                {
                    var renderer = ImagePlane.GetComponent <Renderer>();
                    imagePlaneMaterial      = new Material(renderer.sharedMaterial);
                    renderer.sharedMaterial = imagePlaneMaterial;
                }
                else
                {
                    imagePlaneMaterial = ImagePlane.GetComponent <Renderer>().material;
                }

                // Don't save in the scene : dynamically generated
                ImagePlane.hideFlags = HideFlags.DontSaveInEditor;
            }
        }
Example #2
0
 /// <summary>
 /// Draw the <see cref="ImageTexture"/> on the <see cref="ImagePlane"/>.
 /// </summary>
 public virtual void Draw()
 {
     ImagePlane.SetActive(true);
     ImagePlane.GetComponent <Renderer>().material.mainTexture = ImageTexture;
 }