Example #1
0
    /// <summary>
    /// 取得套件
    /// </summary>
    /// <param name="_partType"></param>
    /// <returns></returns>
    public MBSetPart GetPartByEnum(MeatBall.SetPartType _partType)
    {
        MBSetPart part = null;

        switch (_partType)
        {
        case MeatBall.SetPartType.Glove:
            part = this.Glove;
            break;

        case MeatBall.SetPartType.Suit:
            part = this.Suit;
            break;

        case MeatBall.SetPartType.Hat:
            part = this.Hat;
            break;

        case MeatBall.SetPartType.Weapon:
            part = this.Weapon;
            break;

        default:
            break;
        }
        part.Initial(Name);
        return(part);
    }
Example #2
0
 /// <summary>
 /// 將套件脫離人物
 /// </summary>
 /// <param name="_part"></param>
 public void RecyclePart(MBSetPart _part)
 {
     if (_part.Sections == null)
     {
         return;
     }
     _part.RecycleGameObject(rootTransform);
 }
Example #3
0
    /// <summary>
    /// 取得套裝散件
    /// </summary>
    /// <param name="_setName"></param>
    /// <param name="_type"></param>
    /// <returns></returns>
    protected MBSetPart GetPartGameObject(SetType _setName, MeatBall.SetPartType _type)
    {
        //如果原資料就沒有該部位了就回傳null
        if (dataPool[_setName].GetPartByEnum(_type) == null)
        {
            return(null);
        }
        Debug.Log("Search Suit");
        MBSetPart part = null;

        //尋找該Dictionary
        for (int i = 0; i < objectPool[_setName].Count; i++)
        {
            //找出該套裝
            part = objectPool[_setName][i].GetPartByEnum(_type);
            //如果此物件的該部位正在被使用就繼續找別的
            if (part.IsThisUsing)
            {
                part = null;
                continue;
            }
            //沒在使用就指定該物件
            break;
        }
        //整場物件都沒有空的部位就造新的套裝再取其物件
        if (part == null)
        {
            MeatBallSet newSet = GameObject.Instantiate(GetSet(_setName)) as MeatBallSet;
            objectPool[_setName].Add(newSet);
            newSet.InstantiateParts();
            part = newSet.GetPartByEnum(_type);
        }
        Debug.Log(part.name);
        //事前準備
        part.ReuseGameObject();
        //回傳該物件
        return(part);
    }
    /// <summary>
    /// 替換部件
    /// </summary>
    /// <param name="_part">已經實例化的套件</param>
    /// <param name="_type">套件種類</param>
    private void SetPartsData(MBSetPart _part, SetPartType _type)
    {
        int partIndex = (int)_type;

        //回收舊部件
        if (GetSetPartByEnum(_type) != null)
        {
            MeatBallSetFactory.Instance.RecyclePart(GetSetPartByEnum(_type));
        }
        //資料
        _part.ReuseGameObject();
        //技能
        Skill newSkill = _part.Skill;

        skills[(int)_type] = newSkill;
        SkillChange(newSkill);
        //遊戲物件
        BodyPart[] parts  = Enum.GetValues(typeof(BodyPart)) as BodyPart[];
        Transform  buffer = null;

        for (int i = 0; i < parts.Length; i++)
        {
            if (_part.Sections[i] == null)
            {
                continue;
            }
            if (myBehavior.BodyParts[i] == null)
            {
                throw new Exception("沒有指定貢丸穿戴套裝物件的物件,檢查一下MeatBallBehavior的BodyParts");
            }
            buffer = _part.Sections[i].transform;
            buffer.SetParent(myBehavior.BodyParts[i].transform);
            buffer.localPosition = Vector3.zero;
            buffer.localRotation = Quaternion.Euler(Vector3.zero);
        }
    }