Esempio n. 1
0
    private static SharedVariable BytesToSharedVariable(FieldSerializationData fieldSerializationData, Dictionary <string, int> fieldIndexMap, byte[] bytes, int dataPosition, IVariableSource variableSource, bool fromField, string namePrefix)
    {
        SharedVariable sharedVariable = null;
        string         text           = (string)LoadField(fieldSerializationData, fieldIndexMap, typeof(string), namePrefix + "Type", null);

        if (string.IsNullOrEmpty(text))
        {
            return(null);
        }
        string name  = (string)LoadField(fieldSerializationData, fieldIndexMap, typeof(string), namePrefix + "Name", null);
        bool   flag  = Convert.ToBoolean(LoadField(fieldSerializationData, fieldIndexMap, typeof(bool), namePrefix + "IsShared", null, null, null));
        bool   flag2 = Convert.ToBoolean(LoadField(fieldSerializationData, fieldIndexMap, typeof(bool), namePrefix + "IsGlobal", null, null, null));

        if (flag && fromField)
        {
            if (!flag2)
            {
                sharedVariable = variableSource.GetVariable(name);
            }
            else
            {
                if (globalVariables == null)
                {
                    globalVariables = GlobalVariables.Instance;
                }
                if (globalVariables != null)
                {
                    sharedVariable = globalVariables.GetVariable(name);
                }
            }
        }
        Type typeWithinAssembly = TaskUtility.GetTypeWithinAssembly(text);

        if (typeWithinAssembly == null)
        {
            return(null);
        }
        bool flag3 = true;

        if (sharedVariable == null || !(flag3 = sharedVariable.GetType().Equals(typeWithinAssembly)))
        {
            sharedVariable             = (TaskUtility.CreateInstance(typeWithinAssembly) as SharedVariable);
            sharedVariable.Name        = name;
            sharedVariable.IsShared    = flag;
            sharedVariable.IsGlobal    = flag2;
            sharedVariable.NetworkSync = Convert.ToBoolean(LoadField(fieldSerializationData, fieldIndexMap, typeof(bool), namePrefix + "NetworkSync", null));
            if (!flag2)
            {
                sharedVariable.PropertyMapping      = (string)LoadField(fieldSerializationData, fieldIndexMap, typeof(string), namePrefix + "PropertyMapping", null);
                sharedVariable.PropertyMappingOwner = (GameObject)LoadField(fieldSerializationData, fieldIndexMap, typeof(GameObject), namePrefix + "PropertyMappingOwner", null);
                sharedVariable.InitializePropertyMapping(variableSource as BehaviorSource);
            }
            if (!flag3)
            {
                sharedVariable.IsShared = true;
            }
            LoadFields(fieldSerializationData, fieldIndexMap, sharedVariable, namePrefix, variableSource);
        }
        return(sharedVariable);
    }