コード例 #1
0
ファイル: XmlManager.cs プロジェクト: mengtest/actdemo
    bool LoadCloneSceneProperty()
    {
        byte[] asset = ResourceManager.Instance.GetXml("CloneScene");
        if (asset == null)
        {
            return(false);
        }

        TbXmlNode docNode = TbXml.Load(asset).docNode;

        if (docNode == null)
        {
            return(false);
        }

        List <TbXmlNode> xmlNodeList = docNode.GetNodes("CloneScene/Property");
        int xmlNodeListLength        = xmlNodeList.Count;

        if (xmlNodeListLength < 1)
        {
            return(false);
        }

        for (int i = 0; i < xmlNodeListLength; ++i)
        {
            TbXmlNode          node = xmlNodeList[i] as TbXmlNode;
            CloneSceneProperty cs   = new CloneSceneProperty();
            int id = node.GetIntValue("CloneSceneId");

            cs.mCloneSceneMonsterInfoList = new List <CloneSceneProperty.CloneSceneMonsterInfo>();
            List <TbXmlNode> childNode = node.GetNodes("CloneSceneMonsterInfo");
            for (int j = 0; j < childNode.Count; ++j)
            {
                TbXmlNode child = childNode[j] as TbXmlNode;
                CloneSceneProperty.CloneSceneMonsterInfo csm = new CloneSceneProperty.CloneSceneMonsterInfo();
                csm.mMonsterId        = child.GetIntValue("MonsterId");
                csm.mMonsterPosition  = UtilTools.FormatStringVector3(child.GetStringValue("MonsterPosition"));
                csm.mMonsterRotationY = child.GetFloatValue("MonsterRotationY");
                csm.mMonsterScale     = child.GetFloatValue("MonsterScale");

                cs.mCloneSceneMonsterInfoList.Add(csm);
            }

            mCloneScenePropertyDic.Add(id, cs);
        }

        return(true);
    }
コード例 #2
0
    public void InitMonster(List <CloneSceneProperty.CloneSceneMonsterInfo> list)
    {
        if (list == null)
        {
            return;
        }

        int count = list.Count;

        if (count < 1)
        {
            return;
        }

        //GameObject monsterParent = NGUITools.AddChild(gameObject);
        //monsterParent.transform.localPosition = Vector3.zero;
        //monsterParent.name = "Monsters";

        for (int i = 0; i < count; ++i)
        {
            CloneSceneProperty.CloneSceneMonsterInfo csm = list[i];
            if (csm == null)
            {
                continue;
            }

            int     monsterId = csm.mMonsterId;
            Vector3 postion   = csm.mMonsterPosition;
            float   rotation  = csm.mMonsterRotationY;
            float   scale     = csm.mMonsterScale;
            if (scale.Equals(0.0f))
            {
                scale = 1.0f;
            }

            CMonsterObject cObj = new CMonsterObject();

            GameObject go = ResourceManager.Instance.GetMonsterPrefab(monsterId.ToString());
            if (go == null)
            {
                LogSystem.LogError("GetMonsterPrefab Failed, monsterId = " + monsterId);

                continue;
            }

            ++mIndex;

            cObj.mObjId = monsterId;
            cObj.mIndex = mIndex;

            go.name = monsterId.ToString();
            //go.transform.parent = monsterParent.transform;
            go.transform.position   = postion;
            go.transform.rotation   = Quaternion.Euler(0.0f, rotation, 0.0f);
            go.transform.localScale = new Vector3(scale, scale, scale);

            //ui
            GameObject uiPrefab  = ResourceManager.Instance.GetUIPrefab("UMonsterBloodUI");
            Vector2    position2 = Camera.main.WorldToScreenPoint(postion);
            uiPrefab.transform.position = position2;

            cObj.mGameObject = go;
            cObj.mTransform  = go.transform;

            cObj.mPosition = postion;

            cObj.AddComponent <AnimatorComponent>();

            cObj.AddComponent <RestoreComponent>();
            cObj.AddComponent <InjuredComponent>();

            cObj.AddComponent <FindingPathComponent>();
            cObj.AddComponent <MoveComponent>();
            cObj.AddComponent <AttackComponent>();
            cObj.AddComponent <HatredComponent>();
            cObj.AddComponent <PursuitComponent>();

            cObj.AddComponent <SkillComponent>();
            cObj.AddComponent <EffectComponent>();

            RangeTools.MotifyObjectAoi(ObjectManager.mRole, cObj);

            ObjectManager.mObjectsList.Add(cObj);
        }
    }