示例#1
0
 public void addOneSeason(OneFishSeason oneseason)
 {
     if (fishSeasonList != null && oneseason != null)
     {
         fishSeasonList.Add(oneseason);
     }
 }
示例#2
0
    public void loadFishSeasonConfig(string configPath)
    {
        string filePath = configPath;

        if (false == File.Exists(filePath))
        {
            return;
        }
        XmlDocument xmlDoc = new XmlDocument();

        xmlDoc.Load(filePath);

        XmlNode oneseasonNode = xmlDoc.SelectSingleNode("CapFish/Server/FishSeasonConfig/OneSeason");

        while (oneseasonNode != null)
        {
            if (oneseasonNode.GetType() == typeof(XmlElement))
            {
                XmlElement oneseasonXe = (XmlElement)oneseasonNode;
                if (oneseasonXe.Name == "OneSeason")
                {
                    OneFishSeason oneseason = new OneFishSeason();
                    mSeasonConfig.addOneSeason(oneseason);
                    XmlNode seasonInfoNode = oneseasonNode.FirstChild;
                    while (seasonInfoNode != null)
                    {
                        if (seasonInfoNode.GetType() == typeof(XmlElement))
                        {
                            XmlElement seasoninfoXe = (XmlElement)seasonInfoNode;
                            if (seasoninfoXe.Name == "FishSeasonInfo")
                            {
                                FishSeasonInfo seasonInfo = new FishSeasonInfo();
                                oneseason.addOneSeasonInfo(seasonInfo);
                                seasonInfo.mSpeed = float.Parse(seasoninfoXe.GetAttribute("speed"));
                                seasonInfo.mAngle = float.Parse(seasoninfoXe.GetAttribute("angle"));
                                seasonInfo.mAiId  = int.Parse(seasoninfoXe.GetAttribute("AIID"));
                                string   centerPt = seasoninfoXe.GetAttribute("centerPt");
                                string[] xy       = centerPt.Split(',');
                                float    x        = float.Parse(xy[0].Trim());
                                float    y        = float.Parse(xy[1].Trim());
                                seasonInfo.mCenterPoint = new Vector2(x, y);

                                XmlNode singlefishNode = seasonInfoNode.FirstChild;
                                while (singlefishNode != null)
                                {
                                    if (singlefishNode.GetType() == typeof(XmlElement))
                                    {
                                        XmlElement singleFishXe = (XmlElement)singlefishNode;
                                        if (singleFishXe.Name == "SingleFishOfSeason")
                                        {
                                            SingleFishOfSeason singlefish = new SingleFishOfSeason();
                                            seasonInfo.addSingleFish(singlefish);
                                            singlefish.mFishKindId = int.Parse(singleFishXe.GetAttribute("FishKindID"));
                                            string fishpos = singleFishXe.GetAttribute("FishPos");
                                            xy = fishpos.Split(',');
                                            //Debug.Log(fishpos);
                                            x = float.Parse(xy[0].Trim());
                                            y = float.Parse(xy[1].Trim());
                                            //Debug.Log(fishpos);
                                            singlefish.mFishPos = new Vector2(x, y);
                                        }
                                    }
                                    singlefishNode = singlefishNode.NextSibling;
                                }
                            }
                        }
                        seasonInfoNode = seasonInfoNode.NextSibling;
                    }
                }
            }
            oneseasonNode = oneseasonNode.NextSibling;
        }
    }
示例#3
0
    public void onEventFishSeason(int seasonIndex, bool modifyFlag = false)
    {
        if (modifyFlag)
        {
            this.onModifyOneSeason(seasonIndex);
            return;
        }
        GameObject sourcePoint   = GameObject.Find("Anchor_BottomLeft");
        Transform  objBottomLeft = sourcePoint.transform;
        int        childCnt      = objBottomLeft.childCount;

        for (int i = 0; i < childCnt;)
        {
            Transform child = objBottomLeft.GetChild(i);
            GameObject.DestroyImmediate(child.gameObject);
            childCnt = objBottomLeft.childCount;
        }

        OneFishSeason season    = FishConfigManager.getInstance().getOneSeason(seasonIndex);
        TableFish     fishtable = (TableFish)GameTableManager.getInstance().GetTable("table_fish");

        foreach (FishSeasonInfo seasoninfo in season.seasonInfoList)
        {
            foreach (SingleFishOfSeason singlefish in seasoninfo.fishList)
            {
                TableFish.FishRecord record = fishtable.getRecordByFishKindId(singlefish.mFishKindId);
                if (record == null)
                {
                    continue;
                }
                float fFishLength = record.width;
                //Debug.Log(record.name);
                GameObject fishObj = (GameObject)GameObject.Instantiate(Resources.Load("FishPrefabs/Prefab_Fish_" + record.name));
                fishObj.transform.parent     = sourcePoint.transform;
                fishObj.transform.localScale = Vector3.one * record.scaleFactor;
                //fishObj.transform.localPosition = new Vector3(singlefish.mFishPos.x + seasoninfo.mCenterPoint.x-1200,singlefish.mFishPos.y + seasoninfo.mCenterPoint.y,0);
                Fish fishComponent = fishObj.AddComponent <Fish>();

                fishComponent.Rotation  = seasoninfo.mAngle;
                fishComponent.AiPath    = AiPathManager.getInstance().getPath(seasoninfo.mAiId);
                fishComponent.BaseSpeed = seasoninfo.mSpeed;
                fishComponent.FishWidth = record.width;

                float fDelay = 0.0f;
                if (seasoninfo.mCenterPoint.x <= 0)
                {
                    fishObj.transform.localPosition = new Vector3(-fFishLength, seasoninfo.mCenterPoint.y + singlefish.mFishPos.y, 0);
                    //fishObj.transform.localPosition.y = seasoninfo.mCenterPoint.y + singlefish.mFishPos.y;
                    fDelay = (singlefish.mFishPos.x - seasoninfo.mCenterPoint.x) / seasoninfo.mSpeed;
                }
                else if (seasoninfo.mCenterPoint.x >= 1280)
                {
                    fishObj.transform.localPosition = new Vector3(1280 + fFishLength, seasoninfo.mCenterPoint.y + singlefish.mFishPos.y, 0);
                    //fishObj.transform.localPosition.y = seasoninfo.mCenterPoint.y + singlefish.mFishPos.y;
                    fDelay = (singlefish.mFishPos.x + seasoninfo.mCenterPoint.x - 1280) / seasoninfo.mSpeed;
                }
                else if (seasoninfo.mCenterPoint.y <= 0)
                {
                    fishObj.transform.localPosition = new Vector3(seasoninfo.mCenterPoint.x + singlefish.mFishPos.x, -fFishLength, 0);
                    //fishObj.transform.localPosition.y = (-1) * fFishLength;
                    fDelay = (singlefish.mFishPos.y - seasoninfo.mCenterPoint.y) / seasoninfo.mSpeed;
                }
                else if (seasoninfo.mCenterPoint.y >= 720)
                {
                    fishObj.transform.localPosition = new Vector3(seasoninfo.mCenterPoint.x + singlefish.mFishPos.x, 720 + fFishLength, 0);
                    //fishObj.transform.localPosition.y = 720 + fFishLength;
                    fDelay = (singlefish.mFishPos.y + seasoninfo.mCenterPoint.y - 720) / seasoninfo.mSpeed;
                }
                else
                {
                    fishObj.transform.localPosition = new Vector3(seasoninfo.mCenterPoint.x + singlefish.mFishPos.x, seasoninfo.mCenterPoint.y + singlefish.mFishPos.y, 0);
                    //fishObj.transform.localPosition.y = (seasoninfo.mCenterPoint.y + singlefish.mFishPos.y);
                    fDelay = 0.0f;
                }

                Vector3 pos = fishObj.transform.localPosition;
                fishObj.transform.localPosition = new Vector3(pos.x, 720 - pos.y, 0);
                if (seasonIndex == 4)
                {
                    Debug.Log(fishObj.transform.localPosition + "        " + fDelay);
                }

                fishComponent.DelayActiveTime = fDelay;
            }
        }
    }
示例#4
0
    public void onModifyOneSeason(int seasonIndex)
    {
        GameObject seasonRoot = GameObject.FindWithTag("SeasonRoot");
        Transform  objRoot    = seasonRoot.transform;
        int        childCnt   = objRoot.childCount;

        for (int i = 0; i < childCnt;)
        {
            Transform child = objRoot.GetChild(i);
            GameObject.DestroyImmediate(child.gameObject);
            childCnt = objRoot.childCount;
        }

        OneFishSeason season    = FishConfigManager.getInstance().getOneSeason(seasonIndex);
        TableFish     fishtable = (TableFish)GameTableManager.getInstance().GetTable("table_fish");

        GameObject oneSeasonObj = new GameObject();

        oneSeasonObj.transform.parent = objRoot;
        oneSeasonObj.AddComponent <OneSeasonComponent>();
        oneSeasonObj.name = "OneSeason";
        oneSeasonObj.transform.localScale    = Vector3.one;
        oneSeasonObj.transform.localPosition = Vector3.zero;

        foreach (FishSeasonInfo seasoninfo in season.seasonInfoList)
        {
            GameObject seasonInfoObj = new GameObject();
            seasonInfoObj.transform.parent     = oneSeasonObj.transform;
            seasonInfoObj.name                 = "OneSeasonInfo";
            seasonInfoObj.transform.localScale = Vector3.one;

            FishSeasonInfoComponent seasonInfoCom = seasonInfoObj.AddComponent <FishSeasonInfoComponent>();
            seasonInfoCom.centerPoint.Set(seasoninfo.mCenterPoint.x, seasoninfo.mCenterPoint.y);
            seasonInfoCom.speed = seasoninfo.mSpeed;
            seasonInfoCom.aiId  = seasoninfo.mAiId;
            seasonInfoCom.angle = seasoninfo.mAngle;

            seasonInfoCom.transform.localPosition = new Vector3(seasoninfo.mCenterPoint.x, -(seasoninfo.mCenterPoint.y), 0);

            foreach (SingleFishOfSeason singlefish in seasoninfo.fishList)
            {
                TableFish.FishRecord record = fishtable.getRecordByFishKindId(singlefish.mFishKindId);
                if (record == null)
                {
                    continue;
                }
                float fFishLength = record.width;

                GameObject fishObj = (GameObject)GameObject.Instantiate(Resources.Load("FishPrefabs/Prefab_Fish_" + record.name));
                fishObj.name                    = "Prefab_Fish_" + record.name;
                fishObj.transform.parent        = seasonInfoObj.transform;
                fishObj.transform.localScale    = Vector3.one * record.scaleFactor;
                fishObj.transform.localPosition = new Vector3(singlefish.mFishPos.x, singlefish.mFishPos.y, 0);

                if (seasoninfo.mCenterPoint.x <= 0)
                {
                    fishObj.transform.localPosition = new Vector3(-singlefish.mFishPos.x, singlefish.mFishPos.y, 0);
                }
                else if (seasoninfo.mCenterPoint.x >= 1280)
                {
                    fishObj.transform.localPosition = new Vector3(singlefish.mFishPos.x, singlefish.mFishPos.y, 0);
                }
                else if (seasoninfo.mCenterPoint.y <= 0)
                {
                    fishObj.transform.localPosition = new Vector3(singlefish.mFishPos.x, -singlefish.mFishPos.y, 0);
                }
                else if (seasoninfo.mCenterPoint.y >= 720)
                {
                    fishObj.transform.localPosition = new Vector3(singlefish.mFishPos.x, singlefish.mFishPos.y, 0);
                }
            }

            UnityEditor.EditorApplication.MarkSceneDirty();
        }
    }