Exemplo n.º 1
0
        void LightmapStaticSettings()
        {
#if UNITY_2019_2_OR_NEWER
            bool lightmapStatic = (staticEditorFlagsProp.intValue & (int)StaticEditorFlags.ContributeGI) != 0;
#else
            bool lightmapStatic = (staticEditorFlagsProp.intValue & (int)StaticEditorFlags.LightmapStatic) != 0;
#endif

            EditorGUI.BeginChangeCheck();
            lightmapStatic = EditorGUILayout.Toggle(LightmapStaticContents, lightmapStatic);

            if (EditorGUI.EndChangeCheck())
            {
#if UNITY_2019_2_OR_NEWER
                SceneModeUtility.SetStaticFlags(gameObjectsSerializedObject.targetObjects, (int)StaticEditorFlags.ContributeGI, lightmapStatic);
#else
                SceneModeUtility.SetStaticFlags(gameObjectsSerializedObject.targetObjects, (int)StaticEditorFlags.LightmapStatic, lightmapStatic);
#endif
                gameObjectsSerializedObject.Update();
            }
        }
Exemplo n.º 2
0
        protected GameObject[] FetchGameObjects()
        {
            var prefabStage = PrefabStageUtility.GetCurrentPrefabStage();
            if (prefabStage != null)
                return SceneModeUtility.GetObjects(new[] { prefabStage.prefabContentsRoot }, true);
            
            var goRoots = new List<UnityEngine.Object>();
            for (int i = 0; i < SceneManager.sceneCount; ++i)
            {
                var scene = SceneManager.GetSceneAt(i);
                if (!scene.IsValid() || !scene.isLoaded)
                    continue;

                var sceneRootObjects = scene.GetRootGameObjects();
                if (sceneRootObjects != null && sceneRootObjects.Length > 0)
                    goRoots.AddRange(sceneRootObjects);
            }

            return SceneModeUtility.GetObjects(goRoots.ToArray(), true)
                .Where(o => !o.hideFlags.HasFlag(HideFlags.HideInHierarchy)).ToArray();
        }
Exemplo n.º 3
0
        private void DoStaticFlagsDropDown(GameObject go)
        {
            EditorGUI.BeginChangeCheck();
            EditorGUI.showMixedValue = m_StaticEditorFlags.hasMultipleDifferentValues;
            int  changedFlags;
            bool changedToValue;
            //EditorGUI.EnumFlagsField(
            //    GUILayoutUtility.GetRect(GUIContent.none, s_Styles.staticDropdown, GUILayout.ExpandWidth(false)),
            //    GUIContent.none,
            //    GameObjectUtility.GetStaticEditorFlags(go),
            //    out changedFlags, out changedToValue,
            //    s_Styles.staticDropdown
            //    );
            var paramsX = new object[6]
            {
                GUILayoutUtility.GetRect(GUIContent.none, s_Styles.staticDropdown, GUILayout.ExpandWidth(false)),
                GUIContent.none,
                GameObjectUtility.GetStaticEditorFlags(go),
                null, null,
                s_Styles.staticDropdown
            };

            typeof(EditorGUI).GetMethod("EnumFlagsField", flagX, null, new Type[6] {
                typeof(Rect), typeof(GUIContent), typeof(Enum), typeof(int).MakeByRefType(), typeof(bool).MakeByRefType(), typeof(GUIStyle)
            }, null).Invoke(null, paramsX);
            changedFlags   = (int)paramsX[3];
            changedToValue = (bool)paramsX[4];

            EditorGUI.showMixedValue = false;
            if (EditorGUI.EndChangeCheck())
            {
                SceneModeUtility.SetStaticFlags(targets, changedFlags, changedToValue);
                serializedObject.SetIsDifferentCacheDirty();

                // Displaying the dialog to ask the user whether to update children nukes the gui state (case 962453)
                EditorGUIUtility.ExitGUI();
            }
        }
Exemplo n.º 4
0
        void LightmapStaticSettings()
        {
            m_GameObjectsSerializedObject.Update();

            bool lightmapStatic = (m_StaticEditorFlags.intValue & (int)StaticEditorFlags.LightmapStatic) != 0;

            EditorGUI.BeginChangeCheck();

            lightmapStatic = EditorGUILayout.Toggle(Styles.lightmapStatic, lightmapStatic);

            if (EditorGUI.EndChangeCheck())
            {
                SceneModeUtility.SetStaticFlags(m_GameObjectsSerializedObject.targetObjects, (int)StaticEditorFlags.LightmapStatic, lightmapStatic);
            }

            if (lightmapStatic)
            {
                EditorGUILayout.PropertyField(m_UnwrapParameters, true);

                if (m_UnwrapParameters.isExpanded)
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.FlexibleSpace();

                    if (GUILayout.Button("Reset", Styles.miniButton))
                    {
                        ResetUnwrapParams(m_UnwrapParameters);
                    }

                    if (GUILayout.Button("Apply", Styles.miniButton))
                    {
                        RebuildLightmapUVs();
                    }

                    GUILayout.EndHorizontal();
                    GUILayout.Space(4);
                }

                if (!m_ModifyingMesh)
                {
                    m_AnyMissingLightmapUVs = targets.Any(x =>
                    {
                        if (x is ProBuilderMesh)
                        {
                            return(!((ProBuilderMesh)x).HasArrays(MeshArrays.Texture1));
                        }

                        return(false);
                    });
                }

                if (m_AnyMissingLightmapUVs)
                {
                    EditorGUILayout.HelpBox("Lightmap UVs are missing, please generate Lightmap UVs.", MessageType.Warning);

                    if (GUILayout.Button("Generate Lightmap UVs"))
                    {
                        RebuildLightmapUVs();
                    }
                }
            }
            else
            {
                EditorGUILayout.HelpBox("To enable generation of lightmap UVs for this Mesh, please enable the 'Lightmap Static' property.", MessageType.Info);
            }
        }
        public IEnumerator DefaultUnwrapParamsDoNotOverlap()
        {
#pragma warning disable 618
            var lightmapMode = Lightmapping.giWorkflowMode;

            try
            {
                Lightmapping.giWorkflowMode = Lightmapping.GIWorkflowMode.OnDemand;
#pragma warning restore 618

#if UNITY_2019_2_OR_NEWER
                Lightmapping.bakeStarted   += LightmappingStarted;
                Lightmapping.bakeCompleted += LightmappingCompleted;
#else
                Lightmapping.started += LightmappingStarted;

                if (Lightmapping.completed == null)
                {
                    Lightmapping.completed = LightmappingCompleted;
                }
                else
                {
                    Lightmapping.completed += LightmappingCompleted;
                }
#endif

                Setup();

                float x = -10f;

                using (var shapes = new TestUtility.BuiltInPrimitives())
                {
#if UNITY_2019_2_OR_NEWER
                    SceneModeUtility.SetStaticFlags(shapes.Select(it => it.gameObject).ToArray(), (int)StaticEditorFlags.ContributeGI, true);
#else
                    SceneModeUtility.SetStaticFlags(shapes.Select(it => it.gameObject).ToArray(), (int)StaticEditorFlags.LightmapStatic, true);
#endif

                    foreach (ProBuilderMesh mesh in shapes)
                    {
                        mesh.transform.position = new Vector3(x, 0f, 0f);
                        x += mesh.mesh.bounds.size.x + .5f;
                        mesh.Optimize(true);
                    }

                    Lightmapping.BakeAsync();

                    while (!s_FinishedBaking)
                    {
                        yield return(null);
                    }

                    LogAssert.NoUnexpectedReceived();
                }
            }
            finally
            {
#if UNITY_2019_2_OR_NEWER
                Lightmapping.bakeStarted   -= LightmappingStarted;
                Lightmapping.bakeCompleted -= LightmappingCompleted;
#else
                Lightmapping.started   -= LightmappingStarted;
                Lightmapping.completed -= LightmappingCompleted;
#endif
#pragma warning disable 618
                Lightmapping.giWorkflowMode = lightmapMode;
#pragma warning restore 618
                Cleanup();
            }
        }
Exemplo n.º 6
0
 UnityObject[] GetObjects(bool includeChildren)
 {
     return(SceneModeUtility.GetObjects(targets, includeChildren));
 }
Exemplo n.º 7
0
    void OnSceneGUI()
    {
        SceneView currentSceneView = SceneView.currentDrawingSceneView;

        Vector3 screenPos = currentSceneView.camera.WorldToScreenPoint(_generator.transform.position);

        screenPos.y = SceneView.currentDrawingSceneView.position.height - screenPos.y;

        Rect position = new Rect(screenPos.x, screenPos.y, 50, 16);

        if (!_isLinking)
        {
            Handles.BeginGUI();

            if (GUI.Button(position, "+"))
            {
                _isLinking = true;
                currentSceneView.SetSceneViewFiltering(true);
                SceneModeUtility.SearchForType(typeof(WireMotor));
            }

            int toRemove = -1;
            for (int i = 0; i < _generator.connectedMotor.Length; ++i)
            {
                screenPos   = currentSceneView.camera.WorldToScreenPoint(_generator.connectedMotor[i].transform.position);
                screenPos.y = SceneView.currentDrawingSceneView.position.height - screenPos.y;


                Handles.DrawLine(_generator.transform.position, _generator.connectedMotor[i].transform.position);

                if (GUI.Button(new Rect(screenPos, new Vector2(50, 16)), "-"))
                {
                    toRemove = i;
                }
            }

            if (toRemove != -1)
            {
                WireMotor motor = _generator.connectedMotor[toRemove];
                ArrayUtility.Remove(ref _generator.connectedMotor, motor);
                ArrayUtility.Remove(ref motor.connectedGenerator, _generator);

                EditorUtility.SetDirty(_generator);
                EditorUtility.SetDirty(motor);
            }

            Handles.EndGUI();

            Handles.color = Color.green;
            for (int i = 0; i < _generator.connectedMotor.Length; ++i)
            {
                Handles.DrawLine(_generator.transform.position, _generator.connectedMotor[i].transform.position);
            }
        }
        else
        {
            int controlID = GUIUtility.GetControlID(FocusType.Passive);

            if (Event.current.type == EventType.mouseDown)
            {
                GUIUtility.hotControl = controlID;
                Event.current.Use();
            }
            else if (Event.current.type == EventType.mouseUp)
            {
                GameObject obj   = HandleUtility.PickGameObject(Event.current.mousePosition, true);
                WireMotor  motor = obj == null? null : obj.GetComponent <WireMotor>();

                if (motor != null)
                {
                    if (!ArrayUtility.Contains(_generator.connectedMotor, motor))
                    {
                        ArrayUtility.Add(ref _generator.connectedMotor, motor);
                        ArrayUtility.Add(ref motor.connectedGenerator, _generator);

                        EditorUtility.SetDirty(_generator);
                        EditorUtility.SetDirty(motor);
                    }
                }

                _isLinking = false;
                currentSceneView.SetSceneViewFiltering(false);
                SceneModeUtility.SearchForType(null);
            }
        }
    }
Exemplo n.º 8
0
        private IEnumerator <SearchItem> BuildGODS(SearchContext context, SearchProvider provider)
        {
            //using (new DebugTimer("BuildGODS"))
            {
                var objects     = new GameObject[0];
                var prefabStage = PrefabStageUtility.GetCurrentPrefabStage();
                if (prefabStage != null)
                {
                    objects = SceneModeUtility.GetObjects(new[] { prefabStage.prefabContentsRoot }, true);
                    yield return(null);
                }
                else
                {
                    var goRoots = new List <UnityEngine.Object>();
                    for (int i = 0; i < SceneManager.sceneCount; ++i)
                    {
                        var scene = SceneManager.GetSceneAt(i);
                        if (!scene.IsValid() || !scene.isLoaded)
                        {
                            continue;
                        }

                        var sceneRootObjects = scene.GetRootGameObjects();
                        if (sceneRootObjects != null && sceneRootObjects.Length > 0)
                        {
                            goRoots.AddRange(sceneRootObjects);
                        }
                        yield return(null);
                    }

                    objects = SceneModeUtility.GetObjects(goRoots.ToArray(), true);
                    yield return(null);
                }

                //using (new DebugTimer($"Fetching Scene Objects Components"))
                {
                    List <int> matches        = new List <int>();
                    var        useFuzzySearch = objects.Length < k_LODDetail2 && context.categories.Any(c => c.name.id == "fuzzy" && c.isEnabled);

                    gods = new GOD[objects.Length];
                    for (int i = 0; i < objects.Length; ++i)
                    {
                        gods[i].gameObject = objects[i];
                        var id = gods[i].gameObject.GetInstanceID();
                        if (!componentsById.TryGetValue(id, out gods[i].name))
                        {
                            if (gods.Length > k_LODDetail2)
                            {
                                gods[i].rawname = gods[i].gameObject.name;
                            }
                            else if (gods.Length > k_LODDetail1)
                            {
                                gods[i].rawname = GetTransformPath(gods[i].gameObject.transform);
                            }
                            else
                            {
                                gods[i].rawname = BuildComponents(gods[i].gameObject);
                            }
                            gods[i].name       = CleanString(gods[i].rawname);
                            componentsById[id] = gods[i].name;
                        }
                        gods[i].id = id.ToString();

                        yield return(MatchGOD(context, provider, gods[i], i, useFuzzySearch, CleanString(context.searchQuery), matches));
                    }
                }
            }
        }
Exemplo n.º 9
0
        public SceneObjectsProvider(string providerId, string displayName = null)
            : base(providerId, displayName)
        {
            priority = 50;
            filterId = "h:";

            subCategories = new List <NameId>
            {
                new NameId("fuzzy", "fuzzy"),
                new NameId("limit", $"limit to {k_LimitMatches} matches")
            };

            isEnabledForContextualSearch = () =>
                                           QuickSearchTool.IsFocusedWindowTypeName("SceneView") ||
                                           QuickSearchTool.IsFocusedWindowTypeName("SceneHierarchyWindow");

            EditorApplication.hierarchyChanged += () => componentsById.Clear();

            onEnable = () =>
            {
                //using (new DebugTimer("Building Scene Object Description"))
                {
                    var objects     = new GameObject[0];
                    var prefabStage = PrefabStageUtility.GetCurrentPrefabStage();
                    if (prefabStage != null)
                    {
                        objects = SceneModeUtility.GetObjects(new[] { prefabStage.prefabContentsRoot }, true);
                    }
                    else
                    {
                        var goRoots = new List <UnityEngine.Object>();
                        for (int i = 0; i < UnityEngine.SceneManagement.SceneManager.sceneCount; ++i)
                        {
                            goRoots.AddRange(UnityEngine.SceneManagement.SceneManager.GetSceneAt(i).GetRootGameObjects());
                        }
                        objects = SceneModeUtility.GetObjects(goRoots.ToArray(), true);
                    }

                    //using (new DebugTimer($"Fetching {gods.Length} Scene Objects Components"))
                    {
                        gods = new GOD[objects.Length];
                        for (int i = 0; i < objects.Length; ++i)
                        {
                            gods[i].gameObject = objects[i];
                            var id = gods[i].gameObject.GetInstanceID();
                            if (!componentsById.TryGetValue(id, out gods[i].name))
                            {
                                if (gods.Length > k_LODDetail2)
                                {
                                    gods[i].name = CleanString(gods[i].gameObject.name);
                                }
                                else if (gods.Length > k_LODDetail1)
                                {
                                    gods[i].name = CleanString(GetTransformPath(gods[i].gameObject.transform));
                                }
                                else
                                {
                                    gods[i].name = BuildComponents(gods[i].gameObject);
                                }
                                componentsById[id] = gods[i].name;
                            }
                        }

                        indexer = new SceneSearchIndexer(SceneManager.GetActiveScene().name, gods);
                        indexer.Build();
                    }
                }
            };

            onDisable = () =>
            {
                indexer = null;
                gods    = new GOD[0];
            };

            fetchItems = (context, items, provider) =>
            {
                if (gods == null)
                {
                    return;
                }

                if (indexer != null && indexer.IsReady())
                {
                    var results = indexer.Search(context.searchQuery).Take(201);
                    items.AddRange(results.Select(r =>
                    {
                        if (r.index < 0 || r.index >= gods.Length)
                        {
                            return(provider.CreateItem("invalid"));
                        }

                        var gameObjectId   = gods[r.index].gameObject.GetInstanceID().ToString();
                        var gameObjectName = gods[r.index].gameObject.name;
                        var itemScore      = r.score - 1000;
                        if (gameObjectName.Equals(context.searchQuery, StringComparison.InvariantCultureIgnoreCase))
                        {
                            itemScore *= 2;
                        }
                        var item = provider.CreateItem(gameObjectId, itemScore, null, null, null, r.index);
                        item.descriptionFormat = SearchItemDescriptionFormat.Ellipsis |
                                                 SearchItemDescriptionFormat.RightToLeft |
                                                 SearchItemDescriptionFormat.Highlight;
                        return(item);
                    }));
                }

                SearchGODs(context, provider, items);
            };

            fetchLabel = (item, context) =>
            {
                if (item.label != null)
                {
                    return(item.label);
                }

                var go = ObjectFromItem(item);
                if (!go)
                {
                    return(item.id);
                }

                var transformPath = GetTransformPath(go.transform);
                var components    = go.GetComponents <Component>();
                if (components.Length > 2 && components[1] && components[components.Length - 1])
                {
                    item.label = $"{transformPath} ({components[1].GetType().Name}..{components[components.Length-1].GetType().Name})";
                }
                else if (components.Length > 1 && components[1])
                {
                    item.label = $"{transformPath} ({components[1].GetType().Name})";
                }
                else
                {
                    item.label = $"{transformPath} ({item.id})";
                }

                long       score   = 1;
                List <int> matches = new List <int>();
                var        sq      = CleanString(context.searchQuery);
                if (FuzzySearch.FuzzyMatch(sq, CleanString(item.label), ref score, matches))
                {
                    item.label = RichTextFormatter.FormatSuggestionTitle(item.label, matches);
                }

                return(item.label);
            };

            fetchDescription = (item, context) =>
            {
                #if QUICKSEARCH_DEBUG
                item.description = gods[(int)item.data].name + " * " + item.score;
                #else
                var go = ObjectFromItem(item);
                item.description = GetHierarchyPath(go);
                #endif
                return(item.description);
            };

            fetchThumbnail = (item, context) =>
            {
                if (item.thumbnail)
                {
                    return(item.thumbnail);
                }

                var obj = ObjectFromItem(item);
                if (obj != null)
                {
                    if (SearchSettings.fetchPreview)
                    {
                        var assetPath = GetHierarchyAssetPath(obj, true);
                        if (!String.IsNullOrEmpty(assetPath))
                        {
                            item.thumbnail = AssetPreview.GetAssetPreview(obj);
                            if (item.thumbnail)
                            {
                                return(item.thumbnail);
                            }
                            item.thumbnail = Utils.GetAssetThumbnailFromPath(assetPath, true);
                            if (item.thumbnail)
                            {
                                return(item.thumbnail);
                            }
                        }
                    }

                    item.thumbnail = PrefabUtility.GetIconForGameObject(obj);
                    if (item.thumbnail)
                    {
                        return(item.thumbnail);
                    }
                    item.thumbnail = EditorGUIUtility.ObjectContent(obj, obj.GetType()).image as Texture2D;
                }

                return(item.thumbnail);
            };

            startDrag = (item, context) =>
            {
                var obj = ObjectFromItem(item);
                if (obj != null)
                {
                    DragAndDrop.PrepareStartDrag();
                    DragAndDrop.objectReferences = new[] { obj };
                    DragAndDrop.StartDrag("Drag scene object");
                }
            };

            trackSelection = (item, context) => PingItem(item);
        }