示例#1
0
    private bool doSlowCreate(bool killAll)
    {
        if (slowCreateIds.Count < 1)
        {
            return(false);
        }

        GrowthTriggerInfo info = slowCreateIds[0] as GrowthTriggerInfo;

        if (info.type == "NPC")
        {
            NpcInitParam npcParam = new NpcInitParam();
            npcParam.npc_res_id = info.resId;
            float y = mScene.GetHeight(info.x, info.z);
            npcParam.init_pos = new Vector3(info.x, y, info.z);
            npcParam.init_dir = info.dir;
            npcParam.alias    = info.alias;
            npcParam.talk_id  = info.talkID;

            ObjectBase obj = mScene.CreateSprite(npcParam);
            if (obj == null)
            {
                GameDebug.LogError("创建Npc失败。npcId:" + info.resId);
                return(false);
            }

            if ("ghost" == info.alias)
            {
                mScene.GhostObjects().Add(info);
            }

            if (obj != null)
            {
                if (killAll)
                {
                    cacheIdKillAll.Add(obj.InstanceID);
                }
                else
                {
                    cacheId.Add(obj.InstanceID);
                }
            }
        }
        else if (info.type == "PICK")
        {
            PickGrowthTriggerInfo pickinfo = info as PickGrowthTriggerInfo;

            List <PickInitParam> paramList = new List <PickInitParam>();
            if (SceneObjManager.CreatePickInitParam((Pick.PickType)(System.Enum.Parse(typeof(Pick.PickType), pickinfo.picktype.ToString())),
                                                    pickinfo.resId, pickinfo.content, new Vector3(info.x, mScene.GetHeight(info.x, info.z), info.z), info.dir, out paramList, false,
                                                    Pick.FlyType.FLY_OUT, pickinfo.picktype != (int)Pick.PickType.SUPER_WEAPON))
            {
                foreach (PickInitParam param in paramList)
                {
                    param.init_pos.y = mScene.GetHeight(param.init_pos.x, param.init_pos.z);
                    param.alias      = info.alias;
                    ObjectBase obj = mScene.CreateSprite(param);
                    if (obj == null)
                    {
                        GameDebug.LogError("创建Pick失败。pickId:" + info.resId);
                        return(false);
                    }

                    if (obj != null)
                    {
                        if (killAll)
                        {
                            cacheIdKillAll.Add(obj.InstanceID);
                        }
                        else
                        {
                            cacheId.Add(obj.InstanceID);
                        }
                    }
                }
            }
        }
        else if (info.type == "BUILD")
        {
            BuildGrowthTriggerInfo buildinfo = info as BuildGrowthTriggerInfo;

            BuildInitParam buildParam = new BuildInitParam();
            buildParam.build_res_id = info.resId;
            float y = mScene.GetHeight(info.x, info.z);
            buildParam.init_pos      = new Vector3(info.x, y, info.z);
            buildParam.init_dir      = info.dir;
            buildParam.build_barrier = buildinfo.barrier > 0;
            buildParam.alias         = info.alias;

            ObjectBase obj = mScene.CreateSprite(buildParam);
            if (obj == null)
            {
                GameDebug.LogError("创建Building失败。buildId:" + info.resId);
                return(false);
            }

            if (obj != null)
            {
                if (killAll)
                {
                    cacheIdKillAll.Add(obj.InstanceID);
                }
                else
                {
                    cacheId.Add(obj.InstanceID);
                }
            }
        }
        else if (info.type == "PARTICLE")
        {
            Vector3 pos = new Vector3(info.x, mScene.GetHeight(info.x, info.z), info.z);
            mScene.CreateEffect(info.resId, Vector3.one, pos, info.dir, info.alias);
        }

        slowCreateIds.RemoveAt(0);

        if (slowCreateIds.Count < 1)
        {
            return(false);
        }

        return(true);
    }
    // 解析NpcGrowth
    private void ParseNpcGrowth(XmlNode node)
    {
        GrowthTrigger trigger = new GrowthTrigger(mScene);

        trigger.name = node.Attributes["name"].Value;
        XmlNodeList nodeList = node.ChildNodes;

        for (int i = 0; i < nodeList.Count; ++i)
        {
            XmlNode childNode = nodeList[i];
            if (childNode != null && childNode.Name == "Step")
            {
                GrowthTriggerStep step = new GrowthTriggerStep();
                int ka = System.Convert.ToInt32(childNode.Attributes["killAll"].Value);
                step.killAll = (ka != 0);
                step.time    = System.Convert.ToInt32(childNode.Attributes["time"].Value);

                if (childNode.Attributes["repeat"] != null && childNode.Attributes["spacetime"] != null)
                {
                    step.repeat    = System.Convert.ToInt32(childNode.Attributes["repeat"].Value);
                    step.spacetime = System.Convert.ToInt32(childNode.Attributes["spacetime"].Value);
                }

                XmlNodeList stepList = childNode.ChildNodes;
                for (int j = 0; j < stepList.Count; ++j)
                {
                    XmlNode stepNode = stepList[j];

                    if (stepNode != null && stepNode.Name == "Growth")
                    {
                        GrowthTriggerInfo info       = null;
                        string            growthtype = stepNode.Attributes["type"].Value;
                        if (growthtype.Equals("PICK"))
                        {
                            info = new PickGrowthTriggerInfo();
                            (info as PickGrowthTriggerInfo).picktype = System.Convert.ToInt32(stepNode.Attributes["picktype"].Value);
                            (info as PickGrowthTriggerInfo).content  = System.Convert.ToInt32(stepNode.Attributes["content"].Value);
                        }
                        else if (growthtype.Equals("BUILD"))
                        {
                            info = new BuildGrowthTriggerInfo();
                            (info as BuildGrowthTriggerInfo).barrier = System.Convert.ToInt32(stepNode.Attributes["barrier"].Value);
                        }
                        else
                        {
                            info = new GrowthTriggerInfo();
                        }

                        info.type  = growthtype;
                        info.resId = System.Convert.ToInt32(stepNode.Attributes["resId"].Value);
                        info.x     = System.Convert.ToSingle(stepNode.Attributes["x"].Value);
                        info.z     = System.Convert.ToSingle(stepNode.Attributes["z"].Value);
                        info.dir   = System.Convert.ToSingle(stepNode.Attributes["dir"].Value) * Mathf.Deg2Rad;

                        if (stepNode.Attributes["talkid"] != null)
                        {
                            info.talkID = System.Convert.ToInt32(stepNode.Attributes["talkid"].Value);
                        }

                        if (stepNode.Attributes["name"] != null)
                        {
                            info.alias = stepNode.Attributes["name"].Value;
                        }

                        step.objs.Add(info);
                    }
                }
                trigger.steps.Add(step);
            }
        }

        mTriggers.Add(trigger.name, trigger);
    }