예제 #1
0
        static void DrawLandmarkDefinitionDropdownButton(ICalculateLandmarks landmarkSource, LandmarkController landmarkController)
        {
            var definition = landmarkController.landmarkDefinition;

            using (new EditorGUILayout.HorizontalScope())
            {
                EditorGUILayout.PrefixLabel(k_DefinitionNameLabel);

                var buttonLabel = ObjectNames.NicifyVariableName(definition == null ? k_DefinitionDropdownButtonDefaultLabel : definition.name);
                if (EditorGUILayout.DropdownButton(new GUIContent(buttonLabel), FocusType.Keyboard))
                {
                    var          menu      = new GenericMenu();
                    const string baseTitle = "";
                    foreach (var availableDefinition in landmarkSource.AvailableLandmarkDefinitions)
                    {
                        var title = baseTitle + ObjectNames.NicifyVariableName(availableDefinition.name);

                        var currentlySelected = definition != null && string.Equals(availableDefinition.name, definition.name);
                        menu.AddItem(new GUIContent(title), currentlySelected, () =>
                        {
                            Undo.RegisterFullObjectHierarchyUndo(landmarkController.gameObject, k_ModifyUndoLabel);
                            landmarkController.source             = landmarkSource;
                            landmarkController.landmarkDefinition = availableDefinition;
                        });
                    }

                    menu.ShowAsContext();
                }
            }
        }
예제 #2
0
    private void GetParentSize(ICalculateLandmarks l)
    {
        if (_lockPlayArea.isOn)
        {
            return;
        }
        if (_boundingRec != null)
        {
            _worldVertices = _boundingRec.worldVertices;
        }
        if (_playAreaOutline == null)
        {
            _playAreaOutline = new GameObject();
            _playAreaOutline.AddComponent <LineRenderer>();
        }

        var lineRenderer = _playAreaOutline.GetComponent <LineRenderer>();

        lineRenderer.positionCount = 5;
        lineRenderer.SetPosition(0, _worldVertices[0]);
        lineRenderer.SetPosition(1, _worldVertices[1]);
        lineRenderer.SetPosition(2, _worldVertices[2]);
        lineRenderer.SetPosition(3, _worldVertices[3]);
        lineRenderer.SetPosition(4, _worldVertices[0]);
        lineRenderer.widthCurve = AnimationCurve.Linear(0, 0.01f, 1, 0.01f);
    }
예제 #3
0
        public static void DrawAddLandmarkButton(ICalculateLandmarks landmarkSource)
        {
            if (landmarkSource == null)
            {
                return;
            }

            if (GUILayout.Button(k_AddLandmarkButtonText))
            {
                ShowLandmarksMenu(landmarkSource);
            }
        }
예제 #4
0
 void SourceDataChanged(ICalculateLandmarks dataSource)
 {
     if (source != dataSource) // The source that is firing this event is no longer this landmark's source
     {
         dataSource.dataChanged -= SourceDataChanged;
     }
     else
     {
         if (m_UpdateOnDataChange || m_NeedsInitialUpdate)
         {
             UpdateLandmark();
             m_NeedsInitialUpdate = false;
         }
     }
 }
예제 #5
0
        internal static void ShowLandmarksMenu(ICalculateLandmarks landmarkSource, Action <LandmarkController> onLandmarkCreated = null)
        {
            if (landmarkSource == null)
            {
                return;
            }

            var landmarkMenu = new GenericMenu();
            var definitions  = landmarkSource.AvailableLandmarkDefinitions;

            if (definitions == null || definitions.Count == 0)
            {
                landmarkMenu.AddDisabledItem(styles.noLandmarksMenuItemContent);
            }
            else
            {
                for (var i = 0; i < definitions.Count; i++)
                {
                    var definition = definitions[i];
                    foreach (var outputType in definition.outputTypes)
                    {
                        var outputName  = TrimLandmarkOutputName(outputType.Name);
                        var subMenuName = definition.outputTypes.Length > 1 ? "/" + outputName : "";
                        var title       = EditorGUIUtils.GetContent(ObjectNames.NicifyVariableName(definition.name) + subMenuName);
                        landmarkMenu.AddItem(title, false, () =>
                        {
                            var landmark = landmarkSource.CreateLandmarkAsChild(definition, outputType);

                            var entityVisualsModule = ModuleLoaderCore.instance.GetModule <EntityVisualsModule>();
                            var marsEntity          = (landmarkSource as MonoBehaviour)?.GetComponentInParent <MARSEntity>();
                            if (entityVisualsModule != null && marsEntity != null)
                            {
                                entityVisualsModule.InvalidateVisual(marsEntity);
                            }

                            EditorGUIUtility.PingObject(landmark.gameObject);
                            onLandmarkCreated?.Invoke(landmark);
                        });
                    }
                }
            }

            landmarkMenu.ShowAsContext();
        }
예제 #6
0
        public static LandmarkController CreateLandmarkAsChild(this ICalculateLandmarks source, LandmarkDefinition definition, Type landmarkDataType)
        {
            var landmarkName = definition.name;

#if UNITY_EDITOR
            landmarkName = ObjectNames.NicifyVariableName(landmarkName);
#endif
            var landmarkController = new GameObject(landmarkName).AddComponent <LandmarkController>();
            if (landmarkController == null)
            {
                Debug.LogError(
                    "Error instantiating landmark. Unable to create the landmark "
                    + definition.name);
                return(null);
            }

            Transform parent            = null;
            var       sourceAsComponent = (source as Component);
            if (sourceAsComponent != null)
            {
                parent = sourceAsComponent.transform;
            }

            if (definition.settingsType != null)
            {
                landmarkController.settings = landmarkController.gameObject.AddComponent(definition.settingsType) as ILandmarkSettings;
            }

            landmarkController.output = (ILandmarkOutput)landmarkController.gameObject.AddComponent(landmarkDataType);

            landmarkController.transform.SetParent(parent, false);
            landmarkController.landmarkDefinition = definition;
            landmarkController.source             = source;
#if UNITY_EDITOR
            Undo.RegisterCreatedObjectUndo(landmarkController.gameObject, "Create Landmark");
#endif
            return(landmarkController);
        }
 void UpdateOutline(ICalculateLandmarks calculateLandmarks)
 {
     m_Outline.widthMultiplier = m_OutlineStartWidth * MARSSession.GetWorldScale();
     m_Outline.positionCount   = m_SurfacePolygon.localVertices.Count;
     m_Outline.SetPositions(m_SurfacePolygon.localVertices.ToArray());
 }