コード例 #1
0
    void _AddNode(Vector3 position, Quaternion orientation)
    {
        pathRenderer.numPositions = pathRenderer.numPositions + 1;
        pathRenderer.SetPosition(pathRenderer.numPositions - 1, position);

        PathSample sample = new PathSample();

        sample.position    = position;
        sample.orientation = orientation;
        sample.timestamp   = Time.time;
        path.Add(sample);

        Transform node = Instantiate(nodePrefab, position, orientation, transform);

        nodeObjects.Add(node);
    }
コード例 #2
0
    void SpawnPerson(bool isTarget = true, int activeIndex = -1)
    {
        Transform target = isTarget ? (spawnTargets [heroPreset.female ? 1 : 0]) : spawnTargets [Random.Range(2, spawnTargets.Length)];

        if (isTarget)
        {
            PathSample[] path = HeroPathManager.GetPath();
            if (targetInstance != null)
            {
                Destroy(targetInstance.gameObject);
            }
            targetInstance             = Instantiate(target);
            targetInstance.position    = path[0].position;
            targetInstance.eulerAngles = new Vector3(0, Random.Range(0f, 360f), 0);
            targetInstance.GetComponent <CharacterCustomization> ().SetAppearance(heroPreset);
            targetInstance.gameObject.SetActive(true);
            followCam.target    = targetInstance;
            targetInstance.name = "Hero";
            targetInstance.GetComponent <PersonBehavior> ().UsePath(path, OnPersonEndedPath);
        }
        else
        {
            PathSample spawn  = GetRandomPoint();
            Transform  person = Instantiate(target);
            person.position    = spawn.position;
            person.eulerAngles = new Vector3(0, Random.Range(0f, 360f), 0);
            person.gameObject.SetActive(true);
            PersonBehavior behavior   = person.GetComponent <PersonBehavior> ();
            int            timerIndex = timerLength * 2;
            if (activeIndex != -1)
            {
                Destroy(activePeople [activeIndex].gameObject);
                activePeople [activeIndex] = behavior;
                spawnTimers [activeIndex]  = Time.time + Random.Range(timerValues [timerIndex], timerValues [timerIndex + 1]);
            }
            else
            {
                activePeople.Add(behavior);
                spawnTimers.Add(Time.time + Random.Range(timerValues [timerIndex], timerValues [timerIndex + 1]));
            }
            SetLayerRecursively(person, peopleLayer);
            person.GetComponent <PersonBehavior> ().Wander();
            person.parent = peopleParent;
        }
    }
コード例 #3
0
    public void SetPath(Path p)
    {
        if (p != null && p.Nodes != null && p.Nodes.Length > 1)
        {
            path        = p;
            tr.position = p.Nodes [0].position;
            tr.rotation = p.Nodes [0].orientation;
            curNode     = 1;
            destination = p.Nodes [1];
//			SetControllers ();

            Debug.Log("path set");
        }
        else
        {
            path        = null;
            destination = null;
            following   = false;
        }
    }
コード例 #4
0
    void FixedUpdate()
    {
        Debug.Log("??");
        if (active && destination != null)
        {
            float testDistance = minDist * minDist;
            if ((destination.position - tr.position).sqrMagnitude < testDistance)
            {
                if (curNode == path.Nodes.Length - 1)
                {
                    if (repeatPath)
                    {
                        curNode = 0;
                    }
                    else
                    {
                        path        = null;
                        destination = null;
                        following   = false;
                        // clear the visualization of the path
                        PathPlanner.ClearViz();
                        return;
                    }
                }
                else
                {
                    curNode++;
                }

                arriveDist  = (path.Nodes [curNode].position - destination.position).magnitude * 0.05f;
                destination = path.Nodes [curNode];
//				SetControllers ();
            }
            following = true;
            UpdateSteering();
        }
    }