コード例 #1
0
        /// <summary>
        /// Method called when the effector is removed from the selected trigger
        /// </summary>
        /// <param name="effector">Effector that was removed from the selected trigger</param>
        private void TriggerOnEffectorRemoved(TriggerEffector effector)
        {
            if (this == null)
            {
                return;
            }
            if (visiblePanels.TryGetValue(effector, out var panel))
            {
                panel.EffectorRemovedFromTrigger(selectedTrigger, effector);
                panel.FinishEditing();
                if (panel.gameObject != null)
                {
                    prefabsPools.ReturnInstance(panel.gameObject);
                }
                visiblePanels.Remove(effector);
            }

            UnityUtilities.LayoutRebuild(transform as RectTransform);
            if (!availableEffectorTypes.Contains(effector))
            {
                availableEffectorTypes.Add(effector);
                effectorSelectDropdown.options.Add(new Dropdown.OptionData(effector.TypeName));
                effectorSelectDropdown.RefreshShownValue();
            }
        }
コード例 #2
0
 /// <summary>
 /// Shows this panel with prepared UI elements for currently selected agent
 /// </summary>
 public void Show()
 {
     gameObject.SetActive(true);
     pathTypeDropdown.SetValueWithoutNotify(pathTypeEnums.IndexOf(agentWaypointsPath.PathType));
     loopToggle.SetIsOnWithoutNotify(agentWaypointsPath.Loop);
     UnityUtilities.LayoutRebuild(transform as RectTransform);
 }
コード例 #3
0
        /// <summary>
        /// Setups the policy edit panel according to the passed controllable and policy
        /// </summary>
        /// <param name="controllable">Scenario controllable which policy will be edited</param>
        /// <param name="initialPolicy">Policy that will be applied during the setup</param>
        public void Setup(IControllable controllable, List <ControlAction> initialPolicy)
        {
            if (BoundControllable != null)
            {
                SubmitChangedInputs();
            }
            BoundControllable = controllable;
            if (BoundControllable == null)
            {
                gameObject.SetActive(false);
                UnityUtilities.LayoutRebuild(transform as RectTransform);
                return;
            }

            //List valid actions for this controllable
            validActions = controllable.ValidActions.ToList();
            validStates  = controllable.ValidStates.ToList();
            if (validStates.Count > 0)
            {
                validActions.Add("state");
            }

            //Check if this controllable can use policy
            if (validActions.Count == 0)
            {
                gameObject.SetActive(false);
                UnityUtilities.LayoutRebuild(transform as RectTransform);
                return;
            }

            SetPolicy(initialPolicy);
            gameObject.SetActive(true);
            UnityUtilities.LayoutRebuild(transform as RectTransform);
        }
コード例 #4
0
        /// <summary>
        /// Shows this panel with prepared UI elements for currently selected agent
        /// </summary>
        public void Show()
        {
            var supportsDestinationPoint = destinationPointExtension.DestinationPoint != null;

            if (supportsDestinationPoint)
            {
                var active = destinationPointExtension.DestinationPoint.IsActive;
                destinationPointToggle.SetIsOnWithoutNotify(active);
                pathTypeDropdown.SetValueWithoutNotify(
                    pathTypeEnums.IndexOf(destinationPointExtension.DestinationPoint.PlaybackPath.PathType));
                foreach (var element in shownWhenActive)
                {
                    element.SetActive(active);
                }

                foreach (var element in shownWithPlaybackPath)
                {
                    element.SetActive(active && destinationPointExtension.DestinationPoint.IsPlaybackPathVisible);
                }

                destinationPointExtension.DestinationPoint.SetVisibility(active);
                UnityUtilities.LayoutRebuild(transform as RectTransform);
            }

            gameObject.SetActive(true);
            UnityUtilities.LayoutRebuild(transform as RectTransform);
        }
コード例 #5
0
 /// <summary>
 /// Shows this panel with prepared UI elements for currently selected agent
 /// </summary>
 public void Show()
 {
     availableBehaviours = selectedAgent.Source.Behaviours;
     //Setup behaviour
     if (availableBehaviours != null && availableBehaviours.Count > 0)
     {
         behaviourDropdown.options.Clear();
         behaviourDropdown.AddOptions(availableBehaviours);
         behaviourDropdown.gameObject.SetActive(true);
     }
     else
     {
         behaviourDropdown.gameObject.SetActive(false);
     }
     if (availableBehaviours != null)
     {
         var behaviourId = string.IsNullOrEmpty(behaviourExtension.Behaviour)
             ? 0
             : availableBehaviours.IndexOf(behaviourExtension.Behaviour);
         behaviourDropdown.SetValueWithoutNotify(behaviourId);
         behaviourDropdown.RefreshShownValue();
     }
     gameObject.SetActive(true);
     UnityUtilities.LayoutRebuild(transform as RectTransform);
 }
コード例 #6
0
 /// <summary>
 /// Remove the policy entry from this edit panel
 /// </summary>
 /// <param name="entry">Policy entry to be removed</param>
 public void RemovePolicyEntry(PolicyEntry entry)
 {
     entry.gameObject.SetActive(false);
     entries.Remove(entry);
     entry.Deinitialize();
     UpdatePolicy();
     UnityUtilities.LayoutRebuild(transform as RectTransform);
 }
コード例 #7
0
 /// <summary>
 /// Shows this panel with prepared UI elements for currently selected <see cref="ScenarioNavOrigin"/>
 /// </summary>
 public void Show()
 {
     gameObject.SetActive(true);
     UnityUtilities.LayoutRebuild(transform as RectTransform);
     originXInput.text  = selectedNavOrigin.NavOrigin.OriginX.ToString(CultureInfo.CurrentCulture);
     originYInput.text  = selectedNavOrigin.NavOrigin.OriginY.ToString(CultureInfo.CurrentCulture);
     rotationInput.text = selectedNavOrigin.NavOrigin.Rotation.ToString(CultureInfo.CurrentCulture);
 }
コード例 #8
0
 /// <summary>
 /// Shows this panel with prepared UI elements for currently selected agent
 /// </summary>
 public void Show()
 {
     if (isShown)
     {
         return;
     }
     gameObject.SetActive(true);
     UnityUtilities.LayoutRebuild(transform as RectTransform);
     OnShown();
     isShown = true;
 }
コード例 #9
0
        /// <summary>
        /// Shows this panel with prepared UI elements for currently selected agent
        /// </summary>
        public void Show()
        {
            //Setup variants
            agentSource = selectedAgent.Source;
            variantDropdown.options.Clear();
            variantDropdown.AddOptions(
                agentSource.Variants.Where(variant => variant.IsPrepared).Select(variant => variant.Name).ToList());
            SelectedAgentOnVariantChanged(selectedAgent.Variant);

            gameObject.SetActive(true);
            UnityUtilities.LayoutRebuild(transform as RectTransform);
        }
コード例 #10
0
        /// <summary>
        /// Method called when another scenario trigger has been selected
        /// </summary>
        /// <param name="newTrigger">Scenario trigger that has been selected</param>
        public void OnSelectedNewTrigger(ScenarioTrigger newTrigger)
        {
            if (selectedTrigger != null)
            {
                selectedTrigger.Trigger.EffectorAdded   -= TriggerOnEffectorAdded;
                selectedTrigger.Trigger.EffectorRemoved -= TriggerOnEffectorRemoved;
                selectedTrigger = null;
            }

            foreach (var effectorPanel in visiblePanels)
            {
                effectorPanel.Value.FinishEditing();
                prefabsPools.ReturnInstance(effectorPanel.Value.gameObject);
            }

            visiblePanels.Clear();

            gameObject.SetActive(newTrigger != null);
            if (newTrigger == null)
            {
                return;
            }

            selectedTrigger = newTrigger;
            selectedTrigger.Trigger.EffectorAdded   += TriggerOnEffectorAdded;
            selectedTrigger.Trigger.EffectorRemoved += TriggerOnEffectorRemoved;
            var effectors = selectedTrigger.Trigger.Effectors;

            //Get available effectors that supports this agent and their instance is not added to the trigger yet
            availableEffectorTypes =
                allEffectors.Where(newEffector =>
                                   //Check if multiple effectors can be added, or there is no effector of this type
                                   (effectorPanelsPrefabs[newEffector.TypeName].AllowMany || effectors.All(addedEffector =>
                                                                                                           addedEffector.GetType() != newEffector.GetType())) &&
                                   //Check if effector is supported for selected agent type
                                   !newEffector.UnsupportedAgentTypes.Contains(selectedTrigger.TargetAgentType)).ToList();
            effectorSelectDropdown.options.Clear();
            effectorSelectDropdown.AddOptions(
                availableEffectorTypes.Select(effector => effector.TypeName).ToList());

            for (var i = 0; i < effectors.Count; i++)
            {
                var effector      = effectors[i];
                var effectorPanel = prefabsPools.GetInstance(effectorPanelsPrefabs[effector.TypeName].gameObject)
                                    .GetComponent <EffectorEditPanel>();
                effectorPanel.StartEditing(this, selectedTrigger, effector);
                effectorPanel.transform.SetParent(transform);
                effectorPanel.gameObject.SetActive(true);
                visiblePanels.Add(effector, effectorPanel);
            }

            UnityUtilities.LayoutRebuild(transform as RectTransform);
        }
コード例 #11
0
ファイル: AddElementsPanel.cs プロジェクト: lgsvl/simulator
        /// <inheritdoc/>
        public override void Initialize()
        {
            var sources = ScenarioManager.Instance.GetComponentsInChildren <ScenarioElementSource>();

            for (var i = 0; i < sources.Length; i++)
            {
                var newPanel = Instantiate(sourcePanelPrefab, contentParent);
                newPanel.Initialize(sources[i]);
                sourcePanels.Add(newPanel);
            }
            UnityUtilities.LayoutRebuild(contentParent as RectTransform);
        }
コード例 #12
0
 /// <summary>
 /// Add a single policy entry to this edit panel
 /// </summary>
 /// <param name="newEntry">Policy entry to be added</param>
 private void AddPolicyEntry(PolicyEntry newEntry = null)
 {
     if (newEntry == null)
     {
         newEntry = ScenarioManager.Instance.prefabsPools.GetInstance(policyEntryPrefab.gameObject)
                    .GetComponent <PolicyEntry>();
     }
     entries.Add(newEntry);
     newEntry.Initialize(this, validActions, validStates, validActions[0], "");
     newEntry.transform.SetParent(transform);
     newEntry.gameObject.SetActive(true);
     UnityUtilities.LayoutRebuild(transform as RectTransform);
 }
コード例 #13
0
        /// <summary>
        /// Shows this panel with prepared UI elements for currently selected agent
        /// </summary>
        public void Show()
        {
            var supportsDestinationPoint = destinationPointExtension.DestinationPoint != null;

            if (supportsDestinationPoint)
            {
                var active = destinationPointExtension.DestinationPoint.IsActive;
                destinationPointToggle.SetIsOnWithoutNotify(active);
                activeDestinationPointPanel.SetActive(active);
                destinationPointExtension.DestinationPoint.SetVisibility(active);
            }
            gameObject.SetActive(true);
            UnityUtilities.LayoutRebuild(transform as RectTransform);
        }
コード例 #14
0
    void Update()
    {
        KinectManager kinectManager = KinectManager.Instance;

        if (cam != null && projConfig != null && kinectManager != null && kinectManager.IsInitialized())
        {
            if (kinectManager.autoHeightAngle == KinectManager.AutoHeightAngle.AutoUpdate ||
                kinectManager.autoHeightAngle == KinectManager.AutoHeightAngle.AutoUpdateAndShowInfo)
            {
                Matrix4x4 worldToLocal = RAT2Unity.Convert(projConfig.pose);
                worldToLocal = UnityUtilities.ConvertRHtoLH(worldToLocal);

                this.transform.localPosition = worldToLocal.ExtractTranslation() + new Vector3(0f, kinectManager.sensorHeight, 0f);
            }
        }
    }
コード例 #15
0
        /// <summary>
        /// Sets the value.
        /// </summary>
        /// <param name="target">The target to set the value on.</param>
        /// <param name="value">The value to set on the target.</param>
        public void SetValue(object target, object value)
        {
            try
            {
                if (_setter == null)
                {
                    _setter = DynamicReflectionDelegateFactory.Instance.CreateSet <object>(_memberInfo);
                }

                Type underlyingType = ReflectionUtils.GetMemberUnderlyingType(_memberInfo);

                if (!UnityUtilities.IsNull(value))
                {
                    if (ReferenceHandler.IsTypeReference(value.GetType()) && typeof(UnityEngine.Object).IsAssignableFrom(underlyingType))
                    {
                        ReferenceHandler.AssignObjectValue(value, underlyingType, x =>
                        {
                            _setter(target, x);
                        });

                        return;
                    }
                }

#if DEBUG
                // dynamic method doesn't check whether the type is 'legal' to set
                // add this check for unit tests
                if (value == null)
                {
                    if (!ReflectionUtils.IsNullable(ReflectionUtils.GetMemberUnderlyingType(_memberInfo)))
                    {
                        throw new JsonSerializationException("Incompatible value. Cannot set {0} to null.".FormatWith(CultureInfo.InvariantCulture, _memberInfo));
                    }
                }
                else if (!ReflectionUtils.GetMemberUnderlyingType(_memberInfo).IsAssignableFrom(value.GetType()))
                {
                    throw new JsonSerializationException("Incompatible value. Cannot set {0} to type {1}.".FormatWith(CultureInfo.InvariantCulture, _memberInfo, value.GetType()));
                }
#endif

                _setter(target, value);
            }
            catch (Exception ex)
            {
                throw new JsonSerializationException("Error setting value to '{0}' on '{1}'.".FormatWith(CultureInfo.InvariantCulture, _memberInfo.Name, target.GetType()), ex);
            }
        }
コード例 #16
0
ファイル: PolicyEditPanel.cs プロジェクト: lgsvl/simulator
 /// <summary>
 /// Remove the policy entry from this edit panel, registers the undo record
 /// </summary>
 /// <param name="entry">Policy entry to be removed</param>
 public void RemovePolicyEntryWithUndo(PolicyEntry entry)
 {
     var undo = new Action<PolicyEntry>(revertedEntry =>
     {
         entry.gameObject.SetActive(true);
         entries.Add(entry);
         UpdatePolicy();
         UnityUtilities.LayoutRebuild(transform as RectTransform);
     });
     var dispose = new Action<PolicyEntry>(disposedEntry =>
     {
         ScenarioManager.Instance.prefabsPools.ReturnInstance(disposedEntry.gameObject);
     });
     var undoRecord = new GenericUndo<PolicyEntry>(entry, "Undo removing a policy entry", undo, dispose);
     ScenarioManager.Instance.GetExtension<ScenarioUndoManager>().RegisterRecord(undoRecord);
     RemovePolicyEntry(entry);
 }
コード例 #17
0
        /// <summary>
        /// Method called when another scenario element has been selected
        /// </summary>
        /// <param name="selectedElement">Scenario element that has been selected</param>
        private void OnSelectedOtherElement(ScenarioElement selectedElement)
        {
            if (SelectedControllable != null)
            {
                policyEditPanel.SubmitChangedInputs();
            }
            if (enabledCustomPanel != null)
            {
                enabledCustomPanel.Setup(null, null);
                enabledCustomPanel.PanelObject.SetActive(false);
                enabledCustomPanel = null;
            }

            SelectedControllable = selectedElement as ScenarioControllable;
            //Disable edit panel if there are no valid actions or states
            if (SelectedControllable == null)
            {
                policyEditPanel.Setup(null, null);
                gameObject.SetActive(false);
            }
            else
            {
                var controllable = SelectedControllable.Variant.controllable;
                if (controllable.ValidActions.Length == 0 && controllable.ValidStates.Length == 0)
                {
                    policyEditPanel.Setup(null, null);
                    gameObject.SetActive(false);
                    return;
                }

                if (customEditPanels.TryGetValue(controllable.GetType(), out enabledCustomPanel))
                {
                    enabledCustomPanel.Setup(SelectedControllable, SelectedControllable.Policy);
                    policyEditPanel.gameObject.SetActive(false);
                }
                else
                {
                    policyEditPanel.Setup(SelectedControllable.Variant.controllable, SelectedControllable.Policy);
                    policyEditPanel.gameObject.SetActive(true);
                }

                gameObject.SetActive(true);
                UnityUtilities.LayoutRebuild(transform as RectTransform);
            }
        }
コード例 #18
0
        /// <summary>
        /// Sets playback path visibility
        /// </summary>
        /// <param name="extension">Changed destination point extension</param>
        /// <param name="visible">Should the playback path be visible</param>
        private void SetPlaybackPathVisibility(AgentDestinationPoint extension, bool visible)
        {
            var isSelected = extension == destinationPointExtension;

            extension.DestinationPoint.SetPlaybackPathVisible(visible);
            extension.DestinationPoint.PlaybackPath.SetActive(visible);
            if (isSelected)
            {
                playbackPathToggle.SetIsOnWithoutNotify(visible);
            }
            foreach (var element in shownWithPlaybackPath)
            {
                element.SetActive(isSelected && visible);
            }

            if (isSelected)
            {
                UnityUtilities.LayoutRebuild(transform as RectTransform);
            }
        }
コード例 #19
0
        /// <summary>
        /// Method called when the effector is added to the selected trigger
        /// </summary>
        /// <param name="effector">Effector that was added to the selected trigger</param>
        private void TriggerOnEffectorAdded(TriggerEffector effector)
        {
            var effectorPanel = prefabsPools.GetInstance(effectorPanelsPrefabs[effector.TypeName].gameObject)
                                .GetComponent <EffectorEditPanel>();

            if (!effectorPanel.AllowMany)
            {
                availableEffectorTypes.RemoveAt(effectorSelectDropdown.value);
                effectorSelectDropdown.options.RemoveAt(effectorSelectDropdown.value);
                effectorSelectDropdown.SetValueWithoutNotify(0);
                effectorSelectDropdown.RefreshShownValue();
            }

            effectorPanel.StartEditing(this, selectedTrigger, effector);
            effectorPanel.EffectorAddedToTrigger(selectedTrigger, effector);
            effectorPanel.transform.SetParent(transform);
            effectorPanel.gameObject.SetActive(true);
            visiblePanels.Add(effector, effectorPanel);
            UnityUtilities.LayoutRebuild(effectorPanel.transform as RectTransform);
        }
コード例 #20
0
        /// <summary>
        /// Method called when another scenario element has been selected
        /// </summary>
        /// <param name="previousElement">Scenario element that has been deselected</param>
        /// <param name="selectedElement">Scenario element that has been selected</param>
        private void OnSelectedOtherElement(ScenarioElement previousElement, ScenarioElement selectedElement)
        {
            if (isAddingWaypoints)
            {
                ScenarioManager.Instance.GetExtension <InputManager>().CancelAddingElements(this);
            }

            //Force input apply on deselect
            if (selectedWaypoint != null)
            {
                SubmitChangedInputs();
            }
            selectedWaypoint           = selectedElement as ScenarioAgentWaypoint;
            selectedAgent              = selectedWaypoint != null ? (ScenarioAgent)selectedWaypoint.ParentElement : null;
            selectedAgentWaypointsPath =
                selectedAgent == null ? null : selectedAgent.GetExtension <AgentWaypointsPath>();
            //Disable waypoints for ego vehicles
            if (selectedAgent == null || selectedAgentWaypointsPath == null ||
                !selectedAgent.Source.AgentSupportWaypoints(selectedAgent))
            {
                gameObject.SetActive(false);
            }
            else
            {
                gameObject.SetActive(true);
                speedPanel.SetActive(selectedWaypoint != null);
                accelerationPanel.SetActive(selectedWaypoint != null);
                waitTimePanel.SetActive(selectedWaypoint != null);
                if (selectedWaypoint != null)
                {
                    speedInput.CurrentContext = selectedWaypoint;
                    speedInput.ExternalValueChange(selectedWaypoint.DestinationSpeed, selectedWaypoint, false);
                    accelerationInput.CurrentContext = selectedWaypoint;
                    accelerationInput.ExternalValueChange(selectedWaypoint.Acceleration, selectedWaypoint, false);
                    waitTimeInput.text = selectedWaypoint.WaitTime.ToString("F");
                }

                triggerEditPanel.OnSelectedNewTrigger(selectedWaypoint.LinkedTrigger);
                UnityUtilities.LayoutRebuild(transform as RectTransform);
            }
        }
コード例 #21
0
        /// <summary>
        /// Sets destination point as active or inactive if it is supported by selected agent
        /// </summary>
        /// <param name="extension">Changed destination point extension</param>
        /// <param name="active">Should the destination point be active</param>
        private void SetDestinationPoint(AgentDestinationPoint extension, bool active)
        {
            extension.DestinationPoint.SetActive(active);
            var isSelected = extension == destinationPointExtension;

            extension.DestinationPoint.SetVisibility(isSelected && active);
            if (isSelected)
            {
                destinationPointToggle.SetIsOnWithoutNotify(active);
            }
            foreach (var element in shownWhenActive)
            {
                element.SetActive(isSelected && active);
            }

            SetPlaybackPathVisibility(extension.DestinationPoint.IsPlaybackPathVisible);

            if (isSelected)
            {
                UnityUtilities.LayoutRebuild(transform as RectTransform);
            }
        }
コード例 #22
0
        /// <inheritdoc/>
        public override void Initialize()
        {
            SourcePanel newPanel;
            //Agents panels
            var agentsManager = ScenarioManager.Instance.GetExtension <ScenarioAgentsManager>();
            var sources       = agentsManager.Sources;

            for (var i = 0; i < sources.Count; i++)
            {
                newPanel = Instantiate(sourcePanelPrefab, contentParent);
                newPanel.Initialize(sources[i]);
                sourcePanels.Add(newPanel);
            }

            //Controllables panels
            var controllablesManager = ScenarioManager.Instance.GetExtension <ScenarioControllablesManager>();

            newPanel = Instantiate(sourcePanelPrefab, contentParent);
            newPanel.Initialize(controllablesManager.Source);
            sourcePanels.Add(newPanel);
            UnityUtilities.LayoutRebuild(contentParent as RectTransform);
        }
コード例 #23
0
        /// <summary>
        /// Method called when another scenario element has been selected
        /// </summary>
        /// <param name="previousElement">Scenario element that has been deselected</param>
        /// <param name="selectedElement">Scenario element that has been selected</param>
        private void OnSelectedOtherElement(ScenarioElement previousElement, ScenarioElement selectedElement)
        {
            if (isAddingWaypoints)
            {
                ScenarioManager.Instance.GetExtension <InputManager>().CancelAddingElements(this);
            }

            // Force input apply on deselect
            if (selectedWaypoint != null)
            {
                SubmitChangedInputs();
            }
            selectedWaypoint = selectedElement as ScenarioDestinationPointWaypoint;
            var parentAgent = selectedWaypoint != null ? (ScenarioAgent)selectedWaypoint.ParentElement : null;

            selectedDestinationPoint = parentAgent != null
                ? parentAgent.GetExtension <AgentDestinationPoint>()?.DestinationPoint
                : null;

            selectedWaypointsPath = selectedDestinationPoint != null ? selectedDestinationPoint.PlaybackPath : null;

            // Disable panel if it is not supported
            if (selectedDestinationPoint == null || selectedWaypointsPath == null)
            {
                gameObject.SetActive(false);
            }
            else
            {
                gameObject.SetActive(true);
                speedPanel.SetActive(selectedWaypoint != null);
                if (selectedWaypoint != null)
                {
                    speedInput.CurrentContext = selectedWaypoint;
                    speedInput.ExternalValueChange(selectedWaypoint.DestinationSpeed, selectedWaypoint, false);
                }
                UnityUtilities.LayoutRebuild(transform as RectTransform);
            }
        }
コード例 #24
0
        /// <summary>
        /// Setups maps buttons while waiting until map manager is initialized
        /// </summary>
        /// <returns>Task</returns>
        private async Task SetupButtons()
        {
            await ScenarioManager.Instance.WaitForExtension <ScenarioMapManager>();

            var mapManager = ScenarioManager.Instance.GetExtension <ScenarioMapManager>();

            mapManager.MapChanged += OnMapLoaded;
            var availableMaps  = mapManager.AvailableMaps;
            var currentMapName = mapManager.CurrentMapName;

            for (var i = 0; i < availableMaps.Count; i++)
            {
                var availableMap    = availableMaps[i];
                var mapSelectButton = Instantiate(buttonSample, buttonSample.transform.parent);
                mapSelectButton.Setup(availableMap.name);
                mapSelectButton.gameObject.SetActive(true);
                if (currentMapName == availableMap.name)
                {
                    mapSelectButton.MarkAsCurrent();
                    currentMapButton = mapSelectButton;
                }

                buttons.Add(mapSelectButton);
            }

            //Dynamic height
            var rectTransform = (RectTransform)transform;
            var buttonHeight  = ((RectTransform)buttonSample.transform).sizeDelta.y;
            var firstButtonY  = ((RectTransform)buttons[0].transform).anchoredPosition.y;

            rectTransform.sizeDelta = new Vector2(rectTransform.sizeDelta.x, (buttonHeight + 4) * availableMaps.Count - firstButtonY);

            buttonSample.gameObject.SetActive(false);
            UnityUtilities.LayoutRebuild(rectTransform);
            rectTransform.offsetMin = Vector2.zero;
        }
コード例 #25
0
 /// <summary>
 /// Shows this panel with prepared UI elements for currently selected agent
 /// </summary>
 public void Show()
 {
     SetupSensorsConfigurationDropdown();
     gameObject.SetActive(true);
     UnityUtilities.LayoutRebuild(transform as RectTransform);
 }
コード例 #26
0
 private void Awake() => UnityUtilities.DisableAnalytics();
コード例 #27
0
//	void OnRenderImage (RenderTexture source, RenderTexture destination)
//	{
//		if(flipCameraX && camFlipMat)
//		{
//			Graphics.Blit(source, destination, camFlipMat);
//		}
//	}

    private void LoadCalibrationData()
    {
        projConfig = null;
        cam        = GetComponent <Camera>();

        if (!cam)
        {
            Debug.LogError("Please add the ProjectorCamera-component to a camera in the scene.");
            return;
        }

        if (calibrationXml)
        {
            ensemble = ProjectorCameraEnsemble.ReadCalibration(calibrationXml.text);

            foreach (ProjectorCameraEnsemble.Projector pc in ensemble.projectors)
            {
                if (pc.name == projNameInConfig)
                {
                    projConfig = pc;
                }
            }
        }
        else
        {
            projConfig = null;
        }

        if (projConfig != null)
        {
            if (displayIndex < 0)
            {
                displayIndex = projConfig.displayIndex;
                Debug.Log("ProjCam target display: " + displayIndex);

                if (useProjectorDisplay && displayIndex >= 0)
                {
//#if !UNITY_EDITOR
                    cam.targetDisplay = displayIndex;
//#endif
                }
            }

            //Debug.Log("Projective Rendering - Loading projector calibration information.");
            imageWidth  = projConfig.width;
            imageHeight = projConfig.height;

            if (imageWidth > 0 && imageHeight > 0 && projConfig.cameraMatrix != null)
            {
                cam.aspect = (float)imageWidth / imageHeight;

                // this is the vertical field of view - fy
                float fieldOfViewRad = 2.0f * (float)System.Math.Atan((((double)(imageHeight)) / 2.0) / projConfig.cameraMatrix[1, 1]);
                float fieldOfViewDeg = fieldOfViewRad / 3.14159265359f * 180.0f;

                cam.fieldOfView = fieldOfViewDeg;
                Debug.Log("ProjCam FOV: " + fieldOfViewDeg);

                Matrix4x4 opencvProjMat = GetProjectionMatrix(projConfig.cameraMatrix, cam.nearClipPlane, cam.farClipPlane);
                cam.projectionMatrix = UnityUtilities.ConvertRHtoLH(opencvProjMat);
            }

            if (projConfig.lensDistortion != null)
            {
                //var irCoef = projConfig.lensDistortion.AsFloatArray();
                //! jolaur -- looks like this is not being used and is now 2 elements instead of four in the new xml format
                //! lensDist = new Vector4(irCoef[0], irCoef[1], irCoef[2], irCoef[3]);
                //lensDist = new Vector4();
            }

            if (projConfig.pose != null)
            {
                Matrix4x4 worldToLocal = RAT2Unity.Convert(projConfig.pose);
                worldToLocal = UnityUtilities.ConvertRHtoLH(worldToLocal);

                KinectManager kinectManager = KinectManager.Instance;

                this.transform.localPosition = worldToLocal.ExtractTranslation() + new Vector3(0f, kinectManager.sensorHeight, 0f);
                this.transform.localRotation = worldToLocal.ExtractRotation();
                Debug.Log("ProjCam position: " + transform.localPosition + ", rotation: " + transform.localRotation.eulerAngles);
            }
        }
        else
        {
            Debug.LogError("Make sure the 'Calibration Xml' && 'Proj name in config'-settings are correct.");
            //lensDist = new Vector4();
        }
    }
コード例 #28
0
 /// <inheritdoc/>
 public override void Show()
 {
     gameObject.SetActive(true);
     UnityUtilities.LayoutRebuild(contentParent as RectTransform);
 }
コード例 #29
0
        /// <inheritdoc/>
        public override void Initialize()
        {
            var nonBlockingTask = SetupButtons();

            UnityUtilities.LayoutRebuild(transform as RectTransform);
        }
コード例 #30
0
 /// <summary>
 /// Shows this panel with prepared UI elements for currently selected agent
 /// </summary>
 public void Show()
 {
     colorImage.color = colorExtension.AgentColor;
     gameObject.SetActive(true);
     UnityUtilities.LayoutRebuild(transform as RectTransform);
 }