public static void SetHierarchyFromString(string list, bool logMissingNodes)
        {
            string[] paths = null;
            {
                // Convert the string list to an array
                if (!string.IsNullOrEmpty(list))
                {
                    paths = list.Split(new char[] { '*' }, System.StringSplitOptions.RemoveEmptyEntries);
                }
            }

            // Convert the paths array into an array of objects
            GameObject[] gos = null;
            if (paths != null && paths.Length > 0)
            {
                List <GameObject> goList = new List <GameObject>();
                foreach (string path in paths)
                {
                    // TODO: GameObject.Find doesn't find disabled objects, so we need to handle this
                    GameObject go = GameObject.Find(path);
                    if (go != null)
                    {
                        goList.Add(go);
                    }
                    else if (logMissingNodes)
                    {
                        Debug.LogWarning("[HierarchyRestore] Can't find node with path: '" + path + "'");
                    }
                }
                gos = goList.ToArray();
            }

            if (gos != null && gos.Length > 0)
            {
                HierarchyUtils.SetHierarchyWindowExpandedObjects(gos);
            }
            else
            {
                HierarchyUtils.SetHierarchyWindowExpandedObjects(new GameObject[0]);
            }
        }
Exemplo n.º 2
0
        public static void SetHierarchyFromString(string list, bool logMissingNodes)
        {
            string[] paths = null;
            {
                // Convert the string list to an array
                if (!string.IsNullOrEmpty(list))
                {
                    paths = list.Split(new char[] { '*' }, System.StringSplitOptions.RemoveEmptyEntries);
                }
            }

            // Convert the paths array into an array of objects
            GameObject[] gos          = null;
            int[]        sceneHandles = null;
            if (paths != null && paths.Length > 0)
            {
                List <GameObject> goList    = new List <GameObject>();
                List <int>        sceneList = null;
                foreach (string path in paths)
                {
                    bool isFound = false;
                    if (path.StartsWith("/"))
                    {
                        // TODO: GameObject.Find doesn't find disabled objects, so we need to handle this
                        GameObject go = GameObject.Find(path);
                        if (go != null)
                        {
                            goList.Add(go);
                            isFound = true;
                        }
                    }
#if RH_UNITY_FEATURE_SCENE_HANDLE
                    else
                    {
                        Scene scene = SceneManager.GetSceneByPath(path);
                        if (scene.IsValid())
                        {
                            if (sceneList == null)
                            {
                                sceneList = new List <int>();
                            }
                            sceneList.Add(scene.handle);
                            isFound = true;
                        }
                    }
#endif
                    if (!isFound && logMissingNodes)
                    {
                        Debug.LogWarning("[HierarchyRestore] Can't find node with path: '" + path + "'");
                    }
                }
                gos = goList.ToArray();
                if (sceneList != null)
                {
                    sceneHandles = sceneList.ToArray();
                }
            }

            if ((gos != null && gos.Length > 0) ||
                (sceneHandles != null && sceneHandles.Length > 0))
            {
                HierarchyUtils.SetHierarchyWindowExpandedObjects(gos, sceneHandles);
            }
            else
            {
                HierarchyUtils.SetHierarchyWindowExpandedObjects(new GameObject[0], sceneHandles);
            }
        }