コード例 #1
0
        protected override async Task OnReferencedRNameChangedOverride(ResourceInfo referencedResInfo, EngineNS.RName newRName, EngineNS.RName oldRName)
        {
            if (referencedResInfo.ResourceType == EngineNS.Editor.Editor_RNameTypeAttribute.Texture)
            {
                ReferenceRNameList.Remove(oldRName);
                ReferenceRNameList.Add(referencedResInfo.ResourceName);
                await Save();

                // mat
                bool bFinded = false;
                var  mat     = await EngineNS.CEngine.Instance.MaterialManager.GetMaterialAsync(EngineNS.CEngine.Instance.RenderContext, ResourceName);

                foreach (var param in mat.ParamList)
                {
                    if (param.VarType == EngineNS.EShaderVarType.SVT_Texture && param.TextureRName.Equals(oldRName))
                    {
                        param.SetValueStr(referencedResInfo.ResourceName);
                        bFinded = true;
                    }
                }
                mat.SaveMaterial();

                // link
                if (bFinded)
                {
                    var xndHolder = await EngineNS.IO.XndHolder.LoadXND(ResourceName.Address + EngineNS.Graphics.CGfxMaterial.ShaderLinkExtension);

                    if (xndHolder != null)
                    {
                        var container = new CodeGenerateSystem.Base.NodesContainer();
                        await container.Load(xndHolder.Node);

                        xndHolder.Node.TryReleaseHolder();

                        foreach (var node in container.CtrlNodeList)
                        {
                            if (node is Controls.TextureControl)
                            {
                                var tc = node as Controls.TextureControl;
                                if (tc.TextureRName == oldRName)
                                {
                                    tc.TextureRName = referencedResInfo.ResourceName;
                                }
                            }
                        }

                        var saveHolder = EngineNS.IO.XndHolder.NewXNDHolder();
                        container.Save(saveHolder.Node);
                        EngineNS.IO.XndHolder.SaveXND(ResourceName.Address + EngineNS.Graphics.CGfxMaterial.ShaderLinkExtension, saveHolder);
                    }
                }
            }
        }
コード例 #2
0
        protected override async Task OnReferencedRNameChangedOverride(ResourceInfo referencedResInfo, EngineNS.RName newRName, EngineNS.RName oldRName)
        {
            if (referencedResInfo.ResourceType == EngineNS.Editor.Editor_RNameTypeAttribute.Material)
            {
                ReferenceRNameList.Remove(ParentMaterialRName);
                if (newRName != null)
                {
                    ParentMaterialRName = referencedResInfo.ResourceName;
                    ReferenceRNameList.Add(ParentMaterialRName);
                }
                await Save();

                var matIns = await EngineNS.CEngine.Instance.MaterialInstanceManager.GetMaterialInstanceAsync(EngineNS.CEngine.Instance.RenderContext, ResourceName);

                EngineNS.CEngine.Instance.MaterialInstanceManager.RemoveMaterialFromDic(ResourceName);
                matIns.OnlySetMaterialName(referencedResInfo.ResourceName);
                matIns.SaveMaterialInstance();
            }
            else if (referencedResInfo.ResourceType == EngineNS.Editor.Editor_RNameTypeAttribute.Texture)
            {
                ReferenceRNameList.Remove(oldRName);
                if (newRName != null)
                {
                    ReferenceRNameList.Add(referencedResInfo.ResourceName);
                }
                await Save();

                var matIns = await EngineNS.CEngine.Instance.MaterialInstanceManager.GetMaterialInstanceAsync(EngineNS.CEngine.Instance.RenderContext, ResourceName);

                for (uint i = 0; i < matIns.SRVNumber; i++)
                {
                    var srvName = matIns.GetSRVName(i);
                    if (srvName == oldRName)
                    {
                        var texture = CEngine.Instance.TextureManager.GetShaderRView(CEngine.Instance.RenderContext, referencedResInfo.ResourceName);
                        matIns.SetSRV(i, texture);
                    }
                }
                matIns.SaveMaterialInstance();
            }
        }