GetTransforms() private method

private GetTransforms ( SelectionMode mode ) : UnityEngine.Transform[]
mode SelectionMode
return UnityEngine.Transform[]
Ejemplo n.º 1
0
        private void UpdateSelection()
        {
            var selection = Selection.GetTransforms(SelectionMode.Unfiltered);

            m_TemporarySelection.Clear();

            // Adds rendered transforms that are not part of the m_LockedObjects set
            foreach (var tr in m_TransformsToRender)
            {
                if (!m_LockedObjects.ContainsKey(tr.Transform))
                {
                    m_TemporarySelection.Add(tr.Transform);
                }
            }

            var addedTransforms   = selection.Except(m_TemporarySelection);
            var removedTransforms = m_TemporarySelection.Except(selection);

            foreach (var tr in addedTransforms)
            {
                var newItem = new RenderedTransform(tr);

                if (!m_TransformsToRender.Contains(newItem) && newItem.HasBody)
                {
                    m_TransformsToRender.Add(newItem);
                }
            }

            foreach (var tr in removedTransforms)
            {
                if (!m_LockedObjects.ContainsKey(tr))
                {
                    m_TransformsToRender.Remove(tr);
                }
            }

            Repaint();
        }
Ejemplo n.º 2
0
        static void ExportSelectionToSeparate()
        {
            if (!CreateTargetFolder())
            {
                return;
            }

            Transform[] selection = Selection.GetTransforms(SelectionMode.Editable | SelectionMode.ExcludePrefab);

            if (selection.Length == 0)
            {
                EditorUtility.DisplayDialog("No source object selected!", "Please select one or more target objects", "");
                return;
            }

            int exportedObjects = 0;

            for (int i = 0; i < selection.Length; i++)
            {
                Component[] meshfilter = selection[i].GetComponentsInChildren(typeof(MeshFilter));

                for (int m = 0; m < meshfilter.Length; m++)
                {
                    exportedObjects++;
                    MeshToFile((MeshFilter)meshfilter[m], targetFolder, selection[i].name + "_" + i + "_" + m);
                }
            }

            if (exportedObjects > 0)
            {
                EditorUtility.DisplayDialog("Objects exported", "Exported " + exportedObjects + " objects", "");
            }
            else
            {
                EditorUtility.DisplayDialog("Objects not exported", "Make sure at least some of your selected objects have mesh filters!", "");
            }
        }
Ejemplo n.º 3
0
        private static IEnumerable GetFilteredInternal(Type type, SelectionMode mode)
        {
            IEnumerable result;

            if (typeof(Component).IsAssignableFrom(type) || type.IsInterface)
            {
                result = from t in Selection.GetTransforms(mode)
                         select t.GetComponent(type) into c
                             where c != null
                         select c;
            }
            else if (typeof(GameObject).IsAssignableFrom(type))
            {
                result = from t in Selection.GetTransforms(mode)
                         select t.gameObject;
            }
            else
            {
                result = from o in Selection.GetObjectsMode(mode)
                         where o != null && type.IsAssignableFrom(o.GetType())
                         select o;
            }
            return(result);
        }
Ejemplo n.º 4
0
        // Iterates over selected objects, finds nearest vertex or pivot and sets Tools.handleOffset accordingly
        private static void UpdateVertexSnappingOffset()
        {
            Event evt = Event.current;

            Tools.vertexDragging = true;
            Vector3 nearestVertex;

            Transform[] selection = Selection.GetTransforms(SelectionMode.Deep | SelectionMode.ExcludePrefab | SelectionMode.Editable);

            // Make sure we're not ignoring any objects, that other handles may have set to ignore and forgot to reset.
            HandleUtility.ignoreRaySnapObjects = null;

            Vector3 nearestPivot = FindNearestPivot(selection, evt.mousePosition);
            bool    foundVertex  = HandleUtility.FindNearestVertex(evt.mousePosition, selection, out nearestVertex);

            Vector3 near;

            // Is nearest vertex closer than nearest pivot?
            float distanceToNearestVertex = (HandleUtility.WorldToGUIPoint(nearestVertex) - evt.mousePosition).magnitude;
            float distanceToNearestPivot  = (HandleUtility.WorldToGUIPoint(nearestPivot) - evt.mousePosition).magnitude;

            if (foundVertex && (distanceToNearestVertex < distanceToNearestPivot))
            {
                near = nearestVertex;
            }
            else
            {
                near = nearestPivot;
            }

            // Important to reset handleOffset before querying handlePosition,
            // since handlePosition depends on handleOffset.
            Tools.InvalidateHandlePosition();
            Tools.handleOffset = Vector3.zero;
            Tools.handleOffset = near - Tools.handlePosition;
        }
Ejemplo n.º 5
0
        static void ExportWholeSelectionToSingle()
        {
            if (!CreateTargetFolder())
            {
                return;
            }


            Transform[] selection = Selection.GetTransforms(SelectionMode.Editable | SelectionMode.ExcludePrefab);

            if (selection.Length == 0)
            {
                EditorUtility.DisplayDialog("No source object selected!", "Please select one or more target objects", "");
                return;
            }

            int exportedObjects = 0;

            ArrayList mfList = new ArrayList();

            for (int i = 0; i < selection.Length; i++)
            {
                Component[] meshfilter = selection[i].GetComponentsInChildren(typeof(MeshFilter));

                for (int m = 0; m < meshfilter.Length; m++)
                {
                    exportedObjects++;
                    mfList.Add(meshfilter[m]);
                }
            }

            if (exportedObjects > 0)
            {
                MeshFilter[] mf = new MeshFilter[mfList.Count];

                for (int i = 0; i < mfList.Count; i++)
                {
                    mf[i] = (MeshFilter)mfList[i];
                }

                EditorObjExporter window = new EditorObjExporter(SceneManager.GetActiveScene().name + "_" + exportedObjects);


                window.onFileNameSelected += () =>
                {
                    string filename = window.fileName;

                    int stripIndex = filename.LastIndexOf("/");

                    if (stripIndex >= 0)
                    {
                        filename = filename.Substring(stripIndex + 1).Trim();
                    }

                    MeshesToFile(mf, targetFolder, filename);


                    EditorUtility.DisplayDialog("Objects exported", "Exported " + exportedObjects + " objects to " + filename, "");
                };

                window.ShowUtility();
            }
            else
            {
                EditorUtility.DisplayDialog("Objects not exported", "Make sure at least some of your selected objects have mesh filters!", "");
            }
        }
Ejemplo n.º 6
0
 private bool IsSelected(Transform tr)
 {
     return(Selection.GetTransforms(SelectionMode.Unfiltered).Contains(tr));
 }
Ejemplo n.º 7
0
        private void DrawTiaoZhen()                              // 调整UI
        {
            Transform[] curSelect = Selection.GetTransforms(SelectionMode.TopLevel);
            int         length    = curSelect.Length;

            #region  择一个 GameObject 控制其上下位置

            MyCreate.Box(() =>
            {
                MyCreate.Text("功能:".AddYellow() + " 选择一个 GameObject 控制其上下位置".AddGreen());
                m_Tools.Text_H("  点击 1 个");
                GUI.enabled = length == 1;
                FourButton("  上一格 ↑", "  下一格 ↓", "  最里层 ↑↑↑", "  最外层 ↓↓↓", () =>
                {
                    //上一格
                    int curIndex = curSelect[0].GetSiblingIndex();
                    if (curIndex > 0)
                    {
                        curSelect[0].SetSiblingIndex(curIndex - 1);
                    }
                }, () =>
                {
                    // 下一格
                    int curIndex  = curSelect[0].GetSiblingIndex();
                    int child_num = curSelect[0].parent.childCount;
                    if (curIndex < child_num - 1)
                    {
                        curSelect[0].SetSiblingIndex(curIndex + 1);
                    }
                }, () =>
                {
                    //最里层
                    curSelect[0].SetAsFirstSibling();
                }, () =>
                {
                    //最外层
                    curSelect[0].SetAsLastSibling();
                });
                GUI.enabled = true;
            });

            #endregion

            #region 水平/垂直 均匀排布

            MyCreate.Box(() =>
            {
                MyCreate.Text("功能:".AddYellow() + " 水平/垂直 均匀排布".AddGreen());
                m_Tools.Text_H("  需要点击 3 个或以上");
                GUI.enabled = length > 2;
                ThreeButton("    水平均匀  |||", "    垂直均匀  ☰", "    水平 + 垂直", () =>
                {
                    // 水平均匀 |||
                    ShuiPin(length);
                }, () =>
                {
                    // 垂直均匀  ☰
                    ShuZhi(length);
                }, () =>
                {
                    // 水平 + 垂直
                    ShuiPin(length);
                    ShuZhi(length);
                });
                GUI.enabled = true;
            });

            #endregion

            #region 设置一样大小

            MyCreate.Box(() =>
            {
                GUI.enabled = length > 1;
                MyCreate.Text("功能:".AddYellow() + " 设置一样大小".AddGreen());
                m_Tools.Text_H("  需要点击 2 个或以上,一样大按最大的来算");
                GUI.enabled = length > 1;
                m_Tools.TwoButton("一样大 ■", "一样小 ▪", () =>
                {
                    float height = Mathf.Max(Selection.gameObjects.Select(obj => ((RectTransform)obj.transform).sizeDelta.y).ToArray());
                    float width  = Mathf.Max(Selection.gameObjects.Select(obj => ((RectTransform)obj.transform).sizeDelta.x).ToArray());
                    foreach (GameObject gameObject in Selection.gameObjects)
                    {
                        ((RectTransform)gameObject.transform).sizeDelta = new Vector2(width, height);
                    }
                }, () =>
                {
                    float height = Mathf.Min(Selection.gameObjects.Select(obj => ((RectTransform)obj.transform).sizeDelta.y).ToArray());
                    float width  = Mathf.Min(Selection.gameObjects.Select(obj => ((RectTransform)obj.transform).sizeDelta.x).ToArray());
                    foreach (GameObject gameObject in Selection.gameObjects)
                    {
                        ((RectTransform)gameObject.transform).sizeDelta = new Vector2(width, height);
                    }
                });
                GUI.enabled = true;
            });


            #endregion

            #region 设置一样字体大小

            MyCreate.Box(() =>
            {
                MyCreate.Text("功能:".AddYellow() + " 设置一样字体大小".AddGreen());
                m_Tools.Text_H("  需要点击 2 个或以上的 Text");

                Text[] texts = Selection.GetFiltered <Text>(SelectionMode.TopLevel);
                GUI.enabled  = texts.Length > 1;
                m_Tools.TwoButton("一样大字号", "一样小字号", () =>
                {
                    int maxSiz = 0;
                    foreach (Text text in texts)
                    {
                        if (text.fontSize < maxSiz)
                        {
                            text.fontSize = maxSiz;
                        }
                        else
                        {
                            maxSiz = text.fontSize;
                        }
                    }
                }, () =>
                {
                    int minSiz = 100;
                    foreach (Text text in texts)
                    {
                        if (text.fontSize > minSiz)
                        {
                            text.fontSize = minSiz;
                        }
                        else
                        {
                            minSiz = text.fontSize;
                        }
                    }
                });
                GUI.enabled = true;
            });
            #endregion
        }