Esempio n. 1
0
    private void BuildCreation()
    {
        #region Root Transform
        // [VCCase] - Set creation root Transform

        if (m_Attribute.m_Type == ECreation.Sword)
        {
            Transform pivot = null;
            foreach (VCComponentData cdata in m_IsoData.m_Components)
            {
                if (cdata.m_Type == EVCComponent.cpSwordHilt || cdata.m_Type == EVCComponent.cpLgSwordHilt)
                {
                    pivot = cdata.m_Entity.transform;
                    break;
                }
            }

            m_Root.transform.localRotation = Quaternion.Inverse(pivot.rotation);
            m_Root.transform.Rotate(Vector3.up, -90, Space.World);
            m_Root.transform.Rotate(Vector3.right, 90, Space.World);
            m_Root.transform.localPosition = -pivot.position;
        }
        else if (m_Attribute.m_Type == ECreation.SwordLarge)
        {
            Transform pivot = null;
            foreach (VCComponentData cdata in m_IsoData.m_Components)
            {
                if (cdata.m_Type == EVCComponent.cpLgSwordHilt)
                {
                    pivot = cdata.m_Entity.transform;
                    break;
                }
            }

            m_Root.transform.localRotation = Quaternion.Inverse(pivot.rotation);
            m_Root.transform.Rotate(Vector3.up, -90, Space.World);
            m_Root.transform.Rotate(Vector3.right, 90, Space.World);
            m_Root.transform.localPosition = -pivot.position;
        }
        else if (m_Attribute.m_Type == ECreation.SwordDouble)
        {
            Transform pivot = null;
            int       cdcnt = 0;
            foreach (VCComponentData cdata in m_IsoData.m_Components)
            {
                if (cdata.m_Type == EVCComponent.cpDbSwordHilt && (cdata as VCFixedHandPartData).m_LeftHand)
                {
                    pivot = cdata.m_Entity.transform;
                    //SingleHandSword
                    Transform go = cdata.m_Entity.transform.FindChild("SingleHandSword");//VCConfig.s_Parts[cdata.m_ComponentId].m_ResObj
                    go.gameObject.name = "SingleHandSwordL";
                    m_RootL.transform.localRotation = Quaternion.Inverse(pivot.rotation);
                    m_RootL.transform.Rotate(Vector3.up, -90, Space.World);
                    m_RootL.transform.Rotate(Vector3.right, 90, Space.World);
                    m_RootL.transform.Rotate(Vector3.up, 180, Space.World);
                    m_RootL.transform.Rotate(Vector3.forward, 180, Space.World);
                    m_RootL.transform.localPosition = -pivot.position;
                    cdcnt++;
                }

                if (cdata.m_Type == EVCComponent.cpDbSwordHilt && !(cdata as VCFixedHandPartData).m_LeftHand)
                {
                    pivot = cdata.m_Entity.transform;

                    Transform go = cdata.m_Entity.transform.FindChild("SingleHandSword");
                    go.gameObject.name = "SingleHandSwordR";


                    //m_Root.transform.localRotation = Quaternion.Inverse(pivot.rotation);
                    //m_Root.transform.Rotate(Vector3.up, -90, Space.World);
                    //m_Root.transform.Rotate(Vector3.right, 90, Space.World);
                    //m_Root.transform.localPosition = pivot.position;
                    m_Root.transform.localRotation = Quaternion.Inverse(pivot.rotation);
                    m_Root.transform.Rotate(Vector3.up, -90, Space.World);
                    m_Root.transform.Rotate(Vector3.right, 90, Space.World);
                    m_Root.transform.Rotate(Vector3.up, 180, Space.World);
                    m_Root.transform.Rotate(Vector3.forward, 180, Space.World);
                    m_Root.transform.localPosition = -pivot.position;
                    cdcnt++;
                }

                if (cdcnt == 2)
                {
                    break;
                }
            }
        }

        else if (m_Attribute.m_Type == ECreation.Bow)
        {
            Transform pivot = null;
            foreach (VCComponentData cdata in m_IsoData.m_Components)
            {
                if (cdata.m_Type == EVCComponent.cpBowGrip)
                {
                    pivot = cdata.m_Entity.transform;
                    break;
                }
            }

            AlignPivotInChild(m_Root.transform, pivot);
        }
        else if (m_Attribute.m_Type == ECreation.Axe)
        {
            Transform pivot = null;
            foreach (VCComponentData cdata in m_IsoData.m_Components)
            {
                if (cdata.m_Type == EVCComponent.cpAxeHilt)
                {
                    pivot = cdata.m_Entity.transform;
                    break;
                }
            }

            m_Root.transform.localRotation = Quaternion.Inverse(pivot.rotation);
            m_Root.transform.Rotate(Vector3.up, -90, Space.World);
            m_Root.transform.Rotate(Vector3.right, 90, Space.World);
            m_Root.transform.localPosition = -pivot.position;
        }
        else if (m_Attribute.m_Type == ECreation.Shield)
        {
            Transform pivot = null;
            foreach (VCComponentData cdata in m_IsoData.m_Components)
            {
                if (cdata.m_Type == EVCComponent.cpShieldHandle)
                {
                    pivot = cdata.m_Entity.GetComponent <VCPShieldHandle>().m_PivotPoint;
                    break;
                }
            }
            m_Root.transform.localRotation = Quaternion.Inverse(pivot.rotation);
            m_Root.transform.Rotate(Vector3.right, 90, Space.World);
            m_Root.transform.localPosition = -pivot.position;
        }
        else if (m_Attribute.m_Type == ECreation.HandGun || m_Attribute.m_Type == ECreation.Rifle)
        {
            Transform pivot = null;
            foreach (VCComponentData cdata in m_IsoData.m_Components)
            {
                if (cdata.m_Type == EVCComponent.cpGunHandle)
                {
                    pivot = cdata.m_Entity.GetComponent <VCPGunHandle>().m_FirstHandPoint;
                    break;
                }
            }
            m_Root.transform.localRotation = Quaternion.Inverse(pivot.rotation);
            m_Root.transform.Rotate(Vector3.up, -90, Space.World);
            m_Root.transform.Rotate(Vector3.right, 90, Space.World);
            m_Root.transform.localPosition = -pivot.position;
        }
        else if (m_Attribute.m_Type == ECreation.Vehicle)
        {
            Vector3 pivot     = m_Attribute.m_CenterOfMass;
            float   sum_y     = 0;
            int     wheel_cnt = 0;
            foreach (VCComponentData cdata in m_IsoData.m_Components)
            {
                if (cdata.m_Type == EVCComponent.cpVehicleWheel)
                {
                    sum_y += cdata.m_Entity.GetComponent <VCEComponentTool>().m_DrawPivot.position.y;
                    wheel_cnt++;
                }
            }
            pivot.y = sum_y / (float)wheel_cnt - 0.1f;
            m_Root.transform.localRotation = Quaternion.identity;
            m_Root.transform.localPosition = -pivot;
        }
        else if (m_Attribute.m_Type == ECreation.Aircraft)
        {
            Vector3 pivot = m_Attribute.m_CenterOfMass;
            pivot.y = 0;
            m_Root.transform.localRotation = Quaternion.identity;
            m_Root.transform.localPosition = -pivot;
        }
        else if (m_Attribute.m_Type == ECreation.Boat)
        {
            Vector3 pivot = m_Attribute.m_CenterOfMass;
            pivot.y = 0;
            m_Root.transform.localRotation = Quaternion.identity;
            m_Root.transform.localPosition = -pivot;
        }
        else if (m_Attribute.m_Type == ECreation.SimpleObject)
        {
            VCComponentData pivotCmpt = null;
            foreach (VCComponentData cdata in m_IsoData.m_Components)
            {
                if (cdata.m_Type == EVCComponent.cpPivot)
                {
                    pivotCmpt = cdata;
                    break;
                }
            }

            Vector3 pivot;
            if (pivotCmpt != null)
            {
                pivot = pivotCmpt.m_Position;
            }
            else
            {
                pivot = m_Attribute.m_CenterOfMass;
            }
            pivot.y = 0;
            m_Root.transform.localRotation = Quaternion.identity;
            m_Root.transform.localPosition = -pivot;
        }
        else if (m_Attribute.m_Type == ECreation.Robot)
        {
            Vector3 pivot = m_Attribute.m_CenterOfMass;
            pivot.y = 0;
            m_Root.transform.localRotation = Quaternion.identity;
            m_Root.transform.localPosition = -pivot;
        }
        else if (m_Attribute.m_Type == ECreation.AITurret)
        {
            Vector3 pivot = m_Attribute.m_CenterOfMass;
            pivot.y = 0;
            m_Root.transform.localRotation = Quaternion.identity;
            m_Root.transform.localPosition = -pivot;
        }
        else if (m_Attribute.m_Type == ECreation.ArmorHead ||
                 m_Attribute.m_Type == ECreation.ArmorBody ||
                 m_Attribute.m_Type == ECreation.ArmorArmAndLeg ||
                 m_Attribute.m_Type == ECreation.ArmorHandAndFoot ||
                 m_Attribute.m_Type == ECreation.ArmorDecoration
                 )
        {
            Vector3 pivot = m_Attribute.m_CenterOfMass;
            pivot.y = 0;
            m_Root.transform.localRotation = Quaternion.identity;
            m_Root.transform.localPosition = -pivot;
        }

        #endregion

        #region Top Script

        // [VCCase] - Create top scripts
        creationController         = m_Prefab.AddComponent <CreationController>();
        creationController.enabled = false;
        creationController.Init(
            m_PartGroup.transform,
            m_MeshGroup.transform,
            m_DecalGroup.transform,
            m_EffectGroup.transform,
            this);

        switch (m_Attribute.m_Type)
        {
        case ECreation.Sword:
        {
            PeSword      sword      = m_Prefab.AddComponent <PeSword>();
            VCPSwordHilt properties = FindComponent <VCPSwordHilt>(EVCComponent.cpSwordHilt);
            properties.CopyTo(sword, this);
            float weight = creationController.creationData.m_Attribute.m_Weight;
            sword.m_AnimSpeed = VCUtility.GetSwordAnimSpeed(weight);

            //set attacktrigger height
            if (properties.Attacktrigger != null)
            {
                for (int i = 0; i < properties.Attacktrigger.attackParts.Length; i++)
                {
                    properties.Attacktrigger.attackParts[i].capsule.heigh     = creationController.creationData.m_Attribute.m_AtkHeight.x;
                    properties.Attacktrigger.attackParts[i].capsule.offset.y -= creationController.creationData.m_Attribute.m_AtkHeight.z;
                }
            }
        }
        break;

        case ECreation.SwordLarge:
        {
            PeSword      sword      = m_Prefab.AddComponent <PeSword>();
            VCPSwordHilt properties = FindComponent <VCPSwordHilt>(EVCComponent.cpLgSwordHilt);
            properties.CopyTo(sword, this);
            float weight = creationController.creationData.m_Attribute.m_Weight;
            sword.m_AnimSpeed = VCUtility.GetSwordAnimSpeed(weight);

            //set attacktrigger height
            if (properties.Attacktrigger != null)
            {
                for (int i = 0; i < properties.Attacktrigger.attackParts.Length; i++)
                {
                    properties.Attacktrigger.attackParts[i].capsule.heigh     = creationController.creationData.m_Attribute.m_AtkHeight.x;
                    properties.Attacktrigger.attackParts[i].capsule.offset.y -= creationController.creationData.m_Attribute.m_AtkHeight.z;
                }
            }
        }
        break;

        case ECreation.SwordDouble:
        {
            PETwoHandWeapon sword      = m_Prefab.AddComponent <PETwoHandWeapon>();
            VCPSwordHilt    properties = FindComponent <VCPSwordHilt>(EVCComponent.cpDbSwordHilt);
            properties.CopyTo(sword, this);
            sword.m_LHandWeapon = m_RootL;
            float weight = creationController.creationData.m_Attribute.m_Weight;
            sword.m_AnimSpeed = VCUtility.GetSwordAnimSpeed(weight);

            //set attacktrigger height
            int cnt = 0;
            foreach (VCComponentData cdata in m_IsoData.m_Components)
            {
                if (cdata.m_Type == EVCComponent.cpDbSwordHilt && (cdata as VCFixedHandPartData).m_LeftHand && properties.Attacktrigger != null)
                {
                    cnt++;
                    VCPSwordHilt hiltL = cdata.m_Entity.GetComponent <VCPSwordHilt>();
                    if (hiltL == null)
                    {
                        continue;
                    }

                    for (int i = 0; i < properties.Attacktrigger.attackParts.Length; i++)
                    {
                        hiltL.Attacktrigger.attackParts[i].capsule.heigh     = creationController.creationData.m_Attribute.m_AtkHeight.x;
                        hiltL.Attacktrigger.attackParts[i].capsule.offset.y -= creationController.creationData.m_Attribute.m_AtkHeight.z;
                    }
                }

                if (cdata.m_Type == EVCComponent.cpDbSwordHilt && !(cdata as VCFixedHandPartData).m_LeftHand && properties.Attacktrigger != null)
                {
                    cnt++;
                    VCPSwordHilt hiltR = cdata.m_Entity.GetComponent <VCPSwordHilt>();
                    if (hiltR == null)
                    {
                        continue;
                    }

                    for (int i = 0; i < properties.Attacktrigger.attackParts.Length; i++)
                    {
                        hiltR.Attacktrigger.attackParts[i].capsule.heigh     = creationController.creationData.m_Attribute.m_AtkHeight.y;
                        hiltR.Attacktrigger.attackParts[i].capsule.offset.y -= creationController.creationData.m_Attribute.m_AtkHeight.w;
                    }
                }
                if (cnt == 2)
                {
                    break;
                }
            }
        }
        break;


        case ECreation.Bow:
        {
            PEBow      bow           = m_Prefab.AddComponent <PEBow>();
            VCPBowGrip bowProperties = FindComponent <VCPBowGrip>(EVCComponent.cpBowGrip);
            bowProperties.CopyTo(bow, this);
        }
        break;

        case ECreation.Axe:
        {
            PEAxe      axe           = m_Prefab.AddComponent <PEAxe>();
            VCPAxeHilt axeProperties = FindComponent <VCPAxeHilt>(EVCComponent.cpAxeHilt);
            axeProperties.CopyTo(axe, this);
            float weight = creationController.creationData.m_Attribute.m_Weight;
            axe.m_AnimSpeed = VCUtility.GetAxeAnimSpeed(weight);
        }
        break;

        case ECreation.Shield:
        {
            PESheild sheild = m_Prefab.AddComponent <PESheild>();
            sheild.showOnVehicle = false;
        }
        break;

        case ECreation.Rifle:
        case ECreation.HandGun:
        {
            PEGun        gun = m_Prefab.AddComponent <PEGun>();
            VCPGunHandle handleProperties = FindComponent <VCPGunHandle>(EVCComponent.cpGunHandle);
            VCPGunMuzzle muzzleProperties = FindComponent <VCPGunMuzzle>(EVCComponent.cpGunMuzzle);
            handleProperties.CopyTo(gun);
            muzzleProperties.CopyTo(gun);
        }
        break;

        case ECreation.Vehicle:
        {
            VCParticlePlayer pp = m_Prefab.AddComponent <VCParticlePlayer>();
            pp.FunctionTag   = VCParticlePlayer.ftExplode;
            pp.LocalPosition = creationController.bounds.center;
            break;
        }

        case ECreation.Aircraft:
        {
            VCParticlePlayer pp = m_Prefab.AddComponent <VCParticlePlayer>();
            pp.FunctionTag   = VCParticlePlayer.ftExplode;
            pp.LocalPosition = creationController.bounds.center;
            break;
        }

        case ECreation.Boat:
        {
            VCParticlePlayer pp = m_Prefab.AddComponent <VCParticlePlayer>();
            pp.FunctionTag   = VCParticlePlayer.ftExplode;
            pp.LocalPosition = creationController.bounds.center;
            break;
        }

        case ECreation.Robot:
        {
            VCParticlePlayer pp = m_Prefab.AddComponent <VCParticlePlayer>();
            pp.FunctionTag   = VCParticlePlayer.ftExplode;
            pp.LocalPosition = creationController.bounds.center;
            break;
        }

        case ECreation.AITurret:
        {
            VCParticlePlayer pp = m_Prefab.AddComponent <VCParticlePlayer>();
            pp.FunctionTag   = VCParticlePlayer.ftExplode;
            pp.LocalPosition = creationController.bounds.center;
            break;
        }

        case ECreation.SimpleObject:
            break;

        case ECreation.ArmorHead:
        case ECreation.ArmorBody:
        case ECreation.ArmorArmAndLeg:
        case ECreation.ArmorHandAndFoot:
        case ECreation.ArmorDecoration:
            break;

        default:
            break;
        }

        #endregion
    }