Exemplo n.º 1
0
    protected void GUIViewByMultiSelect()
    {
        List <TextAsset> _TextAssets = new List <TextAsset>();

        if (Selection.objects != null && Selection.objects.Length > 0)
        {
            Object[] _Objects = EditorUtility.CollectDependencies(Selection.objects);

            foreach (Object _Obj in _Objects)
            {
                if (_Obj is TextAsset == false)
                {
                    continue;
                }

                TextAsset _Text = _Obj as TextAsset;
                if (_Text == null)
                {
                    continue;
                }

                _TextAssets.Add(_Text);
            }
        }

        Color _OrgColor = GUI.contentColor;

        GUI.contentColor = Color.green;
        EditorGUILayout.LabelField("檔案清單");
        GUI.contentColor = _OrgColor;

        EditorTool.BeginContents();
        int _Count = 0;

        foreach (TextAsset _Text in _TextAssets)
        {
            _Count++;
            EditorGUILayout.LabelField(_Count.ToString() + "    " + _Text.name);
        }
        EditorTool.EndContents();
        EditorGUILayout.Separator();

        if (_TextAssets.Count == 0)
        {
            EditorTool.CenterButton("Create Scriptable Object", Color.gray);
        }
        else
        {
            if (EditorTool.CenterButton("Create Scriptable Object", Color.green))
            {
                ShowNotification(new GUIContent("Making string table..."));

                foreach (TextAsset _Text in _TextAssets)
                {
                    m_SourcePath    = AssetDatabase.GetAssetPath(_Text.GetInstanceID());
                    m_SourceContent = _Text.text;

                    string _Path = FileTool.GetFolderPath(m_SourcePath);

                    string           _SOPath = _Path + _Text.name + ".asset";
                    ScriptableObject _SO     = ScriptableObject.CreateInstance(_Text.name + "SO");
                    if (_SO != null)
                    {
                        Object _Temp = AssetDatabase.LoadAssetAtPath(_SOPath, _SO.GetType());

                        if (_Temp == null)
                        {
                            System.Reflection.MethodInfo _M = _SO.GetType().GetMethod("DataFromXML");
                            _M.Invoke(_SO, new object[] { m_SourceContent });
                            AssetDatabase.CreateAsset(_SO, _SOPath);
                            AssetDatabase.Refresh();
                        }
                        else
                        {
                            _SO = _Temp as ScriptableObject;
                            System.Reflection.MethodInfo _M = _SO.GetType().GetMethod("DataFromXML");
                            _M.Invoke(_SO, new object[] { m_SourceContent });
                            AssetDatabase.Refresh();
                        }
                    }
                }
            }
        }
    }
Exemplo n.º 2
0
    private void OnGUI()
    {
        Transform _SelectObject = null;

        if (Selection.gameObjects != null && Selection.gameObjects.Length > 0)
        {
            foreach (GameObject _Obj in Selection.gameObjects)
            {
                Transform _Transform = _Obj.transform;
                if (_Transform == null)
                {
                    continue;
                }

                _SelectObject = _Transform;
                break;
            }
        }

        Color _OriginalColor = GUI.contentColor;

        GUI.contentColor = Color.green;
        EditorGUILayout.LabelField("要修改的根結點");
        GUI.contentColor = _OriginalColor;

        EditorTool.BeginContents();
        if (_SelectObject == null)
        {
            EditorGUILayout.LabelField("沒選擇物件");
        }
        else
        {
            EditorGUILayout.LabelField(_SelectObject.name);
        }
        EditorTool.EndContents();
        EditorGUILayout.Separator();

        _OriginalColor   = GUI.contentColor;
        GUI.contentColor = Color.red;
        EditorGUILayout.LabelField("要變更的關鍵字");
        GUI.contentColor = _OriginalColor;

        EditorTool.BeginContents();
        m_BeChangeWord = EditorGUILayout.TextField(m_BeChangeWord);
        EditorTool.EndContents();
        EditorGUILayout.Separator();

        _OriginalColor   = GUI.contentColor;
        GUI.contentColor = Color.yellow;
        EditorGUILayout.LabelField("變更為....");
        GUI.contentColor = _OriginalColor;

        EditorTool.BeginContents();
        m_WantChangeWord = EditorGUILayout.TextField(m_WantChangeWord);
        EditorTool.EndContents();
        EditorGUILayout.Separator();

        if (_SelectObject == null)
        {
            CenterButton("開始轉換", Color.gray);
        }
        else
        {
            if (CenterButton("開始轉換", Color.green))
            {
                RecursiveChangeName(_SelectObject, m_BeChangeWord, m_WantChangeWord);
            }
        }
    }