public void GetRiverPrefab()
    {
        RiverObject obj = (RiverObject)AssetDatabase.LoadAssetAtPath <RiverObject>("Assets/Resources/RiverBuilds/" + uniqName + ".asset");

        if (obj == null)
        {
            Debug.Log("Did not find river with this name.!");
            return;
        }

        vertices.Clear();

        uvs.Clear();
        tris.Clear();
        nodes.Clear();
        for (int i = 0; i < obj.vertices.Length; i++)
        {
            vertices.Add(obj.vertices[i]);
        }
        for (int i = 0; i < obj.uvs.Length; i++)
        {
            uvs.Add(obj.uvs[i]);
        }
        for (int i = 0; i < obj.tris.Length; i++)
        {
            tris.Add(obj.tris[i]);
        }
        for (int i = 0; i < obj.nodes.Length; i++)
        {
            nodes.Add(obj.nodes[i]);
        }
        lenght = obj.lenght;
    }
    public void BuildRiverPrefab()
    {
        if (AssetDatabase.LoadAssetAtPath("Assets/Resources/RiverBuilds/" + uniqName + ".asset", typeof(RiverObject)) != null)
        {
            Debug.Log("River With Name" + uniqName + " Exist! No Option We Auto Overrides.");

            RiverObject obj = (RiverObject)AssetDatabase.LoadAssetAtPath <RiverObject>("Assets/Resources/RiverBuilds/" + uniqName + ".asset");
            obj.vertices = vertices.ToArray();
            obj.tris     = tris.ToArray();
            obj.uvs      = uvs.ToArray();
            obj.nodes    = nodes.ToArray();
            obj.lenght   = lenght;

            AssetDatabase.SaveAssets();
            return;
        }

        RiverObject river = ScriptableObject.CreateInstance <RiverObject>();

        river.name = uniqName;

        river.vertices = vertices.ToArray();
        river.tris     = tris.ToArray();
        river.uvs      = uvs.ToArray();
        river.nodes    = nodes.ToArray();
        river.lenght   = lenght;

        AssetDatabase.CreateAsset(river, "Assets/Resources/RiverBuilds/" + river.name + ".asset");
        AssetDatabase.SaveAssets();
    }
    private void GenerateQuad(RiverObject river, int index, ref List <Vector3> vertices, ref List <int> triangles, ref List <Vector2> uvs, bool fliped)
    {
        int vertCount = vertices.Count;

        vertices.Add(river.vertices[index + 0]);
        vertices.Add(river.vertices[index + 2]);
        vertices.Add(river.vertices[index + 0] + new Vector3(0, quadHeight, 0));
        vertices.Add(river.vertices[index + 2] + new Vector3(0, quadHeight, 0));

        uvs.Add(new Vector2(0, 0));
        uvs.Add(new Vector2(1, 0));
        uvs.Add(new Vector2(0, 1));
        uvs.Add(new Vector2(1, 1));

        if (fliped)
        {
            triangles.Add(vertCount + 0);
            triangles.Add(vertCount + 1);
            triangles.Add(vertCount + 2);
            triangles.Add(vertCount + 1);
            triangles.Add(vertCount + 3);
            triangles.Add(vertCount + 2);
        }
        else
        {
            triangles.Add(vertCount + 2);
            triangles.Add(vertCount + 1);
            triangles.Add(vertCount + 0);
            triangles.Add(vertCount + 2);
            triangles.Add(vertCount + 3);
            triangles.Add(vertCount + 1);
        }
    }
    public void GenerateWalls(RiverObject river)
    {
        Debug.Log("Generate");
        mesh      = new Mesh();
        mesh.name = "GeneratedRiverWall";

        List <Vector3> vertices  = new List <Vector3>();
        List <int>     triangles = new List <int>();
        List <Vector2> uvs       = new List <Vector2>();

        for (int i = 0; i < river.vertices.Length - 2; i += 2)
        {
            GenerateQuad(river, i, ref vertices, ref triangles, ref uvs, false);
        }

        for (int i = 1; i < river.vertices.Length - 2; i += 2)
        {
            GenerateQuad(river, i, ref vertices, ref triangles, ref uvs, true);
        }

        mesh.vertices  = vertices.ToArray();
        mesh.triangles = triangles.ToArray();
        mesh.uv        = uvs.ToArray();
        mesh.RecalculateNormals();

        AddComponentsToRenderGeneratedMesh(mesh);
    }
    void Start()
    {
        RiverObject river = null;

        if (gameObject.GetComponent <RiverController>())
        {
            river = gameObject.GetComponent <RiverController>().riverAsset;
        }

        if (river != null)
        {
            GenerateWalls(river);
        }
    }
        /// <summary>
        /// Container Class for all the properties for organization.
        /// </summary>
        /// <param name="c"></param>
        public TorqueScriptTemplate(ref dnTorque c)
            {
            m_ts = c;
            _mConsoleobject = new ConsoleObject(ref c);
            _mMathobject = new tMath(ref c);
            	_mUtil = new UtilObject(ref c);
	_mHTTPObject = new HTTPObjectObject(ref c);
	_mTCPObject = new TCPObjectObject(ref c);
	_mDynamicConsoleMethodComponent = new DynamicConsoleMethodComponentObject(ref c);
	_mSimComponent = new SimComponentObject(ref c);
	_mArrayObject = new ArrayObjectObject(ref c);
	_mConsoleLogger = new ConsoleLoggerObject(ref c);
	_mFieldBrushObject = new FieldBrushObjectObject(ref c);
	_mPersistenceManager = new PersistenceManagerObject(ref c);
	_mSimDataBlock = new SimDataBlockObject(ref c);
	_mSimObject = new SimObjectObject(ref c);
	_mSimPersistSet = new SimPersistSetObject(ref c);
	_mSimSet = new SimSetObject(ref c);
	_mSimXMLDocument = new SimXMLDocumentObject(ref c);
	_mFileObject = new FileObjectObject(ref c);
	_mFileStreamObject = new FileStreamObjectObject(ref c);
	_mStreamObject = new StreamObjectObject(ref c);
	_mZipObject = new ZipObjectObject(ref c);
	_mDecalRoad = new DecalRoadObject(ref c);
	_mMeshRoad = new MeshRoadObject(ref c);
	_mRiver = new RiverObject(ref c);
	_mScatterSky = new ScatterSkyObject(ref c);
	_mSkyBox = new SkyBoxObject(ref c);
	_mSun = new SunObject(ref c);
	_mGuiRoadEditorCtrl = new GuiRoadEditorCtrlObject(ref c);
	_mForest = new ForestObject(ref c);
	_mForestWindEmitter = new ForestWindEmitterObject(ref c);
	_mForestBrush = new ForestBrushObject(ref c);
	_mForestBrushTool = new ForestBrushToolObject(ref c);
	_mForestEditorCtrl = new ForestEditorCtrlObject(ref c);
	_mForestSelectionTool = new ForestSelectionToolObject(ref c);
	_mCubemapData = new CubemapDataObject(ref c);
	_mDebugDrawer = new DebugDrawerObject(ref c);
	_mGuiTSCtrl = new GuiTSCtrlObject(ref c);
	_mGuiBitmapButtonCtrl = new GuiBitmapButtonCtrlObject(ref c);
	_mGuiButtonBaseCtrl = new GuiButtonBaseCtrlObject(ref c);
	_mGuiCheckBoxCtrl = new GuiCheckBoxCtrlObject(ref c);
	_mGuiIconButtonCtrl = new GuiIconButtonCtrlObject(ref c);
	_mGuiSwatchButtonCtrl = new GuiSwatchButtonCtrlObject(ref c);
	_mGuiToolboxButtonCtrl = new GuiToolboxButtonCtrlObject(ref c);
	_mGuiAutoScrollCtrl = new GuiAutoScrollCtrlObject(ref c);
	_mGuiDynamicCtrlArrayControl = new GuiDynamicCtrlArrayControlObject(ref c);
	_mGuiFormCtrl = new GuiFormCtrlObject(ref c);
	_mGuiFrameSetCtrl = new GuiFrameSetCtrlObject(ref c);
	_mGuiPaneControl = new GuiPaneControlObject(ref c);
	_mGuiRolloutCtrl = new GuiRolloutCtrlObject(ref c);
	_mGuiScrollCtrl = new GuiScrollCtrlObject(ref c);
	_mGuiStackControl = new GuiStackControlObject(ref c);
	_mGuiTabBookCtrl = new GuiTabBookCtrlObject(ref c);
	_mGuiBitmapCtrl = new GuiBitmapCtrlObject(ref c);
	_mGuiColorPickerCtrl = new GuiColorPickerCtrlObject(ref c);
	_mGuiDirectoryFileListCtrl = new GuiDirectoryFileListCtrlObject(ref c);
	_mGuiFileTreeCtrl = new GuiFileTreeCtrlObject(ref c);
	_mGuiGameListMenuCtrl = new GuiGameListMenuCtrlObject(ref c);
	_mGuiGameListOptionsCtrl = new GuiGameListOptionsCtrlObject(ref c);
	_mGuiGradientCtrl = new GuiGradientCtrlObject(ref c);
	_mGuiListBoxCtrl = new GuiListBoxCtrlObject(ref c);
	_mGuiMaterialCtrl = new GuiMaterialCtrlObject(ref c);
	_mGuiMLTextCtrl = new GuiMLTextCtrlObject(ref c);
	_mGuiPopUpMenuCtrl = new GuiPopUpMenuCtrlObject(ref c);
	_mGuiPopUpMenuCtrlEx = new GuiPopUpMenuCtrlExObject(ref c);
	_mGuiSliderCtrl = new GuiSliderCtrlObject(ref c);
	_mGuiTabPageCtrl = new GuiTabPageCtrlObject(ref c);
	_mGuiTextCtrl = new GuiTextCtrlObject(ref c);
	_mGuiTextEditCtrl = new GuiTextEditCtrlObject(ref c);
	_mGuiTextListCtrl = new GuiTextListCtrlObject(ref c);
	_mGuiTreeViewCtrl = new GuiTreeViewCtrlObject(ref c);
	_mGuiCanvas = new GuiCanvasObject(ref c);
	_mGuiControl = new GuiControlObject(ref c);
	_mGuiControlProfile = new GuiControlProfileObject(ref c);
	_mDbgFileView = new DbgFileViewObject(ref c);
	_mGuiEditCtrl = new GuiEditCtrlObject(ref c);
	_mGuiFilterCtrl = new GuiFilterCtrlObject(ref c);
	_mGuiGraphCtrl = new GuiGraphCtrlObject(ref c);
	_mGuiImageList = new GuiImageListObject(ref c);
	_mGuiInspector = new GuiInspectorObject(ref c);
	_mGuiInspectorTypeFileName = new GuiInspectorTypeFileNameObject(ref c);
	_mGuiInspectorTypeBitMask32 = new GuiInspectorTypeBitMask32Object(ref c);
	_mGuiMenuBar = new GuiMenuBarObject(ref c);
	_mGuiParticleGraphCtrl = new GuiParticleGraphCtrlObject(ref c);
	_mGuiShapeEdPreview = new GuiShapeEdPreviewObject(ref c);
	_mGuiInspectorDynamicField = new GuiInspectorDynamicFieldObject(ref c);
	_mGuiInspectorDynamicGroup = new GuiInspectorDynamicGroupObject(ref c);
	_mGuiInspectorField = new GuiInspectorFieldObject(ref c);
	_mGuiVariableInspector = new GuiVariableInspectorObject(ref c);
	_mGuiMessageVectorCtrl = new GuiMessageVectorCtrlObject(ref c);
	_mGuiProgressBitmapCtrl = new GuiProgressBitmapCtrlObject(ref c);
	_mGuiTickCtrl = new GuiTickCtrlObject(ref c);
	_mGuiTheoraCtrl = new GuiTheoraCtrlObject(ref c);
	_mMessageVector = new MessageVectorObject(ref c);
	_mEditTSCtrl = new EditTSCtrlObject(ref c);
	_mGuiMissionAreaCtrl = new GuiMissionAreaCtrlObject(ref c);
	_mMECreateUndoAction = new MECreateUndoActionObject(ref c);
	_mMEDeleteUndoAction = new MEDeleteUndoActionObject(ref c);
	_mWorldEditor = new WorldEditorObject(ref c);
	_mLangTable = new LangTableObject(ref c);
	_mPathedInterior = new PathedInteriorObject(ref c);
	_mMaterial = new MaterialObject(ref c);
	_mSimResponseCurve = new SimResponseCurveObject(ref c);
	_mMenuBar = new MenuBarObject(ref c);
	_mPopupMenu = new PopupMenuObject(ref c);
	_mFileDialog = new FileDialogObject(ref c);
	_mPostEffect = new PostEffectObject(ref c);
	_mRenderBinManager = new RenderBinManagerObject(ref c);
	_mRenderPassManager = new RenderPassManagerObject(ref c);
	_mRenderPassStateToken = new RenderPassStateTokenObject(ref c);
	_mSceneObject = new SceneObjectObject(ref c);
	_mSFXController = new SFXControllerObject(ref c);
	_mSFXParameter = new SFXParameterObject(ref c);
	_mSFXProfile = new SFXProfileObject(ref c);
	_mSFXSource = new SFXSourceObject(ref c);
	_mActionMap = new ActionMapObject(ref c);
	_mNetConnection = new NetConnectionObject(ref c);
	_mNetObject = new NetObjectObject(ref c);
	_mAIClient = new AIClientObject(ref c);
	_mAIConnection = new AIConnectionObject(ref c);
	_mAIPlayer = new AIPlayerObject(ref c);
	_mCamera = new CameraObject(ref c);
	_mDebris = new DebrisObject(ref c);
	_mGroundPlane = new GroundPlaneObject(ref c);
	_mGuiMaterialPreview = new GuiMaterialPreviewObject(ref c);
	_mGuiObjectView = new GuiObjectViewObject(ref c);
	_mItem = new ItemObject(ref c);
	_mLightBase = new LightBaseObject(ref c);
	_mLightDescription = new LightDescriptionObject(ref c);
	_mLightFlareData = new LightFlareDataObject(ref c);
	_mMissionArea = new MissionAreaObject(ref c);
	_mSpawnSphere = new SpawnSphereObject(ref c);
	_mPathCamera = new PathCameraObject(ref c);
	_mPhysicalZone = new PhysicalZoneObject(ref c);
	_mPlayer = new PlayerObject(ref c);
	_mPortal = new PortalObject(ref c);
	_mProjectile = new ProjectileObject(ref c);
	_mProximityMine = new ProximityMineObject(ref c);
	_mShapeBaseData = new ShapeBaseDataObject(ref c);
	_mShapeBase = new ShapeBaseObject(ref c);
	_mStaticShape = new StaticShapeObject(ref c);
	_mTrigger = new TriggerObject(ref c);
	_mTSStatic = new TSStaticObject(ref c);
	_mZone = new ZoneObject(ref c);
	_mRenderMeshExample = new RenderMeshExampleObject(ref c);
	_mLightning = new LightningObject(ref c);
	_mParticleData = new ParticleDataObject(ref c);
	_mParticleEmitterData = new ParticleEmitterDataObject(ref c);
	_mParticleEmitterNode = new ParticleEmitterNodeObject(ref c);
	_mPrecipitation = new PrecipitationObject(ref c);
	_mGameBase = new GameBaseObject(ref c);
	_mGameConnection = new GameConnectionObject(ref c);
	_mPhysicsDebrisData = new PhysicsDebrisDataObject(ref c);
	_mPhysicsForce = new PhysicsForceObject(ref c);
	_mPhysicsShape = new PhysicsShapeObject(ref c);
	_mAITurretShape = new AITurretShapeObject(ref c);
	_mTurretShape = new TurretShapeObject(ref c);
	_mFlyingVehicle = new FlyingVehicleObject(ref c);
	_mWheeledVehicle = new WheeledVehicleObject(ref c);
	_mTerrainBlock = new TerrainBlockObject(ref c);
	_mSettings = new SettingsObject(ref c);
	_mCompoundUndoAction = new CompoundUndoActionObject(ref c);
	_mUndoManager = new UndoManagerObject(ref c);
	_mUndoAction = new UndoActionObject(ref c);
	_mEventManager = new EventManagerObject(ref c);
	_mMessage = new MessageObject(ref c);
}