Esempio n. 1
0
        internal List <INetworkedVar> GetDummyNetworkedVars()
        {
            List <INetworkedVar> networkedVars = new List <INetworkedVar>();

            FieldInfo[] sortedFields = GetFieldInfoForType(GetType());
            for (int i = 0; i < sortedFields.Length; i++)
            {
                Type fieldType = sortedFields[i].FieldType;
                if (fieldType.HasInterface(typeof(INetworkedVar)))
                {
                    INetworkedVar instance = null;
                    if (fieldType.IsGenericTypeDefinition)
                    {
                        Type genericType = fieldType.MakeGenericType(fieldType.GetGenericArguments());
                        instance = (INetworkedVar)Activator.CreateInstance(genericType, true);
                    }
                    else
                    {
                        instance = (INetworkedVar)Activator.CreateInstance(fieldType, true);
                    }
                    instance.SetNetworkedBehaviour(this);
                    networkedVars.Add(instance);
                }
            }
            return(networkedVars);
        }
Esempio n. 2
0
        internal void NetworkedVarInit()
        {
            if (networkedVarInit)
            {
                return;
            }
            networkedVarInit = true;

            FieldInfo[] sortedFields = GetFieldInfoForType(GetType());
            for (int i = 0; i < sortedFields.Length; i++)
            {
                Type fieldType = sortedFields[i].FieldType;
                if (fieldType.HasInterface(typeof(INetworkedVar)))
                {
                    INetworkedVar instance = (INetworkedVar)sortedFields[i].GetValue(this);
                    if (instance == null)
                    {
                        instance = (INetworkedVar)Activator.CreateInstance(fieldType, true);
                        sortedFields[i].SetValue(this, instance);
                    }

                    instance.SetNetworkedBehaviour(this);
                    networkedVarFields.Add(instance);
                }
            }

            //Create index map for channels
            Dictionary <string, int> firstLevelIndex = new Dictionary <string, int>();
            int secondLevelCounter = 0;

            for (int i = 0; i < networkedVarFields.Count; i++)
            {
                string channel = networkedVarFields[i].GetChannel(); //Cache this here. Some developers are stupid. You don't know what shit they will do in their methods
                if (!firstLevelIndex.ContainsKey(channel))
                {
                    firstLevelIndex.Add(channel, secondLevelCounter);
                    channelsForVarGroups.Add(channel);
                    secondLevelCounter++;
                }
                if (firstLevelIndex[channel] >= channelMappedVarIndexes.Count)
                {
                    channelMappedVarIndexes.Add(new HashSet <int>());
                }
                channelMappedVarIndexes[firstLevelIndex[channel]].Add(i);
            }
        }