Example #1
0
        /// <summary>
        /// When the window is loaded, initialize the TreeView.
        /// </summary>
        private void OnEnable()
        {
            var state = SingletonScriptableObject <DataListWindowState> .Instance;

            if (!string.IsNullOrEmpty(state.ActiveDataSetGuid))
            {
                var path = AssetDatabase.GUIDToAssetPath(state.ActiveDataSetGuid);

                // The asset was probably deleted, so stop holding onto its GUID.
                if (!string.IsNullOrEmpty(path))
                {
                    var dataSet = AssetDatabase.LoadAssetAtPath <EntityFileAsset>(path);
                    if (dataSet == null)
                    {
                        state.ActiveDataSetGuid = null;
                    }
                    else
                    {
                        this.activeDataSet = dataSet.GetDataSet();
                    }
                }
                else
                {
                    this.activeDataSet = null;
                }
            }

            IsOpen = true;

            if (this.treeViewState == null)
            {
                this.treeViewState = new TreeViewState();
            }

            if (this.openDataSetGuids == null)
            {
                this.openDataSetGuids = new List <string>();
            }

            Selection.selectionChanged += this.OnUnitySelectionChange;

            this.openDataSetGuids = GetLastOpenDataSets().ToList();
            this.treeView         = new DataListTreeView(
                this.treeViewState,
                this.openDataSetGuids,
                this.activeDataSet,
                SingletonScriptableObject <DataListWindowState> .Instance.FindSceneProxyForEntity);
            this.treeView.Reload();
        }
Example #2
0
        /// <summary>
        /// Create a new Entity of a given type in the active DataSet.
        /// </summary>
        /// <param name="entityType">Type of the Entity to add.</param>
        public Data AddEntity(Type entityType, GenerateEntityNameDelegate generateName = null)
        {
            var instance = Activator.CreateInstance(entityType) as Data;

            if (generateName == null)
            {
                instance.Name = GenerateNameForType(entityType, this.activeDataSet);
            }
            else
            {
                uint index        = 0;
                var  instanceName = generateName(index);
                while (this.activeDataSet.GetDataList().ContainsKey(instanceName))
                {
                    index++;
                    instanceName = generateName(index);
                }

                instance.Name = generateName(index);
            }

            var state = SingletonScriptableObject <DataListWindowState> .Instance;

            instance.DataSetGuid = state.ActiveDataSetGuid;

            this.activeDataSet.AddData(instance.Name, instance);

            // FIXME terrible hack
            DataSet.CreateSceneProxyForEntityDelegate createSceneProxy = entityName => state.CreateSceneProxyForEntity(this.activeDataSet.DataSetGuid, entityName);

            Entity.GetSceneProxyDelegate getSceneProxy = entityName => state.FindSceneProxyForEntity(
                this.activeDataSet.DataSetGuid,
                entityName);

            instance.OnLoaded(() => createSceneProxy(instance.Name));
            instance.PostOnLoaded(getSceneProxy);

            // TODO
            // There must be a better way of doing this
            this.treeView = new DataListTreeView(
                this.treeViewState,
                this.openDataSetGuids,
                this.activeDataSet,
                state.FindSceneProxyForEntity);
            this.treeView.Reload();

            return(instance);
        }