Пример #1
0
        public override void OnInspectorGUI()
        {
            TrackedObject to = target as TrackedObject;

            TrackedObjectEditor.ConfigureInspector(to);
            serializedObject.Update();
            serializedObject.ApplyModifiedProperties();
            DrawPropertiesExcluding(serializedObject, _dontIncludeMe);
            showUnityEvents = EditorGUILayout.Foldout(showUnityEvents, "Tracking Events");
            if (showUnityEvents)
            {
                EditorGUILayout.PropertyField(serializedObject.FindProperty("OnTrackerFound"));
                EditorGUILayout.PropertyField(serializedObject.FindProperty("OnTrackerLost"));
                //EditorGUILayout.PropertyField(serializedObject.FindProperty("OnMarkerlessTrackingGained"));
                //EditorGUILayout.PropertyField(serializedObject.FindProperty("OnMarkerlessTrackingLost"));
            }

            //This lets you save the properties that you set for the prefab the first time
            EditorUtility.SetDirty(target);

            if (GUI.changed)
            {
                //Apparently the above line isn't enough. We need this for subsequent edits to be saved as well.
                EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
            }

            serializedObject.ApplyModifiedProperties();
        }
Пример #2
0
        private static readonly string[] _dontIncludeMe = new string[] { "m_Script", "OnTrackerFound", "OnTrackerLost" };       //, "OnMarkerlessTrackingGained", "OnMarkerlessTrackingLost" };

        public void Awake()
        {
            TrackedObject to = target as TrackedObject;

            if (File.Exists(Path.Combine(TEXTURE_PATH, to.targetName)))
            {
                TrackedObjectEditor.UpdateMesh(to);
                TrackedObjectEditor.UpdateMaterial(to);
                TrackedObjectEditor.UpdateScale(to);
            }
        }
Пример #3
0
        private static void ConfigureInspector(TrackedObject to)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.TextField("Image File", to.targetName);
            if (GUILayout.Button("...", new GUILayoutOption[] { GUILayout.Width(25) }))
            {
                if (TrackedObjectEditor.BrowseAndLoadTexture(to))
                {
                    TrackedObjectEditor.UpdateMesh(to);
                    TrackedObjectEditor.UpdateMaterial(to);
                    TrackedObjectEditor.UpdateScale(to);
                }
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Separator();

            EditorGUILayout.BeginHorizontal();
            if (to.previewImage == null)
            {
                GUILayout.Label("No Preview\n Available", new GUILayoutOption[] {
                    GUILayout.Height(Screen.width / 4),
                    GUILayout.Width(Screen.width / 4)
                });
            }
            else
            {
                GUILayout.Label(to.previewImage, new GUILayoutOption[] {
                    GUILayout.Height(Screen.width / 10),
                    GUILayout.Width(Screen.width / 10)
                });
                EditorGUILayout.BeginVertical();
                float rwWidth = EditorGUILayout.FloatField("Physical Width (m)", to.WidthInMeters, new GUILayoutOption[0]);
                to.HeightInMeters = (rwWidth / to.previewImage.width) * to.previewImage.height;
                float rwHeight = EditorGUILayout.FloatField("Physical Height (m)", to.HeightInMeters, new GUILayoutOption[0]);

                EditorGUILayout.BeginHorizontal();
                if (Application.isPlaying)
                {
                    string status = to.IsVisible ? "Status: Tracking" : "Status: Not Tracking";
                    EditorGUILayout.LabelField(status, new GUILayoutOption[] { GUILayout.Width(115) });
                }
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.EndVertical();

                //if width is updated in the inspector, adjust the height and update mesh
                if (rwWidth != to.WidthInMeters)
                {
                    to.WidthInMeters  = rwWidth;
                    rwHeight          = (rwWidth / to.previewImage.width) * to.previewImage.height;
                    to.HeightInMeters = rwHeight;
                    TrackedObjectEditor.UpdateMesh(to);
                    TrackedObjectEditor.UpdateMaterial(to);
                    TrackedObjectEditor.UpdateScale(to);
                }

                //if height is updated in the inpector, adjust the width and update mesh
                if (rwHeight != to.HeightInMeters)
                {
                    to.HeightInMeters = rwHeight;
                    rwWidth           = (rwHeight / to.previewImage.height) * to.previewImage.width;
                    to.WidthInMeters  = rwWidth;
                    TrackedObjectEditor.UpdateMesh(to);
                    TrackedObjectEditor.UpdateMaterial(to);
                    TrackedObjectEditor.UpdateScale(to);
                }
            }
            EditorGUILayout.EndHorizontal();
        }