Esempio n. 1
0
        public static bool SavePlayerData(PlayerData pd, PokemonEntityData ped)
        {
            FileStream     file = null;
            PlayerSaveData psd  = new PlayerSaveData
            {
                playerData        = pd,
                pokemonEntityData = ped,
                isValid           = true
            };

            try
            {
                BinaryFormatter bf = new BinaryFormatter();
                file = File.Create(Application.persistentDataPath + "/Players/" + psd.playerData.Name + ".dat");
                bf.Serialize(file, psd);
                return(true);
            }
            catch (Exception e)
            {
                if (e != null)
                {
                    //handle exception
                    Debug.LogError("Failed to save the player data" + e);
                }
            }
            finally
            {
                if (file != null)
                {
                    file.Close();
                }
            }
            return(false);
        }
Esempio n. 2
0
 public static PokemonEntityData[] GenerateBasePokemonEntityDatas(int[] exclude = null)
 {
     if (exclude == null)
     {
         exclude = new int[0];
     }
     PokemonEntityData[] pokemonEntityDatas = new PokemonEntityData[MaxPokedexNumber];
     for (int i = 1; i < MaxPokedexNumber; i++)
     {
         if (exclude != null && exclude.Length > 0)
         {
             //	if (exclude.Length > 0)
             //	{
             bool match = false;
             for (int j = 0; j < exclude.Length; j++)
             {
                 if (exclude[j] != i)
                 {
                     match = true; break;
                 }
             }
             if (!match)
             {
                 pokemonEntityDatas[i] = GenerateBasePokemonEntityData(i);
             }
             //	}
             //	else
         }
         else
         {
             pokemonEntityDatas[i] = GenerateBasePokemonEntityData(i);
         }
     }
     return(pokemonEntityDatas);
 }
Esempio n. 3
0
        //Pokemon Entity Data Related

        /// <summary>
        /// Returns Invalid PokemonEntityData (since the structs can't be null)
        /// </summary>
        /// <returns>PokemonEntityData</returns>
        public static PokemonEntityData CreateInvalidPokemonEntityData()
        {
            PokemonEntityData pokemonEntityData = new PokemonEntityData()
            {
                PokedexNumber = 0, Height = -1.0f
            };

            return(pokemonEntityData);
        }
Esempio n. 4
0
/*		/// <summary>
 *              /// Saves the EnviromentData
 *              /// </summary>
 *              /// <param name="enviromentData">Enviroment Data to save</param>
 *              /// <param name="position">Position</param>
 *              /// <param name="rotation">Rotation</param>
 *              /// <param name="scale">Scale</param>
 *              public static void SaveEnviromentData(EnviromentData enviromentData, Translation position, Rotation rotation,Scale scale)
 *              {
 *                      BinaryFormatter binaryFormatter = new BinaryFormatter();
 *                      string dataPath = Application.dataPath + "/Resources/Scenes/" + GetCurrentSceneName() + "/IEnviroment/" +
 *                              GenerateObjectName(GetObjectType(enviromentData.pathString)) + "/" + ByteString30ToString(enviromentData.entityId) + ".dat";
 *                      FileStream file = File.Open(dataPath, FileMode.OpenOrCreate);
 *                      EnviromentEntityDataSave enviromentEntityDataSave = new EnviromentEntityDataSave() {
 *                              EntityId = enviromentData.entityId,
 *                              EntityName = enviromentData.entityName,
 *                              EntityParentId = enviromentData.entityParentId,
 *                              PathString = enviromentData.pathString,
 *                              Position = position,
 *                              Rotation = rotation,
 *                              Scale = scale
 *                      };
 *                      binaryFormatter.Serialize(file, enviromentEntityDataSave);
 *                      file.Close();
 *              }
 *              /// <summary>
 *              /// generates a path based on the pathSring
 *              /// </summary>
 *              /// <param name="enviromentData">data to process</param>
 *              /// <returns></returns>
 *              public static string GenerateEnviromentPath(EnviromentData enviromentData)
 *              {
 *                      string a = "";
 *                      switch (enviromentData.pathString.A)
 *                      {
 *                              case 0: a += "Kanto/"; break;
 *                              default: PrintString("GenerateEnviromentPath", "unable to determine path A", 1); a += "Kanto"; break;
 *                      }
 *                      switch (enviromentData.pathString.B)
 *                      {
 *                              case 0: a += "Forest/"; break;
 *                              case 1: a += "Desert/"; break;
 *                              case 2: a += "Town/"; break;
 *                              default: PrintString("GenerateEnviromentPath", "unable to determine path B", 1); a += "Forest/"; break;
 *                      }
 *                      //uses Generate ObjectName
 *                      a += GenerateObjectName(enviromentData.pathString.C) + "/";
 *                      if (enviromentData.pathString.length > 3)
 *                      {
 *                              //town specific stuff
 *                              switch (enviromentData.pathString.D)
 *                              {
 *                                      case 0: a += "Buildings/"; break;
 *                                      case 1: a += "People/"; break;
 *                                      default: PrintString("GenerateEnviromentPath", "unable to determine path D", 1); a += "People/"; break;
 *                              }
 *                      }
 *                      return a;
 *              }
 *              /// <summary>
 *              /// Generates the stirng of the object type
 *              /// </summary>
 *              /// <param name="type">thing to be converted</param>
 *              /// <returns></returns>
 *              private static string GenerateObjectName(byte type)
 *              {
 *                      switch (type)
 *                      {
 *                              case 0: return "Landscapes";
 *                              case 1: return "Buildings";
 *                              case 255: return "PalletTown";
 *                              default: PrintString("GeneratePbjectType", "unable to determine object type woth byte \"" + type + "\"", 1); return "Landscapes";
 *                      }
 *              }
 *              /// <summary>
 *              /// returns the enviromentPath using the given Path string
 *              /// </summary>
 *              /// <param name="pathString">pathString to cbe heck</param>
 *              /// <returns></returns>
 *              public static byte GetEnviromentType(ByteString30 pathString) { return pathString.B; }
 *              /// <summary>
 *              /// returns the object type using the given path string
 *              /// </summary>
 *              /// <param name="pathString">pathStirng to be checked</param>
 *              /// <returns></returns>
 *              public static byte GetObjectType(ByteString30 pathString) { return pathString.C; }
 *              /// <summary>
 *              /// creates a new EnviromentDataEntity saves saves it in IEnviroment (For Dev Use Only)
 *              /// </summary>
 *              /// <param name="enviromentId">the id of the enviroment entity</param>
 *              /// <param name="enviromentName">the name</param>
 *              /// <param name="enviromentParentId">the id of the parent (if it ha one)</param>
 *              /// <param name="pathString">a path string see GenerateEnviromentPath for more explination</param>
 *              /// <param name="enviromentType">the type of enviroment</param>
 *              /// <param name="boundType">the type of bound
 *              /// <para>0 = floor   1 = wall   2 = roof   3= solid</para>
 *              /// </param>
 *              /// <param name="position">the position of the entity</param>
 *              /// <param name="rotation">the rotation of the eneity</param>
 *              /// <param name="scale">the scale of the eneity</param>
 *              public static void CreateNewEnviromentData(byte boundType, ByteString30 enviromentId, ByteString30 enviromentName, ByteString30 enviromentParentId, ByteString30 pathString,
 *                      Translation position = new Translation(), Rotation rotation = new Rotation(), Scale scale = new Scale())
 *              {
 *                      EnviromentData enviromentData = new EnviromentData()
 *                      {
 *                              BoundType = boundType,
 *                              entityId = enviromentId,
 *                              entityName = enviromentName,
 *                              entityParentId = enviromentParentId,
 *                              pathString = pathString,
 *                      };
 *                      //	if (scale.Value == 0f && scale.Value.y == 0f && scale.Value.z == 0f) scale.Value = new float3(0f,0f,0f);
 *                      SaveEnviromentData(enviromentData, position, rotation, scale);
 *              }
 */

        /// <summary>
        /// creates new Player Data
        /// </summary>
        /// <param name="pokemonName">Name of the  pokemon</param>
        /// <param name="playerId">player's name/Id</param>
        /// <param name="pokedexEntry"></param>
        /// <returns></returns>
        public static PlayerData CreateNewPlayerData(string playerId, PokemonEntityData pokemonEntityData, string pokemonName = "_00")
        {
            return(new PlayerData
            {
                Name = new ByteString30(playerId),
                PokemonName = new ByteString30(pokemonName),
//				PokemonEntityData = pokemonEntityData
            });
        }
Esempio n. 5
0
 protected override void OnUpdate()
 {
     //get entity array
     pokemonEntities = PokemonEntitySpawnQuery.ToEntityArray(Allocator.TempJob);
     for (int i = 0; i < pokemonEntities.Length; i++)
     {
         PhysicsCollider   pc     = EntityManager.GetComponentData <PhysicsCollider>(pokemonEntities[i]);
         PokemonEntityData ped    = EntityManager.GetComponentData <PokemonEntityData>(pokemonEntities[i]);
         PhysicsMass       pm     = EntityManager.GetComponentData <PhysicsMass>(pokemonEntities[i]);
         float             radius = calculateSphereRadius(pc.Value.Value.MassProperties.Volume);
         //		Debug.Log("Mass = " + ped.Mass + "InverseMAss = " + (1 / ped.Mass) + " inverseInertia ="+ (1/(0.4f*ped.Mass*(radius*radius))));
         EntityManager.SetComponentData <PhysicsMass>(pokemonEntities[i], new PhysicsMass
         {
             AngularExpansionFactor = pm.AngularExpansionFactor,
             Transform      = pm.Transform,
             InverseMass    = (1 / ped.Mass),
             InverseInertia = (1 / (0.4f * ped.Mass * (radius * radius)))
         });
         EntityManager.RemoveComponent(pokemonEntities[i], typeof(PokemonEntitySpawnData));
     }
     pokemonEntities.Dispose();
 }
Esempio n. 6
0
        public static void LoadPlayerData(EntityManager entityManager, Entity entity, string playerName)
        {
            FileStream     file = null;
            PlayerSaveData psd  = new PlayerSaveData {
            };

            try
            {
                BinaryFormatter bf = new BinaryFormatter();
                file = File.Open(Application.persistentDataPath + "/Players/" + playerName + ".dat", FileMode.Open);
                psd  = (PlayerSaveData)bf.Deserialize(file);
            }
            catch (Exception e)
            {
                if (e != null)
                {
                    //handle exception
                    Debug.LogError("Failed to load the player data");
                }
            }
            finally
            {
                if (file != null)
                {
                    file.Close();
                }
                if (psd.isValid)
                {
                    Debug.Log("Loading player data, name = '" + psd.playerData.Name + "' pokemon = '" + psd.playerData.PokemonName + "'");
                    string pokemonName = psd.playerData.PokemonName.ToString();
                    if (entityManager.HasComponent <PlayerData>(entity))
                    {
                        entityManager.SetComponentData(entity, psd.isValid ? psd.playerData : new PlayerData {
                            Name = new ByteString30(playerName), PokemonName = new ByteString30("Bulbasaur")
                        });
                    }
                    else
                    {
                        entityManager.AddComponentData(entity, psd.isValid ? psd.playerData : new PlayerData {
                            Name = new ByteString30(playerName), PokemonName = new ByteString30("Electrode")
                        });
                    }
                    LoadPokemonEntity(entity, entityManager, psd);
                }
                else
                {
                    Debug.LogWarning("Attempting to save new player data and reload");
                    string pokemonName = psd.playerData.PokemonName.ToString();
                    if (pokemonName == "")
                    {
                        pokemonName = "Electrode";
                    }
                    PlayerData pd = new PlayerData {
                        Name = new ByteString30(playerName), PokemonName = new ByteString30(pokemonName)
                    };
                    PokemonEntityData ped = PokemonDataClass.GenerateBasePokemonEntityData(PokemonDataClass.StringToPokedexEntry(pokemonName));
                    if (SavePlayerData(pd, ped))
                    {
                        LoadPlayerData(entityManager, entity, playerName);
                    }
                }
            }
        }
Esempio n. 7
0
        public static Entity GeneratePokemonEntity(CoreData cdata, EntityManager entityManager, quaternion rotation, float3 position = new float3(), float scale = 1f)
        {
            Debug.Log("Generating new pokemon!");
            Entity          entity;
            EntityArchetype ea = entityManager.CreateArchetype(
                typeof(Translation),
                typeof(Rotation),
                typeof(Scale),
                typeof(LocalToWorld),
                typeof(RenderMesh),
                typeof(PokemonCameraData),
                typeof(PokemonEntityData),
                typeof(PhysicsMass),
                typeof(PhysicsCollider),
                typeof(PhysicsVelocity),
                typeof(PhysicsDamping),
                typeof(GroupIndexInfo),
                typeof(UIComponent),
                typeof(CoreData)
                );

            entity = entityManager.CreateEntity(ea);
            entityManager.SetName(entity, cdata.Name.ToString());
            entityManager.SetComponentData(entity, new Scale {
                Value = scale
            });
            entityManager.SetComponentData(entity, new Rotation {
                Value = rotation
            });
            entityManager.SetComponentData(entity, new Translation {
                Value = position
            });
            entityManager.SetComponentData(entity, cdata);
            SetPokemonCameraData(cdata.BaseName, entity, entityManager);
            PokemonEntityData ped = GenerateBasePokemonEntityData(StringToPokedexEntry(cdata.BaseName.ToString()));

            SetPhysicsDamping(entityManager, entity, cdata.BaseName, ped);
            entityManager.SetComponentData(entity, ped);

            /*	NativeArray<CompoundCollider.ColliderBlobInstance> cc = new NativeArray<CompoundCollider.ColliderBlobInstance>(PokemonBaseColliderData[StringToPokedexEntry(cdata.BaseName.ToString())],Allocator.TempJob);
             *      PhysicsCollider pc = new PhysicsCollider{
             *              Value = CompoundCollider.Create(cc)
             *      };
             *      cc.Dispose();*/
            PhysicsCollider pc = getPokemonPhysicsCollider(cdata.BaseName.ToString(), ped, new CollisionFilter
            {
                BelongsTo    = TriggerEventClass.Collidable | TriggerEventClass.Pokemon,
                CollidesWith = TriggerEventClass.Collidable | TriggerEventClass.Pokemon,
                GroupIndex   = 1
            }, scale);

            entityManager.SetComponentData(entity, PhysicsMass.CreateDynamic(pc.MassProperties, ped.Mass));
            entityManager.SetComponentData(entity, pc);
            entityManager.SetComponentData(entity, new PhysicsVelocity {
                Angular = float3.zero, Linear = float3.zero
            });
            entityManager.SetComponentData(entity, new GroupIndexInfo {
                CurrentGroupIndex  = 1,
                OldGroupIndex      = 1,
                OriginalGroupIndex = 1,
                Update             = true
            });

            /*	entityManager.AddComponentData(entity, new GroupIndexChangeRequest
             *      {
             *              newIndexGroup = 1,
             *              pokemonName = cdata.BaseName
             *      });*/
            entityManager.AddComponentData <UIComponentRequest>(entity, new UIComponentRequest {
                addToWorld   = true,
                followPlayer = true,
                visible      = true
            });
            if (!SetRenderMesh(entityManager, entity, cdata.BaseName, 0))
            {
                return(new Entity());
            }
            return(entity);
        }
Esempio n. 8
0
        /// <summary>
        /// creates and returns the pokemoon's PhysicsCollider
        /// </summary>
        /// <param name="pokemonName">Name of the pokemon</param>
        /// <returns>PhysicsCollider</returns>
        public static PhysicsCollider getPokemonPhysicsCollider(string pokemonName, PokemonEntityData ped,
                                                                CollisionFilter collisionFilter = new CollisionFilter(), float scale = 1f, Unity.Physics.Material material = new Unity.Physics.Material(),
                                                                int groupIndex = 1)
        {
            ///FUTURE UPDATE
            ///allow specific colliders to recieve specific filters and materials!

            //needs collision groups
            PhysicsCollider physicsCollider = new PhysicsCollider {
            };
            Quaternion rotation             = new quaternion();

            //if default collision filter is detected then create one realted to the pokemon
            if (collisionFilter.Equals(new CollisionFilter()))
            {
                Debug.Log("Creating new Collision Filter");
                collisionFilter = new CollisionFilter
                {
                    BelongsTo    = TriggerEventClass.Pokemon | TriggerEventClass.Collidable,
                    CollidesWith = TriggerEventClass.Collidable,
                    GroupIndex   = groupIndex
                };
            }
            if (material.Equals(new Unity.Physics.Material()))
            {
                material = GetPokemonColliderMaterial(StringToPokedexEntry(pokemonName));
            }
            switch (pokemonName)
            {
            case "Cubone":
                var colliders = new NativeArray <CompoundCollider.ColliderBlobInstance>(5, Allocator.Temp);
                colliders[0] = new CompoundCollider.ColliderBlobInstance
                {
                    Collider = Unity.Physics.SphereCollider.Create(new SphereGeometry {
                        Center = new float3(0, 0.27f, 0.03f), Radius = 0.225f
                    }, collisionFilter, material),
                    CompoundFromChild = new RigidTransform {
                        pos = new float3 {
                            x = 0, y = 0, z = 0
                        }, rot = quaternion.identity
                    }
                };
                var a = GenerateCapsuleData(float3.zero, Vector3.right, 0.1f, 0.3f);
                rotation.SetFromToRotation(Vector3.right, new Vector3(0, 90f, 0));
                colliders[1] = new CompoundCollider.ColliderBlobInstance
                {
                    Collider = Unity.Physics.CapsuleCollider.Create(new CapsuleGeometry {
                        Vertex0 = a.pointA, Vertex1 = a.pointB, Radius = 0.1f
                    }, collisionFilter, material),
                    CompoundFromChild = new RigidTransform {
                        pos = new float3(-0.17f, 0.19f, 0), rot = rotation
                    }
                };
                colliders[2] = new CompoundCollider.ColliderBlobInstance
                {
                    Collider = Unity.Physics.CapsuleCollider.Create(new CapsuleGeometry {
                        Vertex0 = a.pointA, Vertex1 = a.pointB, Radius = 0.1f
                    }, collisionFilter, material),
                    CompoundFromChild = new RigidTransform {
                        pos = new float3(0.17f, 0.19f, 0), rot = rotation
                    }
                };
                colliders[3] = new CompoundCollider.ColliderBlobInstance
                {
                    Collider = Unity.Physics.SphereCollider.Create(new SphereGeometry {
                        Center = float3.zero, Radius = 0.23f
                    }, collisionFilter, material),
                    CompoundFromChild = new RigidTransform {
                        pos = new float3(0, 0.75f, 0.03f), rot = rotation
                    }
                };
                a            = GenerateCapsuleData(float3.zero, Vector3.right, 0.1f, 0.3f);
                rotation     = Quaternion.Euler(0, 90f, 26f);
                colliders[4] = new CompoundCollider.ColliderBlobInstance
                {
                    Collider = Unity.Physics.CapsuleCollider.Create(new CapsuleGeometry {
                        Vertex0 = a.pointA, Vertex1 = a.pointB, Radius = 0.1f
                    }, collisionFilter, material),
                    CompoundFromChild = new RigidTransform {
                        pos = new float3(0, 0.63f, 0.33f), rot = rotation
                    }
                };
                physicsCollider = new PhysicsCollider {
                    Value = CompoundCollider.Create(colliders)
                };
                if (scale > 1f)
                {
                    Debug.LogWarning("Cannot scale Cubone");
                }
                colliders.Dispose();
                break;

            case "Electrode":
                Debug.Log("Creating PHysicwsCollider for Electrode");
                physicsCollider = new PhysicsCollider {
                    Value = Unity.Physics.SphereCollider.Create(new SphereGeometry
                    {
                        Center = float3.zero,
                        Radius = ped.Height / 2 * scale
                    },
                                                                collisionFilter,
                                                                material
                                                                )
                };
                break;

            default:
                Debug.LogError("Failed to find collider for pokemon \"" + pokemonName + "\"");
                physicsCollider = new PhysicsCollider
                {
                    Value = Unity.Physics.SphereCollider.Create(new SphereGeometry
                    {
                        Center = float3.zero,
                        Radius = ped.Height / 2 * scale
                    },
                                                                collisionFilter,
                                                                material
                                                                )
                };
                break;
            }
            //		Debug.Log("Returning Physics Collide for \""+pokemonName+"\"");
            return(physicsCollider);
        }
Esempio n. 9
0
        public static bool SetPhysicsDamping(EntityManager entityManager, Entity entity, ByteString30 name, PokemonEntityData ped)
        {
            PhysicsDamping ps = new PhysicsDamping
            {
                Angular = 0.05f,
                Linear  = 0.01f
            };

            switch (name.ToString())
            {
            case "Electrode":
                ps = new PhysicsDamping
                {
                    Angular = 0.5f,
                    Linear  = 0.1f
                };
                break;

            default: Debug.LogError("failed to find PhysicsDamping for pokemon \"" + name + "\""); break;
            }
            try
            {
                if (entityManager.HasComponent <PhysicsDamping>(entity))
                {
                    entityManager.SetComponentData <PhysicsDamping>(entity, ps);
                }
                else
                {
                    entityManager.AddComponentData(entity, ps);
                }
                return(true);
            }
            catch
            {
                Debug.LogError("Failed to set AngularDamping!");
            }
            return(false);
        }