Пример #1
0
    // CREATION OF NEW BELT OBJECT
    private GameObject CreateBeltObject(int parentPoleID, BeltParams beltParams, ref PoleModification poleModif, GameObject parentPole, float localHeight)
    {
        // PREPARING OBJECTS AND PREFABS FOR CREATION
        GameObject beltPrefab       = null;
        GameObject unitPrefab       = null;
        GameObject projectilePrefab = null;
        GameObject newBelt;
        GameObject newUnit;
        Transform  parentPoleAssemblyTransf = null;

        // INIT OF PARENT POLE ASSEMBLY TRANSFORM AND INV SCALE
        foreach (Transform transf in parentPole.GetComponentInChildren <Transform>())
        {
            if (transf.tag == "PoleAssembly")
            {
                parentPoleAssemblyTransf = transf;
            }
        }
        Vector3 poleAssamblyScaleInv = new Vector3(1 / parentPoleAssemblyTransf.lossyScale.x, 1 / parentPoleAssemblyTransf.lossyScale.y, 1 / parentPoleAssemblyTransf.lossyScale.z);

        // PREPARING UNIT PARAMS AND CONNECTING THEM TO BELT PARAMS
        UnitParams newUnitParams = CreateUnitParams(beltParams.type, parentPoleID);

        beltParams.unitParams = newUnitParams;

        // PREPARING TMP PARAMS FOR CREATION
        Vector3    newBeltGlobalPos = parentPoleAssemblyTransf.TransformPoint(new Vector3(0, localHeight, 0));
        Vector3    newUnitGlobalPos;
        Vector3    newUnitLocalPosShift = new Vector3(0, 0, 0);
        Quaternion unitRotation         = parentPoleAssemblyTransf.rotation;

        // CHOOSING UNIT AND PROJECTILE PREFAB BASED ON BELT TYPE
        switch (beltParams.type)
        {
        case BeltType.gun:
            if (beltParams.side == BeltSide.left)
            {
                unitPrefab = gunLeftPrefub;
            }
            else
            {
                unitPrefab = gunRigthPrefub;
            }

            projectilePrefab = gunProjectilePrefub;
            break;

        case BeltType.machinegun:
            if (beltParams.side == BeltSide.left)
            {
                unitPrefab = machinegunLeftPrefub;
            }
            else
            {
                unitPrefab = machinegunRigthPrefub;
            }

            projectilePrefab = machinegunProjectilePrefub;
            break;

        case BeltType.rocket:
            if (beltParams.side == BeltSide.left)
            {
                unitPrefab = rocketLeftPrefub;
            }
            else
            {
                unitPrefab = rocketRigthPrefub;
            }

            projectilePrefab = rocketProjectilePrefub;
            break;

        case BeltType.plasma:
            break;

        case BeltType.grenadelauncher:
            break;

        case BeltType.railgun:
            break;

        case BeltType.missile:
            break;

        case BeltType.autotracking_lasers:
            break;

        case BeltType.shield:
            break;

        case BeltType.radar:
            break;

        default:
            break;
        }

        // CHOOSING BELT PREFAB, UNIT POSITION SHIFT AND BELT ROTATION AFTER CREATION
        switch (beltParams.side)
        {
        case BeltSide.left:
            beltPrefab           = beltLeftPrefab;
            newUnitLocalPosShift = new Vector3(-0.79f, 0, 0);
            break;

        case BeltSide.right:
            beltPrefab           = beltRightPrefab;
            newUnitLocalPosShift = new Vector3(0.79f, 0, 0);
            break;

        case BeltSide.front:
            beltPrefab           = beltFrontPrefab;
            newUnitLocalPosShift = new Vector3(0, 0, 0.79f);
            break;

        case BeltSide.back:
            beltPrefab           = beltBackPrefab;
            newUnitLocalPosShift = new Vector3(0, 0, -0.79f);
            break;
        }


        // CREATION OF NEW BELT GAMEOBJECT
        newBelt = Instantiate(beltPrefab, newBeltGlobalPos, parentPoleAssemblyTransf.rotation, parentPoleAssemblyTransf);
        newBelt.transform.localScale = poleAssamblyScaleInv;
        Vector3     newBeltScaleInv = new Vector3(1 / newBelt.transform.lossyScale.x, 1 / newBelt.transform.lossyScale.y, 1 / newBelt.transform.lossyScale.z);
        BeltControl newBeltControl  = newBelt.GetComponent <BeltControl>();

        // CREATION OF NEW UNIT GAMEOBJECT FOR CURRENT BELT
        newUnitGlobalPos             = newBelt.transform.TransformPoint(newUnitLocalPosShift);
        newUnit                      = Instantiate(unitPrefab, newUnitGlobalPos, unitRotation, newBelt.transform);
        newUnit.transform.localScale = newBeltScaleInv;

        //UnitControl newUnitControl = newUnit.GetComponent<UnitControl>();

        // TRANSFERRING BELT SCRIPT PARAMETERS
        newBeltControl.globalObjects    = globalObjects;
        newBeltControl.parentPole       = parentPole;
        newBeltControl.thisBeltUnit     = newUnit;
        newBeltControl.projectilePrefab = projectilePrefab;
        newBeltControl.poleModif        = poleModif;
        newBeltControl.beltParams       = beltParams;
        Transform[] tmpChildTransfs = newUnit.GetComponentsInChildren <Transform>();
        foreach (Transform child in tmpChildTransfs)
        {
            if (child.tag == "UnitDir")
            {
                newBeltControl.unitDirTransf = child;
                //newUnitControl.unitDirTransf = child;
            }
        }

        //newUnitControl.unitParams = newBeltControl.beltParams.unitParams;

        return(newBelt);
    }
Пример #2
0
    // ********************************************************************************************************
    // PARAMS CREATION ****************************************************************************************
    // ********************************************************************************************************


    // CREATION OF BELT PARAMS
    private BeltParams CreateBeltParams(BeltType beltType, BeltSide beltSide, int parentPoleID)
    {
        BeltParams beltParams = null;

        switch (beltType)
        {
        case BeltType.gun:
            beltParams = new BeltParams()
            {
                beltMaxSpin       = 1.5f,
                beltMinSpin       = 0.1F,
                beltSpinPrecision = 1f,
                unitMaxSpin       = 1.5f,
                unitSpinPrecision = 1f,
                unitMinAngle      = -30,
                unitMaxAngle      = 30,
            };
            break;

        case BeltType.machinegun:
            beltParams = new BeltParams()
            {
                beltMaxSpin       = 2f,
                beltMinSpin       = 0.1F,
                beltSpinPrecision = 0.1f,
                unitMaxSpin       = 2f,
                unitSpinPrecision = 0.1f,
                unitMinAngle      = -45,
                unitMaxAngle      = 45,
            };
            break;

        case BeltType.rocket:
            beltParams = new BeltParams()
            {
                beltMaxSpin       = 1f,
                beltMinSpin       = 0.1F,
                beltSpinPrecision = 3f,
                unitMaxSpin       = 1f,
                unitSpinPrecision = 3f,
                unitMinAngle      = -20,
                unitMaxAngle      = 20,
            };
            break;

        case BeltType.plasma:
            break;

        case BeltType.grenadelauncher:
            break;

        case BeltType.railgun:
            break;

        case BeltType.missile:
            break;

        case BeltType.autotracking_lasers:
            break;

        case BeltType.shield:
            break;

        case BeltType.radar:
            break;

        default:
            break;
        }

        beltParams.type = beltType;
        beltParams.side = beltSide;
        return(beltParams);
    }
Пример #3
0
    // ********************************************************************************************************
    // OBJECTS CREATION ***************************************************************************************
    // ********************************************************************************************************


    // CREATION OF NEW NORM POLE
    public GameObject CreateNormPole(int poleID, Vector3 startPoint, float startYRotation, BeltType[] beltTypes, PoleParams poleParams, PoleModification poleModif)
    {
        // CREATE THE NORM POLE
        GameObject  newNormPole          = Instantiate(poleNormPrefab, startPoint + new Vector3(0, 2.5f, 0), Quaternion.Euler(0, 0, 0));
        PoleControl newNormPoleControl   = newNormPole.GetComponent <PoleControl>();
        Vector3     newNormPoleScale     = newNormPole.transform.lossyScale;
        Vector3     newNormPoleScaleInv  = new Vector3(1 / newNormPoleScale.x, 1 / newNormPoleScale.y, 1 / newNormPoleScale.z);
        Vector3     newNormPoleAIMoveDir = Quaternion.Euler(0, startYRotation, 0) * newNormPole.transform.forward;

        // TRANSFERRING  GLOBAL OBJECTS, POLE PARAMS, MODIFICATION AND ASSEMBLY TO NEW POLE
        newNormPoleControl.globalObjects = globalObjects;
        newNormPoleControl.poleParams    = poleParams;
        newNormPoleControl.poleModif     = poleModif;
        newNormPoleControl.poleAssembly  = newNormPole.transform.GetChild(0).gameObject;
        newNormPoleControl.AIMoveDir     = newNormPoleAIMoveDir;

        // IF NEW POLE IS PLAYER - UPDATING GLOBAL PARAMS
        if (poleParams.type == PoleType.Player)
        {
            globalObjects.playerPole = newNormPole;
            playerPole = newNormPole;
            mainCamera.GetComponent <CameraControl>().focusObject = newNormPole;
        }

        // SENSOR CREATION
        GameObject newSensor = Instantiate(sensor1Prefab, startPoint + new Vector3(0, 4.5f, 0), newNormPole.transform.rotation, newNormPoleControl.poleAssembly.transform);

        newNormPoleControl.selfSensor  = newSensor;
        newSensor.transform.localScale = newNormPoleScaleInv;

        // CREATING TEXT
        Text newText = Instantiate <Text>(infoText);

        newText.transform.SetParent(mainCanvas.transform);
        newText.transform.position = mainCanvas.transform.TransformPoint((poleID + 1) * 200 - Screen.width / 2 + 10, Screen.height / 2 - 10, 0);

        // CREATING ENERGYBAR
        Image newEnergyBar = Instantiate <Image>(globalObjects.barPrefab);

        newEnergyBar.transform.SetParent(mainCanvas.transform);
        BarControl newEnergyBarControl = newEnergyBar.GetComponent <BarControl>();

        newEnergyBarControl.maxValue     = poleParams.poleMaxEnergy * poleModif.energyMaxCoef;
        newEnergyBarControl.currValue    = poleParams.poleMaxEnergy * poleModif.energyMaxCoef;
        newEnergyBarControl.transparency = poleParams.barTransparency;
        newEnergyBarControl.barHeight    = barHeight;

        // DEFINING COLORS AND TAG
        switch (poleParams.type)
        {
        case PoleType.Player:
            newEnergyBarControl.backGroundCol = new Color32(0, 10, 73, newEnergyBarControl.transparency);
            newEnergyBarControl.foreGroundCol = new Color32(70, 100, 230, newEnergyBarControl.transparency);
            newText.color   = new Color32(0, 230, 10, 255);
            newNormPole.tag = "PlayerTeam";
            break;

        case PoleType.Enemy:
            newEnergyBarControl.backGroundCol = new Color32(0, 10, 73, newEnergyBarControl.transparency);
            newEnergyBarControl.foreGroundCol = new Color32(70, 100, 230, newEnergyBarControl.transparency);
            newText.color   = new Color32(225, 0, 0, 255);
            newNormPole.tag = "EnemyTeam";
            break;

        case PoleType.NeutralStatic:
            newText.color   = new Color32(160, 160, 160, 255);
            newNormPole.tag = "NeutralTeam";
            break;

        case PoleType.NeutralMovable:
            newText.color   = new Color32(200, 200, 200, 255);
            newNormPole.tag = "NeutralTeam";
            break;
        }

        // CREATING BELTS
        if (beltTypes.Length > 4)
        {
            Array.Resize(ref beltTypes, 4);
        }

        GameObject[] belts = new GameObject[beltTypes.Length];
        if (beltTypes.Length > 0)
        {
            // INITIALIZING FIRST BELT PARAMS WITH UNIT PARAMS
            BeltParams[] newBeltsParams = new BeltParams[beltTypes.Length];

            for (int i = 0; i < beltTypes.Length; i++)
            {
                // DEFINITION OF BELT SIDE
                if (UnitGroups.frontUnits.Contains(beltTypes[i]))
                {
                    // FRONT-ORIENTED BELT
                    newBeltsParams[i] = CreateBeltParams(beltTypes[i], BeltSide.front, poleID);
                }
                else if (UnitGroups.backUnits.Contains(beltTypes[i]))
                {
                    // BACK-ORIENTED BELT
                    newBeltsParams[i] = CreateBeltParams(beltTypes[i], BeltSide.back, poleID);
                }
                else
                {
                    // SIDE-ORIENTED BELT
                    if ((i == 0) || (!UnitGroups.sideUnits.Contains(beltTypes[i - 1])))
                    {
                        // RANDOM SIDE DEFINITION
                        if (UnityEngine.Random.Range(0, 100) < 50)
                        {
                            // BELT IS RANDOMLY LEFT
                            newBeltsParams[i] = CreateBeltParams(beltTypes[i], BeltSide.left, poleID);
                        }
                        else
                        {
                            // BELT IS RANDOMLY RIGHT
                            newBeltsParams[i] = CreateBeltParams(beltTypes[i], BeltSide.right, poleID);
                        }
                    }
                    else
                    {
                        // DEFINING OTHER DIRECTION THEN IN PREVIOUS BELT
                        if (newBeltsParams[i - 1].side == BeltSide.left)
                        {
                            newBeltsParams[i] = CreateBeltParams(beltTypes[i], BeltSide.right, poleID);
                        }
                        else
                        {
                            newBeltsParams[i] = CreateBeltParams(beltTypes[i], BeltSide.left, poleID);
                        }
                    }
                }

                // CREATING BELT OBJECT
                belts[i] = CreateBeltObject(poleID, newBeltsParams[i], ref poleModif, newNormPole, 0.55f - i * 0.1f);
            }
        }

        // TRANSFERRING BELTS, SENSOR, TEXT AND HEALTHBAR TO THE NEW POLE OBJECT
        if (beltTypes.Length > 0)
        {
            Array.Resize(ref newNormPoleControl.belts, belts.Length);
            Array.Resize(ref newNormPoleControl.beltTypes, beltTypes.Length);
            belts.CopyTo(newNormPoleControl.belts, 0);
            beltTypes.CopyTo(newNormPoleControl.beltTypes, 0);
        }
        newNormPoleControl.poleSensor = newSensor;
        newNormPoleControl.lifeText   = newText;
        newNormPoleControl.energyBar  = newEnergyBar;

        return(newNormPole);
    }