Example #1
0
    public override void OnAssembled(EnumEquipSlot slot, GameObject go, FC_EQUIPMENTS_TYPE equipmentType)
    {
        //_bladeInfosIdx = 0;
        if (_bladeInfos != null && _bladeInfosIdx >= _bladeInfos.Length)
        {
            _bladeInfosIdx = 0;
        }
        Transform []           transforms = go.GetComponentsInChildren <Transform>();
        List <GameObject>      gl         = new List <GameObject>();
        List <MessageReciever> ml         = new List <MessageReciever>();
        List <BladeSlide>      bl         = new List <BladeSlide>();

        _bladeInfos[_bladeInfosIdx] = new BladeInfo();

        _bladeInfos[_bladeInfosIdx]._bladeType         = equipmentType;
        _bladeInfos[_bladeInfosIdx]._bladeTransform    = go.transform;
        _bladeInfos[_bladeInfosIdx]._originalTransform = go.transform.parent;
        _bladeInfos[_bladeInfosIdx]._currentTransform  = go.transform.parent;

        foreach (Transform t in transforms)
        {
            GameObject subgo = t.gameObject;
            Collider   c     = subgo.GetComponent <Collider>();
            if (c != null)
            {
                gl.Add(subgo);
            }

            MessageReciever mr = subgo.GetComponent <MessageReciever>();
            if (mr != null)
            {
                ml.Add(mr);
            }
            BladeSlide blade = subgo.GetComponent <BladeSlide>();
            if (blade != null)
            {
                bl.Add(blade);
            }
        }

        _bladeInfos[_bladeInfosIdx]._colliders        = gl.ToArray();
        _bladeInfos[_bladeInfosIdx]._messageReceivers = ml.ToArray();
        _bladeInfos[_bladeInfosIdx]._bladerCenter     = new Vector3[_bladeInfos[_bladeInfosIdx]._colliders.Length];
        _bladeInfos[_bladeInfosIdx]._bladerSize       = new Vector3[_bladeInfos[_bladeInfosIdx]._colliders.Length];
        _bladeInfos[_bladeInfosIdx]._bladeReal        = new BoxCollider[_bladeInfos[_bladeInfosIdx]._colliders.Length];
        _bladeInfos [_bladeInfosIdx].cubes            = new GameObject[_bladeInfos [_bladeInfosIdx]._colliders.Length];

        if (_bladeInfos[_bladeInfosIdx]._colliders.Length != 0)
        {
            for (int i = 0; i < _bladeInfos[_bladeInfosIdx]._colliders.Length; i++)
            {
                _bladeInfos[_bladeInfosIdx]._bladeReal[i]             = _bladeInfos[_bladeInfosIdx]._colliders[i].collider as BoxCollider;
                _bladeInfos[_bladeInfosIdx]._bladerCenter[i]          = _bladeInfos[_bladeInfosIdx]._bladeReal[i].center;
                _bladeInfos[_bladeInfosIdx]._bladerSize[i]            = _bladeInfos[_bladeInfosIdx]._bladeReal[i].size;
                _bladeInfos[_bladeInfosIdx].cubes[i]                  = GameObject.CreatePrimitive(PrimitiveType.Cube);
                _bladeInfos[_bladeInfosIdx].cubes[i].transform.parent = go.transform;
                _bladeInfos[_bladeInfosIdx].cubes[i].transform.gameObject.SetActive(false);
            }
        }

        _bladeInfos[_bladeInfosIdx]._bladeSlide = bl.ToArray();
        _bladeInfosIdx++;
    }
Example #2
0
    //open or close blade of weapon and resize the collider bounds
    //if bladeLayer == FC_CONST.LAYER_DEFAULT, means deactive the blade of weapon
    private static void ReleaseBlade(BladeInfo bi, int bladeLayer, bool openIt, int xScale, int yScale, int zScale, bool needHitID)
    {
        int i = 0;

        foreach (GameObject go in bi._colliders)
        {
            go.layer = bladeLayer;

            GameObject  collider      = bi._colliders[i];
            BoxCollider bladeCollider = bi._bladeReal[i];
            Vector3     center        = bi._bladerCenter[i];
            Vector3     sizeNew       = bi._bladerSize[i];

            if (openIt)
            {
                if (xScale != 100)
                {
                    sizeNew.x = sizeNew.x * (xScale / 100f);
                }
                if (yScale != 100)
                {
                    sizeNew.y = sizeNew.y * (yScale / 100f);
                }
                //we only need weapon to be longer at one direction
                if (zScale != 100)
                {
                    sizeNew.z = sizeNew.z * (zScale / 100f);
                    center.z  = center.z + (sizeNew.z - bi._bladerSize[i].z) / 2;
                }
            }

            bladeCollider.center = center;
            bladeCollider.size   = sizeNew;

            if (CheatManager.weaponCollider)
            {
                Transform t = bi.cubes[i].transform;
                t.localPosition = collider.transform.localPosition + center;
                t.localRotation = collider.transform.localRotation;
                t.localScale    = sizeNew;
                t.gameObject.SetActive(openIt);
            }

            i++;
        }
        foreach (MessageReciever mr in bi._messageReceivers)
        {
            if (openIt)
            {
                if (needHitID)
                {
                    mr._hitID = GameManager.GainHitID();
                }
                else
                {
                    mr._hitID = 0;
                }
            }
            else
            {
                mr._hitID = -1;
            }
        }
        foreach (BladeSlide blade in bi._bladeSlide)
        {
            blade.Emit = openIt;
        }
    }
Example #3
0
 public void Initialize(BladeInfo bladeInfo)
 {
     BladeInfo = bladeInfo;
 }