Exemplo n.º 1
0
        public static void Save(string filename)
        {
            using (var st = System.IO.File.CreateText(filename))
            {
                foreach (var cvar in ConfigVars.Values)
                {
                    if ((cvar.flags & Flags.Save) == Flags.Save)
                    {
                        st.WriteLine("{0} \"{1}\"", cvar.name, cvar.Value);
                    }
                }

                DirtyFlags &= ~Flags.Save;
            }

            GameDebug.Log("saved: " + filename);
        }
Exemplo n.º 2
0
        public static AssetBundle LoadLevelAssetBundle(string name)
        {
            var bundle_pathname = GetRuntimeBundlePath() + "/" + name;

            GameDebug.Log("loading:" + bundle_pathname);

            var cacheKey = name.ToLower();

            AssetBundle result;

            if (!m_levelBundles.TryGetValue(cacheKey, out result))
            {
                result = AssetBundle.LoadFromFile(bundle_pathname);
                if (result != null)
                {
                    m_levelBundles.Add(cacheKey, result);
                }
            }

            return(result);
        }
Exemplo n.º 3
0
        public void Register(int entityId, Entity entity)
        {
            if (showInfo.IntValue > 0)
            {
                if (entityManager.HasComponent <Transform>(entity))
                {
                    GameDebug.Log("RepEntity REGISTER NetID:" + entityId + " Entity:" + entity + " GameObject:" +
                                  entityManager.GetComponentObject <Transform>(entity).name);
                }
                else
                {
                    GameDebug.Log("RepEntity REGISTER NetID:" + entityId + " Entity:" + entity);
                }
            }


            // Grow to make sure there is room for entity
            if (entityId >= replicatedData.Count)
            {
                var count     = entityId - replicatedData.Count + 1;
                var emptyData = new ReplicatedData();
                for (var i = 0; i < count; i++)
                {
                    replicatedData.Add(emptyData);
                }
            }

            GameDebug.Assert(replicatedData[entityId].Entity == Entity.Null, "ReplicatedData has entity set:{0}",
                             replicatedData[entityId].Entity);

            netSerializables.Clear();
            netPredicted.Clear();
            netInterpolated.Clear();

            //var go = entityManager.HasComponent<Transform>(entity)
            //    ? entityManager.GetComponentObject<Transform>(entity).gameObject
            //    : null;


            FindSerializers(entity);

            if (entityManager.HasComponent <EntityGroupChildren>(entity))
            {
                var buffer = entityManager.GetBuffer <EntityGroupChildren>(entity);
                for (var i = 0; i < buffer.Length; i++)
                {
                    var childEntity = buffer[i].Entity;
                    if (showInfo.IntValue > 0)
                    {
                        GameDebug.Log(" ReplicatedEntityChildren: " + i + " = " + childEntity);
                    }
                    FindSerializers(childEntity);
                }
            }

            var data = new ReplicatedData
            {
                Entity = entity,
                //      gameObject = go,
                SerializableArray = netSerializables.ToArray(),
                PredictedArray    = netPredicted.ToArray(),
                InterpolatedArray = netInterpolated.ToArray()
            };

            replicatedData[entityId] = data;
        }
Exemplo n.º 4
0
        private void FindSerializers(Entity entity)
        {
            // Add entity data handlers
            if (showInfo.IntValue > 0)
            {
                GameDebug.Log("  FindSerializers");
            }
            var componentTypes = entityManager.GetComponentTypes(entity);

            // Sort to ensure order when serializing components
            var typeArray = componentTypes.ToArray();

            Array.Sort(typeArray, (type1, type2) =>
                       string.Compare(type1.GetManagedType().Name, type2.GetManagedType().Name, StringComparison.Ordinal));

            var serializedComponentType   = typeof(IReplicatedState);
            var predictedComponentType    = typeof(IPredictedStateBase);
            var interpolatedComponentType = typeof(IInterpolatedStateBase);

            foreach (var componentType in typeArray)
            {
                var managedType = componentType.GetManagedType();

                if (!typeof(IComponentData).IsAssignableFrom(managedType))
                {
                    continue;
                }

                if (serializedComponentType.IsAssignableFrom(managedType))
                {
                    if (showInfo.IntValue > 0)
                    {
                        GameDebug.Log("   new SerializedComponentDataHandler for:" + managedType.Name);
                    }

                    var serializer = serializers.CreateNetSerializer(managedType, entityManager, entity, this);
                    if (serializer != null)
                    {
                        netSerializables.Add(serializer);
                    }
                }
                else if (predictedComponentType.IsAssignableFrom(managedType))
                {
                    var interfaceTypes = managedType.GetInterfaces();
                    foreach (var it in interfaceTypes)
                    {
                        if (it.IsGenericType)
                        {
                            var type = it.GenericTypeArguments[0];
                            if (showInfo.IntValue > 0)
                            {
                                GameDebug.Log("   new IPredictedDataHandler for:" + it.Name + " arg type:" + type);
                            }

                            var serializer =
                                serializers.CreatePredictedSerializer(managedType, entityManager, entity, this);
                            if (serializer != null)
                            {
                                netPredicted.Add(serializer);
                            }

                            break;
                        }
                    }
                }
                else if (interpolatedComponentType.IsAssignableFrom(managedType))
                {
                    var interfaceTypes = managedType.GetInterfaces();
                    foreach (var it in interfaceTypes)
                    {
                        if (it.IsGenericType)
                        {
                            var type = it.GenericTypeArguments[0];
                            if (showInfo.IntValue > 0)
                            {
                                GameDebug.Log("   new IInterpolatedDataHandler for:" + it.Name + " arg type:" + type);
                            }

                            var serializer =
                                serializers.CreateInterpolatedSerializer(managedType, entityManager, entity, this);
                            if (serializer != null)
                            {
                                netInterpolated.Add(serializer);
                            }

                            break;
                        }
                    }
                }
            }
        }