예제 #1
0
        internal void PrepareNodesForCopy(IList <CNode> nodes)
        {
            CScriptSerializer.PrepareNodesForSerialization(nodes);
            for (int i = 0; i < nodes.Count; i++)
            {
                if (nodes[i] is CKlaxVariableNode variableNode)
                {
                    if (variableNode.SourceVariable == null)
                    {
                        throw new NullReferenceException("Tried to serialize a KlaxVariable node without a valid reference to an existing variable");
                    }

                    variableNode.m_sourceVariableGuid = variableNode.SourceVariable.Guid;
                }
            }
        }
예제 #2
0
 internal void ResolveNodesAfterSerialization(CKlaxScriptObject outerScriptObject)
 {
     ScriptableObject = outerScriptObject;
     for (int i = 0; i < m_nodes.Count; i++)
     {
         if (m_nodes[i] is CKlaxVariableNode variableNode)
         {
             int varIndex = variableNode.m_sourceVariableIndex;
             variableNode.m_sourceVariable = variableNode.m_bIsLocalVariable ? m_localVariables[varIndex] : outerScriptObject.KlaxVariables[varIndex];
         }
         else if (m_nodes[i] is CExecuteCustomFunctionNode functionNode)
         {
             functionNode.ResolveFunctionReference(outerScriptObject);
         }
     }
     CScriptSerializer.ResolveNodeReferences(m_nodes);
 }
예제 #3
0
        internal void ResolveNodesForPaste(IList <CNode> nodes)
        {
            List <CNode> invalidNodes = new List <CNode>();

            for (int i = nodes.Count - 1; i >= 0; i--)
            {
                if (nodes[i] is CKlaxVariableNode variableNode)
                {
                    bool bFoundVariable = false;
                    foreach (CKlaxVariable localVariable in m_localVariables)
                    {
                        if (localVariable.Guid == variableNode.m_sourceVariableGuid)
                        {
                            variableNode.SourceVariable = localVariable;
                            bFoundVariable = true;
                            break;
                        }
                    }

                    if (!bFoundVariable)
                    {
                        foreach (CKlaxVariable objectVariable in ScriptableObject.KlaxVariables)
                        {
                            if (objectVariable.Guid == variableNode.m_sourceVariableGuid)
                            {
                                bFoundVariable = true;
                                variableNode.SourceVariable = objectVariable;
                                break;
                            }
                        }
                    }

                    if (!bFoundVariable)
                    {
                        nodes.RemoveAt(i);
                    }
                }
                else if (nodes[i] is CExecuteCustomFunctionNode functionNode)
                {
                    functionNode.ResolveFunctionReference(ScriptableObject);
                }
            }
            CScriptSerializer.ResolveNodeReferences(nodes);
        }
예제 #4
0
        internal void PrepareNodesForSerialization(CKlaxScriptObject outerScriptObject)
        {
            CScriptSerializer.PrepareNodesForSerialization(m_nodes);
            Dictionary <CKlaxVariable, int> objectVariableToIndex = new Dictionary <CKlaxVariable, int>();

            for (var i = 0; i < outerScriptObject.KlaxVariables.Count; i++)
            {
                objectVariableToIndex.Add(outerScriptObject.KlaxVariables[i], i);
            }

            Dictionary <CKlaxVariable, int> localVariableToIndex = new Dictionary <CKlaxVariable, int>();

            for (int i = 0; i < m_localVariables.Count; i++)
            {
                localVariableToIndex.Add(m_localVariables[i], i);
            }

            for (int i = 0; i < m_nodes.Count; i++)
            {
                if (m_nodes[i] is CKlaxVariableNode variableNode)
                {
                    if (variableNode.SourceVariable == null)
                    {
                        throw new NullReferenceException("Tried to serialize a KlaxVariable node without a valid reference to an existing variable");
                    }

                    if (objectVariableToIndex.TryGetValue(variableNode.SourceVariable, out int index))
                    {
                        variableNode.m_sourceVariableIndex = index;
                        variableNode.m_bIsLocalVariable    = false;
                        continue;
                    }

                    if (localVariableToIndex.TryGetValue(variableNode.SourceVariable, out int localIndex))
                    {
                        variableNode.m_sourceVariableIndex = localIndex;
                        variableNode.m_bIsLocalVariable    = true;
                        continue;
                    }

                    throw new Exception("KlaxVariable Node Referenced a variable that does not exist in its context");
                }
            }
        }