Exemple #1
0
    // DESTRACTION OF POLE
    public void Destruction()
    {
        gameObject.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.None;

        /*Light tmpLight = gameObject.GetComponentInChildren<Light>();
         * if (tmpLight != null)
         *  Destroy(tmpLight.gameObject);*/
        gameObject.transform.Rotate((float)UnityEngine.Random.Range(-5, 5), 0, (float)UnityEngine.Random.Range(-5, 5));
        poleAssemblyTransform.parent = null;

        energyBar.transform.position = new Vector3(-10000, 10000, 0);
        energyBar.enabled            = false;
        Destroy(energyBar);

        List <Transform> childsToEmbody  = new List <Transform>();
        List <Transform> childsToDestroy = new List <Transform>();

        // GETTING ALL POLE ASSEMBLY CHILDS INTO TWO GROUPS
        for (int i = 0; i < poleAssemblyTransform.childCount; i++)
        {
            if (poleAssemblyTransform.GetChild(i).tag != "Light")
            {
                childsToEmbody.Add(poleAssemblyTransform.GetChild(i));
            }
            else
            {
                childsToDestroy.Add(poleAssemblyTransform.GetChild(i));
            }
        }

        // GIVING POLE ASSEMBLY CHILD TRANSFORM FREEDOM, RIGIDBODY AND MAKING THEIR COLLIDERS NON-TRIGGER
        foreach (Transform child in childsToEmbody)
        {
            child.parent = null;
            //child.gameObject.AddComponent<Rigidbody>();
            child.gameObject.GetComponent <Rigidbody>().isKinematic = false;
            child.gameObject.GetComponent <Collider>().isTrigger    = false;
            BeltControl tmpBeltControl = child.GetComponent <BeltControl>();
            if (tmpBeltControl != null)
            {
                tmpBeltControl.enabled = false;
            }
        }

        // DESTOYING OTHER CHILDREN
        foreach (Transform child in childsToDestroy)
        {
            Destroy(child.gameObject);
        }

        if (poleParams.type == PoleType.Player)
        {
            globalObjects.mainCamera.GetComponent <CameraControl>().focusObject = null;
        }

        gameObject.GetComponent <PoleControl>().enabled = false;
        Destroy(gameObject);
    }
Exemple #2
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);
    }