コード例 #1
0
        protected virtual void InitializeResources(IReadOnlyList <ILevelEditorResource> resourcesList)
        {
#if !ALE_STRIP_SAFETY || UNITY_EDITOR
            if (!(resourcesList is IReadOnlyList <LevelEditorResource>))
            {
                throw new NotSupportedException("LevelEditorResourceView only works with LevelEditorResource classes.");
            }
#endif

            // This needs to be done to avoid a problem with opening up the resources object in the editor.
            LevelEditorResource[] newResources = new LevelEditorResource[resourcesList.Count];
            for (int i = 0; i < newResources.Length; i++)
            {
                newResources[i] = new LevelEditorResource(resourcesList[i] as LevelEditorResource);
            }

            // Need to create a copy here or else the children will not work in the asset view.
            LevelEditorResource[] resourcesCopy = new LevelEditorResource[newResources.Length];
            for (int i = 0; i < resourcesList.Count; i++)
            {
                resourcesCopy[i] = new LevelEditorResource(newResources[i]);
            }

            allAssets     = TreeUtility.AssignChildren(newResources);
            treeRoot      = TreeUtility.ListToTree(resourcesCopy, true);
            treeRoot.Name = rootName;

            folderTree.Initialize(child => ((LevelEditorResource)child).Parent, parent =>
            {
                List <object> children = new List <object>();
                children.AddRange(((LevelEditorResource)parent).Children);

                return(children);
            });

            if (showRoot)
            {
                folderTree.SetItems(new LevelEditorResource[1] {
                    treeRoot
                });
                folderTree.SelectItem(treeRoot);
            }
            else
            {
                for (int i = 0; i < treeRoot.Children.Count; i++)
                {
                    treeRoot.Children[i].Parent = null;                     // Remove parent so they don't get indented.
                }

                folderTree.SetItems(treeRoot.Children);
                folderTree.SelectItem(treeRoot.Children[0]);
            }
        }
コード例 #2
0
        /// <summary>
        /// Adds a resource to the list.
        /// </summary>
        /// <param name="resource">The new resource you want to add.</param>
        /// <exception cref="DuplicateIDException">If a resource with the same ID already exists.</exception>
        public void AddResource(LevelEditorResource resource)
        {
            for (int i = 0; i < resources.Count; i++)
            {
                if (resources[i].ID == resource.ID)
                {
                    throw new DuplicateIDException($"There's already a resource in the list with the ID '{resource.ID}'.");
                }
            }

            resources.Add(resource);
        }
コード例 #3
0
 public bool RemoveResource(LevelEditorResource resource)
 {
     return(resources.Remove(resource));
 }