Пример #1
0
        GameObjectDataInScene SaveGameObjectDataInScene(Transform tran, string scenePath)
        {
            GameObjectDataInScene data = new GameObjectDataInScene();

            data.scenePath = scenePath;
            List <int> siblingList = new List <int>();

            while (tran != null)
            {
                siblingList.Add(tran.GetSiblingIndex());
                tran = tran.parent;
            }
            siblingList.Reverse();
            data.locationInScece = siblingList.ToArray();
            return(data);
        }
Пример #2
0
        GameObject FindGameObjectByDataInScene(GameObjectDataInScene data)
        {
            var allObjects = FindObjectsOfType <Transform>();

            foreach (var obj in allObjects)
            {
                if (obj.parent == null && obj.GetSiblingIndex() == data.locationInScece[0])
                {
                    Transform tran = obj;
                    for (int i = 1; i < data.locationInScece.Length; i++)
                    {
                        tran = GetChildBySiblingIndex(tran, data.locationInScece[i]);
                    }
                    return(tran.gameObject);
                }
            }
            return(null);
        }