public static IEnumerator CreateTownUnitAsync(Vector3 pos, System.Action <InteractionNPC> callback, params object[] args)
    {
        GameObject _townNPCUnit = new GameObject();

        _townNPCUnit.name = "InteractionNPC";

        InteractionNPC tu = _townNPCUnit.AddComponent <InteractionNPC>();

        NavMeshHit hit;

        if (NavMesh.SamplePosition(pos, out hit, 10, -1))
        {
            pos = hit.position;
        }

        tu.transform.position = pos;

        tu.Height = 2.47f;

        yield return(SceneManager.instance.StartCoroutine(tu.InitAsync(args)));

        InteractionNPCInfo n = (InteractionNPCInfo)args [3];

        tu.gameObject.transform.localScale = new Vector3(n.scale, n.scale, n.scale);

        NGUITools.SetLayer(_townNPCUnit, 14);

        callback(tu);
    }
Beispiel #2
0
 void Awake()
 {
     pi = transform.parent.GetComponentInChildren <InteractionNPC> ();
     //pi = GameObject.FindGameObjectWithTag ("NPC").GetComponentInChildren<InteractionNPC> ();
     nav    = GetComponent <NavMeshAgent> ();
     player = GameObject.FindGameObjectWithTag("Player");
 }
    public static InteractionNPC CreateTownUnit(Vector3 pos, params object[] args)
    {
        GameObject _townNPCUnit = new GameObject();

        _townNPCUnit.name = "InteractionNPC";

        InteractionNPC tu = _townNPCUnit.AddComponent <InteractionNPC>();

        NavMeshHit hit;

        if (NavMesh.SamplePosition(pos, out hit, 10, -1))
        {
            pos = hit.position;
        }

        tu.transform.position = pos;

        tu.Height = 2.47f;
        tu.Init(args); // load

        InteractionNPCInfo n = (InteractionNPCInfo)args [3];

        tu.gameObject.transform.localScale = new Vector3(n.scale, n.scale, n.scale);

        NGUITools.SetLayer(_townNPCUnit, 14);

        return(tu);
    }
Beispiel #4
0
    //강아지나 고양이와 같은 크리쳐들
    IEnumerator CreateCreatures()
    {
        int n = _LowDataMgr.instance.getNumOfNonInteractiveNpc();

        for (int i = 1; i < n + 1; i++)
        {
            yield return(new WaitForSeconds(2f));

            NonInteractiveNpcData.NonInteractiveNpcDataInfo npcData = _LowDataMgr.instance.getNonInteractiveNpc((ushort)i);

            InteractionNPCInfo testData = new InteractionNPCInfo();
            testData.NPCPref   = npcData.prefab;
            testData.MoveSpeed = npcData.moveSpeed;
            testData.scale     = npcData.scale;
            testData.moveRange = npcData.moveRange;

            if (testData.NPCPref == "npc_cat_01")
            {
                testData.AniID = 90001;
            }
            else if (testData.NPCPref == "npc_cat_02")
            {
                testData.AniID = 90002;
            }
            else if (testData.NPCPref == "npc_sibainue_01")
            {
                testData.AniID = 90003;
            }

            object[] initialData = new object[4] {
                0, 0, (int)UnitType.TownNINPC, testData
            };

            bool findRegenPos = false;

            NavMeshHit hit;
            Vector3    RandomPos = new Vector3();
            while (!findRegenPos)
            {
                RandomPos.x = Random.Range((float)npcData.firstPosMin, (float)npcData.firstPosMax);
                RandomPos.y = -5f;
                RandomPos.z = Random.Range(-110f, 105f);

                if (NavMesh.SamplePosition(RandomPos, out hit, 10, -1))
                {
                    RandomPos    = hit.position;
                    findRegenPos = true;
                }
            }

            InteractionNPC tu = null;

            yield return(StartCoroutine(InteractionNPC.CreateTownUnitAsync(RandomPos, (retVal) => { tu = retVal; }, initialData)));

            tu.gameObject.GetComponentInChildren <Animation>().cullingType = AnimationCullingType.AlwaysAnimate;

            //tu.transform.position = pos;
            //tu.GetComponent<NavMeshAgent>().Warp(pos);

            tu.ChangeState(UnitState.Wander);
        }
    }