<commit_before>// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using Microsoft.MixedReality.Toolkit.Utilities;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

namespace Microsoft.MixedReality.Toolkit.Boundary
{
    public abstract class BaseBoundarySystem : BaseCoreSystem, IMixedRealityBoundarySystem
    {
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="profile">The configuration profile for the service.</param>
        /// <param name="scale">The application's configured <see cref="Utilities.ExperienceScale"/>.</param>
        protected BaseBoundarySystem(
            MixedRealityBoundaryVisualizationProfile profile,
            ExperienceScale scale) : base(profile)
        {
            Scale = scale;
            BoundaryProfile = profile;
        }

        /// <summary>
        /// Reads the visualization profile contents and stores the values in class properties.
        /// </summary>
        private void ReadProfile()
        {
            if (BoundaryProfile == null) { return; }

            BoundaryHeight = BoundaryProfile.BoundaryHeight;
            ShowFloor = BoundaryProfile.ShowFloor;
            FloorPhysicsLayer = BoundaryProfile.FloorPhysicsLayer;
            ShowPlayArea = BoundaryProfile.ShowPlayArea;
            PlayAreaPhysicsLayer = BoundaryProfile.PlayAreaPhysicsLayer;
            ShowTrackedArea = BoundaryProfile.ShowTrackedArea;
            TrackedAreaPhysicsLayer = BoundaryProfile.TrackedAreaPhysicsLayer;
            ShowBoundaryWalls = BoundaryProfile.ShowBoundaryWalls;
            BoundaryWallsPhysicsLayer = BoundaryProfile.BoundaryWallsPhysicsLayer;
            ShowBoundaryCeiling = BoundaryProfile.ShowBoundaryCeiling;
            CeilingPhysicsLayer = BoundaryProfile.CeilingPhysicsLayer;
        }

        /// <summary>
        /// Whether any XR device is present.
        /// </summary>
        [System.Obsolete("This value is no longer used.")]
        protected virtual bool IsXRDevicePresent { get; } = true;

        #region IMixedRealityService Implementation

        private MixedRealityBoundaryVisualizationProfile BoundaryProfile { get; }

        private BoundaryEventData boundaryEventData = null;

        /// <inheritdoc/>
        public override string Name { get; protected set; } = "Mixed Reality Boundary System";

        /// <inheritdoc/>
        public override void Initialize()
        {
            // Initialize this value earlier than other systems, so we can use it to block boundary events being raised too early
            IsInitialized = false;

            // The profile needs to be read on initialization to ensure that re-initialization
            // after profile change reads the correct data.
            ReadProfile();

            if (!Application.isPlaying || !DeviceUtility.IsPresent) { return; }

            boundaryEventData = new BoundaryEventData(EventSystem.current);

            SetTrackingSpace();
            CalculateBoundaryBounds();

            base.Initialize();

            RefreshVisualization();
            RaiseBoundaryVisualizationChanged();
        }


        /// <inheritdoc/>
        public override void Destroy()
        {
            // First, detach the child objects (we are tracking them separately)
            // and clean up the parent.
            if (boundaryVisualizationParent != null)
            {
                if (Application.isEditor)
                {<commit_msg>Late init boundary in case a device is attached later<commit_after>// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using Microsoft.MixedReality.Toolkit.Utilities;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

namespace Microsoft.MixedReality.Toolkit.Boundary
{
    public abstract class BaseBoundarySystem : BaseCoreSystem, IMixedRealityBoundarySystem
    {
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="profile">The configuration profile for the service.</param>
        /// <param name="scale">The application's configured <see cref="Utilities.ExperienceScale"/>.</param>
        protected BaseBoundarySystem(
            MixedRealityBoundaryVisualizationProfile profile,
            ExperienceScale scale) : base(profile)
        {
            Scale = scale;
            BoundaryProfile = profile;
        }

        /// <summary>
        /// Reads the visualization profile contents and stores the values in class properties.
        /// </summary>
        private void ReadProfile()
        {
            if (BoundaryProfile == null) { return; }

            BoundaryHeight = BoundaryProfile.BoundaryHeight;
            ShowFloor = BoundaryProfile.ShowFloor;
            FloorPhysicsLayer = BoundaryProfile.FloorPhysicsLayer;
            ShowPlayArea = BoundaryProfile.ShowPlayArea;
            PlayAreaPhysicsLayer = BoundaryProfile.PlayAreaPhysicsLayer;
            ShowTrackedArea = BoundaryProfile.ShowTrackedArea;
            TrackedAreaPhysicsLayer = BoundaryProfile.TrackedAreaPhysicsLayer;
            ShowBoundaryWalls = BoundaryProfile.ShowBoundaryWalls;
            BoundaryWallsPhysicsLayer = BoundaryProfile.BoundaryWallsPhysicsLayer;
            ShowBoundaryCeiling = BoundaryProfile.ShowBoundaryCeiling;
            CeilingPhysicsLayer = BoundaryProfile.CeilingPhysicsLayer;
        }

        /// <summary>
        /// Whether any XR device is present.
        /// </summary>
        [System.Obsolete("This value is no longer used.")]
        protected virtual bool IsXRDevicePresent { get; } = true;

        #region IMixedRealityService Implementation

        private MixedRealityBoundaryVisualizationProfile BoundaryProfile { get; }

        private BoundaryEventData boundaryEventData = null;

        /// <inheritdoc/>
        public override string Name { get; protected set; } = "Mixed Reality Boundary System";

        /// <inheritdoc/>
        public override void Initialize()
        {
            // Initialize this value earlier than other systems, so we can use it to block boundary events being raised too early
            IsInitialized = false;

            // The profile needs to be read on initialization to ensure that re-initialization
            // after profile change reads the correct data.
            ReadProfile();

            if (!Application.isPlaying || !DeviceUtility.IsPresent) { return; }

            boundaryEventData = new BoundaryEventData(EventSystem.current);

            SetTrackingSpace();
            CalculateBoundaryBounds();

            base.Initialize();

            RefreshVisualization();
            RaiseBoundaryVisualizationChanged();
        }

        public override void Update()
        {
            base.Update();

            // If a device is attached late, initialize with the new state of the world
            if (!IsInitialized && DeviceUtility.IsPresent)
            {
                Initialize();
            }
        }

        /// <inheritdoc/>
        public override void Destroy()
        {
            // First, detach the child objects (we are tracking them separately)
            // and clean up the parent.
            if (boundaryVisualizationParent != null)
            {
                if (Application.isEditor)
                {
{'fraction_non_alphanumeric': 0.07771951055533145, 'fraction_numerical': 0.0, 'mean_word_length': 2.2227036395147315, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1879821', 'n_tokens_mistral': 1807, 'n_tokens_neox': 1724, 'n_words': 482}