Inheritance: MonoBehaviour
Beispiel #1
0
 public Node NPCBehavior_ApproachAndCheerMusic(Transform location, NPCBehavior performer)
 {
     return(new Sequence(
                NPCBehavior_ApproximateArea(location),
                NPCBehavior_OrientTowards(performer.transform.position),
                NPCBehavior_LookAt(performer.transform, true),
                new DecoratorLoop(
                    new Sequence(
                        new LeafAssert(() => {
         return performer.InEvent;
     }),
                        new SequenceShuffle(
                            new NodeWeight(0.4f, new Sequence(
                                               NPCBehavior_DoGesture(GESTURE_CODE.CLAP, true),
                                               new LeafWait(5000),
                                               NPCBehavior_DoGesture(GESTURE_CODE.CLAP, false)
                                               )
                                           ),
                            new NodeWeight(0.3f, new Sequence(
                                               NPCBehavior_DoGesture(GESTURE_CODE.MUSIC_HEADBANG, true),
                                               new LeafWait(5000),
                                               NPCBehavior_DoGesture(GESTURE_CODE.MUSIC_HEADBANG, false)
                                               )
                                           ),
                            new NodeWeight(0.8f, NPCBehavior_DoGesture(GESTURE_CODE.HURRAY)),
                            new NodeWeight(0.8f, NPCBehavior_DoGesture(GESTURE_CODE.GREET_AT_DISTANCE))
                            )
                        )
                    ),
                NPCBehavior_LookAt(performer.transform, false)
                ));
 }
Beispiel #2
0
 public void InitializeModule()
 {
     g_BehaviorAgent     = GetComponent <NPCBehavior>();
     g_Camera            = Camera.main.transform;
     g_MouseLastPosition = Input.mousePosition;
     g_Camera.forward    = Vector3.Normalize(
         g_NPCController.GetTransform().position - g_Camera.position + new Vector3(0, CameraTargetHeight, 0));
     CameraOffset = Camera.main.transform.position - g_NPCController.GetTransform().position;
     StartCoroutine(MenuListener());
     if (InteractionsPanel != null)
     {
         foreach (Image go in InteractionsPanel.GetComponents <Image>())
         {
             Color c = go.color;
             c.a     -= 0.05f;
             go.color = c;
         }
         InteractionsPanel.SetActive(false);
         g_InteractionsMap = new Dictionary <GameObject, InteractionMapping>();
         foreach (InteractionMapping im in InteractionsMap)
         {
             g_InteractionsMap.Add(im.InteractionIcon, im);
         }
     }
     g_Initialized = true;
 }
Beispiel #3
0
    public Node NPCBehavior_CasualConversation(NPCBehavior agentA, NPCBehavior agentB)
    {
        return(new Sequence(
                   agentB.NPCBehavior_GoToAtDistance(agentA.transform, 1.5f, false),
                   agentB.NPCBehavior_OrientTowards(agentA.transform),
                   agentB.NPCBehavior_LookAt(agentA.transform, true),
                   agentB.NPCBehavior_DoGesture(GESTURE_CODE.WAVE_HELLO),
                   agentA.NPCBehavior_OrientTowards(agentB.transform),
                   agentA.NPCBehavior_LookAt(agentB.transform, true),
                   new DecoratorLoop(
                       new SelectorParallel(
                           new SequenceShuffle(
                               agentA.NPCBehavior_DoGesture(GESTURE_CODE.TALK_SHORT),
                               agentB.NPCBehavior_DoGesture(GESTURE_CODE.TALK_LONG),
                               agentA.NPCBehavior_DoGesture(GESTURE_CODE.ACKNOWLEDGE),
                               agentA.NPCBehavior_DoGesture(GESTURE_CODE.HURRAY),
                               agentA.NPCBehavior_DoGesture(GESTURE_CODE.DRUNK)
                               ),
                           new SequenceShuffle(
                               agentA.NPCBehavior_DoGesture(GESTURE_CODE.PHONEME_A),
                               agentB.NPCBehavior_DoGesture(GESTURE_CODE.PHONEME_E),
                               agentA.NPCBehavior_DoGesture(GESTURE_CODE.PHONEME_O),
                               agentA.NPCBehavior_DoGesture(GESTURE_CODE.PHONEME_U),
                               agentA.NPCBehavior_DoGesture(GESTURE_CODE.PHONEME_P)
                               )
                           )

                       ),
                   agentB.NPCBehavior_LookAt(null, false),
                   agentA.NPCBehavior_LookAt(null, false),
                   agentB.NPCBehavior_DoGesture(GESTURE_CODE.WAVE_HELLO)
                   ));
    }
Beispiel #4
0
    void Tick()
    {
        if (npcNew && specialSO)
        {
            specialSO.dead = true;
            Destroy(npcNew);
        }
        if (objNew)
        {
            Destroy(objNew);
        }
        if (specialSO && specialSO.dead && specialSO.unitStatus == UnitStatus.People)
        {
            specialSO.unitStatus = UnitStatus.Empty;
        }
        lostSO.units.Remove(specialSO);

        // get random special
        //CopyUnitSO(RandomUnit(lostSO), specialSO);
        if (lostSO.units.Count != 0)
        {
            specialSO = RandomUnit(lostSO);
            showSO.units.Clear();
            showSO.units.Add(specialSO);
            specialSO.unitStatus = UnitStatus.Empty;

            // random and create npc movement;
            NPCBehavior npcBe = npc.GetComponent <NPCBehavior>();
            npcBe.unitSO = specialSO;
            RandomNewNPC(npcBe.npcSO);
            npcNew = Instantiate(npc);

            headIconUI.unitSO_test = specialSO;
            headIconUI.currentNPC  = npcNew;

            headIconUI.enabled = true;

            // create obj
            obj.GetComponent <ObjectBehavior>().unitSO   = specialSO;
            obj.GetComponent <ObjectBehavior>().mapPanel = mapPanel;
            mapPanel.GetComponent <MapPanel>().isChanged = true;

            objSpawner.GetComponent <CharacterItemsSpawner>().npcSO  = npcBe.npcSO;
            objSpawner.GetComponent <CharacterItemsSpawner>().soList = new UnitSO[] { specialSO };

            tempSpawner = Instantiate(objSpawner);
            GlobalControl.Instance.objPos = tempSpawner.GetComponent <CharacterItemsSpawner>().InstancedCharacterItemList[0].position;

            objTemplete.GetComponent <ObjectBehavior>().unitSO   = specialSO;
            objTemplete.GetComponent <ObjectBehavior>().mapPanel = mapPanel;
            mapPanel.GetComponent <MapPanel>().isChanged         = true;


            GameObject tempObj = Instantiate(objTemplete, GlobalControl.Instance.objPos, objTemplete.transform.rotation);
            Debug.Log(tempObj);
        }
    }
Beispiel #5
0
 void Start()
 {
     //StartCoroutine(StartCountdown());
     npcBehavior     = npcScript.GetComponent <NPCBehavior>();
     designerChanges = designerScript.GetComponent <DesignerChanges>();
     //countdownTime = designerChanges.guestNeedsInterval;
     InvokeRepeating("GuestNeeds", 0, designerChanges.guestSpawnRate);
     //npcScript = GameObject.Find("NPC");
 }
 public void Release()
 {
     if (this.npcEvent != null)
     {
         this.npcEvent.Release();
         this.npcEvent = null;
     }
     Object.Destroy(this);
 }
 public void Init(int id, int modelID, NPCBehavior theNPCEvent)
 {
     this.npcEvent = theNPCEvent;
     base.get_gameObject().SetActive(true);
     base.get_gameObject().set_name(id.ToString());
     if (this.npcEvent != null)
     {
         this.npcEvent.Init(id, modelID, base.get_transform());
     }
 }
Beispiel #8
0
    public ActorNPC CreateNPC(int id, int modelID, NPCBehavior npcEvent)
    {
        GameObject gameObject = new GameObject();

        UGUITools.ResetTransform(gameObject.get_transform(), NPCPool.Instance.root.get_transform());
        ActorNPC actorNPC = gameObject.AddUniqueComponent <ActorNPC>();

        actorNPC.Init(id, modelID, npcEvent);
        this.npcLogicList.Add(actorNPC);
        return(actorNPC);
    }
Beispiel #9
0
 private void Start()
 {
     movement = GetComponent <Movement>();
     behavior = GetComponent <NPCBehavior>();
     if (!isTrainer)
     {
         sight = 0;
     }
     else
     {
         hasBattled = false;
     }
 }
Beispiel #10
0
    // Start is called before the first frame update
    void Start()
    {
        m_RedButton.onClick.AddListener(RedButtonClick);
        m_BlueButton.onClick.AddListener(BlueButtonClick);
        m_GreenButton.onClick.AddListener(GreenButtonClick);
        playerInteraction = playerScript.GetComponent <PlayerInteraction>();

        if (npcBehavior != null)
        {
            npcBehavior = npcScript.GetComponent <NPCBehavior>();
        }
        npcSpawning     = spawningScript.GetComponent <NPCSpawning>();
        designerChanges = designerScript.GetComponent <DesignerChanges>();
        //npcScript = GameObject.Find("NPC");
        npcSpawning.guest = GameObject.FindGameObjectsWithTag("NPC");
    }
Beispiel #11
0
    public NPCBehavior CreateNPC(uint sceneid, string uid, int entityType, GameObject go)
    {
        NPCBehavior npc = go.GetComponent <NPCBehavior>();

        if (npc == null)
        {
            npc = go.AddComponent <NPCBehavior>();
        }
        entityBehaviors.Add(uid, npc);
        npc.uid        = uid;
        npc.entityType = entityType;
        npc.sceneid    = sceneid;

        npc.OnNewObject();
        return(npc);
    }
Beispiel #12
0
    private void Start()
    {
        designerScript    = GameObject.Find("Designer Changes");
        playerInteraction = playerScript.GetComponent <PlayerInteraction>();
        npcBehavior       = npcScript.GetComponent <NPCBehavior>();
        cd = cdScript.GetComponent <Countdown>();
        designerChanges = designerScript.GetComponent <DesignerChanges>();


        // InvokeRepeating("NPCSpawn", 0, designerChanges.guestSpawnRate);

        m_RedButton.onClick.AddListener(RedButtonClick);
        m_BlueButton.onClick.AddListener(BlueButtonClick);
        m_GreenButton.onClick.AddListener(GreenButtonClick);
        //buttonParent.SetActive(false);
    }
Beispiel #13
0
    // when the bullet hits something, this is what you do.
    void OnBulletHit(RaycastHit hit)
    {
        GameObject hitObject = hit.transform.gameObject;

        if (hitObject.name == "Agent(Clone)")
        {
            NPCBehavior NPC = hitObject.GetComponent <NPCBehavior>();
            //NPC =
            NPC.turnFrozen();
            NPC.setTargetNodeFrozen();
            Debug.Log("freeze");
        }

        if (hitObject.tag == "Wall")
        {
            Destroy(gameObject);
        }
    }
    // Update is called once per frame
    void Update()
    {
        //CHECK INTERACTION
        if (!paused && !dPanel.activeSelf && !interacting)                                                              // Interactions can only happen if the game is 1. Not Paused, 2. Textbox is not open, or 3. Not already Interacting,
        {
            if (Input.GetButtonDown("Fire1"))                                                                           //Currently Mouse1
            {
                if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, 40.0f)) //Sends a ray 40.0f forward out of the player to check for NPCS
                {
                    if (hit.collider != null)                                                                           //if an NPC has been interacted with, then tell it that it has been interactedWith
                    {
                        colObj = hit.collider.gameObject.GetComponent <NPCBehavior>();                                  //get NPC's script.
                        colObj.interactedWith = true;                                                                   //See NPCBehavior for how this works
                        interacting           = true;                                                                   //begin NPC cooldown
                    }
                }
            }
        }
        if (interacting && !dPanel.activeSelf) //NPC COOLDOWN SCRIPT.
        {                                      // two seconds until the player can talk to another NPC
            timeLeft -= Time.deltaTime;
            if (timeLeft <= 0.0)
            {
                timeLeft    = 2.0f;
                interacting = false;
            }
        }


        //MOVEMENT
        if (!paused && !dPanel.activeSelf)                  //Only move if 1. Not Paused, 2. Textbox is Not open.
        {
            float horizontal = Input.GetAxis("Horizontal"); //Horizontal and Vertical movement axis. Uses WASD/ULDR
            float vertical   = Input.GetAxis("Vertical");

            Vector3 move = new Vector3(horizontal, 0.0f, vertical); //movement vector
            if (horizontal != 0 || vertical != 0)                   //Odd glitch where the player shuffles after stopping. Fix this if possible
            {
                transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(move), 0.15F);
            }

            transform.Translate(move * movespeed * Time.deltaTime, Space.World); //actually moving character
        }
    }
Beispiel #15
0
    public void Register(GameObject g)
    {
        //find the first room with null occupant and put this gameobject into that slot
        List <KeyValuePair <GameObject, GameObject> > kvps = new List <KeyValuePair <GameObject, GameObject> >(POIs);

        foreach (KeyValuePair <GameObject, GameObject> kvp in kvps)
        {
            if (kvp.Value == null)
            {
                POIs[kvp.Key] = g;
                NPCBehavior npc = POIs[kvp.Key].GetComponent <NPCBehavior>();
                if (npc != null)
                {
                    npc.SetNavTarget(kvp.Key.transform);
                }
                break;
            }
        }
    }
 static int CreateNPC(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 5);
         EntityBehaviorMgr obj       = (EntityBehaviorMgr)ToLua.CheckObject(L, 1, typeof(EntityBehaviorMgr));
         uint   arg0                 = (uint)LuaDLL.luaL_checknumber(L, 2);
         string arg1                 = ToLua.CheckString(L, 3);
         int    arg2                 = (int)LuaDLL.luaL_checknumber(L, 4);
         UnityEngine.GameObject arg3 = (UnityEngine.GameObject)ToLua.CheckUnityObject(L, 5, typeof(UnityEngine.GameObject));
         NPCBehavior            o    = obj.CreateNPC(arg0, arg1, arg2, arg3);
         ToLua.Push(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Beispiel #17
0
 void OnTriggerExit(Collider other)
 {
     if (other.tag == "NPC")
     {
         triggering    = false;
         triggeringNpc = null;
         npcScript     = null;
         buttons.nPC   = null;
         npcBehavior   = null;
     }
     if (other.tag == "Table")
     {
         triggeringTable = false;
         triggeringNpc   = null;
     }
     if (other.tag == "Music")
     {
         triggeringMusic = false;
         triggeringNpc   = null;
     }
 }
Beispiel #18
0
 private void Start()
 {
     playerAndObstacleLayerMask = LayerMask.GetMask("Player", "Obstacle");
     movableObj        = GetComponent <MovableObjectScript>();
     behavior          = GetComponent <NPCBehavior>();
     stateToUpdateDict = new Dictionary <TrackingState, Action> {
         { TrackingState.ROAMING, Roam },
         { TrackingState.APPROACHING, Approach },
         { TrackingState.BEHAVING, this.behavior.Behave }
     };
     stateToInitDict = new Dictionary <TrackingState, Action> {
         { TrackingState.ROAMING, () => { } },
         { TrackingState.APPROACHING, () => { } },
         { TrackingState.BEHAVING, this.behavior.Init }
     };
     stateToExitDict = new Dictionary <TrackingState, Action> {
         { TrackingState.ROAMING, () => {} },
         { TrackingState.APPROACHING, () => {} },
         { TrackingState.BEHAVING, this.behavior.Exit }
     };
 }
Beispiel #19
0
 void OnTriggerEnter(Collider other)
 {
     if (other.tag == "NPC")
     {
         triggering           = true;
         triggeringNpc        = other.gameObject;
         redButtonText.text   = designerChanges.redButtonFoodText;
         blueButtonText.text  = designerChanges.blueButtonFoodText;
         greenButtonText.text = designerChanges.greenButtonFoodText;
         buttons.nPC          = other.gameObject;
         npcBehavior          = other.gameObject.GetComponent <NPCBehavior>();
         npcScript            = other.gameObject;
     }
     if (other.tag == "NPC" && npcBehavior.needsConvo == true || other.tag == "NPC" && npcBehavior.npcState == 2)
     {
         triggering           = true;
         triggeringNpc        = other.gameObject;
         redButtonText.text   = designerChanges.redButtonConversationText;
         blueButtonText.text  = designerChanges.blueButtonConversationText;
         greenButtonText.text = designerChanges.greenButtonConversationText;
     }
     if (other.tag == "Table")
     {
         triggeringTable      = true;
         triggeringNpc        = other.gameObject;
         redButtonText.text   = designerChanges.redButtonTableText;
         blueButtonText.text  = designerChanges.blueButtonTableText;
         greenButtonText.text = designerChanges.greenButtonTableText;
     }
     if (other.tag == "Music")
     {
         triggeringMusic      = true;
         triggeringNpc        = other.gameObject;
         redButtonText.text   = designerChanges.redButtonMusicText;
         blueButtonText.text  = designerChanges.blueButtonMusicText;
         greenButtonText.text = designerChanges.greenButtonMusicText;
     }
 }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetButton("Run") && !isRunning)
        {
            isRunning = true;
        }

        if (Input.GetButtonUp("Run"))
        {
            isRunning = false;
        }

        Vector3 Movement = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));

        if (((Mathf.Abs(Input.GetAxis("Horizontal")) > 0 || Mathf.Abs(Input.GetAxis("Vertical")) > 0) && !isJumping))
        {
            animationController.SetInteger("State", 1);

            isDancing = false;
            if (isRunning)
            {
                animationController.SetInteger("State", 3);
            }
            else
            {
            }
        }
        else if (!isJumping && !isDancing)
        {
            animationController.SetInteger("State", 0);
            isDancing = true;
            if (isOnTable && !dancedOnTable)
            {
                yaySoundPlayer.GetComponent <AudioSource>().Play();
                gameController.incrementHype(20);

                dancedOnTable = true;
            }
        }

        Vector3 camF = Camera.main.transform.forward;
        Vector3 camR = Camera.main.transform.right;

        camF.y = 0;
        camR.y = 0;
        camF   = camF.normalized;
        camR   = camR.normalized;

        Movement = Vector3.ClampMagnitude(Movement, 1);

        if (isRunning)
        {
            this.transform.position += (camF * Movement.y + camR * Movement.x) * (walkSpeed + 3f) * Time.deltaTime;
        }
        else
        {
            this.transform.position += (camF * Movement.y + camR * Movement.x) * walkSpeed * Time.deltaTime;
        }

        if (Mathf.Abs(Input.GetAxis("Vertical")) > 0 || Mathf.Abs(Input.GetAxis("Horizontal")) > 0)
        {
            transform.rotation = Quaternion.LookRotation((camF * Movement.y + camR * Movement.x));
        }

        if (Input.GetButtonDown("Interact"))
        {
            if (nearMicrowave && !isHoldingItem)
            {
                isHoldingItem = true;
                pizza.SetActive(true);
                hasPizza = true;
            }
            else if (nearFridge && !isHoldingItem)
            {
                isHoldingItem = true;
                beer.SetActive(true);
                hasBeer = true;
            }

            if (nearBanana)
            {
                bananaSuit.SetActive(true);
                bananaInCloset.SetActive(false);
            }

            if (nearNPC && isHoldingItem)
            {
                NPCBehavior nPCBehavior = NPC.GetComponent <NPCBehavior>();
                nPCBehavior.interact();
                if (nPCBehavior == null)
                {
                    Debug.Log("npc behavior is null");
                }
                isHoldingItem = false;
                hasPizza      = false;
                hasBeer       = false;
                pizza.SetActive(false);
                beer.SetActive(false);
                gameController.incrementHype(20);
            }
        }

        if (Input.GetButtonDown("Jump") && !isJumping)
        {
            isJumping = true;
            this.GetComponent <Rigidbody>().AddForce(transform.up * 5, ForceMode.Impulse);
            Debug.Log("Jump");
            animationController.SetInteger("State", 2);
            isDancing = false;
        }
    }
Beispiel #21
0
 public Node NPCBehavior_SimpleFollow(Transform leader, NPCBehavior member)
 {
     return(new Sequence(
                NPCBehavior_Follow(leader, false)
                ));
 }
 public SelectionStoryDialog(NPCBehavior npc, string text, SelectionResult resultRef, string[] options)
     : base(npc, text, true)
 {
     this.resultRef = resultRef;
     this.options = options;
 }
Beispiel #23
0
 public StoryDialog(NPCBehavior npc, string text)
     : this(npc, text, false)
 {
 }
Beispiel #24
0
 public StoryDialog(NPCBehavior npc, string text, bool disableNext)
 {
     this.npc = npc;
     this.text = text;
     this.disableNext = disableNext;
 }