コード例 #1
0
    public Context(GameObject _parentCat, ref CatPersonality _personality, ref CatStats _stats, ref CatActivity _activity)
    {
        parentCat   = _parentCat;
        personality = _personality;
        stats       = _stats;
        activity    = _activity;

        //Debug.Log("In Context constructor: ");
        //Debug.Log(personality);
        //Debug.Log(stats);
        //Debug.Log(activity);
        //Debug.Log("Exiting Context constructor.");
    }
コード例 #2
0
ファイル: Cat.cs プロジェクト: kev-the-dev/CatSimulator
    // Start is called before the first frame update
    void Start()
    {
        last_autosave_time = 0F;
        // Initialize agent
        agent = GetComponent <NavMeshAgent>();
        // Initialize animator
        animator    = GameObject.Find("Cat_Model_Latest").GetComponent <Animator>();
        forced_walk = false;
        forced_sit  = false;

        // Cat position for petting / brushing
        inFrontOfUserPosition = new Vector3(0F, -0.5F, -6F);

        // Get the laser pointer GameObject
        laserPointer = GameObject.Find("Laser Pointer");
        // Get the laser pointer GameObject's attached script
        laserPointerScript = laserPointer.GetComponent <LaserPointer>();
        // Deactivate laser pointer game object to turn it off
        laserPointer.SetActive(false);
        // Cat is not on catnip
        on_catnip = false;

        // Get Buttons
        hand_button   = GameObject.Find("hand_button").GetComponent <Button>();
        brush_button  = GameObject.Find("brush_button").GetComponent <Button>();
        food_button   = GameObject.Find("food_button").GetComponent <Button>();
        laser_button  = GameObject.Find("laser_button").GetComponent <Button>();
        litter_button = GameObject.Find("litter_button").GetComponent <Button>();

        // Initialize listeners
        hand_button.onClick.AddListener(delegate { SelectTool(SelectedTool.HAND); });
        brush_button.onClick.AddListener(delegate { SelectTool(SelectedTool.BRUSH); });
        food_button.onClick.AddListener(delegate { SelectTool(SelectedTool.FOOD); });
        laser_button.onClick.AddListener(delegate { SelectTool(SelectedTool.LASER_POINTER); });
        litter_button.onClick.AddListener(delegate { SelectTool(SelectedTool.LITTER_SCOOPER); });

        // Initialize tool to none, then set as hand tool
        selected_tool = SelectedTool.NONE;
        SelectTool(SelectedTool.HAND);

        // Previous save should always exist (otherwise adoption center would be loaded)
        // If for some reason we got here, crash.
        if (!GameSave.Valid())
        {
            Debug.Log("LivingRoom loaded without a save! Quiting.");
#if UNITY_EDITOR
            UnityEditor.EditorApplication.isPlaying = false;
#else
            Application.Quit();
            return;
#endif
        }

        // Load previous save / adopted cat
        Load();

        // Start off idle
        activity = new CatActivity(CatActivityEnum.Idle);

        // Initialize variables needed by behavior tree nodes
        contextObject = new Context(gameObject, ref personality, ref stats, ref activity);
        getPointDelegate getPointDel = laserPointerScript.getLaserIntersectionPoint;
        waiting = false;
        rng     = new System.Random();

        // Construct the cat's behavior tree
        autonomousCatBehaviorTree = new BehaviorTree(new SelectorNode(contextObject,

                                                                      /* Energy Sequence */ new SequenceNode(contextObject,
                                                                                                             new CheckEnergyNode(contextObject),
                                                                                                             new SleepNode(contextObject, GameObject.Find("SleepingParticles"))
                                                                                                             ),
                                                                      /* Bladder Sequence */ new SequenceNode(contextObject,
                                                                                                              new CheckBladderNode(contextObject),
                                                                                                              new GoToObjectNode(contextObject, GameObject.Find("Litterbox")),
                                                                                                              new RelieveBladderNode(contextObject)
                                                                                                              ),
                                                                      /* Hunger Sequence */ new SequenceNode(contextObject,
                                                                                                             new CheckFullnessNode(contextObject),
                                                                                                             new CheckObjectStatusNode(contextObject, GameObject.Find("food_in_bowl")),
                                                                                                             new GoToObjectNode(contextObject, GameObject.Find("Food Bowl")),
                                                                                                             new EatNode(contextObject, GameObject.Find("food_in_bowl"))
                                                                                                             ),
                                                                      /* Chase Laser Pointer Sequence */ new SequenceNode(contextObject,
                                                                                                                          new CheckObjectStatusNode(contextObject, laserPointer),
                                                                                                                          new GoToDynamicPointNode(contextObject, getPointDel),
                                                                                                                          new ChaseLaserNode(contextObject)
                                                                                                                          ),
                                                                      /* Chase Toy Ball Sequence */ new SequenceNode(contextObject,
                                                                                                                     new CheckFunNode(contextObject),
                                                                                                                     new CoinFlipNode(contextObject, rng, 15F),
                                                                                                                     new CheckObjectStatusNode(contextObject, GameObject.Find("Toy Ball")),
                                                                                                                     new PlayNode(contextObject),
                                                                                                                     new GoToObjectNode(contextObject, GameObject.Find("Toy Ball"))
                                                                                                                     ),
                                                                      /* Chase Toy Mouse Sequence */ new SequenceNode(contextObject,
                                                                                                                      new WaitNode(contextObject, 5F),
                                                                                                                      new CheckFunNode(contextObject),
                                                                                                                      new CheckObjectStatusNode(contextObject, GameObject.Find("Mouse")),
                                                                                                                      new PlayNode(contextObject),
                                                                                                                      new GoToObjectNode(contextObject, GameObject.Find("Mouse"))
                                                                                                                      ),
                                                                      /* Wandering Sequence */ new SequenceNode(contextObject,
                                                                                                                new WaitNode(contextObject, 5F),
                                                                                                                new GoToRandomPointNode(contextObject),
                                                                                                                new IdleNode(contextObject)
                                                                                                                )
                                                                      )
                                                     );
        autonomousCatBehaviorTree.paused = false;

        userInteractionBehaviorTree = new BehaviorTree(new SequenceNode(contextObject,
                                                                        new GoToPointNode(contextObject, inFrontOfUserPosition),
                                                                        new FocusOnUserNode(contextObject, 7F)
                                                                        )
                                                       );
        userInteractionBehaviorTree.paused = true;


        // Initialize last update time to now
        last_update_time = Time.time;
    }
コード例 #3
0
    // Should be called at each update loop. Update cat stats based on time passing
    public void UpdateStats(ref CatStats stats, CatActivity activity, float dt)
    {
        // Update bond
        stats.Bond += dt * bond_increase_per_second * stats.bond_buff.Value;
        // TODO: lower bond if cat is extreamly unhappy?
        stats.Bond += dt * bond_increase_per_happieness_per_second * stats.bond_buff.Value;

        if (CatActivityEnum.BeingPet == activity.current)
        {
            stats.Bond += dt * bond_increase_when_being_pet_per_second * stats.bond_buff.Value;
        }

        // Update fullness
        if (CatActivityEnum.Eating == activity.current)
        {
            stats.Fullness += dt * fullness_increase_when_eating_per_second * stats.fullness_buff.Value;
        }
        else
        {
            stats.Fullness -= dt * fullness_decrease_per_second * stats.fullness_debuff.Value;
        }

        // Update energy
        if (CatActivityEnum.Sleeping == activity.current)
        {
            stats.Energy += dt * energy_increase_when_sleeping_per_second * stats.energy_buff.Value;
        }
        else
        {
            stats.Energy -= dt * energy_decrease_per_second * stats.energy_debuff.Value;
        }

        // Update fun
        if (CatActivityEnum.Playing == activity.current)
        {
            stats.Fun  += dt * fun_increase_when_playing_with_yarn_per_second * stats.fun_buff.Value;
            agent.speed = 7F;
        }
        else if (CatActivityEnum.FollowingLaser == activity.current)
        {
            stats.Fun  += dt * fun_increase_when_following_laser_per_second * stats.fun_buff.Value;
            agent.speed = 7F;
        }
        else if (CatActivityEnum.OnCatnip == activity.current)
        {
            stats.Fun  += dt * fun_increase_when_on_catnip_per_second * stats.fun_buff.Value;
            agent.speed = 7F;
        }
        else
        {
            stats.Fun  -= dt * fun_decrease_per_second * stats.fun_debuff.Value;
            agent.speed = 3.5F;
        }

        // Update hygiene
        if (CatActivityEnum.BeingBrushed == activity.current)
        {
            stats.Hygiene += dt * hygiene_increase_when_being_brushed_per_second * stats.hygiene_buff.Value * 0.5f;            //Added in 0.2 multiplier for brushing for VR Conversion :) 6/12/19
        }
        else
        {
            // If cat is using the litterbox, its hygiene stat decays twice as fast
            if (CatActivityEnum.UsingLitterbox == activity.current)
            {
                stats.hygiene_debuff.Value = 2;
                stats.Hygiene -= dt * hygiene_decrease_per_second * stats.hygiene_debuff.Value;
            }
            else
            {
                stats.hygiene_debuff.Value = CatStats.DEFAULT_BUFF_VALUE;
                stats.Hygiene -= dt * hygiene_decrease_per_second * stats.hygiene_debuff.Value;
            }
        }

        // Update bladder
        if (CatActivityEnum.UsingLitterbox == activity.current)
        {
            stats.Bladder += dt * bladder_increase_when_using_litter_box_per_second * stats.bladder_buff.Value;
        }
        else
        {               // If cat is eating, its bladder stat decays twice as fast
            if (CatActivityEnum.Eating == activity.current)
            {
                stats.bladder_debuff.Value = 2;
                stats.Bladder -= dt * bladder_decrease_per_second * stats.bladder_debuff.Value;
            }
            else
            {
                stats.bladder_debuff.Value = CatStats.DEFAULT_BUFF_VALUE;
                stats.Bladder -= dt * bladder_decrease_per_second * stats.bladder_debuff.Value;
            }
        }
    }
コード例 #4
0
    // Start is called before the first frame update
    void Start()
    {
        last_autosave_time = 0F;

        // Check if VR is detected
        if (XRDevice.isPresent)
        {
            Debug.Log("XR device detected.");
        }
        else
        {
            Debug.Log("XR device not detected.");
        }


        // Initialize agent
        agent = GetComponent <NavMeshAgent>();
        // Initialize animator
        animator    = GameObject.Find("Cat_Model_Latest").GetComponent <Animator>();
        forced_walk = false;
        forced_sit  = false;

        // Cat position for petting / brushing
        inFrontOfUserPosition = new Vector3(-0.24F, -0.42F, -7.84F);        //new Vector3(0F, -0.5F, -6F);

        // Get the laser pointer GameObject
        laserPointer = GameObject.Find("Laser Pointer");
        // Get the laser pointer GameObject's attached script
        laserPointerScript = laserPointer.GetComponent <LaserPointer>();
        // Deactivate laser pointer game object to turn it off
        laserPointer.SetActive(false);

        // Find brush and deactivate
        brush = GameObject.Find("Brush");
        brush.SetActive(false);

        // Cat is not on catnip
        on_catnip = false;

        // Get Buttons
        hand_button   = GameObject.Find("hand_button").GetComponent <Button>();
        brush_button  = GameObject.Find("brush_button").GetComponent <Button>();
        food_button   = GameObject.Find("food_button").GetComponent <Button>();
        laser_button  = GameObject.Find("laser_button").GetComponent <Button>();
        litter_button = GameObject.Find("litter_button").GetComponent <Button>();

        // Initialize listeners
        hand_button.onClick.AddListener(delegate { SelectTool(SelectedTool.HAND); });
        brush_button.onClick.AddListener(delegate { SelectTool(SelectedTool.BRUSH); });
        food_button.onClick.AddListener(delegate { SelectTool(SelectedTool.FOOD); });
        laser_button.onClick.AddListener(delegate { SelectTool(SelectedTool.LASER_POINTER); });
        litter_button.onClick.AddListener(delegate { SelectTool(SelectedTool.LITTER_SCOOPER); });

        // Initialize tool to none, then set as hand tool
        selected_tool = SelectedTool.NONE;
        SelectTool(SelectedTool.HAND);

        // Create completely new cat
        CreateNew();
        Save();

        // Start off idle
        activity = new CatActivity(CatActivityEnum.Idle);

        // Initialize variables needed by behavior tree nodes
        contextObject = new Context(gameObject, ref personality, ref stats, ref activity);
        getPointDelegate getPointDel = laserPointerScript.getLaserIntersectionPoint;

        waiting = false;
        rng     = new System.Random();

        // Construct the cat's behavior tree
        autonomousCatBehaviorTree = new BehaviorTree(new SelectorNode(contextObject,

                                                                      /* Energy Sequence */ new SequenceNode(contextObject,
                                                                                                             new CheckEnergyNode(contextObject),
                                                                                                             new SleepNode(contextObject, GameObject.Find("SleepingParticles"))
                                                                                                             ),
                                                                      /* Bladder Sequence */ new SequenceNode(contextObject,
                                                                                                              new CheckBladderNode(contextObject),
                                                                                                              new GoToObjectNode(contextObject, GameObject.Find("Litterbox")),
                                                                                                              new RelieveBladderNode(contextObject)
                                                                                                              ),
                                                                      /* Hunger Sequence */ new SequenceNode(contextObject,
                                                                                                             new CheckFullnessNode(contextObject),
                                                                                                             new CheckObjectStatusNode(contextObject, GameObject.Find("food_in_bowl")),
                                                                                                             new GoToObjectNode(contextObject, GameObject.Find("Food Bowl")),
                                                                                                             new EatNode(contextObject, GameObject.Find("food_in_bowl"))
                                                                                                             ),
                                                                      /* Chase Laser Pointer Sequence */ new SequenceNode(contextObject,
                                                                                                                          new CheckObjectStatusNode(contextObject, laserPointer),
                                                                                                                          new GoToDynamicPointNode(contextObject, getPointDel),
                                                                                                                          new ChaseLaserNode(contextObject)
                                                                                                                          ),
                                                                      /* Chase Toy Ball Sequence */ new SequenceNode(contextObject,
                                                                                                                     new CheckFunNode(contextObject),
                                                                                                                     new CoinFlipNode(contextObject, rng, 15F),
                                                                                                                     new CheckObjectStatusNode(contextObject, GameObject.Find("Toy Ball")),
                                                                                                                     new PlayNode(contextObject),
                                                                                                                     new GoToObjectNode(contextObject, GameObject.Find("Toy Ball"))
                                                                                                                     ),
                                                                      /* Chase Toy Mouse Sequence */ new SequenceNode(contextObject,
                                                                                                                      new WaitNode(contextObject, 5F),
                                                                                                                      new CheckFunNode(contextObject),
                                                                                                                      new CheckObjectStatusNode(contextObject, GameObject.Find("Mouse")),
                                                                                                                      new PlayNode(contextObject),
                                                                                                                      new GoToObjectNode(contextObject, GameObject.Find("Mouse"))
                                                                                                                      ),
                                                                      /* Wandering Sequence */ new SequenceNode(contextObject,
                                                                                                                new WaitNode(contextObject, 5F),
                                                                                                                new GoToRandomPointNode(contextObject),
                                                                                                                new IdleNode(contextObject)
                                                                                                                )
                                                                      )
                                                     );
        autonomousCatBehaviorTree.paused = false;

        userInteractionBehaviorTree = new BehaviorTree(new SequenceNode(contextObject,
                                                                        new GoToObjectNode(contextObject, Camera.main.gameObject),
                                                                        new FocusOnUserNode(contextObject, 7F)
                                                                        )
                                                       );
        userInteractionBehaviorTree.paused = true;


        // Initialize last update time to now
        last_update_time = Time.time;
    }