예제 #1
0
        public void OnGUI(Rect pos)
        {
            m_Position = pos;
            EditorGUILayout.Space();
            GUILayout.BeginHorizontal();

            if (GUILayout.Button("Add Generic Property", GUILayout.MaxWidth(150f)))
            {
                CreateProperty(false);
            }
            if (GUILayout.Button("Add Specific Property", GUILayout.MaxWidth(150f)))
            {
                CreateProperty(true);
            }
            GUILayout.EndHorizontal();
            EditorGUILayout.Space();

            if (m_Properties.Count > 0)
            {
                m_resizablePanel.OnGUI(m_Position);

                float halfWidth = m_resizablePanel.LeftPanelWidth();
                m_PropertyTreeView.OnGUI(new Rect(m_Position.x, m_Position.y + 30, halfWidth, m_Position.height - 30));
                m_PropertyInspector.OnGUI(new Rect(m_Position.x + halfWidth, m_Position.y + 30,
                                                   m_resizablePanel.RightPanelWidth(), m_Position.height - 30));

                m_resizablePanel.Repaint();
            }
        }
예제 #2
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();
            }
        }