protected override void CollectionErrorMsg() { foreach (var pardata in mInParamDataList) { if (pardata.mInElement == null) { continue; } var lOI = pardata.mInElement; if (!lOI.HasLink) { if (mTemplateClassInstance != null) { if (mTemplateClassInstance.GetType().GetProperty(pardata.mStrName) == null) { HasError = true; ErrorDescription = "未连接参数!"; } } else { HasError = true; ErrorDescription = "未连接参数!"; } } } }
public AnimationAsset(AnimationAssetConstructionParams csParam) : base(csParam) { InitConstruction(); if (csParam.AnimAsset == null) { csParam.AnimAsset = new AnimAsset(); if (csParam.HostNodesContainer.HostNode is AnimStateControl) { csParam.AnimAsset.AnimAssetLocationName = csParam.HostNodesContainer.HostNode.NodeName; csParam.AnimAsset.AnimAssetLocation = AnimAssetLocation.State; csParam.AnimAsset.AnimAssetName = csParam.NodeName.PureName(); } else { System.Diagnostics.Debugger.Break(); } } var cpInfos = new List <CodeGenerateSystem.Base.CustomPropertyInfo>(); cpInfos.Add(CodeGenerateSystem.Base.CustomPropertyInfo.GetFromParamInfo(typeof(bool), "IsLoop", new Attribute[] { new EngineNS.Rtti.MetaDataAttribute() })); mTemplateClassInstance = CodeGenerateSystem.Base.PropertyClassGenerator.CreateClassInstanceFromCustomPropertys(cpInfos, this); var clsType = mTemplateClassInstance.GetType(); var xNamePro = clsType.GetProperty("IsLoop"); xNamePro.SetValue(mTemplateClassInstance, csParam.IsLoop); RNameNodeName = csParam.NodeName; NodeName = csParam.NodeName.PureName(); Notifies = csParam.Notifies; IsOnlyReturnValue = true; AddLinkPinInfo("AnimAssetLinkHandle", mCtrlValueLinkHandle, null); }
void BindingTemplateClassInstanceProperties() { var cpInfos = new List <CodeGenerateSystem.Base.CustomPropertyInfo>(); cpInfos.Add(CodeGenerateSystem.Base.CustomPropertyInfo.GetFromParamInfo(typeof(bool), "PerformanceFirst", new Attribute[] { new EngineNS.Rtti.MetaDataAttribute() })); cpInfos.Add(CodeGenerateSystem.Base.CustomPropertyInfo.GetFromParamInfo(typeof(float), "FadeTime", new Attribute[] { new EngineNS.Rtti.MetaDataAttribute() })); mTemplateClassInstance = CodeGenerateSystem.Base.PropertyClassGenerator.CreateClassInstanceFromCustomPropertys(cpInfos, this, null, false); var clsType = mTemplateClassInstance.GetType(); var performanceFirstPro = clsType.GetProperty("PerformanceFirst"); performanceFirstPro.SetValue(mTemplateClassInstance, PerformanceFirst); SetBinding(TransitionCrossfadeShow.PerformanceFirstProperty, new Binding("PerformanceFirst") { Source = mTemplateClassInstance, Mode = BindingMode.TwoWay }); var fadeTimePro = clsType.GetProperty("FadeTime"); fadeTimePro.SetValue(mTemplateClassInstance, FadeTime); SetBinding(TransitionCrossfadeShow.FadeTimeProperty, new Binding("FadeTime") { Source = mTemplateClassInstance, Mode = BindingMode.TwoWay }); }
partial void RefreshValueFromTemplateClass2PropertyInfoList() { if (mTemplateClassInstance == null) { return; } var tempClassType = mTemplateClassInstance.GetType(); foreach (var proInfo in mCustomPropertyInfos) { var pro = tempClassType.GetProperty(proInfo.PropertyName); if (pro == null) { continue; } proInfo.CurrentValue = pro.GetValue(mTemplateClassInstance); } }
protected void CreateTemplateClassInstance() { if (mCustomPropertyInfos.Count == 0) { return; } var classType = CodeGenerateSystem.Base.PropertyClassGenerator.CreateTypeFromCustomPropertys(mCustomPropertyInfos); mTemplateClassInstance = System.Activator.CreateInstance(classType) as CodeGenerateSystem.Base.GeneratorClassBase; var field = mTemplateClassInstance.GetType().GetField("HostNode"); if (field != null) { field.SetValue(mTemplateClassInstance, this); } foreach (var property in mTemplateClassInstance.GetType().GetProperties()) { property.SetValue(mTemplateClassInstance, CodeGenerateSystem.Program.GetDefaultValueFromType(property.PropertyType)); } }
public Function(CodeGenerateSystem.Base.ConstructionParams smParam) : base(smParam) { InitializeComponent(); var splits = CSParam.ConstructParam.Split('|'); var include = splits[0]; if (include.Contains(":")) { include = EngineNS.CEngine.Instance.FileManager._GetRelativePathFromAbsPath(include, EngineNS.CEngine.Instance.FileManager.Bin); } include = include.Replace("\\", "/"); if (include.Contains("bin/")) { var nIdx = include.IndexOf("bin/"); include = include.Substring(nIdx + 4); } System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument(); xmlDoc.LoadXml(splits[1]); mStrFuncName = xmlDoc.DocumentElement.GetAttribute("Name"); NodeName = mStrFuncName; var tempElements = xmlDoc.GetElementsByTagName("Param"); if (tempElements.Count > 0) { var cpInfos = new List <CodeGenerateSystem.Base.CustomPropertyInfo>(); var paramInElm = tempElements[0]; int nIdx = 0; foreach (System.Xml.XmlElement node in paramInElm.ChildNodes) { var typeStr = node.GetAttribute("Type"); var nameStr = node.GetAttribute("Name"); var strAttr = node.GetAttribute("Attribute"); switch (strAttr) { case "out": case "return": break; default: { var cpInfo = CodeGenerateSystem.Base.CustomPropertyInfo.GetFromParamInfo(Program.GetTypeFromValueType(typeStr), nameStr, new Attribute[] { new EngineNS.Rtti.MetaDataAttribute() }); if (cpInfo != null) { cpInfos.Add(cpInfo); } } break; } AddLink(nIdx, typeStr, nameStr, strAttr); nIdx++; } mTemplateClassInstance = CodeGenerateSystem.Base.PropertyClassGenerator.CreateClassInstanceFromCustomPropertys(cpInfos, this, $"{this.GetType().FullName}.PropertyClass_{mStrFuncName}", false); foreach (var property in mTemplateClassInstance.GetType().GetProperties()) { property.SetValue(mTemplateClassInstance, CodeGenerateSystem.Program.GetDefaultValueFromType(property.PropertyType)); } if (HostNodesContainer != null && HostNodesContainer.HostControl != null) { mTemplateClassInstance.EnableUndoRedo(HostNodesContainer.HostControl.UndoRedoKey, mStrFuncName); } } this.UpdateLayout(); }
void CreateTemplateClass_Show() { var allType = mTemplateClassInstance_All.GetType(); if (mTemplateClassInstance_Show != null) { foreach (var pro in mTemplateClassInstance_Show.GetType().GetProperties()) { var allPro = allType.GetProperty(pro.Name); allPro.SetValue(mTemplateClassInstance_All, pro.GetValue(mTemplateClassInstance_Show)); } } var cpInfos_Show = new List <CodeGenerateSystem.Base.CustomPropertyInfo>(); var param = CSParam as ExpandNodeConstructParam; foreach (var pro in param.ExpandType.GetProperties()) { if (!pro.CanWrite) { continue; } var atts = pro.GetCustomAttributes(typeof(EngineNS.Editor.MacrossMemberAttribute), false); if (atts == null || atts.Length == 0) { continue; } var mm = atts[0] as EngineNS.Editor.MacrossMemberAttribute; // 只读不能设置 if (mm.HasType(EngineNS.Editor.MacrossMemberAttribute.enMacrossType.ReadOnly)) { continue; } if (param.ActiveMembers.Contains(pro.Name)) { var cpInfo = new CodeGenerateSystem.Base.CustomPropertyInfo(); cpInfo.PropertyName = pro.Name; cpInfo.PropertyType = pro.PropertyType; foreach (var att in pro.GetCustomAttributes(false)) { cpInfo.PropertyAttributes.Add(att as System.Attribute); } cpInfo.DefaultValue = CodeGenerateSystem.Program.GetDefaultValueFromType(cpInfo.PropertyType); cpInfo.CurrentValue = cpInfo.DefaultValue; cpInfos_Show.Add(cpInfo); } } foreach (var field in param.ExpandType.GetFields()) { var atts = field.GetCustomAttributes(typeof(EngineNS.Editor.MacrossMemberAttribute), false); if (atts == null || atts.Length == 0) { continue; } var mm = atts[0] as EngineNS.Editor.MacrossMemberAttribute; // 只读不能设置 if (mm.HasType(EngineNS.Editor.MacrossMemberAttribute.enMacrossType.ReadOnly)) { continue; } if (param.ActiveMembers.Contains(field.Name)) { var cpInfo = new CodeGenerateSystem.Base.CustomPropertyInfo(); cpInfo.PropertyName = field.Name; cpInfo.PropertyType = field.FieldType; foreach (var att in field.GetCustomAttributes(false)) { cpInfo.PropertyAttributes.Add(att as System.Attribute); } cpInfo.DefaultValue = CodeGenerateSystem.Program.GetDefaultValueFromType(cpInfo.PropertyType); cpInfo.CurrentValue = cpInfo.DefaultValue; cpInfos_Show.Add(cpInfo); } } mTemplateClassInstance_Show = CodeGenerateSystem.Base.PropertyClassGenerator.CreateClassInstanceFromCustomPropertys(cpInfos_Show, this, "ExpandShow" + Guid.NewGuid().ToString(), false); bool createNewAllTC = false; foreach (var pro in mTemplateClassInstance_Show.GetType().GetProperties()) { var allPro = allType.GetProperty(pro.Name); if (allPro == null) { createNewAllTC = true; } else { pro.SetValue(mTemplateClassInstance_Show, allPro.GetValue(mTemplateClassInstance_All)); } } if (createNewAllTC) { var showType = mTemplateClassInstance_Show.GetType(); CreateTemplateClass_All(); foreach (var pro in mTemplateClassInstance_All.GetType().GetProperties()) { var showPro = showType.GetProperty(pro.Name); pro.SetValue(mTemplateClassInstance_All, showPro.GetValue(mTemplateClassInstance_Show)); } } }
public override async System.Threading.Tasks.Task GCode_CodeDom_GenerateCode(CodeTypeDeclaration codeClass, CodeStatementCollection codeStatementCollection, LinkPinControl element, GenerateCodeContext_Method context) { /*生成代码 * EngineNS.Graphics.Mesh.Animation.CGfxAnimationSequence batmanidle = new EngineNS.Graphics.Mesh.Animation.CGfxAnimationSequence(); * EngineNS.RName animName; * animName = EngineNS.RName.GetRName("titandemo/character/batman/animation/[email protected]"); * batmanidle.Init(animName); * batmanidle.AnimationPose = animPose; * state.AddTickComponent(batmanidle); * batmanidle.Notifies[0].OnNotify += this.Anim_Notify_Walk; * return true; */ await EngineNS.Thread.AsyncDummyClass.DummyFunc(); var validName = StringRegex.GetValidName(NodeName); System.CodeDom.CodeVariableDeclarationStatement st = new CodeVariableDeclarationStatement(new CodeTypeReference(typeof(EngineNS.Bricks.Animation.AnimNode.AnimationClip)), validName, new CodeObjectCreateExpression(new CodeTypeReference(typeof(EngineNS.Bricks.Animation.AnimNode.AnimationClip)))); codeStatementCollection.Add(st); var calcMethod = new CodeGenerateSystem.CodeDom.CodeMethodInvokeExpression(new CodeSnippetExpression("EngineNS.RName"), "GetRName", new CodePrimitiveExpression(RNameNodeName.Name)); CodeAssignStatement nodeNameAssign = new CodeAssignStatement(); CodeVariableDeclarationStatement rNameSt = new CodeVariableDeclarationStatement(new CodeTypeReference(typeof(EngineNS.RName)), "animName"); nodeNameAssign.Left = new CodeVariableReferenceExpression("animName"); nodeNameAssign.Right = calcMethod; codeStatementCollection.Add(rNameSt); codeStatementCollection.Add(nodeNameAssign); CodeVariableReferenceExpression animRef = new CodeVariableReferenceExpression(validName); CodeMethodReferenceExpression methodRef = new CodeMethodReferenceExpression(animRef, "Init"); var methodInvoke = new CodeGenerateSystem.CodeDom.CodeMethodInvokeExpression(methodRef, new CodeExpression[] { new CodeVariableReferenceExpression("animName") }); codeStatementCollection.Add(methodInvoke); var animCP = CSParam as AnimationAssetConstructionParams; CodeFieldReferenceExpression isLoopField = new CodeFieldReferenceExpression(); isLoopField.FieldName = "IsLoop"; isLoopField.TargetObject = animRef; CodeAssignStatement isLoopAssign = new CodeAssignStatement(); isLoopAssign.Left = isLoopField; isLoopAssign.Right = new CodePrimitiveExpression((bool)mTemplateClassInstance.GetType().GetProperty("IsLoop").GetValue(mTemplateClassInstance)); codeStatementCollection.Add(isLoopAssign); CodeFieldReferenceExpression animPoseField = new CodeFieldReferenceExpression(); animPoseField.FieldName = "AnimationPoseProxy"; animPoseField.TargetObject = animRef; CodeAssignStatement animPoseAssign = new CodeAssignStatement(); animPoseAssign.Left = animPoseField; animPoseAssign.Right = context.AnimAssetAnimPoseProxyReferenceExpression; codeStatementCollection.Add(animPoseAssign); CodeMethodReferenceExpression addAnimTickComponentRef = new CodeMethodReferenceExpression(context.AnimAssetTickHostReferenceExpression, "AddTickComponent"); var addAnimTickComponentInvoke = new CodeGenerateSystem.CodeDom.CodeMethodInvokeExpression(addAnimTickComponentRef, new CodeExpression[] { animRef }); codeStatementCollection.Add(addAnimTickComponentInvoke); var info = await EditorCommon.Resources.ResourceInfoManager.Instance.CreateResourceInfoFromFile(RNameNodeName.Address + ".rinfo", null); var animationInfo = info as EditorCommon.ResourceInfos.AnimationClipResourceInfo; animCP.Notifies.Clear(); foreach (var pair in animationInfo.NotifyTrackMap) { animCP.Notifies.Add(pair.NotifyName); } for (int i = 0; i < Notifies.Count; ++i) { var notify = Notifies[i]; var validNotifyName = StringRegex.GetValidName(notify); validNotifyName = "Anim_Notify_" + validNotifyName; if (hasTheNotifyMethod(codeClass, validNotifyName)) { var attachNotifyEventExp = new CodeGenerateSystem.CodeDom.CodeMethodInvokeExpression(new CodeMethodReferenceExpression(animRef, "AttachNotifyEvent"), new CodeExpression[] { new CodePrimitiveExpression(i), new CodeMethodReferenceExpression(new CodeThisReferenceExpression(), validNotifyName) }); //CodeArrayIndexerExpression arrayIndex = new CodeArrayIndexerExpression(new CodeFieldReferenceExpression(animRef, "Notifies"), new CodePrimitiveExpression(i)); //CodeAttachEventStatement attachEvent = new CodeAttachEventStatement(arrayIndex, "OnNotify", new CodeMethodReferenceExpression(new CodeThisReferenceExpression(), validNotifyName)); codeStatementCollection.Add(attachNotifyEventExp); } } }
public override async System.Threading.Tasks.Task GCode_CodeDom_GenerateCode(System.CodeDom.CodeTypeDeclaration codeClass, System.CodeDom.CodeStatementCollection codeStatementCollection, CodeGenerateSystem.Base.LinkPinControl element, CodeGenerateSystem.Base.GenerateCodeContext_Method context) { MethodInvokeParameterControl retCtrl = null; Dictionary <BaseNodeControl, System.CodeDom.CodeExpression> paramCodeExps = new Dictionary <BaseNodeControl, System.CodeDom.CodeExpression>(); foreach (var paramNode in mChildNodes) { if (paramNode is MethodInvokeParameterControl) { var pm = paramNode as MethodInvokeParameterControl; var param = pm.CSParam as MethodInvokeParameterControl.MethodInvokeParameterConstructionParams; if (param.ParamInfo.ParamName == "Return") { retCtrl = pm; continue; } if (pm.HasLink()) { await pm.GCode_CodeDom_GenerateCode(codeClass, codeStatementCollection, pm.ParamPin, context); var exp = new CodeGenerateSystem.CodeDom.CodeCastExpression(param.ParamInfo.ParameterType, pm.GCode_CodeDom_GetValue(pm.ParamPin, context)); paramCodeExps[paramNode] = exp; codeStatementCollection.Add(new System.CodeDom.CodeAssignStatement( new System.CodeDom.CodeVariableReferenceExpression(param.ParamInfo.ParamName), exp)); } else if (mTemplateClassInstance != null) { var proInfo = mTemplateClassInstance.GetType().GetProperty(param.ParamInfo.ParamName); object proValue; if (proInfo == null) { proValue = CodeGenerateSystem.Program.GetDefaultValueFromType(param.ParamInfo.ParameterType); } else { proValue = proInfo.GetValue(mTemplateClassInstance); } var valueExp = Program.GetValueCode(codeStatementCollection, param.ParamInfo.ParameterType, proValue); paramCodeExps[paramNode] = valueExp; codeStatementCollection.Add(new System.CodeDom.CodeAssignStatement(new System.CodeDom.CodeVariableReferenceExpression(param.ParamInfo.ParamName), valueExp)); } } else { throw new InvalidOperationException(); } } if (retCtrl != null) { if (retCtrl.HasLink()) { await retCtrl.GCode_CodeDom_GenerateCode(codeClass, codeStatementCollection, retCtrl.ParamPin, context); } System.CodeDom.CodeExpression retExp = null; if (retCtrl.HasLink()) { var retStatement = new System.CodeDom.CodeMethodReturnStatement(); retExp = retCtrl.GCode_CodeDom_GetValue(retCtrl.ParamPin, context); paramCodeExps[retCtrl] = retExp; } else if (mTemplateClassInstance != null) { var param = retCtrl.CSParam as MethodInvokeParameterControl.MethodInvokeParameterConstructionParams; var proInfo = mTemplateClassInstance.GetType().GetProperty("Return"); object proValue; if (proInfo == null) { proValue = CodeGenerateSystem.Program.GetDefaultValueFromType(param.ParamInfo.ParameterType); } else { proValue = proInfo.GetValue(mTemplateClassInstance); } retExp = Program.GetValueCode(codeStatementCollection, param.ParamInfo.ParameterType, proValue); paramCodeExps[retCtrl] = retExp; } #region Debug var debugCodes = CodeDomNode.BreakPoint.BeginMacrossDebugCodeStatments(codeStatementCollection); foreach (var paramNode in mChildNodes) { if (paramNode is MethodInvokeParameterControl) { var pm = paramNode as MethodInvokeParameterControl; System.CodeDom.CodeExpression exp; if (paramCodeExps.TryGetValue(paramNode, out exp)) { CodeDomNode.BreakPoint.GetGatherDataValueCodeStatement(debugCodes, pm.ParamPin.GetLinkPinKeyName(), exp, pm.GCode_GetTypeString(pm.ParamPin, context), context); } } else { throw new InvalidOperationException("未实现"); } } var breakCondStatement = CodeDomNode.BreakPoint.BreakCodeStatement(codeClass, debugCodes, HostNodesContainer.GUID, Id); CodeDomNode.BreakPoint.EndMacrossDebugCodeStatements(codeStatementCollection, debugCodes); #endregion var returnParam = CSParam as ReturnConstructParam; foreach (var param in returnParam.MethodInfo.Params) { // ref或out,需要将displayType造成的临时变量再赋给原函数参数 if ((param.FieldDirection == FieldDirection.Out || param.FieldDirection == FieldDirection.Ref) && param.ParameterDisplayType != null) { codeStatementCollection.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("temp___" + param.ParamName), new CodeGenerateSystem.CodeDom.CodeCastExpression(param.ParameterType, new CodeVariableReferenceExpression(param.ParamName)))); } } if (returnParam.MethodInfo.ReturnType.BaseType == typeof(System.Threading.Tasks.Task)) { var genericType = returnParam.MethodInfo.ReturnType.GetGenericArguments()[0]; codeStatementCollection.Add(new System.CodeDom.CodeMethodReturnStatement(new CodeGenerateSystem.CodeDom.CodeCastExpression(genericType, retExp))); } else { codeStatementCollection.Add(new System.CodeDom.CodeMethodReturnStatement(new CodeGenerateSystem.CodeDom.CodeCastExpression(returnParam.MethodInfo.ReturnType, retExp))); } } else { #region Debug var debugCodes = CodeDomNode.BreakPoint.BeginMacrossDebugCodeStatments(codeStatementCollection); var breakCondStatement = CodeDomNode.BreakPoint.BreakCodeStatement(codeClass, debugCodes, HostNodesContainer.GUID, Id); CodeDomNode.BreakPoint.EndMacrossDebugCodeStatements(codeStatementCollection, debugCodes); #endregion var returnParam = CSParam as ReturnConstructParam; foreach (var param in returnParam.MethodInfo.Params) { // ref或out,需要将displayType造成的临时变量再赋给原函数参数 if ((param.FieldDirection == FieldDirection.Out || param.FieldDirection == FieldDirection.Ref) && param.ParameterDisplayType != null) { codeStatementCollection.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("temp___" + param.ParamName), new CodeGenerateSystem.CodeDom.CodeCastExpression(param.ParameterType, new CodeVariableReferenceExpression(param.ParamName)))); } } codeStatementCollection.Add(new System.CodeDom.CodeMethodReturnStatement()); } }