コード例 #1
0
        protected override void OnGetValue()
        {
            base.OnGetValue();
            IContentRef[] values = this.GetValue().Cast <IContentRef>().ToArray();

            this.BeginUpdate();
            string lastPath     = this.contentPath;
            bool   lastMultiple = this.multiple;

            if (!values.Any())
            {
                this.contentPath = null;
            }
            else
            {
                IContentRef first = values.NotNull().FirstOrDefault();
                this.contentPath = first.Path;
                this.multiple    = (values.Any(o => o == null) || values.Any(o => o.Path != first.Path));

                this.GeneratePreview();
            }
            this.EndUpdate();
            if (lastPath != this.contentPath || lastMultiple != this.multiple)
            {
                this.Invalidate();
            }
        }
コード例 #2
0
ファイル: HelpInfo.cs プロジェクト: hbcameleon/duality
        public static HelpInfo FromResource(IContentRef res)
        {
            Type resType = res.ResType;

            // Default content? Attempt to retrieve the associated Property description.
            if (res.IsDefaultContent)
            {
                string[]     defaultPath = res.Path.Split(':');
                PropertyInfo property    = null;
                for (int i = 1; i < defaultPath.Length; i++)
                {
                    string memberName = string.Join("_", defaultPath.Skip(i));
                    property = resType.GetProperty(memberName, BindingFlags.Static | BindingFlags.Public);
                    if (property != null)
                    {
                        break;
                    }
                }
                if (property != null)
                {
                    return(FromMember(property));
                }
            }

            // Default to Type description.
            return(FromMember(resType));
        }
コード例 #3
0
            public ReferenceNode(IContentRef resource)
            {
                this.Name = resource.Name;
                this.Path = resource.FullName;
                this.Text = this.Name;

                this.ResourceReference = resource;
                this.Image             = resource.ResType.GetEditorImage();
            }
コード例 #4
0
        public void AddOutput(IContentRef resource, IEnumerable <string> inputPaths)
        {
            // If this is not a preparation step, require all output Resources to be actually available.
            if (!this.isPrepareStep && !resource.IsAvailable)
            {
                throw new ArgumentException("Can't add a non-existent output Resource", "resource");
            }

            this.output.Add(new AssetImportOutput(resource.As <Resource>(), inputPaths));
        }
コード例 #5
0
        public override void ShowReferencedContent()
        {
            if (string.IsNullOrEmpty(this.contentPath))
            {
                return;
            }
            IContentRef resRef = ContentProvider.RequestContent(this.contentPath);

            DualityEditorApp.Highlight(this, new ObjectSelection(resRef.Res));
        }
コード例 #6
0
        /// <summary>
        /// Retrieves the value of an import parameter for the specified <see cref="Resource"/>.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="resource">A reference to the <see cref="Duality.Resource"/> that is parameterized.</param>
        /// <param name="parameterName">The name of the parameter.</param>
        /// <param name="value">An out reference to the variable to which the retrieved value will be assigned.</param>
        /// <returns>True, if the value was retrieved successfully. False otherwise.</returns>
        public bool GetParameter <T>(IContentRef resource, string parameterName, out T value)
        {
            // If we're importing this asset for the first time, there is no data available.
            if (!this.isReImport)
            {
                value = default(T);
                return(false);
            }

            return(AssetInternalHelper.GetAssetInfoCustomValue <T>(resource.Res, parameterName, out value));
        }
コード例 #7
0
        /// <summary>
        /// Retrieves the value of an import parameter for the specified <see cref="Resource"/>.
        /// If the parameter was undefined, it will be (persistently) initialized with the specified default value.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="env"></param>
        /// <param name="resource">A reference to the <see cref="Duality.Resource"/> that is parameterized.</param>
        /// <param name="parameterName">The name of the parameter.</param>
        /// <param name="defaultValue">If the value wasn't defined for the given Resource, the default value will be used instead.</param>
        /// <returns>The retrieved value, or the default value that was specified.</returns>
        public static T GetOrInitParameter <T>(this IAssetImportEnvironment env, IContentRef resource, string parameterName, T defaultValue)
        {
            T value;

            if (env.GetParameter <T>(resource, parameterName, out value))
            {
                return(value);
            }

            env.SetParameter <T>(resource, parameterName, defaultValue);
            return(defaultValue);
        }
コード例 #8
0
        /// <summary>
        /// Sets the value of an import parameter for the specified <see cref="Resource"/>
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="resource">A reference to the <see cref="Duality.Resource"/> that is parameterized.</param>
        /// <param name="parameterName">The name of the parameter.</param>
        /// <param name="value">The new value that should be assigned to the parameter.</param>
        public void SetParameter <T>(IContentRef resource, string parameterName, T value)
        {
            // Disallow adjusting parameters in the preparation step.
            if (this.isPrepareStep)
            {
                throw new InvalidOperationException(
                          "Cannot adjust parameter values in the preparation step. " +
                          "At this point, any Resource data is considered read-only.");
            }

            AssetInternalHelper.SetAssetInfoCustomValue <T>(resource.Res, parameterName, value);
        }
コード例 #9
0
        /// <summary>
        /// Submits the specified <see cref="Duality.Resource"/> as a generated output of the current importer.
        /// </summary>
        /// <param name="resource">A reference to the generated output <see cref="Duality.Resource"/>.</param>
        /// <param name="inputPaths">An enumeration of input paths that are used to generate this output <see cref="Duality.Resource"/>.</param>
        public void AddOutput(IContentRef resource, IEnumerable <string> inputPaths)
        {
            // Make sure that the provided input paths aren't null or whitespace.
            if (inputPaths == null)
            {
                throw new ArgumentNullException("inputPaths");
            }
            if (inputPaths.Any(p => string.IsNullOrWhiteSpace(p)))
            {
                throw new ArgumentException("Input paths enumerable may not contain null or whitespace items.", "inputPaths");
            }

            // If this is not a preparation step, require all output Resources to be actually available.
            if (!this.isPrepareStep && !resource.IsAvailable)
            {
                throw new ArgumentException("Can't add a non-existent output Resource", "resource");
            }

            this.output.Add(new AssetImportOutput(resource.As <Resource>(), inputPaths));
        }
コード例 #10
0
ファイル: DualityEventArgs.cs プロジェクト: ymoussaba/duality
 public ResourceEventArgs(IContentRef resRef) : this(new ContentRef <Resource>(resRef.ResWeak, resRef.Path))
 {
 }
コード例 #11
0
ファイル: ProjectFolderView.cs プロジェクト: KSLcom/duality
 public ResourceNode(IContentRef res)
     : base(res.Path, null, res.IsDefaultContent)
 {
     this.res = res;
     this.resType = res.ResType;
     this.ApplyPathToName();
 }
コード例 #12
0
 public ResourceNode(string path) : base(path, null, false)
 {
     this.res     = new ContentRef <Resource>(null, path);
     this.resType = Resource.GetTypeByFileName(path);
     this.ApplyPathToName();
 }
コード例 #13
0
        /// <summary>
        /// Make sure textures are loaded first
        /// </summary>
        /// <param name="arg"></param>
        /// <returns></returns>
        private static object OrderByType(IContentRef arg)
        {
            if (arg.Is<Texture>())
                return 0;

            return 1;
        }
コード例 #14
0
 /// <summary>
 /// Some textures don't work when loaded through the preloader like this, but we don't know why, so just exclude those for now.
 /// </summary>
 /// <param name="contentRef"></param>
 /// <returns></returns>
 private static bool IsExcluded(IContentRef contentRef)
 {
     return _excludedTextures.Contains(contentRef.Path);
 }
コード例 #15
0
ファイル: ModelItems.cs プロジェクト: ChrisLakeZA/duality
		public ResourceNode(string path) : base(path, null, false)
		{
			this.res = new ContentRef<Resource>(null, path);
			this.resType = Resource.GetTypeByFileName(path);
			this.ApplyPathToName();
		}
コード例 #16
0
 public static Image GetTypeImage(Type type, IContentRef resLink = null)
 {
     return((type ?? typeof(Resource)).GetEditorImage());
 }
コード例 #17
0
 public ResourceNode(IContentRef res) : base(res.Path, null, res.IsDefaultContent)
 {
     this.res     = res;
     this.resType = res.ResType;
     this.ApplyPathToName();
 }
コード例 #18
0
			public static Image GetTypeImage(Type type, IContentRef resLink = null)
			{
				if (resLink == null) resLink = ContentRef<Resource>.Null;

				Image result = null;
				if (type == typeof(Duality.Resources.Prefab))
				{
					bool prefabHasContent = (resLink.IsAvailable && (resLink.Res as Duality.Resources.Prefab).ContainsData);
					result = CorePluginRegistry.GetTypeImage(type, prefabHasContent ? 
						CorePluginRegistry.ImageContext_Icon + "_Full" : 
						CorePluginRegistry.ImageContext_Icon);
				}
				else
				{
					result = CorePluginRegistry.GetTypeImage(type);
				}

				return result ?? PluginRes.EditorBaseResCache.IconResUnknown;
			}
コード例 #19
0
		public ResourceEventArgs(IContentRef resRef) : this(new ContentRef<Resource>(resRef.ResWeak, resRef.Path)) {}
コード例 #20
0
        private static System.Collections.IEnumerable async_RenameContentRefs(ProcessingBigTaskDialog.WorkerInterface state)
        {
            var renameData   = state.Data as List <ResourceRenamedEventArgs>;
            int totalCounter = 0;
            int fileCounter  = 0;

            // Rename in static application data
            state.StateDesc = "DualityApp Data"; yield return(null);

            DualityApp.LoadAppData();
            DualityApp.LoadUserData();
            state.Progress += 0.04f; yield return(null);

            totalCounter   += async_RenameContentRefs_Perform(DualityApp.AppData, renameData);
            totalCounter   += async_RenameContentRefs_Perform(DualityApp.UserData, renameData);
            state.Progress += 0.02f; yield return(null);

            DualityApp.SaveAppData();
            DualityApp.SaveUserData();
            state.Progress += 0.04f; yield return(null);

            // Special case: Current Scene in sandbox mode
            if (Sandbox.IsActive)
            {
                // Because changes we'll do will be discarded when leaving the sandbox we'll need to
                // do it the hard way - manually load an save the file.
                state.StateDesc = "Current Scene"; yield return(null);

                Scene curScene = Resource.Load <Scene>(Scene.CurrentPath, null, false);
                fileCounter   = async_RenameContentRefs_Perform(curScene, renameData);
                totalCounter += fileCounter;
                if (fileCounter > 0)
                {
                    curScene.Save(Scene.CurrentPath, false);
                }
            }
            // Special case: Current Scene NOT in sandbox mode, but still unsaved
            else if (Scene.Current.IsRuntimeResource)
            {
                state.StateDesc = "Current Scene"; yield return(null);

                fileCounter = async_RenameContentRefs_Perform(Scene.Current, renameData);
                if (fileCounter > 0)
                {
                    DualityEditorApp.NotifyObjPropChanged(null, new ObjectSelection(Scene.Current.AllObjects));
                }
                totalCounter += fileCounter;
            }

            // Rename in actual content
            var             targetResTypes = renameData.Any(e => e.IsDirectory) ? null : renameData.Select(e => e.ContentType).ToArray();
            var             loadedContent  = ContentProvider.GetLoadedContent <Resource>();
            var             reloadContent  = new List <IContentRef>();
            List <string>   resFiles       = Resource.GetResourceFiles();
            List <Resource> modifiedRes    = new List <Resource>();

            foreach (string file in resFiles)
            {
                // Early-out, if this kind of Resource isn't able to reference the renamed Resource
                if (targetResTypes != null)
                {
                    Type resType = Resource.GetTypeByFileName(file);

                    if (resType == null)
                    {
                        Log.Editor.WriteWarning("Could not determine Resource type for File '{0}' using file name only. Skipping it during rename.", file);
                        continue;
                    }

                    bool canReferenceRes = false;
                    foreach (Type targetType in targetResTypes)
                    {
                        if (ReflectionHelper.CanReferenceResource(resType, targetType))
                        {
                            canReferenceRes = true;
                            break;
                        }
                    }
                    if (!canReferenceRes)
                    {
                        state.Progress += 0.9f / resFiles.Count;
                        continue;
                    }
                }

                // Set displayed name
                state.StateDesc = file; yield return(null);

                // Wasn't loaded before? Unload it later to keep the memory footprint small.
                bool wasLoaded = loadedContent.Any(r => r.Path == file);
                // Keep in mind that this operation is performed while Duality content was
                // in an inconsistent state. Loading Resources now may lead to wrong data.
                // Because the ContentRefs might be wrong right now.

                if (wasLoaded)
                {
                    // Retrieve already loaded content
                    IContentRef cr = ContentProvider.RequestContent(file);
                    state.Progress += 0.45f / resFiles.Count; yield return(null);

                    // Perform rename and flag unsaved / modified
                    fileCounter = async_RenameContentRefs_Perform(cr.Res, renameData);
                    if (fileCounter > 0)
                    {
                        modifiedRes.Add(cr.Res);
                    }
                }
                else
                {
                    // Load content without initializing it
                    Resource res = Resource.Load <Resource>(file, null, false);
                    state.Progress += 0.45f / resFiles.Count; yield return(null);

                    // Perform rename and save it without making it globally available
                    fileCounter = async_RenameContentRefs_Perform(res, renameData);
                    if (fileCounter > 0)
                    {
                        res.Save(null, false);
                    }
                }

                totalCounter   += fileCounter;
                state.Progress += 0.45f / resFiles.Count; yield return(null);
            }

            // Notify the editor about modified Resources
            if (modifiedRes.Count > 0)
            {
                DualityEditorApp.NotifyObjPropChanged(null, new ObjectSelection(modifiedRes));
            }
        }
コード例 #21
0
		public static HelpInfo FromResource(IContentRef res)
		{
			return FromMember(res.ResType);
		}
コード例 #22
0
 public static Image GetTypeImage(Type type, IContentRef resLink = null)
 {
     return type.GetEditorImage();
 }
コード例 #23
0
 public ResourceSaveEventArgs(IContentRef resRef, string saveAsPath) : this(new ContentRef <Resource>(resRef.ResWeak, resRef.Path), saveAsPath)
 {
 }
コード例 #24
0
ファイル: EventArgs.cs プロジェクト: swtrse/duality
		public ResourceSaveEventArgs(IContentRef resRef, string saveAsPath) : this(new ContentRef<Resource>(resRef.ResWeak, resRef.Path), saveAsPath) {}
コード例 #25
0
 /// <summary>
 /// Submits the specified <see cref="Duality.Resource"/> as a generated output of the current importer.
 /// </summary>
 /// <param name="resource">A reference to the generated output <see cref="Duality.Resource"/>.</param>
 /// <param name="inputPath">The input path that is used to generate this output <see cref="Duality.Resource"/>.</param>
 public static void AddOutput(this IAssetImportEnvironment env, IContentRef resource, string inputPath)
 {
     env.AddOutput(resource, new string[] { inputPath });
 }
コード例 #26
0
ファイル: ProjectFolderView.cs プロジェクト: KSLcom/duality
 public static Image GetTypeImage(Type type, IContentRef resLink = null)
 {
     return (type ?? typeof(Resource)).GetEditorImage();
 }
コード例 #27
0
			public ResourceNode(IContentRef res) : base(res.Path, null, res.Path.Contains(':'))
			{
				this.res = res;
				this.resType = res.ResType;
				this.ApplyPathToName();
			}
コード例 #28
0
ファイル: HelpInfo.cs プロジェクト: ChrisLakeZA/duality
		public static HelpInfo FromResource(IContentRef res)
		{
			Type resType = res.ResType;

			// Default content? Attempt to retrieve the associated Property description.
			if (res.IsDefaultContent)
			{
				string[] defaultPath = res.Path.Split(':');
				PropertyInfo property = null;
				for (int i = 1; i <  defaultPath.Length; i++)
				{
					string memberName = string.Join("_", defaultPath.Skip(i));
					property = resType.GetProperty(memberName, BindingFlags.Static | BindingFlags.Public);
					if (property != null) break;
				}
				if (property != null)
				{
					return FromMember(property);
				}
			}

			// Default to Type description.
			return FromMember(resType);
		}
コード例 #29
0
ファイル: ModelItems.cs プロジェクト: gitMaxim/duality
        public ResourceNode(string path)
            : base(path, null, false)
        {
            string[] fileNameSplit = Path.GetFileNameWithoutExtension(path).Split('.');

            this.res = new ContentRef<Resource>(null, path);
            this.resType = Resource.GetTypeByFileName(path);
            this.ApplyPathToName();
        }