Exemple #1
0
        public void Open(Device _name, string _path)
        {
            CloseAll = false;
            index++;
            Rect wr = new Rect(0, 0, 300, 300);
            DevicesSettingWindow frameworkConfigEditorWindow = (DevicesSettingWindow)EditorWindow.GetWindowWithRect(typeof(DevicesSettingWindow), wr, false, "Add DeviceStting");

            frameworkConfigEditorWindow.mDeviceName       = _name;
            frameworkConfigEditorWindow._serializedObject = new SerializedObject(frameworkConfigEditorWindow);
            frameworkConfigEditorWindow._assetLstProperty = frameworkConfigEditorWindow._serializedObject.FindProperty("m_CurrentDeviceSetting");
            frameworkConfigEditorWindow.path = _path;
            frameworkConfigEditorWindow.Show();
        }
Exemple #2
0
        //void OnHierarchyChange()
        //{
        //    this.Close();
        //    this.Show();
        //}

        //void OnProjectChange()
        //{
        //    this.Close();
        //    this.Show();
        //}

        void OnGUI()
        {
            EditorGUILayout.BeginVertical();
            GUI.skin.label.fontSize = 12;

            GUILayout.Space(10);
            GUILayout.Space(10);
            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.EndHorizontal();
            //Debug.Log(Application.dataPath);

            ScrollPos = EditorGUILayout.BeginScrollView(ScrollPos, true, false, GUILayout.Width(800), GUILayout.Height(900));

            if (Path == null || Path.Equals(string.Empty))
            {
                UnityEngine.Object tempObj = Selection.activeObject;
                Path = AssetDatabase.GetAssetPath(tempObj);
                if (!Path.Contains("devices"))
                {
                    return;
                }
                StreamReader m_reader = new StreamReader(Path);
                m_Devices = m_reader.ReadToEnd();

                m_CurrentWindows = this;
                EditorFileText   = "pvt_";
                m_CurrentDevices = new Device();
                isOpen           = false;
            }
            if (m_Devices != null && !m_Devices.Equals(string.Empty))
            {
                if (_serializedObject == null)
                {
                    StreamReader m_reader = new StreamReader(Path);
                    m_Devices     = m_reader.ReadToEnd();
                    m_DevicesData = JsonUtility.FromJson <Devices>(m_Devices);

                    List <Device> m_DeviceList = m_DevicesData.Platforms.Find(item => item.Platform.Equals("Android")).Devices;
                    string        temp         = Path;
                    temp = temp.Replace("Assets/", "/");
                    string latPath = Application.dataPath + temp;
                    latPath = latPath.Replace("devices.json", "");

                    DirectoryInfo dir = new DirectoryInfo(latPath);

                    FileInfo[]    allInfo       = dir.GetFiles();
                    List <string> m_HasFileList = new List <string>();

                    for (int i = 0; i < allInfo.Length; i++)
                    {
                        m_HasFileList.Add(allInfo[i].Name);
                    }
                    int index = 0;
                    if (!isOpen)
                    {
                        isOpen = true;
                        for (int i = 0; i < m_DeviceList.Count; i++)
                        {
                            if (!m_HasFileList.Contains(m_DeviceList[i].SettingsFile))
                            {
                                DevicesSettingWindow tempWindows = new DevicesSettingWindow();
                                tempWindows.Open(m_DeviceList[i], latPath);
                                tempWindows.position = new Rect(++index * position.x, position.yMax / 2, 300, 300);
                            }
                        }
                    }

                    _serializedObject = new SerializedObject(this);
                    _assetLstProperty = _serializedObject.FindProperty("m_DevicesData");
                }

                if (_assetLstProperty != null && _serializedObject != null)
                {
                    EditorGUILayout.PropertyField(_assetLstProperty, true);
                }

                //Debug.Log(Path);
            }
            EditorGUILayout.EndScrollView();

            #region 保存

            if (GUILayout.Button("Apply"))
            {
                string temp = Path;
                temp = temp.Replace("Assets/", "/");
                _serializedObject.ApplyModifiedProperties();
                EditorUtility.SetDirty(this);
                int[] list = new int[m_DevicesData.Platforms.Count];

                for (int i = 0; i < m_DevicesData.Platforms.Count; i++)
                {
                    list[i] = m_DevicesData.Platforms[i].Devices.Count;
                }
                Devices tempDevices = JsonUtility.FromJson <Devices>(m_Devices);
                int[]   list2       = new int[tempDevices.Platforms.Count];
                for (int i = 0; i < tempDevices.Platforms.Count; i++)
                {
                    list2[i] = tempDevices.Platforms[i].Devices.Count;
                }

                for (int i = 0; i < list.Length; i++)
                {
                    if (list[i] <= list2[i])
                    {
                        continue;
                    }

                    int NewInt = list[i] - list2[i];
                    for (int j = list2[i]; j < list[i]; j++)
                    {
                        string latPath = Application.dataPath + temp;
                        latPath = latPath.Replace("devices.json", "");
                        DevicesSettingWindow tempWindows = new DevicesSettingWindow();
                        tempWindows.Open(m_DevicesData.Platforms[i].Devices[j], latPath);
                        tempWindows.position = new Rect(j - list2[i] + 0.3f * position.x, position.yMax / 2, 300, 300);
                    }
                }

                File.WriteAllText(Application.dataPath + temp, JsonUtility.ToJson(m_DevicesData, true));
                AssetDatabase.Refresh();
                AssetDatabase.SaveAssets();
            }
            #endregion

            #region 添加
            if (GUILayout.Button("Add"))
            {
                string temp = Path;
                temp = temp.Replace("Assets/", "/");
                string latPath = Application.dataPath + temp;
                latPath = latPath.Replace("devices.json", "");
                AddDeviceWindows.Open(latPath);
            }
            #endregion

            #region 重置
            if (GUILayout.Button("Reset"))
            {
                _serializedObject = null;
                isOpen            = false;
            }
            #endregion

            EditorGUILayout.EndVertical();
        }