public void SetPGradient(EngineNS.Bricks.Particle.CGfxParticleSystem sys)
        {
            ParticleNode = null;

            //ShowValues.Clear();
            var TempShowValues = ShowValues;

            ShowValues = new List <MaterialInstanceEditProperty>();
            if (sys.SubParticleSystems != null)
            {
                for (int s = 0; s < sys.SubParticleSystems.Count; s++)
                {
                    var subsys = sys.SubParticleSystems[s];
                    if (subsys.MaterialInstanceNode != null && subsys.MaterialInstanceNode.GetType().Name.Equals(GetClassName()))
                    {
                        if (subsys.HostActorMesh != null && subsys.HostActorMesh.SceneMesh != null && subsys.HostActorMesh.SceneMesh.MtlMeshArray != null)
                        {
                            bool needcreate = subsys.HostActorMesh.SceneMesh.MtlMeshArray.Length != TempShowValues.Count;
                            if (needcreate == false)
                            {
                                for (int i = 0; i < subsys.HostActorMesh.SceneMesh.MtlMeshArray.Length; i++)
                                {
                                    var mtl = subsys.HostActorMesh.SceneMesh.MtlMeshArray[i];
                                    if (mtl.MtlInst == null)
                                    {
                                        needcreate = true;
                                        break;
                                    }

                                    if (mtl.MtlInst.Name.Equals(TempShowValues[i].MaterialInstanceName) == false)
                                    {
                                        needcreate = true;
                                        break;
                                    }
                                }
                            }

                            for (int i = 0; i < subsys.HostActorMesh.SceneMesh.MtlMeshArray.Length; i++)
                            {
                                var mtl = subsys.HostActorMesh.SceneMesh.MtlMeshArray[i];
                                //if (mtl.MtlInst != null)
                                {
                                    var ShowValue = new MaterialInstanceEditProperty();
                                    ShowValue.SetMaterialInstance(mtl.MtlInst, subsys.HostActorMesh.SceneMesh, i);
                                    if (needcreate == false)
                                    {
                                        ShowValue.SyncValues(TempShowValues[i]);
                                    }
                                    ShowValues.Add(ShowValue);
                                }
                            }
                        }
                    }
                }
            }
        }
        public void SyncValues(MaterialInstanceEditProperty showvalue)
        {
            foreach (var varvalue in showvalue.VarRNameValues)
            {
                var varkey   = varvalue.Key;
                var objvalue = varvalue.Value;

                var ShowName = SceneMesh.MtlMeshArray[MtlIndex].MtlInst.GetVarName((uint)varkey, true);
                var index    = SceneMesh.McFindVar((uint)MtlIndex, ShowName);

                if (objvalue.GetType().Equals(typeof(float)))
                {
                    SceneMesh.McSetVarFloat((uint)MtlIndex, index, (float)objvalue, 0);
                    //elem.VarObject.mMaterialInstance.SetVarValue(elem.VarObject.Index, 0, ref value);
                }
                else if (objvalue.GetType().Equals(typeof(Vector2)))
                {
                    SceneMesh.McSetVarVector2((uint)MtlIndex, index, (Vector2)objvalue, 0);
                }
                else if (objvalue.GetType().Equals(typeof(Vector3)))
                {
                    SceneMesh.McSetVarVector3((uint)MtlIndex, index, (Vector3)objvalue, 0);
                }
                else if (objvalue.GetType().Equals(typeof(Vector4)))
                {
                    SceneMesh.McSetVarColor4((uint)MtlIndex, index, (Vector4)objvalue, 0);
                }
                else if (objvalue.GetType().Equals(typeof(EngineNS.Color)))
                {
                    SceneMesh.McSetVarColor4((uint)MtlIndex, index, (EngineNS.Color)objvalue, 0);
                }

                AddVarValue(varkey, objvalue);
            }

            foreach (var srvvalue in showvalue.SRVRNameValues)
            {
                var varkey   = srvvalue.Key;
                var objvalue = srvvalue.Value;
                SceneMesh.McSetTexture((uint)MtlIndex, varkey, objvalue as RName);

                AddSRVValue(varkey, objvalue);
            }
        }
        //EngineNS.Thread.Async.TaskLoader.WaitContext WaitContext = new EngineNS.Thread.Async.TaskLoader.WaitContext();
        //async System.Threading.Tasks.Task<EngineNS.Thread.Async.TaskLoader.WaitContext> AwaitLoad()
        //{
        //    return await EngineNS.Thread.Async.TaskLoader.Awaitload(WaitContext);
        //}
        public override async System.Threading.Tasks.Task Load(XndNode xndNode)
        {
            //await AwaitLoad();
            await ParticleDataSaveLoad.LoadData("ParticleMaterialInstanceNode", xndNode, CSParam as ParticleMaterialInstanceControlConstructionParams, this, mLinkedNodesContainer);

            await base.Load(xndNode);

            InitValueDatas = new List <MaterialInstanceEditProperty>();
            var attr = xndNode.FindAttrib("MaterialInstance_control");

            attr.BeginRead();
            if (attr.Version == 0)
            {
                int count;
                attr.Read(out count);
                for (int i = 0; i < count; i++)
                {
                    var   showvalue = new MaterialInstanceEditProperty();
                    RName materialname;
                    attr.Read(out materialname);
                    showvalue.MaterialInstanceName = materialname;
                    int varcount;
                    attr.Read(out varcount);
                    //foreach (var varvalue in showvalue.VarRNameValues)
                    for (int varn = 0; varn < varcount; varn++)
                    {
                        int    key;
                        string typefullname;
                        attr.Read(out key);
                        attr.Read(out typefullname);
                        {
                            if (typefullname.Equals(typeof(float).FullName))
                            {
                                float value;
                                attr.Read(out value);
                                //elem.VarObject.mMaterialInstance.SetVarValue(elem.VarObject.Index, 0, ref value);
                                showvalue.VarRNameValues.Add(key, value);
                            }
                            else if (typefullname.Equals(typeof(Vector2).FullName))
                            {
                                Vector2 value;
                                attr.Read(out value);
                                showvalue.VarRNameValues.Add(key, value);
                            }
                            else if (typefullname.Equals(typeof(Vector3).FullName))
                            {
                                Vector3 value;
                                attr.Read(out value);
                                showvalue.VarRNameValues.Add(key, value);
                            }
                            else if (typefullname.Equals(typeof(Vector4).FullName))
                            {
                                Vector4 value;
                                attr.Read(out value);
                                showvalue.VarRNameValues.Add(key, value);
                            }
                            else if (typefullname.Equals(typeof(EngineNS.Color).FullName))
                            {
                                Vector4 value;
                                attr.Read(out value);
                                showvalue.VarRNameValues.Add(key, value);
                            }
                        }
                    }

                    int srvcount;
                    attr.Read(out srvcount);
                    //foreach (var srvvalue in showvalue.SRVRNameValues)
                    for (int srvn = 0; srvn < srvcount; srvn++)
                    {
                        string key;
                        RName  rname;
                        attr.Read(out key);
                        attr.Read(out rname);
                        showvalue.SRVRNameValues.Add(key, rname);
                    }

                    InitValueDatas.Add(showvalue);
                }
                attr.EndRead();
            }

            if (InitValueDatas.Count > 0)
            {
                ShowValues = InitValueDatas;
            }
        }