Beispiel #1
0
    /// <summary>
    /// Load player game
    /// Currently only player position
    /// </summary>
    /// <param name="saveName"></param>
    public void LoadGame(string saveName)
    {
        if (PlayerPrefs.HasKey("Savegames"))
        {
            string    allSavegamesString = PlayerPrefs.GetString("Savegames");
            Savegames allSavegames       = JsonUtility.FromJson <Savegames>(allSavegamesString);

            Savegame save = null;
            foreach (Savegame s in allSavegames.savegames)
            {
                if (s.name == saveName)
                {
                    save = s;
                }
            }

            if (save != null)
            {
                foreach (string s in save.itemsNamesInventory)
                {
                    _player.inventory.Add(GetItem(s));
                }
                foreach (string s in save.itemsNamesStock)
                {
                    _player.stock.Add(GetItem(s));
                }

                Vector3 position = save.position;
                GameObject.Find("PlayerController").transform.position = position;

                foreach (AnimalData ad in save.animals)
                {
                    AnimalBody concernedAnimal = GetAnimal(ad.name);
                    Food       eat             = GetItem(ad.eat) as Food;
                    int        happiness       = ad.happiness;
                    int        hunger          = ad.hunger;
                    Vector3    animalPosition  = ad.position;
                    Vector3    animalRotation  = ad.rotation;
                    string     wearStr         = ad.wear;
                    RareItem   wear            = null;
                    if (wearStr != null)
                    {
                        wear = GetItem(wearStr) as RareItem;
                    }
                    RareItem canWear = GetItem(ad.canWear) as RareItem;
                    concernedAnimal.animal.SetProperties(happiness, hunger, eat, wear, canWear);
                    concernedAnimal.transform.position = animalPosition;
                    concernedAnimal.transform.rotation = Quaternion.Euler(animalRotation);
                }
            }
        }
    }
Beispiel #2
0
    /// <summary>
    /// Get animal by his name
    /// </summary>
    /// <param name="name">Animal name</param>
    /// <returns></returns>
    public AnimalBody GetAnimal(string name)
    {
        AnimalBody res = null;

        foreach (AnimalBody ab in _animals)
        {
            if (ab.animal.name == name)
            {
                res = ab;
            }
        }
        return(res);
    }
    public void InitializeMe()
    {
        sensory = gameObject.GetComponent<AnimalSensory>();
        body = gameObject.GetComponent<AnimalBody>();
        brain = gameObject.GetComponent<AnimalBrain>();
        stateMachine = gameObject.GetComponent<AnimalStateMachine>();
        possesor = GameObject.FindGameObjectWithTag("Player").GetComponent<PhantomController>();
        moveSpeed = body.moveSpeed;
        isInitialized = true;

        if(stateMachine.myType == AnimalType.prairieDog)
            jumpController = gameObject.GetComponent<JumpController>();
    }
 void InitBodyControl(Vector3 spawn)
 {
     if (species == "Human")
     {
         animalBody  = new PrimateBody(this, spawn);
         motorSystem = new SimplePrimateMotorSystem(this);
     }
     else
     {
         animalBody = new AnimalBody(this, spawn);
     }
     body = animalBody;
     visualInputCamera = animalBody.GetGameObject().GetComponentInChildren <Camera>();
 }
Beispiel #5
0
    public MotorSystem(Animal passed)
    {
        thisAnimal    = passed;
        this.thisBody = thisAnimal.GetBody();

        stateLabelList = new List <string> {
            "take steps",   // 0
            "rotate",       // 1
            "sit down",     // 2
            "sit up",       // 3
            "stand up",     // 4
            "crouch",       // 5
            "lay down",     // 6
            "sleep",        // 7
            "rest",         // 8
            "look",         // 9
            "pick up",      // 10
            "consume",      // 11
            "index"
        };
        this.InitStates(stateLabelList);
        this.InitActionDict();
        this.numArgs = 4;
    }
Beispiel #6
0
 public StateMachine(AnimalBody animal)
 {
     _animal = animal;
     _isDead = false;
 }
Beispiel #7
0
 public AnimalStateMachine(AnimalBody animal) : base(animal)
 {
     _current = new StateWalking(this);
 }
Beispiel #8
0
 void Start()
 {
     myState = BehaviorState.idle;
     stateMachine = gameObject.GetComponent<AnimalStateMachine>();
     animator = gameObject.transform.FindChild("AnimatedChild").gameObject.GetComponent<Animator>();
     body = gameObject.GetComponent<AnimalBody>();
     foodMap = GameObject.FindGameObjectWithTag("Map").GetComponent<FoodMap>();
     animalMap = GameObject.FindGameObjectWithTag("Map").GetComponent<AnimalMap>();
     PrairieBrainStart(); //Only meaningful in the child class PrairieDogBrain
 }