예제 #1
0
        void Clicked()
        {
            var        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit = new RaycastHit();

            if (Physics.Raycast(ray, out hit))
            {
                moveTowards = hit.point;
            }

            GameObject newNPC = Instantiate(Resources.Load <GameObject>("NPC/test_001"), hit.point, new Quaternion(0, 0, 0, 0));

            MoveStep ms = new MoveStep();

            ms.pointName = newNPC.name;
        }
예제 #2
0
        void RandomNPC()
        {
            NPCAction randomAction = new NPCAction();

            var            numSteps = Random.Range(5, 25);
            List <NPCStep> steps    = new List <NPCStep>();

            // Initial Wait Step
            WaitStep initialWait = new WaitStep();

            initialWait.seconds = Random.Range(1, 2);

            steps.Add(initialWait);

            for (int i = 0; i < numSteps; i++)
            {
                // Move Step
                if (Random.Range(0, 2) == 0 || i == 0)
                {
                    // TODO: System for somewhat prioritizing another point in the same cluster for the next move or two

                    MoveStep moveStep = new MoveStep();
                    moveStep.pointName = npcPointNames[Random.Range(0, npcPointNames.Count)];

                    steps.Add(moveStep);
                }

                // Wait Step
                else
                {
                    WaitStep waitStep = new WaitStep();
                    waitStep.seconds = Random.Range(1, 300);

                    steps.Add(waitStep);
                }
            }

            WaitStep finalWait = new WaitStep();

            finalWait.seconds = Random.Range(1, 301);
            steps.Add(finalWait);
            randomAction.steps = steps;
            randomAction.reqs  = new Dictionary <int, string>();

            SpawnNPC(randomAction, true, finalWait.seconds % 2 == 0 ? true : false);
        }
예제 #3
0
        void LoopStep()
        {
            if (currStep is MoveStep)
            {
                MoveStep ms = (MoveStep)currStep;

                //var distToDest = Vector3.Distance(npcTransform.position, ziggyPoints[0]);
                //float distTest = navMeshAgent.remainingDistance;

                //Debug.Log(navMeshAgent.remainingDistance);

                // TODO
                // if (distToDest <= 1.0f)
                //if (navMeshAgent.remainingDistance <= navMeshAgent.stoppingDistance)
                //if (navMeshAgent.pathStatus == NavMeshPathStatus.PathComplete)
                if (navMeshAgent.remainingDistance <= 1.75f && navMeshAgent.remainingDistance != 0)
                {
                    ziggyPoints.RemoveAt(0);

                    if (ziggyPoints.Count > 0)
                    {
                        //rotateTowards = true;
                        //navMeshAgent.isStopped = true;
                        //anim.CrossFade(hashes.npc_idle, 0.02f);
                        navMeshAgent.SetDestination(ziggyPoints[0]);
                    }
                    else
                    {
                        navMeshAgent.isStopped = true;
                        navMeshAgent.speed     = 0;
                        navMeshAgent.velocity  = Vector3.zero;
                        //navMeshAgent.GetComponent<Rigidbody>().drag = 100000;

                        StepOver();
                    }
                }
            }

            else if (currStep is MsgStep)
            {
                if (waitingForPals)
                {
                    MsgStep ms = (MsgStep)currStep;

                    bool allPalsHere = false;

                    foreach (int pal in ms.waitForPals)
                    {
                        GameObject bbb = GameObject.Find("NPC_" + pal);

                        if (bbb != null)
                        {
                            var distToPals = Vector3.Distance(bbb.transform.position, npcTransform.position);

                            if (distToPals <= 5.0f)
                            {
                                allPalsHere = true;
                            }
                            else
                            {
                                allPalsHere = false;
                            }
                        }
                        else
                        {
                            allPalsHere = false;
                        }
                    }

                    if (allPalsHere)
                    {
                        waitingForPals = false;
                        msg.text       = ms.msg;
                        StartCoroutine(Wait(5));
                    }
                }
            }
        }
예제 #4
0
        void NextStep()
        {
            currStep = steps[currStepNum];

            navMeshAgent.isStopped = true;

            if (currStep is MoveStep)
            {
                MoveStep ms = (MoveStep)currStep;

                Vector3 destinationPoint = spawnerManager.npcPoints[ms.pointName];

                // TODO
                ziggyPoints = GenZiggyPoints(npcTransform.position, destinationPoint);
                //ziggyPoints[0] = destinationPoint;

                navMeshAgent.SetDestination(ziggyPoints[0]);
                navMeshAgent.isStopped = false;

                destination = ziggyPoints[0];


                if (Random.Range(0, 101) <= runLikelihood)
                {
                    anim.CrossFade(hashes.npc_run, 0.02f);
                    navMeshAgent.speed = 9.0f;
                }
                else
                {
                    anim.CrossFade(hashes.npc_walk, 0.02f);
                    navMeshAgent.speed = 3.5f;
                }

                //anim.CrossFade(hashes.npc_run, 0.02f);
                //rotateTowards = true;

                //StartCoroutine(MoveTurn(1.5f));
            }
            else if (currStep is WaitStep)
            {
                WaitStep ws = (WaitStep)currStep;

                if (!currentlyUsing)
                {
                    anim.CrossFade(hashes.npc_idle, 0.02f);
                }

                StartCoroutine(Wait(ws.seconds));
            }
            else if (currStep is MsgStep)
            {
                MsgStep ms = (MsgStep)currStep;

                if (!currentlyUsing)
                {
                    anim.CrossFade(hashes.npc_idle, 0.02f);
                }

                if (ms.waitForPals.Count > 0)
                {
                    waitingForPals = true;
                }
                else
                {
                    msg.text = ms.msg;
                    StartCoroutine(Wait(5));
                }
            }
            else if (currStep is UseStep)
            {
                UseStep us = (UseStep)currStep;

                // If NPC is stopping whatever they're doing
                if (us.objToUse == "stop")
                {
                    currentlyUsing = false;

                    // TODO: move NPC back off of the object
                    MoveForUse(us.objToUse);
                }

                else
                {
                    anim.CrossFade(hashes.npc_sit_idle, 0.02f);

                    currentlyUsing = true;

                    MoveForUse(us.objToUse);
                }

                return;
            }

            loopStep = true;
        }
예제 #5
0
        private void ReadActions()
        {
            foreach (XmlElement node in actionsDoc.SelectNodes("actions/action"))
            {
                NPCAction                newAction = new NPCAction(int.Parse(node.GetAttribute("id")));
                List <NPCStep>           steps     = new List <NPCStep>();
                Dictionary <int, string> reqs      = new Dictionary <int, string>();
                List <int>               pals      = new List <int>();

                foreach (XmlElement reqsNode in node.SelectNodes("reqs/req"))
                {
                    reqs.Add(int.Parse(reqsNode.GetAttribute("id")), reqsNode.GetAttribute("value"));
                }

                foreach (XmlElement palsNode in node.SelectNodes("pals/pal"))
                {
                    pals.Add(int.Parse(palsNode.GetAttribute("id")));
                }

                foreach (XmlElement stepsNode in node.SelectNodes("steps/step"))
                {
                    switch (stepsNode.GetAttribute("type"))
                    {
                    case "move":
                        MoveStep moveStep = new MoveStep();
                        moveStep.pointName = stepsNode.GetAttribute("point");
                        steps.Add(moveStep);
                        break;

                    case "wait":
                        WaitStep waitStep = new WaitStep();
                        waitStep.seconds = float.Parse(stepsNode.GetAttribute("time"));
                        steps.Add(waitStep);
                        break;

                    case "msg":
                        MsgStep msgStep = new MsgStep();
                        msgStep.msg = stepsNode.GetAttribute("words");
                        string waitForString = stepsNode.GetAttribute("waitFor");

                        List <int> palsList = new List <int>();

                        if (!waitForString.Equals(""))
                        {
                            palsList = new List <int>(Array.ConvertAll(waitForString.Split(','), int.Parse));
                        }

                        msgStep.waitForPals = palsList;

                        //msgStep.waitForPals = (stepsNode.GetAttribute("waitForPals") == "t" ? true : false);

                        steps.Add(msgStep);
                        break;

                    case "use":
                        UseStep useStep = new UseStep();
                        useStep.objToUse = stepsNode.GetAttribute("obj");
                        steps.Add(useStep);
                        break;

                    default:
                        break;
                    }
                }

                newAction.steps = steps;
                newAction.reqs  = reqs;
                newAction.pals  = pals;
                npcActions.Add(newAction);
            }
        }