public void InitMacroPort(IMacroPort port) { if (port == null) { return; } if (m_port == null) { m_port = port; } if (m_port == port) // Make sure to init macro only one times. { Refresh(); if (CodeGenerator.isGenerating) { foreach (VariableData variable in variables) { variable.modifier.SetPrivate(); CodeGenerator.AddVariable(variable); } } } }
public void InitMacroPort(IMacroPort port) { if (port == null) { return; } if (m_port == null) { m_port = port; } if (m_port == port) // Make sure to init macro only one times. { Refresh(); if (CodeGenerator.isGenerating) { foreach (VariableData variable in variables) { variable.modifier.SetPrivate(); CodeGenerator.AddVariable(variable); } m_generatedVariable = new List <VariableData>(); //Ensure to register default variable from macro graph var macroVariable = macroAsset.Variables; foreach (var variable in macroVariable) { if (!variables.Any(v => v.Name == variable.Name)) { var tmpVar = new VariableData(variable); tmpVar.modifier.SetPrivate(); CodeGenerator.AddVariable(tmpVar); m_generatedVariable.Add(tmpVar); } } } if (macroAsset != null) { if (CodeGenerator.isGenerating || Application.isPlaying) { if (runtimeMacro != null) { DestroyImmediate(runtimeMacro.gameObject); } runtimeMacro = uNodeUtility.TempManagement.CreateTempObject(macroAsset); var behaviors = runtimeMacro.RootObject.GetComponentsInChildren <MonoBehaviour>(true); AnalizerUtility.RetargetNodeOwner(runtimeMacro, owner, behaviors, (obj) => { MemberData member = obj as MemberData; if (member != null && member.targetType == MemberData.TargetType.uNodeVariable && GetVariableData(member.startName) != null) { member.RefactorUnityObject(new Object[] { runtimeMacro }, new Object[] { this }); } }); Dictionary <int, MacroPortNode> portMap = new Dictionary <int, MacroPortNode>(); foreach (var p in inputFlows) { if (p != null && p.linkedPort != null) { portMap[p.linkedPort.port.transform.GetSiblingIndex()] = p; } } foreach (var p in inputValues) { if (p != null && p.linkedPort != null) { portMap[p.linkedPort.port.transform.GetSiblingIndex()] = p; } } foreach (var p in outputFlows) { if (p != null && p.linkedPort != null) { portMap[p.linkedPort.port.transform.GetSiblingIndex()] = p; } } foreach (var p in outputValues) { if (p != null && p.linkedPort != null) { portMap[p.linkedPort.port.transform.GetSiblingIndex()] = p; } } foreach (Transform t in runtimeMacro.RootObject.transform) { var comp = t.GetComponent <Node>(); if (comp != null) { comp.parentComponent = this; var p = comp as MacroPortNode; MacroPortNode originP; if (portMap.TryGetValue(t.GetSiblingIndex(), out originP)) { switch (originP.kind) { case PortKind.FlowInput: case PortKind.ValueOutput: originP.target = new MemberData(p.target); break; case PortKind.FlowOutput: case PortKind.ValueInput: p.target = new MemberData(originP.target); break; } } } } runtimeMacro.SetLinkedOwner(owner); //Make sure all get/set property will be liked to actual owner. if (CodeGenerator.isGenerating) { foreach (var b in behaviors) { if (b is NodeComponent) { CodeGenerator.RegisterAsGroupedNode(b as NodeComponent); } } } } } } }