Esempio n. 1
0
        public void OnGUI(Rect pos)
        {
            m_Position = pos;

            EditorGUILayout.Space();
            EditorGUILayout.BeginHorizontal();
            EditorGUI.BeginChangeCheck();
            m_SelectedConfigIndex = EditorGUILayout.Popup("Configuration", m_SelectedConfigIndex, m_ConfigNames);
            if (GUILayout.Button("Create New", GUILayout.MaxWidth(100f)))
            {
                string binPath = Application.streamingAssetsPath + "/Data/GeneralConfig.asset";
                binPath = EditorUtility.SaveFilePanel("Create new Config", binPath, "newConfig",
                                                      "asset");
                if (!string.IsNullOrEmpty(binPath))
                {
                    ConfigData.CreateConfigData(binPath);
                    GetAllConfigurations();
                    SetConfingSelected(System.IO.Path.GetFileNameWithoutExtension(binPath));
                    GUI.changed = true;
                }
            }
            if (EditorGUI.EndChangeCheck())
            {
                m_SelectedConfig = m_SelectedConfigIndex == 0 ? null :
                                   AssetDatabase.LoadAssetAtPath <ConfigData>(AssetDatabase.GUIDToAssetPath(m_ConfigGuids[m_SelectedConfigIndex - 1]));
            }
            EditorGUILayout.EndHorizontal();

            if (m_SelectedConfig != null)
            {
                RefreshData();
                EditorGUILayout.Space();
                EditorGUI.BeginChangeCheck();

                SerializedObject serializedObject = new SerializedObject(m_SelectedConfig);
                serializedObject.Update();
                SerializedProperty version = serializedObject.FindProperty("m_ConfigVersion");
                version.stringValue = EditorGUILayout.TextField("Version ", version.stringValue);

                m_resizablePanel.OnGUI(m_Position);

                float panelTop     = m_Position.y + k_TopHeight;
                float panelBottom  = (m_Position.height - k_TopHeightWithMargin) - (k_ButtonHeight + k_TopMargin);
                float buttonBottom = panelTop + panelBottom + k_TopMargin;

                var bundleTreeRect = new Rect(
                    m_Position.x,
                    panelTop,
                    m_resizablePanel.LeftPanelWidth(),
                    panelBottom);

                float panelLeft  = m_Position.x + m_resizablePanel.LeftPanelWidth();
                float panelWidth = m_resizablePanel.RightPanelWidth();

                m_ConfigTreeView.OnGUI(bundleTreeRect);
                m_ConfigInspector.OnGUI(new Rect(
                                            panelLeft,
                                            panelTop,
                                            panelWidth,
                                            panelBottom));

                m_resizablePanel.Repaint();

                var buttonTreeRect = new Rect(
                    m_Position.x + 15f,
                    buttonBottom,
                    m_Position.width - 15f * 2f,
                    20f);


                if (EditorGUI.EndChangeCheck())
                {
                    string guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(m_SelectedConfig));
                    if (serializedObject.targetObject != m_SelectedConfig)
                    {
                        Debug.Log("--------><color=green>Changed=" + guid + "</color>");
                        ConfigWarning.AddChangedGuid(guid);
                    }
                    else
                    {
                        ConfigWarning.RemoveChangedGuid(guid);
                    }
                }
                serializedObject.ApplyModifiedProperties();
                if (GUI.Button(buttonTreeRect, "Save binary"))
                {
                    string binPath = Application.streamingAssetsPath + "/Data/GeneralConfig.asset";
                    binPath = EditorUtility.SaveFilePanel("Save Binary Config", binPath, m_SelectedConfig.name,
                                                          "asset");
                    if (!string.IsNullOrEmpty(binPath))
                    {
                        // SerializationUtil.SerializeObjectToFile(m_SelectedConfig, binPath,
                        //     m_SelectedConfig.CreateSurrogateSelector<ConfigData>());
                        EditorUtility.DisplayDialog("Saved", "Config saved in " + binPath, "Accept");
                        AssetDatabase.Refresh();

                        string guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(m_SelectedConfig));
                        ConfigWarning.RemoveChangedGuid(guid);
                    }
                }
                EditorGUILayout.Space();
            }
        }