Exemplo n.º 1
0
    public GoToDynamicPointNode(Context _context, getPointDelegate _del) : base(_context)
    {
        getPoint = _del;

        catAgent = _context.parentCat.GetComponent <NavMeshAgent>();
        catAgent.stoppingDistance = 2F;
        catTransform = _context.parentCat.GetComponent <Transform>();
    }
Exemplo n.º 2
0
    // 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;
    }
Exemplo n.º 3
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;
    }