Beispiel #1
0
        public static void Create(Type dataType, DataListWindow.DataListCallback callback)
        {
            DataCreationWindow window = GetWindow <DataCreationWindow>();

            if (dataType.IsSubclassOf(typeof(BaseData)))
            {
                window._data = Activator.CreateInstance(dataType) as BaseData;
                int  id;
                bool uniqueId = true;
                do
                {
                    id = UnityEngine.Random.Range(1, int.MaxValue);
                    if (DataEditorCache.Instance.Data.Any(info => info.Id == id))
                    {
                        uniqueId = false;
                    }
                } while (!uniqueId);

                if (window._data != null)
                {
                    window._data.Id   = id;
                    window._data.Name = DefaultDataName;
                }
                window._dataPath = "Data" + Path.DirectorySeparatorChar + dataType.Name + Path.DirectorySeparatorChar +
                                   DefaultDataName;
                window._callback = callback;
            }
            window.Show();
        }
Beispiel #2
0
        protected void DrawSubTypes(Type baseType, ref int i)
        {
            foreach (Type t in DataUtils.GetDataTypes())
            {
                if (t.BaseType != baseType)
                {
                    continue;
                }

                GUILayout.BeginHorizontal();
                string typeName = t.ToString();

                IOrderedEnumerable <DataEditorCache.DataInfo> dataInstances = (from info in DataEditorCache.Instance.Data
                                                                               where (info.Type == typeName) && info.Name.Contains(_searchString)
                                                                               select info).OrderBy(info => info.Name);

                Color textColor = Color.black;
                if (!dataInstances.Any())
                {
                    textColor = Color.gray;
                }
                GUIStyle style = EditorStyles.foldout;
                style.normal.textColor = textColor;
                Expanded[i]            = EditorGUILayout.Foldout(Expanded[i], t.Name, style);
                if (GUILayout.Button("Create"))
                {
                    DataCreationWindow.Create(t, Callback);
                }
                GUI.color = Color.white;
                GUILayout.EndHorizontal();

                if (!Expanded[i++])
                {
                    continue;
                }

                EditorGUI.indentLevel++;

                DrawSubTypes(t, ref i);

                foreach (DataEditorCache.DataInfo dataInfo in dataInstances)
                {
                    if (GUILayout.Button(dataInfo.Name))
                    {
                        Callback(Serializer.Deserialize(t, Application.dataPath + dataInfo.FilePath) as BaseData,
                                 dataInfo.FilePath);
                    }
                }

                EditorGUI.indentLevel--;
            }
        }